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