ad571dbdf6924bebee3e7bd9f9fc1b3b8bccb72b
[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 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 rcText = rc;
983 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 InflateRect(&rcText, -GetSystemMetrics(SM_CXEDGE), 0);
1011 if (dwStyle & TBSTYLE_LIST)
1012 {
1013 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
1014 }
1015 else
1016 {
1017 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
1018 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
1019 else
1020 rcText.top += infoPtr->szPadding.cy/2 + 2;
1021 }
1022 }
1023
1024 /* Initialize fields in all cases, because we use these later
1025 * NOTE: applications can and do alter these to customize their
1026 * toolbars */
1027 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1028 tbcd.clrText = comctl32_color.clrBtnText;
1029 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
1030 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
1031 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
1032 tbcd.clrMark = comctl32_color.clrHighlight;
1033 tbcd.clrHighlightHotTrack = 0;
1034 tbcd.nStringBkMode = TRANSPARENT;
1035 tbcd.nHLStringBkMode = OPAQUE;
1036 tbcd.rcText.left = 0;
1037 tbcd.rcText.top = 0;
1038 tbcd.rcText.right = rcText.right - rc.left;
1039 tbcd.rcText.bottom = rcText.bottom - rc.top;
1040 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
1041 tbcd.nmcd.hdc = hdc;
1042 tbcd.nmcd.rc = btnPtr->rect;
1043 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
1044
1045 /* FIXME: what are these used for? */
1046 tbcd.hbrLines = 0;
1047 tbcd.hpenLines = 0;
1048
1049 /* Issue Item Prepaint notify */
1050 dwItemCustDraw = 0;
1051 dwItemCDFlag = 0;
1052 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
1053 {
1054 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
1055 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
1056 tbcd.nmcd.lItemlParam = btnPtr->dwData;
1057 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1058 /* reset these fields so the user can't alter the behaviour like native */
1059 tbcd.nmcd.hdc = hdc;
1060 tbcd.nmcd.rc = btnPtr->rect;
1061
1062 dwItemCustDraw = ntfret & 0xffff;
1063 dwItemCDFlag = ntfret & 0xffff0000;
1064 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
1065 return;
1066 /* save the only part of the rect that the user can change */
1067 rcText.right = tbcd.rcText.right + rc.left;
1068 rcText.bottom = tbcd.rcText.bottom + rc.top;
1069 }
1070
1071 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
1072 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
1073 OffsetRect(&rcText, 1, 1);
1074
1075 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
1076 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
1077 TOOLBAR_DrawPattern (&rc, &tbcd);
1078
1079 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
1080 && (tbcd.nmcd.uItemState & CDIS_HOT))
1081 {
1082 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
1083 {
1084 COLORREF oldclr;
1085
1086 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
1087 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
1088 if (hasDropDownArrow)
1089 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
1090 SetBkColor(hdc, oldclr);
1091 }
1092 }
1093
1094 #ifdef __REACTOS__
1095 if (theme && !(dwItemCDFlag & TBCDRF_NOBACKGROUND))
1096 #else
1097 if (theme)
1098 #endif
1099 {
1100 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
1101 int stateId = TS_NORMAL;
1102
1103 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1104 stateId = TS_DISABLED;
1105 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1106 stateId = TS_PRESSED;
1107 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1108 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1109 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1110 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1111 stateId = TS_HOT;
1112
1113 DrawThemeBackground (theme, hdc, partId, stateId, &rc, NULL);
1114 }
1115
1116 #ifdef __REACTOS__
1117 if (!theme)
1118 #else
1119 else
1120 #endif
1121 TOOLBAR_DrawFrame(infoPtr, &tbcd, &rc, dwItemCDFlag);
1122
1123 if (drawSepDropDownArrow)
1124 {
1125 if (theme)
1126 {
1127 int stateId = TS_NORMAL;
1128
1129 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1130 stateId = TS_DISABLED;
1131 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1132 stateId = TS_PRESSED;
1133 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1134 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1135 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1136 stateId = TS_HOT;
1137
1138 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1139 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1140 }
1141 else
1142 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1143 }
1144
1145 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1146 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1147 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1148 SetBkMode (hdc, oldBkMode);
1149
1150 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1151
1152 if (hasDropDownArrow && !drawSepDropDownArrow)
1153 {
1154 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1155 {
1156 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1157 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1158 }
1159 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1160 {
1161 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1162 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1163 }
1164 else
1165 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1166 }
1167
1168 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1169 {
1170 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1171 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1172 }
1173
1174 }
1175
1176
1177 static void
1178 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1179 {
1180 TBUTTON_INFO *btnPtr;
1181 INT i;
1182 RECT rcTemp, rcClient;
1183 NMTBCUSTOMDRAW tbcd;
1184 DWORD ntfret;
1185 DWORD dwBaseCustDraw;
1186
1187 /* the app has told us not to redraw the toolbar */
1188 if (!infoPtr->bDoRedraw)
1189 return;
1190
1191 /* if imagelist belongs to the app, it can be changed
1192 by the app after setting it */
1193 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1194 {
1195 infoPtr->nNumBitmaps = 0;
1196 for (i = 0; i < infoPtr->cimlDef; i++)
1197 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1198 }
1199
1200 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1201
1202 /* change the imagelist icon size if we manage the list and it is necessary */
1203 TOOLBAR_CheckImageListIconSize(infoPtr);
1204
1205 /* Send initial notify */
1206 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1207 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1208 tbcd.nmcd.hdc = hdc;
1209 tbcd.nmcd.rc = ps->rcPaint;
1210 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1211 dwBaseCustDraw = ntfret & 0xffff;
1212
1213 GetClientRect(infoPtr->hwndSelf, &rcClient);
1214
1215 /* redraw necessary buttons */
1216 btnPtr = infoPtr->buttons;
1217 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1218 {
1219 BOOL bDraw;
1220 if (!RectVisible(hdc, &btnPtr->rect))
1221 continue;
1222 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1223 {
1224 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1225 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1226 }
1227 else
1228 bDraw = TRUE;
1229 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1230 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1231 if (bDraw)
1232 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1233 }
1234
1235 /* draw insert mark if required */
1236 if (infoPtr->tbim.iButton != -1)
1237 {
1238 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1239 RECT rcInsertMark;
1240 rcInsertMark.top = rcButton.top;
1241 rcInsertMark.bottom = rcButton.bottom;
1242 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1243 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1244 else
1245 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1246 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1247 }
1248
1249 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1250 {
1251 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1252 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1253 tbcd.nmcd.hdc = hdc;
1254 tbcd.nmcd.rc = ps->rcPaint;
1255 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1256 }
1257 }
1258
1259 /***********************************************************************
1260 * TOOLBAR_MeasureString
1261 *
1262 * This function gets the width and height of a string in pixels. This
1263 * is done first by using GetTextExtentPoint to get the basic width
1264 * and height. The DrawText is called with DT_CALCRECT to get the exact
1265 * width. The reason is because the text may have more than one "&" (or
1266 * prefix characters as M$ likes to call them). The prefix character
1267 * indicates where the underline goes, except for the string "&&" which
1268 * is reduced to a single "&". GetTextExtentPoint does not process these
1269 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1270 */
1271 static void
1272 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1273 HDC hdc, LPSIZE lpSize)
1274 {
1275 RECT myrect;
1276
1277 lpSize->cx = 0;
1278 lpSize->cy = 0;
1279
1280 if (infoPtr->nMaxTextRows > 0 &&
1281 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1282 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1283 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1284 {
1285 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1286
1287 if(lpText != NULL) {
1288 /* first get size of all the text */
1289 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1290
1291 /* feed above size into the rectangle for DrawText */
1292 SetRect(&myrect, 0, 0, lpSize->cx, lpSize->cy);
1293
1294 /* Use DrawText to get true size as drawn (less pesky "&") */
1295 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1296 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1297 DT_NOPREFIX : 0));
1298
1299 /* feed back to caller */
1300 lpSize->cx = myrect.right;
1301 lpSize->cy = myrect.bottom;
1302 }
1303 }
1304
1305 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1306 }
1307
1308 /***********************************************************************
1309 * TOOLBAR_CalcStrings
1310 *
1311 * This function walks through each string and measures it and returns
1312 * the largest height and width to caller.
1313 */
1314 static void
1315 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1316 {
1317 TBUTTON_INFO *btnPtr;
1318 INT i;
1319 SIZE sz;
1320 HDC hdc;
1321 HFONT hOldFont;
1322
1323 lpSize->cx = 0;
1324 lpSize->cy = 0;
1325
1326 if (infoPtr->nMaxTextRows == 0)
1327 return;
1328
1329 hdc = GetDC (infoPtr->hwndSelf);
1330 hOldFont = SelectObject (hdc, infoPtr->hFont);
1331
1332 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1333 {
1334 TEXTMETRICW tm;
1335
1336 GetTextMetricsW(hdc, &tm);
1337 lpSize->cy = tm.tmHeight;
1338 }
1339
1340 btnPtr = infoPtr->buttons;
1341 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1342 if(TOOLBAR_GetText(infoPtr, btnPtr))
1343 {
1344 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1345 if (sz.cx > lpSize->cx)
1346 lpSize->cx = sz.cx;
1347 if (sz.cy > lpSize->cy)
1348 lpSize->cy = sz.cy;
1349 }
1350 }
1351
1352 SelectObject (hdc, hOldFont);
1353 ReleaseDC (infoPtr->hwndSelf, hdc);
1354
1355 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1356 }
1357
1358 /***********************************************************************
1359 * TOOLBAR_WrapToolbar
1360 *
1361 * This function walks through the buttons and separators in the
1362 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1363 * wrapping should occur based on the width of the toolbar window.
1364 * It does *not* calculate button placement itself. That task
1365 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1366 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1367 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1368 *
1369 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1370 * vertical toolbar lists.
1371 */
1372
1373 static void
1374 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1375 {
1376 TBUTTON_INFO *btnPtr;
1377 INT x, cx, i, j, width;
1378 BOOL bButtonWrap;
1379
1380 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1381 /* no layout is necessary. Applications may use this style */
1382 /* to perform their own layout on the toolbar. */
1383 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1384 !(infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL) ) return;
1385
1386 btnPtr = infoPtr->buttons;
1387 x = infoPtr->nIndent;
1388 width = infoPtr->client_rect.right - infoPtr->client_rect.left;
1389
1390 bButtonWrap = FALSE;
1391
1392 TRACE("start ButtonWidth=%d, BitmapWidth=%d, width=%d, nIndent=%d\n",
1393 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, width,
1394 infoPtr->nIndent);
1395
1396 for (i = 0; i < infoPtr->nNumButtons; i++ )
1397 {
1398 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1399
1400 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1401 continue;
1402
1403 if (btnPtr[i].cx > 0)
1404 cx = btnPtr[i].cx;
1405 /* horizontal separators are treated as buttons for width */
1406 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1407 !(infoPtr->dwStyle & CCS_VERT))
1408 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1409 else
1410 cx = infoPtr->nButtonWidth;
1411
1412 if (!btnPtr[i].cx && button_has_ddarrow( infoPtr, btnPtr + i ))
1413 cx += DDARROW_WIDTH;
1414
1415 /* Two or more adjacent separators form a separator group. */
1416 /* The first separator in a group should be wrapped to the */
1417 /* next row if the previous wrapping is on a button. */
1418 if( bButtonWrap &&
1419 (btnPtr[i].fsStyle & BTNS_SEP) &&
1420 (i + 1 < infoPtr->nNumButtons ) &&
1421 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1422 {
1423 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1424 btnPtr[i].fsState |= TBSTATE_WRAP;
1425 x = infoPtr->nIndent;
1426 i++;
1427 bButtonWrap = FALSE;
1428 continue;
1429 }
1430
1431 /* The layout makes sure the bitmap is visible, but not the button. */
1432 /* Test added to also wrap after a button that starts a row but */
1433 /* is bigger than the area. - GA 8/01 */
1434 if ((x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2 > width) ||
1435 ((x == infoPtr->nIndent) && (cx > width)))
1436 {
1437 BOOL bFound = FALSE;
1438
1439 /* If the current button is a separator and not hidden, */
1440 /* go to the next until it reaches a non separator. */
1441 /* Wrap the last separator if it is before a button. */
1442 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1443 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1444 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1445 i < infoPtr->nNumButtons )
1446 {
1447 i++;
1448 bFound = TRUE;
1449 }
1450
1451 if( bFound && i < infoPtr->nNumButtons )
1452 {
1453 i--;
1454 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1455 i, btnPtr[i].fsStyle, x, cx);
1456 btnPtr[i].fsState |= TBSTATE_WRAP;
1457 x = infoPtr->nIndent;
1458 bButtonWrap = FALSE;
1459 continue;
1460 }
1461 else if ( i >= infoPtr->nNumButtons)
1462 break;
1463
1464 /* If the current button is not a separator, find the last */
1465 /* separator and wrap it. */
1466 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1467 {
1468 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1469 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1470 {
1471 bFound = TRUE;
1472 i = j;
1473 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1474 i, btnPtr[i].fsStyle, x, cx);
1475 x = infoPtr->nIndent;
1476 btnPtr[j].fsState |= TBSTATE_WRAP;
1477 bButtonWrap = FALSE;
1478 break;
1479 }
1480 }
1481
1482 /* If no separator available for wrapping, wrap one of */
1483 /* non-hidden previous button. */
1484 if (!bFound)
1485 {
1486 for ( j = i - 1;
1487 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1488 {
1489 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1490 continue;
1491
1492 bFound = TRUE;
1493 i = j;
1494 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1495 i, btnPtr[i].fsStyle, x, cx);
1496 x = infoPtr->nIndent;
1497 btnPtr[j].fsState |= TBSTATE_WRAP;
1498 bButtonWrap = TRUE;
1499 break;
1500 }
1501 }
1502
1503 /* If all above failed, wrap the current button. */
1504 if (!bFound)
1505 {
1506 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1507 i, btnPtr[i].fsStyle, x, cx);
1508 btnPtr[i].fsState |= TBSTATE_WRAP;
1509 x = infoPtr->nIndent;
1510 if (btnPtr[i].fsStyle & BTNS_SEP )
1511 bButtonWrap = FALSE;
1512 else
1513 bButtonWrap = TRUE;
1514 }
1515 }
1516 else {
1517 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1518 i, btnPtr[i].fsStyle, x, cx);
1519 x += cx;
1520 }
1521 }
1522 }
1523
1524
1525 /***********************************************************************
1526 * TOOLBAR_MeasureButton
1527 *
1528 * Calculates the width and height required for a button. Used in
1529 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1530 * the width of buttons that are autosized.
1531 *
1532 * Note that it would have been rather elegant to use one piece of code for
1533 * both the laying out of the toolbar and for controlling where button parts
1534 * are drawn, but the native control has inconsistencies between the two that
1535 * prevent this from being effectively. These inconsistencies can be seen as
1536 * artefacts where parts of the button appear outside of the bounding button
1537 * rectangle.
1538 *
1539 * There are several cases for the calculation of the button dimensions and
1540 * button part positioning:
1541 *
1542 * List
1543 * ====
1544 *
1545 * With Bitmap:
1546 *
1547 * +--------------------------------------------------------+ ^
1548 * | ^ ^ | |
1549 * | | pad.cy / 2 | centered | |
1550 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1551 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1552 * | |<------------>| | | | |
1553 * | +--------------+ +------------+ | |
1554 * |<-------------------------------------->| | |
1555 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1556 * | szText.cx | |
1557 * +--------------------------------------------------------+ -
1558 * <-------------------------------------------------------->
1559 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1560 *
1561 * Without Bitmap (I_IMAGENONE):
1562 *
1563 * +-----------------------------------+ ^
1564 * | ^ | |
1565 * | | centered | | LISTPAD_CY +
1566 * | +------------+ | | szText.cy
1567 * | | Text | | |
1568 * | | | | |
1569 * | +------------+ | |
1570 * |<----------------->| | |
1571 * | cxedge |<-----------> | |
1572 * | szText.cx | |
1573 * +-----------------------------------+ -
1574 * <----------------------------------->
1575 * szText.cx + pad.cx
1576 *
1577 * Without text:
1578 *
1579 * +--------------------------------------+ ^
1580 * | ^ | |
1581 * | | padding.cy/2 | | DEFPAD_CY +
1582 * | +------------+ | | nBitmapHeight
1583 * | | Bitmap | | |
1584 * | | | | |
1585 * | +------------+ | |
1586 * |<------------------->| | |
1587 * | cxedge + iListGap/2 |<-----------> | |
1588 * | nBitmapWidth | |
1589 * +--------------------------------------+ -
1590 * <-------------------------------------->
1591 * 2*cxedge + nBitmapWidth + iListGap
1592 *
1593 * Non-List
1594 * ========
1595 *
1596 * With bitmap:
1597 *
1598 * +-----------------------------------+ ^
1599 * | ^ | |
1600 * | | pad.cy / 2 | | nBitmapHeight +
1601 * | - | | szText.cy +
1602 * | +------------+ | | DEFPAD_CY + 1
1603 * | centered | Bitmap | | |
1604 * |<----------------->| | | |
1605 * | +------------+ | |
1606 * | ^ | |
1607 * | 1 | | |
1608 * | - | |
1609 * | centered +---------------+ | |
1610 * |<--------------->| Text | | |
1611 * | +---------------+ | |
1612 * +-----------------------------------+ -
1613 * <----------------------------------->
1614 * pad.cx + max(nBitmapWidth, szText.cx)
1615 *
1616 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1617 *
1618 * +---------------------------------------+ ^
1619 * | ^ | |
1620 * | | 2 + pad.cy / 2 | |
1621 * | - | | szText.cy +
1622 * | centered +-----------------+ | | pad.cy + 2
1623 * |<--------------->| Text | | |
1624 * | +-----------------+ | |
1625 * | | |
1626 * +---------------------------------------+ -
1627 * <--------------------------------------->
1628 * 2*cxedge + pad.cx + szText.cx
1629 *
1630 * Without text:
1631 * As for with bitmaps, but with szText.cx zero.
1632 */
1633 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1634 BOOL bHasBitmap, BOOL bValidImageList)
1635 {
1636 SIZE sizeButton;
1637 if (infoPtr->dwStyle & TBSTYLE_LIST)
1638 {
1639 /* set button height from bitmap / text height... */
1640 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1641 sizeString.cy);
1642
1643 /* ... add on the necessary padding */
1644 if (bValidImageList)
1645 {
1646 #ifdef __REACTOS__
1647 sizeButton.cy += infoPtr->szPadding.cy;
1648 if (!bHasBitmap)
1649 #else
1650 if (bHasBitmap)
1651 sizeButton.cy += DEFPAD_CY;
1652 else
1653 #endif
1654 sizeButton.cy += LISTPAD_CY;
1655 }
1656 else
1657 sizeButton.cy += infoPtr->szPadding.cy;
1658
1659 /* calculate button width */
1660 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1661 infoPtr->nBitmapWidth + infoPtr->iListGap;
1662 if (sizeString.cx > 0)
1663 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1664
1665 }
1666 else
1667 {
1668 if (bHasBitmap)
1669 {
1670 #ifdef __REACTOS__
1671 sizeButton.cy = infoPtr->nBitmapHeight + infoPtr->szPadding.cy;
1672 #else
1673 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1674 #endif
1675 if (sizeString.cy > 0)
1676 sizeButton.cy += 1 + sizeString.cy;
1677 sizeButton.cx = infoPtr->szPadding.cx +
1678 max(sizeString.cx, infoPtr->nBitmapWidth);
1679 }
1680 else
1681 {
1682 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1683 NONLIST_NOTEXT_OFFSET;
1684 sizeButton.cx = infoPtr->szPadding.cx +
1685 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1686 }
1687 }
1688 return sizeButton;
1689 }
1690
1691
1692 /***********************************************************************
1693 * TOOLBAR_CalcToolbar
1694 *
1695 * This function calculates button and separator placement. It first
1696 * calculates the button sizes, gets the toolbar window width and then
1697 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1698 * on. It assigns a new location to each item and sends this location to
1699 * the tooltip window if appropriate. Finally, it updates the rcBound
1700 * rect and calculates the new required toolbar window height.
1701 */
1702 static void
1703 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1704 {
1705 SIZE sizeString, sizeButton;
1706 BOOL validImageList = FALSE;
1707
1708 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1709
1710 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1711
1712 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1713 validImageList = TRUE;
1714 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1715 infoPtr->nButtonWidth = sizeButton.cx;
1716 infoPtr->nButtonHeight = sizeButton.cy;
1717 infoPtr->iTopMargin = default_top_margin(infoPtr);
1718
1719 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1720 infoPtr->nButtonWidth = infoPtr->cxMin;
1721 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1722 infoPtr->nButtonWidth = infoPtr->cxMax;
1723
1724 TOOLBAR_LayoutToolbar(infoPtr);
1725 }
1726
1727 static void
1728 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1729 {
1730 TBUTTON_INFO *btnPtr;
1731 SIZE sizeButton;
1732 INT i, nRows, nSepRows;
1733 INT x, y, cx, cy;
1734 BOOL bWrap;
1735 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1736
1737 TOOLBAR_WrapToolbar(infoPtr);
1738
1739 x = infoPtr->nIndent;
1740 y = infoPtr->iTopMargin;
1741 cx = infoPtr->nButtonWidth;
1742 cy = infoPtr->nButtonHeight;
1743
1744 nRows = nSepRows = 0;
1745
1746 infoPtr->rcBound.top = y;
1747 infoPtr->rcBound.left = x;
1748 infoPtr->rcBound.bottom = y + cy;
1749 infoPtr->rcBound.right = x;
1750
1751 btnPtr = infoPtr->buttons;
1752
1753 TRACE("cy=%d\n", cy);
1754
1755 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1756 {
1757 bWrap = FALSE;
1758 if (btnPtr->fsState & TBSTATE_HIDDEN)
1759 {
1760 SetRectEmpty (&btnPtr->rect);
1761 continue;
1762 }
1763
1764 cy = infoPtr->nButtonHeight;
1765
1766 if (btnPtr->fsStyle & BTNS_SEP) {
1767 if (infoPtr->dwStyle & CCS_VERT) {
1768 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1769 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nButtonWidth;
1770 }
1771 else
1772 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1773 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1774 }
1775 else
1776 {
1777 if (btnPtr->cx)
1778 cx = btnPtr->cx;
1779 #ifdef __REACTOS__
1780 /* Revert Wine Commit 5b7b911 as it breaks Explorer Toolbar Buttons
1781 FIXME: Revisit this when the bug is fixed. CORE-9970 */
1782 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1783 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1784 #else
1785 else if (btnPtr->fsStyle & BTNS_AUTOSIZE)
1786 #endif
1787 {
1788 SIZE sz;
1789 HDC hdc;
1790 HFONT hOldFont;
1791
1792 hdc = GetDC (infoPtr->hwndSelf);
1793 hOldFont = SelectObject (hdc, infoPtr->hFont);
1794
1795 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1796
1797 SelectObject (hdc, hOldFont);
1798 ReleaseDC (infoPtr->hwndSelf, hdc);
1799
1800 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1801 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1802 validImageList);
1803 cx = sizeButton.cx;
1804 }
1805 else
1806 cx = infoPtr->nButtonWidth;
1807
1808 /* if size has been set manually then don't add on extra space
1809 * for the drop down arrow */
1810 if (!btnPtr->cx && button_has_ddarrow( infoPtr, btnPtr ))
1811 cx += DDARROW_WIDTH;
1812 }
1813 if (btnPtr->fsState & TBSTATE_WRAP)
1814 bWrap = TRUE;
1815
1816 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1817
1818 if (infoPtr->rcBound.left > x)
1819 infoPtr->rcBound.left = x;
1820 if (infoPtr->rcBound.right < x + cx)
1821 infoPtr->rcBound.right = x + cx;
1822 if (infoPtr->rcBound.bottom < y + cy)
1823 infoPtr->rcBound.bottom = y + cy;
1824
1825 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1826
1827 /* btnPtr->nRow is zero based. The space between the rows is */
1828 /* also considered as a row. */
1829 btnPtr->nRow = nRows + nSepRows;
1830
1831 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1832 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1833 x, y, x+cx, y+cy);
1834
1835 if( bWrap )
1836 {
1837 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1838 y += cy;
1839 else
1840 {
1841 if ( !(infoPtr->dwStyle & CCS_VERT))
1842 y += cy + ( (btnPtr->cx > 0 ) ?
1843 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1844 else
1845 y += cy;
1846
1847 /* nSepRows is used to calculate the extra height following */
1848 /* the last row. */
1849 nSepRows++;
1850 }
1851 x = infoPtr->nIndent;
1852
1853 /* Increment row number unless this is the last button */
1854 /* and it has Wrap set. */
1855 if (i != infoPtr->nNumButtons-1)
1856 nRows++;
1857 }
1858 else
1859 x += cx;
1860 }
1861
1862 /* infoPtr->nRows is the number of rows on the toolbar */
1863 infoPtr->nRows = nRows + nSepRows + 1;
1864
1865 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1866 }
1867
1868
1869 static INT
1870 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
1871 {
1872 TBUTTON_INFO *btnPtr;
1873 INT i;
1874
1875 if (button)
1876 *button = FALSE;
1877
1878 btnPtr = infoPtr->buttons;
1879 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1880 if (btnPtr->fsState & TBSTATE_HIDDEN)
1881 continue;
1882
1883 if (btnPtr->fsStyle & BTNS_SEP) {
1884 if (PtInRect (&btnPtr->rect, *lpPt)) {
1885 TRACE(" ON SEPARATOR %d!\n", i);
1886 return -i;
1887 }
1888 }
1889 else {
1890 if (PtInRect (&btnPtr->rect, *lpPt)) {
1891 TRACE(" ON BUTTON %d!\n", i);
1892 if (button)
1893 *button = TRUE;
1894 return i;
1895 }
1896 }
1897 }
1898
1899 TRACE(" NOWHERE!\n");
1900 return TOOLBAR_NOWHERE;
1901 }
1902
1903
1904 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1905 static BOOL
1906 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1907 {
1908 INT nOldButtons, nNewButtons, iButton;
1909 BOOL fHasString = FALSE;
1910
1911 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1912 iIndex = infoPtr->nNumButtons;
1913
1914 nOldButtons = infoPtr->nNumButtons;
1915 nNewButtons = nOldButtons + nAddButtons;
1916
1917 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1918 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1919 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1920 infoPtr->nNumButtons += nAddButtons;
1921
1922 /* insert new buttons data */
1923 for (iButton = 0; iButton < nAddButtons; iButton++) {
1924 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1925 INT_PTR str;
1926
1927 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1928
1929 ZeroMemory(btnPtr, sizeof(*btnPtr));
1930
1931 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1932 btnPtr->idCommand = lpTbb[iButton].idCommand;
1933 btnPtr->fsState = lpTbb[iButton].fsState;
1934 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1935 btnPtr->dwData = lpTbb[iButton].dwData;
1936
1937 if (btnPtr->fsStyle & BTNS_SEP)
1938 str = -1;
1939 else
1940 str = lpTbb[iButton].iString;
1941 set_string_index( btnPtr, str, fUnicode );
1942 fHasString |= TOOLBAR_ButtonHasString( btnPtr );
1943
1944 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1945 }
1946
1947 if (infoPtr->nNumStrings > 0 || fHasString)
1948 TOOLBAR_CalcToolbar(infoPtr);
1949 else
1950 TOOLBAR_LayoutToolbar(infoPtr);
1951 TOOLBAR_AutoSize(infoPtr);
1952
1953 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1954 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1955 return TRUE;
1956 }
1957
1958
1959 static INT
1960 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1961 {
1962 TBUTTON_INFO *btnPtr;
1963 INT i;
1964
1965 if (CommandIsIndex) {
1966 TRACE("command is really index command=%d\n", idCommand);
1967 if (idCommand >= infoPtr->nNumButtons) return -1;
1968 return idCommand;
1969 }
1970 btnPtr = infoPtr->buttons;
1971 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1972 if (btnPtr->idCommand == idCommand) {
1973 TRACE("command=%d index=%d\n", idCommand, i);
1974 return i;
1975 }
1976 }
1977 TRACE("no index found for command=%d\n", idCommand);
1978 return -1;
1979 }
1980
1981
1982 static INT
1983 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1984 {
1985 TBUTTON_INFO *btnPtr;
1986 INT nRunIndex;
1987
1988 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1989 return -1;
1990
1991 /* check index button */
1992 btnPtr = &infoPtr->buttons[nIndex];
1993 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1994 if (btnPtr->fsState & TBSTATE_CHECKED)
1995 return nIndex;
1996 }
1997
1998 /* check previous buttons */
1999 nRunIndex = nIndex - 1;
2000 while (nRunIndex >= 0) {
2001 btnPtr = &infoPtr->buttons[nRunIndex];
2002 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2003 if (btnPtr->fsState & TBSTATE_CHECKED)
2004 return nRunIndex;
2005 }
2006 else
2007 break;
2008 nRunIndex--;
2009 }
2010
2011 /* check next buttons */
2012 nRunIndex = nIndex + 1;
2013 while (nRunIndex < infoPtr->nNumButtons) {
2014 btnPtr = &infoPtr->buttons[nRunIndex];
2015 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
2016 if (btnPtr->fsState & TBSTATE_CHECKED)
2017 return nRunIndex;
2018 }
2019 else
2020 break;
2021 nRunIndex++;
2022 }
2023
2024 return -1;
2025 }
2026
2027
2028 static VOID
2029 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
2030 WPARAM wParam, LPARAM lParam)
2031 {
2032 MSG msg;
2033
2034 msg.hwnd = hwndMsg;
2035 msg.message = uMsg;
2036 msg.wParam = wParam;
2037 msg.lParam = lParam;
2038 msg.time = GetMessageTime ();
2039 msg.pt.x = (short)LOWORD(GetMessagePos ());
2040 msg.pt.y = (short)HIWORD(GetMessagePos ());
2041
2042 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
2043 }
2044
2045 #ifdef __REACTOS__
2046 static LRESULT
2047 TOOLBAR_ThemeChanged(HWND hwnd)
2048 {
2049 HTHEME theme = GetWindowTheme(hwnd);
2050 CloseThemeData(theme);
2051 OpenThemeData(hwnd, themeClass);
2052 return 0;
2053 }
2054 #endif
2055
2056 static void
2057 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2058 {
2059 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
2060 TTTOOLINFOW ti;
2061
2062 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
2063 ti.cbSize = sizeof (TTTOOLINFOW);
2064 ti.hwnd = infoPtr->hwndSelf;
2065 ti.uId = button->idCommand;
2066 ti.hinst = 0;
2067 ti.lpszText = LPSTR_TEXTCALLBACKW;
2068 /* ti.lParam = random value from the stack? */
2069
2070 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
2071 0, (LPARAM)&ti);
2072 }
2073 }
2074
2075 static void
2076 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2077 {
2078 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
2079 TTTOOLINFOW ti;
2080
2081 ZeroMemory(&ti, sizeof(ti));
2082 ti.cbSize = sizeof(ti);
2083 ti.hwnd = infoPtr->hwndSelf;
2084 ti.uId = button->idCommand;
2085
2086 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
2087 }
2088 }
2089
2090 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
2091 {
2092 /* Set the toolTip only for non-hidden, non-separator button */
2093 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
2094 {
2095 TTTOOLINFOW ti;
2096
2097 ZeroMemory(&ti, sizeof(ti));
2098 ti.cbSize = sizeof(ti);
2099 ti.hwnd = infoPtr->hwndSelf;
2100 ti.uId = button->idCommand;
2101 ti.rect = button->rect;
2102 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
2103 }
2104 }
2105
2106 /* Creates the tooltip control */
2107 static void
2108 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
2109 {
2110 int i;
2111 NMTOOLTIPSCREATED nmttc;
2112
2113 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2114 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2115 infoPtr->hwndSelf, 0, 0, 0);
2116
2117 if (!infoPtr->hwndToolTip)
2118 return;
2119
2120 /* Send NM_TOOLTIPSCREATED notification */
2121 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2122 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2123
2124 for (i = 0; i < infoPtr->nNumButtons; i++)
2125 {
2126 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2127 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2128 }
2129 }
2130
2131 /* keeps available button list box sorted by button id */
2132 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2133 {
2134 int i;
2135 int count;
2136 PCUSTOMBUTTON btnInfo;
2137 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2138
2139 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2140
2141 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2142
2143 /* position 0 is always separator */
2144 for (i = 1; i < count; i++)
2145 {
2146 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2147 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2148 {
2149 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2150 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2151 return;
2152 }
2153 }
2154 /* id higher than all others add to end */
2155 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2156 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2157 }
2158
2159 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2160 {
2161 NMTOOLBARW nmtb;
2162
2163 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2164
2165 if (nIndexFrom == nIndexTo)
2166 return;
2167
2168 /* MSDN states that iItem is the index of the button, rather than the
2169 * command ID as used by every other NMTOOLBAR notification */
2170 nmtb.iItem = nIndexFrom;
2171 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2172 {
2173 PCUSTOMBUTTON btnInfo;
2174 NMHDR hdr;
2175 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2176 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2177
2178 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2179
2180 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2181 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2182 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2183 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2184
2185 if (nIndexTo <= 0)
2186 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2187 else
2188 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2189
2190 /* last item is always separator, so -2 instead of -1 */
2191 if (nIndexTo >= (count - 2))
2192 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2193 else
2194 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2195
2196 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2197 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2198
2199 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2200 }
2201 }
2202
2203 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2204 {
2205 NMTOOLBARW nmtb;
2206
2207 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2208
2209 /* MSDN states that iItem is the index of the button, rather than the
2210 * command ID as used by every other NMTOOLBAR notification */
2211 nmtb.iItem = nIndexAvail;
2212 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2213 {
2214 PCUSTOMBUTTON btnInfo;
2215 NMHDR hdr;
2216 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2217 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2218 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2219
2220 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2221
2222 if (nIndexAvail != 0) /* index == 0 indicates separator */
2223 {
2224 /* remove from 'available buttons' list */
2225 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2226 if (nIndexAvail == count-1)
2227 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2228 else
2229 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2230 }
2231 else
2232 {
2233 PCUSTOMBUTTON btnNew;
2234
2235 /* duplicate 'separator' button */
2236 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2237 *btnNew = *btnInfo;
2238 btnInfo = btnNew;
2239 }
2240
2241 /* insert into 'toolbar button' list */
2242 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2243 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2244
2245 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2246
2247 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2248 }
2249 }
2250
2251 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2252 {
2253 PCUSTOMBUTTON btnInfo;
2254 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2255
2256 TRACE("Remove: index %d\n", index);
2257
2258 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2259
2260 /* send TBN_QUERYDELETE notification */
2261 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2262 {
2263 NMHDR hdr;
2264
2265 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2266 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2267
2268 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2269
2270 /* insert into 'available button' list */
2271 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2272 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2273 else
2274 Free(btnInfo);
2275
2276 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2277 }
2278 }
2279
2280 /* drag list notification function for toolbar buttons list box */
2281 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2282 const DRAGLISTINFO *pDLI)
2283 {
2284 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2285 switch (pDLI->uNotification)
2286 {
2287 case DL_BEGINDRAG:
2288 {
2289 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2290 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2291 /* no dragging for last item (separator) */
2292 if (nCurrentItem >= (nCount - 1)) return FALSE;
2293 return TRUE;
2294 }
2295 case DL_DRAGGING:
2296 {
2297 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2298 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2299 /* no dragging past last item (separator) */
2300 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2301 {
2302 DrawInsert(hwnd, hwndList, nCurrentItem);
2303 /* FIXME: native uses "move button" cursor */
2304 return DL_COPYCURSOR;
2305 }
2306
2307 /* not over toolbar buttons list */
2308 if (nCurrentItem < 0)
2309 {
2310 POINT ptWindow = pDLI->ptCursor;
2311 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2312 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2313 /* over available buttons list? */
2314 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2315 /* FIXME: native uses "move button" cursor */
2316 return DL_COPYCURSOR;
2317 }
2318 /* clear drag arrow */
2319 DrawInsert(hwnd, hwndList, -1);
2320 return DL_STOPCURSOR;
2321 }
2322 case DL_DROPPED:
2323 {
2324 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2325 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2326 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2327 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2328 {
2329 /* clear drag arrow */
2330 DrawInsert(hwnd, hwndList, -1);
2331 /* move item */
2332 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2333 }
2334 /* not over toolbar buttons list */
2335 if (nIndexTo < 0)
2336 {
2337 POINT ptWindow = pDLI->ptCursor;
2338 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2339 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2340 /* over available buttons list? */
2341 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2342 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2343 }
2344 break;
2345 }
2346 case DL_CANCELDRAG:
2347 /* Clear drag arrow */
2348 DrawInsert(hwnd, hwndList, -1);
2349 break;
2350 }
2351
2352 return 0;
2353 }
2354
2355 /* drag list notification function for available buttons list box */
2356 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2357 const DRAGLISTINFO *pDLI)
2358 {
2359 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2360 switch (pDLI->uNotification)
2361 {
2362 case DL_BEGINDRAG:
2363 return TRUE;
2364 case DL_DRAGGING:
2365 {
2366 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2367 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2368 /* no dragging past last item (separator) */
2369 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2370 {
2371 DrawInsert(hwnd, hwndList, nCurrentItem);
2372 /* FIXME: native uses "move button" cursor */
2373 return DL_COPYCURSOR;
2374 }
2375
2376 /* not over toolbar buttons list */
2377 if (nCurrentItem < 0)
2378 {
2379 POINT ptWindow = pDLI->ptCursor;
2380 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2381 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2382 /* over available buttons list? */
2383 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2384 /* FIXME: native uses "move button" cursor */
2385 return DL_COPYCURSOR;
2386 }
2387 /* clear drag arrow */
2388 DrawInsert(hwnd, hwndList, -1);
2389 return DL_STOPCURSOR;
2390 }
2391 case DL_DROPPED:
2392 {
2393 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2394 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2395 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2396 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2397 {
2398 /* clear drag arrow */
2399 DrawInsert(hwnd, hwndList, -1);
2400 /* add item */
2401 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2402 }
2403 }
2404 case DL_CANCELDRAG:
2405 /* Clear drag arrow */
2406 DrawInsert(hwnd, hwndList, -1);
2407 break;
2408 }
2409 return 0;
2410 }
2411
2412 extern UINT uDragListMessage DECLSPEC_HIDDEN;
2413
2414 /***********************************************************************
2415 * TOOLBAR_CustomizeDialogProc
2416 * This function implements the toolbar customization dialog.
2417 */
2418 static INT_PTR CALLBACK
2419 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2420 {
2421 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2422 PCUSTOMBUTTON btnInfo;
2423 NMTOOLBARA nmtb;
2424 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2425
2426 switch (uMsg)
2427 {
2428 case WM_INITDIALOG:
2429 custInfo = (PCUSTDLG_INFO)lParam;
2430 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2431
2432 if (custInfo)
2433 {
2434 WCHAR Buffer[256];
2435 int i = 0;
2436 int index;
2437 NMTBINITCUSTOMIZE nmtbic;
2438
2439 infoPtr = custInfo->tbInfo;
2440
2441 /* send TBN_QUERYINSERT notification */
2442 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2443
2444 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2445 return FALSE;
2446
2447 nmtbic.hwndDialog = hwnd;
2448 /* Send TBN_INITCUSTOMIZE notification */
2449 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2450 TBNRF_HIDEHELP)
2451 {
2452 TRACE("TBNRF_HIDEHELP requested\n");
2453 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2454 }
2455
2456 /* add items to 'toolbar buttons' list and check if removable */
2457 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2458 {
2459 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2460 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2461 btnInfo->btn.fsStyle = BTNS_SEP;
2462 btnInfo->bVirtual = FALSE;
2463 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2464
2465 /* send TBN_QUERYDELETE notification */
2466 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2467
2468 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2469 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2470 }
2471
2472 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2473
2474 /* insert separator button into 'available buttons' list */
2475 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2476 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2477 btnInfo->btn.fsStyle = BTNS_SEP;
2478 btnInfo->bVirtual = FALSE;
2479 btnInfo->bRemovable = TRUE;
2480 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2481 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2482 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2483
2484 /* insert all buttons into dsa */
2485 for (i = 0;; i++)
2486 {
2487 /* send TBN_GETBUTTONINFO notification */
2488 NMTOOLBARW nmtb;
2489 nmtb.iItem = i;
2490 nmtb.pszText = Buffer;
2491 nmtb.cchText = 256;
2492
2493 /* Clear previous button's text */
2494 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2495
2496 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2497 break;
2498
2499 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2500 nmtb.tbButton.fsStyle, i,
2501 nmtb.tbButton.idCommand,
2502 nmtb.tbButton.iString,
2503 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2504 : "");
2505
2506 /* insert button into the appropriate list */
2507 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2508 if (index == -1)
2509 {
2510 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2511 btnInfo->bVirtual = FALSE;
2512 btnInfo->bRemovable = TRUE;
2513 }
2514 else
2515 {
2516 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2517 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2518 }
2519
2520 btnInfo->btn = nmtb.tbButton;
2521 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2522 {
2523 if (lstrlenW(nmtb.pszText))
2524 lstrcpyW(btnInfo->text, nmtb.pszText);
2525 else if (nmtb.tbButton.iString >= 0 &&
2526 nmtb.tbButton.iString < infoPtr->nNumStrings)
2527 {
2528 lstrcpyW(btnInfo->text,
2529 infoPtr->strings[nmtb.tbButton.iString]);
2530 }
2531 }
2532
2533 if (index == -1)
2534 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2535 }
2536
2537 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2538
2539 /* select first item in the 'available' list */
2540 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2541
2542 /* append 'virtual' separator button to the 'toolbar buttons' list */
2543 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2544 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2545 btnInfo->btn.fsStyle = BTNS_SEP;
2546 btnInfo->bVirtual = TRUE;
2547 btnInfo->bRemovable = FALSE;
2548 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2549 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2550 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2551
2552 /* select last item in the 'toolbar' list */
2553 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2554 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2555
2556 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2557 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2558
2559 /* set focus and disable buttons */
2560 PostMessageW (hwnd, WM_USER, 0, 0);
2561 }
2562 return TRUE;
2563
2564 case WM_USER:
2565 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2566 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2567 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2568 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2569 return TRUE;
2570
2571 case WM_CLOSE:
2572 EndDialog(hwnd, FALSE);
2573 return TRUE;
2574
2575 case WM_COMMAND:
2576 switch (LOWORD(wParam))
2577 {
2578 case IDC_TOOLBARBTN_LBOX:
2579 if (HIWORD(wParam) == LBN_SELCHANGE)
2580 {
2581 PCUSTOMBUTTON btnInfo;
2582 NMTOOLBARA nmtb;
2583 int count;
2584 int index;
2585
2586 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2587 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2588
2589 /* send TBN_QUERYINSERT notification */
2590 nmtb.iItem = index;
2591 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2592
2593 /* get list box item */
2594 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2595
2596 if (index == (count - 1))
2597 {
2598 /* last item (virtual separator) */
2599 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2600 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2601 }
2602 else if (index == (count - 2))
2603 {
2604 /* second last item (last non-virtual item) */
2605 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2606 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2607 }
2608 else if (index == 0)
2609 {
2610 /* first item */
2611 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2612 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2613 }
2614 else
2615 {
2616 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2617 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2618 }
2619
2620 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2621 }
2622 break;
2623
2624 case IDC_MOVEUP_BTN:
2625 {
2626 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2627 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2628 }
2629 break;
2630
2631 case IDC_MOVEDN_BTN: /* move down */
2632 {
2633 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2634 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2635 }
2636 break;
2637
2638 case IDC_REMOVE_BTN: /* remove button */
2639 {
2640 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2641
2642 if (LB_ERR == index)
2643 break;
2644
2645 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2646 }
2647 break;
2648 case IDC_HELP_BTN:
2649 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2650 break;
2651 case IDC_RESET_BTN:
2652 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2653 break;
2654
2655 case IDOK: /* Add button */
2656 {
2657 int index;
2658 int indexto;
2659
2660 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2661 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2662
2663 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2664 }
2665 break;
2666
2667 case IDCANCEL:
2668 EndDialog(hwnd, FALSE);
2669 break;
2670 }
2671 return TRUE;
2672
2673 case WM_DESTROY:
2674 {
2675 int count;
2676 int i;
2677
2678 /* delete items from 'toolbar buttons' listbox*/
2679 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2680 for (i = 0; i < count; i++)
2681 {
2682 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2683 Free(btnInfo);
2684 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2685 }
2686 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2687
2688
2689 /* delete items from 'available buttons' listbox*/
2690 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2691 for (i = 0; i < count; i++)
2692 {
2693 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2694 Free(btnInfo);
2695 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2696 }
2697 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2698 }
2699 return TRUE;
2700
2701 case WM_DRAWITEM:
2702 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2703 {
2704 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2705 RECT rcButton;
2706 RECT rcText;
2707 HPEN hPen, hOldPen;
2708 HBRUSH hOldBrush;
2709 COLORREF oldText = 0;
2710 COLORREF oldBk = 0;
2711
2712 /* get item data */
2713 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, lpdis->itemID, 0);
2714 if (btnInfo == NULL)
2715 {
2716 FIXME("btnInfo invalid!\n");
2717 return TRUE;
2718 }
2719
2720 /* set colors and select objects */
2721 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2722 if (btnInfo->bVirtual)
2723 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2724 else
2725 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2726 hPen = CreatePen( PS_SOLID, 1,
2727 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2728 hOldPen = SelectObject (lpdis->hDC, hPen );
2729 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2730
2731 /* fill background rectangle */
2732 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2733 lpdis->rcItem.right, lpdis->rcItem.bottom);
2734
2735 /* calculate button and text rectangles */
2736 rcButton = lpdis->rcItem;
2737 InflateRect (&rcButton, -1, -1);
2738 rcText = rcButton;
2739 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2740 rcText.left = rcButton.right + 2;
2741
2742 /* draw focus rectangle */
2743 if (lpdis->itemState & ODS_FOCUS)
2744 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2745
2746 /* draw button */
2747 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2748 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2749
2750 /* draw image and text */
2751 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2752 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2753 btnInfo->btn.iBitmap));
2754 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2755 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2756 }
2757 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2758 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2759
2760 /* delete objects and reset colors */
2761 SelectObject (lpdis->hDC, hOldBrush);
2762 SelectObject (lpdis->hDC, hOldPen);
2763 SetBkColor (lpdis->hDC, oldBk);
2764 SetTextColor (lpdis->hDC, oldText);
2765 DeleteObject( hPen );
2766 return TRUE;
2767 }
2768 return FALSE;
2769
2770 case WM_MEASUREITEM:
2771 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2772 {
2773 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2774
2775 lpmis->itemHeight = 15 + 8; /* default height */
2776
2777 return TRUE;
2778 }
2779 return FALSE;
2780
2781 default:
2782 if (uDragListMessage && (uMsg == uDragListMessage))
2783 {
2784 if (wParam == IDC_TOOLBARBTN_LBOX)
2785 {
2786 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2787 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2788 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2789 return TRUE;
2790 }
2791 else if (wParam == IDC_AVAILBTN_LBOX)
2792 {
2793 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2794 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2795 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2796 return TRUE;
2797 }
2798 }
2799 return FALSE;
2800 }
2801 }
2802
2803 static BOOL
2804 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2805 {
2806 HBITMAP hbmLoad;
2807 INT nCountBefore = ImageList_GetImageCount(himlDef);
2808 INT nCountAfter;
2809 INT cxIcon, cyIcon;
2810 INT nAdded;
2811 INT nIndex;
2812
2813 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2814 /* Add bitmaps to the default image list */
2815 if (bitmap->hInst == NULL) /* a handle was passed */
2816 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2817 else if (bitmap->hInst == COMCTL32_hModule)
2818 hbmLoad = LoadImageW( bitmap->hInst, MAKEINTRESOURCEW(bitmap->nID),
2819 IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
2820 else
2821 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2822
2823 /* enlarge the bitmap if needed */
2824 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2825 if (bitmap->hInst != COMCTL32_hModule)
2826 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2827
2828 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2829 DeleteObject(hbmLoad);
2830 if (nIndex == -1)
2831 return FALSE;
2832
2833 nCountAfter = ImageList_GetImageCount(himlDef);
2834 nAdded = nCountAfter - nCountBefore;
2835 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2836 {
2837 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2838 } else if (nAdded > (INT)bitmap->nButtons) {
2839 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2840 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2841 }
2842
2843 infoPtr->nNumBitmaps += nAdded;
2844 return TRUE;
2845 }
2846
2847 static void
2848 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2849 {
2850 HIMAGELIST himlDef;
2851 HIMAGELIST himlNew;
2852 INT cx, cy;
2853 INT i;
2854
2855 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2856 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2857 return;
2858 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2859 return;
2860 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2861 return;
2862
2863 TRACE("Update icon size: %dx%d -> %dx%d\n",
2864 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2865
2866 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2867 ILC_COLOR32|ILC_MASK, 8, 2);
2868 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2869 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2870 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2871 infoPtr->himlInt = himlNew;
2872
2873 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2874 ImageList_Destroy(himlDef);
2875 }
2876
2877 /***********************************************************************
2878 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2879 *
2880 */
2881 static LRESULT
2882 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2883 {
2884 TBITMAP_INFO info;
2885 INT iSumButtons, i;
2886 HIMAGELIST himlDef;
2887
2888 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2889 if (!lpAddBmp)
2890 return -1;
2891
2892 if (lpAddBmp->hInst == HINST_COMMCTRL)
2893 {
2894 info.hInst = COMCTL32_hModule;
2895 switch (lpAddBmp->nID)
2896 {
2897 case IDB_STD_SMALL_COLOR:
2898 info.nButtons = 15;
2899 info.nID = IDB_STD_SMALL;
2900 break;
2901 case IDB_STD_LARGE_COLOR:
2902 info.nButtons = 15;
2903 info.nID = IDB_STD_LARGE;
2904 break;
2905 case IDB_VIEW_SMALL_COLOR:
2906 info.nButtons = 12;
2907 info.nID = IDB_VIEW_SMALL;
2908 break;
2909 case IDB_VIEW_LARGE_COLOR:
2910 info.nButtons = 12;
2911 info.nID = IDB_VIEW_LARGE;
2912 break;
2913 case IDB_HIST_SMALL_COLOR:
2914 info.nButtons = 5;
2915 info.nID = IDB_HIST_SMALL;
2916 break;
2917 case IDB_HIST_LARGE_COLOR:
2918 info.nButtons = 5;
2919 info.nID = IDB_HIST_LARGE;
2920 break;
2921 default:
2922 return -1;
2923 }
2924
2925 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2926
2927 /* Windows resize all the buttons to the size of a newly added standard image */
2928 if (lpAddBmp->nID & 1)
2929 {
2930 /* large icons: 24x24. Will make the button 31x30 */
2931 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2932 }
2933 else
2934 {
2935 /* small icons: 16x16. Will make the buttons 23x22 */
2936 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2937 }
2938
2939 TOOLBAR_CalcToolbar (infoPtr);
2940 }
2941 else
2942 {
2943 info.nButtons = count;
2944 info.hInst = lpAddBmp->hInst;
2945 info.nID = lpAddBmp->nID;
2946 TRACE("adding %d bitmaps!\n", info.nButtons);
2947 }
2948
2949 /* check if the bitmap is already loaded and compute iSumButtons */
2950 iSumButtons = 0;
2951 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2952 {
2953 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2954 infoPtr->bitmaps[i].nID == info.nID)
2955 return iSumButtons;
2956 iSumButtons += infoPtr->bitmaps[i].nButtons;
2957 }
2958
2959 if (!infoPtr->cimlDef) {
2960 /* create new default image list */
2961 TRACE ("creating default image list!\n");
2962
2963 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2964 ILC_COLOR32 | ILC_MASK, info.nButtons, 2);
2965 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2966 infoPtr->himlInt = himlDef;
2967 }
2968 else {
2969 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2970 }
2971
2972 if (!himlDef) {
2973 WARN("No default image list available\n");
2974 return -1;
2975 }
2976
2977 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2978 return -1;
2979
2980 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2981 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2982 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2983 infoPtr->nNumBitmapInfos++;
2984 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2985
2986 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2987 return iSumButtons;
2988 }
2989
2990
2991 static LRESULT
2992 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
2993 {
2994 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
2995
2996 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2997 }
2998
2999
3000 static LRESULT
3001 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
3002 {
3003 #define MAX_RESOURCE_STRING_LENGTH 512
3004 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3005 INT nIndex = infoPtr->nNumStrings;
3006
3007 TRACE("%p, %lx\n", hInstance, lParam);
3008
3009 if (IS_INTRESOURCE(lParam)) {
3010 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
3011 WCHAR delimiter;
3012 WCHAR *next_delim;
3013 HRSRC hrsrc;
3014 WCHAR *p;
3015 INT len;
3016
3017 TRACE("adding string from resource\n");
3018
3019 if (!hInstance) return -1;
3020
3021 hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
3022 (LPWSTR)RT_STRING );
3023 if (!hrsrc)
3024 {
3025 TRACE("string not found in resources\n");
3026 return -1;
3027 }
3028
3029 len = LoadStringW (hInstance, (UINT)lParam,
3030 szString, MAX_RESOURCE_STRING_LENGTH);
3031
3032 TRACE("len=%d %s\n", len, debugstr_w(szString));
3033 if (len == 0 || len == 1)
3034 return nIndex;
3035
3036 TRACE("delimiter: 0x%x\n", *szString);
3037 delimiter = *szString;
3038 p = szString + 1;
3039
3040 while ((next_delim = strchrW(p, delimiter)) != NULL) {
3041 *next_delim = 0;
3042 if (next_delim + 1 >= szString + len)
3043 {
3044 /* this may happen if delimiter == '\0' or if the last char is a
3045 * delimiter (then it is ignored like the native does) */
3046 break;
3047 }
3048
3049 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3050 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
3051 infoPtr->nNumStrings++;
3052
3053 p = next_delim + 1;
3054 }
3055 }
3056 else {
3057 LPWSTR p = (LPWSTR)lParam;
3058 INT len;
3059
3060 if (p == NULL)
3061 return -1;
3062 TRACE("adding string(s) from array\n");
3063 while (*p) {
3064 len = strlenW (p);
3065
3066 TRACE("len=%d %s\n", len, debugstr_w(p));
3067 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3068 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
3069 infoPtr->nNumStrings++;
3070
3071 p += (len+1);
3072 }
3073 }
3074
3075 if (fFirstString)
3076 TOOLBAR_CalcToolbar(infoPtr);
3077 return nIndex;
3078 }
3079
3080
3081 static LRESULT
3082 TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
3083 {
3084 BOOL fFirstString = (infoPtr->nNumStrings == 0);
3085 LPSTR p;
3086 INT nIndex;
3087 INT len;
3088
3089 TRACE("%p, %lx\n", hInstance, lParam);
3090
3091 if (IS_INTRESOURCE(lParam)) /* load from resources */
3092 return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
3093
3094 p = (LPSTR)lParam;
3095 if (p == NULL)
3096 return -1;
3097
3098 TRACE("adding string(s) from array\n");
3099 nIndex = infoPtr->nNumStrings;
3100 while (*p) {
3101 len = strlen (p);
3102 TRACE("len=%d \"%s\"\n", len, p);
3103
3104 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
3105 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
3106 infoPtr->nNumStrings++;
3107
3108 p += (len+1);
3109 }
3110
3111 if (fFirstString)
3112 TOOLBAR_CalcToolbar(infoPtr);
3113 return nIndex;
3114 }
3115
3116
3117 static LRESULT
3118 TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
3119 {
3120 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3121 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3122
3123 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3124 {
3125 RECT window_rect, parent_rect;
3126 UINT uPosFlags = SWP_NOZORDER | SWP_NOACTIVATE;
3127 HWND parent;
3128 INT x, y, cx, cy;
3129
3130 parent = GetParent (infoPtr->hwndSelf);
3131
3132 if (!parent || !infoPtr->bDoRedraw)
3133 return 0;
3134
3135 GetClientRect(parent, &parent_rect);
3136
3137 x = parent_rect.left;
3138 y = parent_rect.top;
3139
3140 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3141 cx = parent_rect.right - parent_rect.left;
3142
3143 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3144 {
3145 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3146 MapWindowPoints( 0, parent, (POINT *)&window_rect, 2 );
3147 y = window_rect.top;
3148 }
3149 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3150 {
3151 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3152 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3153 }
3154
3155 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3156 uPosFlags |= SWP_NOMOVE;
3157
3158 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3159 cy += GetSystemMetrics(SM_CYEDGE);
3160
3161 if (infoPtr->dwStyle & WS_BORDER)
3162 {
3163 cx += 2 * GetSystemMetrics(SM_CXBORDER);
3164 cy += 2 * GetSystemMetrics(SM_CYBORDER);
3165 }
3166
3167 SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
3168 }
3169
3170 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL))
3171 {
3172 TOOLBAR_LayoutToolbar(infoPtr);
3173 InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
3174 }
3175
3176 return 0;
3177 }
3178
3179
3180 static inline LRESULT
3181 TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
3182 {
3183 return infoPtr->nNumButtons;
3184 }
3185
3186
3187 static inline LRESULT
3188 TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
3189 {
3190 infoPtr->dwStructSize = Size;
3191
3192 return 0;
3193 }
3194
3195
3196 static LRESULT
3197 TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
3198 {
3199 TBUTTON_INFO *btnPtr;
3200 INT nIndex;
3201
3202 TRACE("button %d, iBitmap now %d\n", Id, Index);
3203
3204 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3205 if (nIndex == -1)
3206 return FALSE;
3207
3208 btnPtr = &infoPtr->buttons[nIndex];
3209 btnPtr->iBitmap = Index;
3210
3211 /* we HAVE to erase the background, the new bitmap could be */
3212 /* transparent */
3213 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3214
3215 return TRUE;
3216 }
3217
3218
3219 static LRESULT
3220 TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3221 {
3222 TBUTTON_INFO *btnPtr;
3223 INT nIndex;
3224 INT nOldIndex = -1;
3225 BOOL bChecked = FALSE;
3226
3227 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3228
3229 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
3230
3231 if (nIndex == -1)
3232 return FALSE;
3233
3234 btnPtr = &infoPtr->buttons[nIndex];
3235
3236 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) != 0;
3237
3238 if (!LOWORD(lParam))
3239 btnPtr->fsState &= ~TBSTATE_CHECKED;
3240 else {
3241 if (btnPtr->fsStyle & BTNS_GROUP) {
3242 nOldIndex =
3243 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3244 if (nOldIndex == nIndex)
3245 return 0;
3246 if (nOldIndex != -1)
3247 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3248 }
3249 btnPtr->fsState |= TBSTATE_CHECKED;
3250 }
3251
3252 if( bChecked != LOWORD(lParam) )
3253 {
3254 if (nOldIndex != -1)
3255 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
3256 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3257 }
3258
3259 /* FIXME: Send a WM_NOTIFY?? */
3260
3261 return TRUE;
3262 }
3263
3264
3265 static LRESULT
3266 TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
3267 {
3268 return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3269 }
3270
3271
3272 static LRESULT
3273 TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
3274 {
3275 CUSTDLG_INFO custInfo;
3276 LRESULT ret;
3277 NMHDR nmhdr;
3278
3279 custInfo.tbInfo = infoPtr;
3280 custInfo.tbHwnd = infoPtr->hwndSelf;
3281
3282 /* send TBN_BEGINADJUST notification */
3283 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3284
3285 ret = DialogBoxParamW (COMCTL32_hModule, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3286 infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc, (LPARAM)&custInfo);
3287
3288 /* send TBN_ENDADJUST notification */
3289 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3290
3291 return ret;
3292 }
3293
3294
3295 static LRESULT
3296 TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
3297 {
3298 NMTOOLBARW nmtb;
3299 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3300
3301 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3302 return FALSE;
3303
3304 memset(&nmtb, 0, sizeof(nmtb));
3305 nmtb.iItem = btnPtr->idCommand;
3306 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3307 nmtb.tbButton.idCommand = btnPtr->idCommand;
3308 nmtb.tbButton.fsState = btnPtr->fsState;
3309 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3310 nmtb.tbButton.dwData = btnPtr->dwData;
3311 nmtb.tbButton.iString = btnPtr->iString;
3312 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3313
3314 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3315
3316 if (infoPtr->nNumButtons == 1) {
3317 TRACE(" simple delete!\n");
3318 free_string( infoPtr->buttons );
3319 Free (infoPtr->buttons);
3320 infoPtr->buttons = NULL;
3321 infoPtr->nNumButtons = 0;
3322 }
3323 else {
3324 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3325 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3326
3327 infoPtr->nNumButtons--;
3328 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3329 if (nIndex > 0) {
3330 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3331 nIndex * sizeof(TBUTTON_INFO));
3332 }
3333
3334 if (nIndex < infoPtr->nNumButtons) {
3335 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3336 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3337 }
3338
3339 free_string( oldButtons + nIndex );
3340 Free (oldButtons);
3341 }
3342
3343 TOOLBAR_LayoutToolbar(infoPtr);
3344
3345 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3346
3347 return TRUE;
3348 }
3349
3350
3351 static LRESULT
3352 TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3353 {
3354 TBUTTON_INFO *btnPtr;
3355 INT nIndex;
3356 DWORD bState;
3357
3358 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3359
3360 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
3361
3362 if (nIndex == -1)
3363 return FALSE;
3364
3365 btnPtr = &infoPtr->buttons[nIndex];
3366
3367 bState = btnPtr->fsState & TBSTATE_ENABLED;
3368
3369 /* update the toolbar button state */
3370 if(!LOWORD(lParam)) {
3371 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3372 } else {
3373 btnPtr->fsState |= TBSTATE_ENABLED;
3374 }
3375
3376 /* redraw the button only if the state of the button changed */
3377 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3378 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3379
3380 return TRUE;
3381 }
3382
3383
3384 static inline LRESULT
3385 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
3386 {
3387 return infoPtr->bAnchor;
3388 }
3389
3390
3391 static LRESULT
3392 TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
3393 {
3394 INT nIndex;
3395
3396 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3397 if (nIndex == -1)
3398 return -1;
3399
3400 return infoPtr->buttons[nIndex].iBitmap;
3401 }
3402
3403
3404 static inline LRESULT
3405 TOOLBAR_GetBitmapFlags (void)
3406 {
3407 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3408 }
3409
3410
3411 static LRESULT
3412 TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
3413 {
3414 TBUTTON_INFO *btnPtr;
3415
3416 if (lpTbb == NULL)
3417 return FALSE;
3418
3419 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3420 return FALSE;
3421
3422 btnPtr = &infoPtr->buttons[nIndex];
3423 lpTbb->iBitmap = btnPtr->iBitmap;
3424 lpTbb->idCommand = btnPtr->idCommand;
3425 lpTbb->fsState = btnPtr->fsState;
3426 lpTbb->fsStyle = btnPtr->fsStyle;
3427 lpTbb->bReserved[0] = 0;
3428 lpTbb->bReserved[1] = 0;
3429 lpTbb->dwData = btnPtr->dwData;
3430 lpTbb->iString = btnPtr->iString;
3431
3432 return TRUE;
3433 }
3434
3435
3436 static LRESULT
3437 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
3438 {
3439 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3440 TBUTTON_INFO *btnPtr;
3441 INT nIndex;
3442
3443 if (lpTbInfo == NULL)
3444 return -1;
3445
3446 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3447 * the headers and tests shows that even with comctl 6 Vista accepts only the
3448 * original TBBUTTONINFO size
3449 */
3450 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3451 {
3452 WARN("Invalid button size\n");
3453 return -1;
3454 }
3455
3456 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
3457 if (nIndex == -1)
3458 return -1;
3459
3460 btnPtr = &infoPtr->buttons[nIndex];
3461 if (lpTbInfo->dwMask & TBIF_COMMAND)
3462 lpTbInfo->idCommand = btnPtr->idCommand;
3463 if (lpTbInfo->dwMask & TBIF_IMAGE)
3464 lpTbInfo->iImage = btnPtr->iBitmap;
3465 if (lpTbInfo->dwMask & TBIF_LPARAM)
3466 lpTbInfo->lParam = btnPtr->dwData;
3467 if (lpTbInfo->dwMask & TBIF_SIZE)
3468 /* tests show that for separators TBIF_SIZE returns not calculated width,
3469 but cx property, that differs from 0 only if application have
3470 specifically set it */
3471 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3472 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3473 if (lpTbInfo->dwMask & TBIF_STATE)
3474 lpTbInfo->fsState = btnPtr->fsState;
3475 if (lpTbInfo->dwMask & TBIF_STYLE)
3476 lpTbInfo->fsStyle = btnPtr->fsStyle;
3477 if (lpTbInfo->dwMask & TBIF_TEXT) {
3478 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3479 can't use TOOLBAR_GetText here */
3480 if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1)) {
3481 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3482 if (bUnicode)
3483 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3484 else
3485 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3486 } else
3487 lpTbInfo->pszText[0] = '\0';
3488 }
3489 return nIndex;
3490 }
3491
3492
3493 static inline LRESULT
3494 TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
3495 {
3496 return MAKELONG((WORD)infoPtr->nButtonWidth,
3497 (WORD)infoPtr->nButtonHeight);
3498 }
3499
3500
3501 static LRESULT
3502 TOOLBAR_GetButtonText (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr, BOOL isW)
3503 {
3504 INT nIndex;
3505 LPWSTR lpText;
3506 LRESULT ret = 0;
3507
3508 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3509 if (nIndex == -1)
3510 return -1;
3511
3512 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3513
3514 if (isW)