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