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