Sync with trunk revision 63128.
[reactos.git] / dll / win32 / comctl32 / toolbar.c
1 /*
2 * Toolbar control
3 *
4 * Copyright 1998,1999 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2004 Robert Shearman
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 *
22 * NOTES
23 *
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Mar. 14, 2004, by Robert Shearman.
26 *
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features or bugs please note them below.
30 *
31 * TODO:
32 * - Styles:
33 * - TBSTYLE_REGISTERDROP
34 * - TBSTYLE_EX_DOUBLEBUFFER
35 * - Messages:
36 * - TB_GETMETRICS
37 * - TB_GETOBJECT
38 * - TB_INSERTMARKHITTEST
39 * - TB_SAVERESTORE
40 * - TB_SETMETRICS
41 * - WM_WININICHANGE
42 * - Notifications:
43 * - NM_CHAR
44 * - TBN_GETOBJECT
45 * - TBN_SAVE
46 * - Button wrapping (under construction).
47 * - Fix TB_SETROWS and Separators.
48 * - iListGap custom draw support.
49 *
50 * Testing:
51 * - Run tests using Waite Group Windows95 API Bible Volume 2.
52 * The second cdrom contains executables addstr.exe, btncount.exe,
53 * btnstate.exe, butstrsz.exe, chkbtn.exe, chngbmp.exe, customiz.exe,
54 * enablebtn.exe, getbmp.exe, getbtn.exe, getflags.exe, hidebtn.exe,
55 * indetbtn.exe, insbtn.exe, pressbtn.exe, setbtnsz.exe, setcmdid.exe,
56 * setparnt.exe, setrows.exe, toolwnd.exe.
57 * - Microsoft's controlspy examples.
58 * - Charles Petzold's 'Programming Windows': gadgets.exe
59 *
60 * Differences between MSDN and actual native control operation:
61 * 1. MSDN says: "TBSTYLE_LIST: Creates a flat toolbar with button text
62 * to the right of the bitmap. Otherwise, this style is
63 * identical to TBSTYLE_FLAT."
64 * As implemented by both v4.71 and v5.80 of the native COMCTL32.DLL
65 * you can create a TBSTYLE_LIST without TBSTYLE_FLAT and the result
66 * is non-flat non-transparent buttons. Therefore TBSTYLE_LIST does
67 * *not* imply TBSTYLE_FLAT as documented. (GA 8/2001)
68 *
69 */
70
71 #include "comctl32.h"
72
73 WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
74
75 static HCURSOR hCursorDrag = NULL;
76
77 typedef struct
78 {
79 INT iBitmap;
80 INT idCommand;
81 BYTE fsState;
82 BYTE fsStyle;
83 BOOL bHot;
84 BOOL bDropDownPressed;
85 DWORD_PTR dwData;
86 INT_PTR iString;
87 INT nRow;
88 RECT rect;
89 INT cx; /* manually set size */
90 } TBUTTON_INFO;
91
92 typedef struct
93 {
94 UINT nButtons;
95 HINSTANCE hInst;
96 UINT nID;
97 } TBITMAP_INFO;
98
99 typedef struct
100 {
101 HIMAGELIST himl;
102 INT id;
103 } IMLENTRY, *PIMLENTRY;
104
105 typedef struct
106 {
107 DWORD dwStructSize; /* size of TBBUTTON struct */
108 INT nWidth; /* width of the toolbar */
109 RECT client_rect;
110 RECT rcBound; /* bounding rectangle */
111 INT nButtonHeight;
112 INT nButtonWidth;
113 INT nBitmapHeight;
114 INT nBitmapWidth;
115 INT nIndent;
116 INT nRows; /* number of button rows */
117 INT nMaxTextRows; /* maximum number of text rows */
118 INT cxMin; /* minimum button width */
119 INT cxMax; /* maximum button width */
120 INT nNumButtons; /* number of buttons */
121 INT nNumBitmaps; /* number of bitmaps */
122 INT nNumStrings; /* number of strings */
123 INT nNumBitmapInfos;
124 INT nButtonDown; /* toolbar button being pressed or -1 if none */
125 INT nButtonDrag; /* toolbar button being dragged or -1 if none */
126 INT nOldHit;
127 INT nHotItem; /* index of the "hot" item */
128 SIZE szPadding; /* padding values around button */
129 INT iTopMargin; /* the top margin */
130 INT iListGap; /* default gap between text and image for toolbar with list style */
131 HFONT hDefaultFont;
132 HFONT hFont; /* text font */
133 HIMAGELIST himlInt; /* image list created internally */
134 PIMLENTRY *himlDef; /* default image list array */
135 INT cimlDef; /* default image list array count */
136 PIMLENTRY *himlHot; /* hot image list array */
137 INT cimlHot; /* hot image list array count */
138 PIMLENTRY *himlDis; /* disabled image list array */
139 INT cimlDis; /* disabled image list array count */
140 HWND hwndToolTip; /* handle to tool tip control */
141 HWND hwndNotify; /* handle to the window that gets notifications */
142 HWND hwndSelf; /* my own handle */
143 BOOL bAnchor; /* anchor highlight enabled */
144 BOOL bDoRedraw; /* Redraw status */
145 BOOL bDragOutSent; /* has TBN_DRAGOUT notification been sent for this drag? */
146 BOOL bUnicode; /* Notifications are ASCII (FALSE) or Unicode (TRUE)? */
147 BOOL bCaptured; /* mouse captured? */
148 DWORD dwStyle; /* regular toolbar style */
149 DWORD dwExStyle; /* extended toolbar style */
150 DWORD dwDTFlags; /* DrawText flags */
151
152 COLORREF clrInsertMark; /* insert mark color */
153 COLORREF clrBtnHighlight; /* color for Flat Separator */
154 COLORREF clrBtnShadow; /* color for Flag Separator */
155 INT iVersion;
156 LPWSTR pszTooltipText; /* temporary store for a string > 80 characters
157 * for TTN_GETDISPINFOW notification */
158 TBINSERTMARK tbim; /* info on insertion mark */
159 TBUTTON_INFO *buttons; /* pointer to button array */
160 LPWSTR *strings; /* pointer to string array */
161 TBITMAP_INFO *bitmaps;
162 } TOOLBAR_INFO, *PTOOLBAR_INFO;
163
164
165 /* used by customization dialog */
166 typedef struct
167 {
168 PTOOLBAR_INFO tbInfo;
169 HWND tbHwnd;
170 } CUSTDLG_INFO, *PCUSTDLG_INFO;
171
172 typedef struct
173 {
174 TBBUTTON btn;
175 BOOL bVirtual;
176 BOOL bRemovable;
177 WCHAR text[64];
178 } CUSTOMBUTTON, *PCUSTOMBUTTON;
179
180 typedef enum
181 {
182 IMAGE_LIST_DEFAULT,
183 IMAGE_LIST_HOT,
184 IMAGE_LIST_DISABLED
185 } IMAGE_LIST_TYPE;
186
187 #define SEPARATOR_WIDTH 8
188 #define TOP_BORDER 2
189 #define BOTTOM_BORDER 2
190 #define DDARROW_WIDTH 11
191 #define ARROW_HEIGHT 3
192 #define INSERTMARK_WIDTH 2
193
194 #define DEFPAD_CX 7
195 #define DEFPAD_CY 6
196 #define DEFLISTGAP 4
197
198 /* vertical padding used in list mode when image is present */
199 #define LISTPAD_CY 9
200
201 /* how wide to treat the bitmap if it isn't present */
202 #define NONLIST_NOTEXT_OFFSET 2
203
204 #define TOOLBAR_NOWHERE (-1)
205
206 /* Used to find undocumented extended styles */
207 #define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
208 TBSTYLE_EX_VERTICAL | \
209 TBSTYLE_EX_MIXEDBUTTONS | \
210 TBSTYLE_EX_DOUBLEBUFFER | \
211 TBSTYLE_EX_HIDECLIPPEDBUTTONS)
212
213 /* all of the CCS_ styles */
214 #define COMMON_STYLES (CCS_TOP|CCS_NOMOVEY|CCS_BOTTOM|CCS_NORESIZE| \
215 CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_VERT)
216
217 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i)
218 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0)
219 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id)
220 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id)
221 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id)
222
223 static const WCHAR themeClass[] = { 'T','o','o','l','b','a','r',0 };
224
225 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb);
226 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo);
227 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id);
228 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id);
229 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies);
230 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id);
231 static LRESULT TOOLBAR_LButtonDown(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
232 static void TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr);
233 static LRESULT TOOLBAR_AutoSize(TOOLBAR_INFO *infoPtr);
234 static void TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr);
235 static void TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
236 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button);
237
238
239 static inline int default_top_margin(const TOOLBAR_INFO *infoPtr)
240 {
241 return (infoPtr->dwStyle & TBSTYLE_FLAT ? 0 : TOP_BORDER);
242 }
243
244 static inline BOOL TOOLBAR_HasDropDownArrows(DWORD exStyle)
245 {
246 return (exStyle & TBSTYLE_EX_DRAWDDARROWS) != 0;
247 }
248
249 static LPWSTR
250 TOOLBAR_GetText(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr)
251 {
252 LPWSTR lpText = NULL;
253
254 /* NOTE: iString == -1 is undocumented */
255 if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1))
256 lpText = (LPWSTR)btnPtr->iString;
257 else if ((btnPtr->iString >= 0) && (btnPtr->iString < infoPtr->nNumStrings))
258 lpText = infoPtr->strings[btnPtr->iString];
259
260 return lpText;
261 }
262
263 static void
264 TOOLBAR_DumpTBButton(const TBBUTTON *tbb, BOOL fUnicode)
265 {
266 TRACE("TBBUTTON: id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx (%s)\n",
267 tbb->idCommand,tbb->iBitmap, tbb->fsState, tbb->fsStyle, tbb->dwData, tbb->iString,
268 (fUnicode ? wine_dbgstr_w((LPWSTR)tbb->iString) : wine_dbgstr_a((LPSTR)tbb->iString)));
269 }
270
271 static void
272 TOOLBAR_DumpButton(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *bP, INT btn_num)
273 {
274 if (TRACE_ON(toolbar)){
275 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08lx\n",
276 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap),
277 bP->fsState, bP->fsStyle, bP->dwData, bP->iString);
278 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP)));
279 TRACE("button %d id %d, hot=%s, row=%d, rect=(%s)\n",
280 btn_num, bP->idCommand, (bP->bHot) ? "TRUE":"FALSE", bP->nRow,
281 wine_dbgstr_rect(&bP->rect));
282 }
283 }
284
285
286 static void
287 TOOLBAR_DumpToolbar(const TOOLBAR_INFO *iP, INT line)
288 {
289 if (TRACE_ON(toolbar)) {
290 INT i;
291
292 TRACE("toolbar %p at line %d, exStyle=%08x, buttons=%d, bitmaps=%d, strings=%d, style=%08x\n",
293 iP->hwndSelf, line,
294 iP->dwExStyle, iP->nNumButtons, iP->nNumBitmaps,
295 iP->nNumStrings, iP->dwStyle);
296 TRACE("toolbar %p at line %d, himlInt=%p, himlDef=%p, himlHot=%p, himlDis=%p, redrawable=%s\n",
297 iP->hwndSelf, line,
298 iP->himlInt, iP->himlDef, iP->himlHot, iP->himlDis,
299 (iP->bDoRedraw) ? "TRUE" : "FALSE");
300 for(i=0; i<iP->nNumButtons; i++) {
301 TOOLBAR_DumpButton(iP, &iP->buttons[i], i);
302 }
303 }
304 }
305
306 static inline BOOL
307 TOOLBAR_ButtonHasString(const TBUTTON_INFO *btnPtr)
308 {
309 return HIWORD(btnPtr->iString) && btnPtr->iString != -1;
310 }
311
312 /***********************************************************************
313 * TOOLBAR_CheckStyle
314 *
315 * This function validates that the styles set are implemented and
316 * issues FIXMEs warning of possible problems. In a perfect world this
317 * function should be null.
318 */
319 static void
320 TOOLBAR_CheckStyle (const TOOLBAR_INFO *infoPtr)
321 {
322 if (infoPtr->dwStyle & TBSTYLE_REGISTERDROP)
323 FIXME("[%p] TBSTYLE_REGISTERDROP not implemented\n", infoPtr->hwndSelf);
324 }
325
326
327 static INT
328 TOOLBAR_SendNotify (NMHDR *nmhdr, const TOOLBAR_INFO *infoPtr, UINT code)
329 {
330 if(!IsWindow(infoPtr->hwndSelf))
331 return 0; /* we have just been destroyed */
332
333 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
334 nmhdr->hwndFrom = infoPtr->hwndSelf;
335 nmhdr->code = code;
336
337 TRACE("to window %p, code=%08x, %s\n", infoPtr->hwndNotify, code,
338 (infoPtr->bUnicode) ? "via Unicode" : "via ANSI");
339
340 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
341 }
342
343 /***********************************************************************
344 * TOOLBAR_GetBitmapIndex
345 *
346 * This function returns the bitmap index associated with a button.
347 * If the button specifies I_IMAGECALLBACK, then the TBN_GETDISPINFO
348 * is issued to retrieve the index.
349 */
350 static INT
351 TOOLBAR_GetBitmapIndex(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr)
352 {
353 INT ret = btnPtr->iBitmap;
354
355 if (ret == I_IMAGECALLBACK)
356 {
357 /* issue TBN_GETDISPINFO */
358 NMTBDISPINFOW nmgd;
359
360 memset(&nmgd, 0, sizeof(nmgd));
361 nmgd.idCommand = btnPtr->idCommand;
362 nmgd.lParam = btnPtr->dwData;
363 nmgd.dwMask = TBNF_IMAGE;
364 nmgd.iImage = -1;
365 /* Windows also send TBN_GETDISPINFOW even if the control is ANSI */
366 TOOLBAR_SendNotify(&nmgd.hdr, infoPtr, TBN_GETDISPINFOW);
367 if (nmgd.dwMask & TBNF_DI_SETITEM)
368 btnPtr->iBitmap = nmgd.iImage;
369 ret = nmgd.iImage;
370 TRACE("TBN_GETDISPINFO returned bitmap id %d, mask=%08x, nNumBitmaps=%d\n",
371 ret, nmgd.dwMask, infoPtr->nNumBitmaps);
372 }
373
374 if (ret != I_IMAGENONE)
375 ret = GETIBITMAP(infoPtr, ret);
376
377 return ret;
378 }
379
380
381 static BOOL
382 TOOLBAR_IsValidBitmapIndex(const TOOLBAR_INFO *infoPtr, INT index)
383 {
384 HIMAGELIST himl;
385 INT id = GETHIMLID(infoPtr, index);
386 INT iBitmap = GETIBITMAP(infoPtr, index);
387
388 if (((himl = GETDEFIMAGELIST(infoPtr, id)) &&
389 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) ||
390 (index == I_IMAGECALLBACK))
391 return TRUE;
392 else
393 return FALSE;
394 }
395
396
397 static inline BOOL
398 TOOLBAR_IsValidImageList(const TOOLBAR_INFO *infoPtr, INT index)
399 {
400 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, index));
401 return (himl != NULL) && (ImageList_GetImageCount(himl) > 0);
402 }
403
404
405 /***********************************************************************
406 * TOOLBAR_GetImageListForDrawing
407 *
408 * This function validates the bitmap index (including I_IMAGECALLBACK
409 * functionality) and returns the corresponding image list.
410 */
411 static HIMAGELIST
412 TOOLBAR_GetImageListForDrawing (const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
413 IMAGE_LIST_TYPE imagelist, INT * index)
414 {
415 HIMAGELIST himl;
416
417 if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
418 if (btnPtr->iBitmap == I_IMAGENONE) return NULL;
419 WARN("bitmap for ID %d, index %d is not valid, number of bitmaps in imagelist: %d\n",
420 HIWORD(btnPtr->iBitmap), LOWORD(btnPtr->iBitmap), infoPtr->nNumBitmaps);
421 return NULL;
422 }
423
424 if ((*index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
425 if ((*index == I_IMAGECALLBACK) ||
426 (*index == I_IMAGENONE)) return NULL;
427 ERR("TBN_GETDISPINFO returned invalid index %d\n",
428 *index);
429 return NULL;
430 }
431
432 switch(imagelist)
433 {
434 case IMAGE_LIST_DEFAULT:
435 himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
436 break;
437 case IMAGE_LIST_HOT:
438 himl = GETHOTIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
439 break;
440 case IMAGE_LIST_DISABLED:
441 himl = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap));
442 break;
443 default:
444 himl = NULL;
445 FIXME("Shouldn't reach here\n");
446 }
447
448 if (!himl)
449 TRACE("no image list\n");
450
451 return himl;
452 }
453
454
455 static void
456 TOOLBAR_DrawFlatSeparator (const RECT *lpRect, HDC hdc, const TOOLBAR_INFO *infoPtr)
457 {
458 RECT myrect;
459 COLORREF oldcolor, newcolor;
460
461 myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
462 myrect.right = myrect.left + 1;
463 myrect.top = lpRect->top + 2;
464 myrect.bottom = lpRect->bottom - 2;
465
466 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
467 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
468 oldcolor = SetBkColor (hdc, newcolor);
469 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
470
471 myrect.left = myrect.right;
472 myrect.right = myrect.left + 1;
473
474 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
475 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
476 SetBkColor (hdc, newcolor);
477 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
478
479 SetBkColor (hdc, oldcolor);
480 }
481
482
483 /***********************************************************************
484 * TOOLBAR_DrawFlatHorizontalSeparator
485 *
486 * This function draws horizontal separator for toolbars having CCS_VERT style.
487 * In this case, the separator is a pixel high line of COLOR_BTNSHADOW,
488 * followed by a pixel high line of COLOR_BTNHIGHLIGHT. These separators
489 * are horizontal as opposed to the vertical separators for not dropdown
490 * type.
491 *
492 * FIXME: It is possible that the height of each line is really SM_CYBORDER.
493 */
494 static void
495 TOOLBAR_DrawFlatHorizontalSeparator (const RECT *lpRect, HDC hdc,
496 const TOOLBAR_INFO *infoPtr)
497 {
498 RECT myrect;
499 COLORREF oldcolor, newcolor;
500
501 myrect.left = lpRect->left;
502 myrect.right = lpRect->right;
503 myrect.top = lpRect->top + (lpRect->bottom - lpRect->top - 2)/2;
504 myrect.bottom = myrect.top + 1;
505
506 InflateRect (&myrect, -2, 0);
507
508 TRACE("rect=(%s)\n", wine_dbgstr_rect(&myrect));
509
510 newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
511 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
512 oldcolor = SetBkColor (hdc, newcolor);
513 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
514
515 myrect.top = myrect.bottom;
516 myrect.bottom = myrect.top + 1;
517
518 newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
519 comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
520 SetBkColor (hdc, newcolor);
521 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
522
523 SetBkColor (hdc, oldcolor);
524 }
525
526
527 static void
528 TOOLBAR_DrawArrow (HDC hdc, INT left, INT top, COLORREF clr)
529 {
530 INT x, y;
531 HPEN hPen, hOldPen;
532
533 if (!(hPen = CreatePen( PS_SOLID, 1, clr))) return;
534 hOldPen = SelectObject ( hdc, hPen );
535 x = left + 2;
536 y = top;
537 MoveToEx (hdc, x, y, NULL);
538 LineTo (hdc, x+5, y++); x++;
539 MoveToEx (hdc, x, y, NULL);
540 LineTo (hdc, x+3, y++); x++;
541 MoveToEx (hdc, x, y, NULL);
542 LineTo (hdc, x+1, y);
543 SelectObject( hdc, hOldPen );
544 DeleteObject( hPen );
545 }
546
547 /*
548 * Draw the text string for this button.
549 * note: infoPtr->himlDis *SHOULD* be non-zero when infoPtr->himlDef
550 * is non-zero, so we can simply check himlDef to see if we have
551 * an image list
552 */
553 static void
554 TOOLBAR_DrawString (const TOOLBAR_INFO *infoPtr, RECT *rcText, LPCWSTR lpText,
555 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
556 {
557 HDC hdc = tbcd->nmcd.hdc;
558 HFONT hOldFont = 0;
559 COLORREF clrOld = 0;
560 COLORREF clrOldBk = 0;
561 int oldBkMode = 0;
562 UINT state = tbcd->nmcd.uItemState;
563
564 /* draw text */
565 if (lpText && infoPtr->nMaxTextRows > 0) {
566 TRACE("string=%s rect=(%s)\n", debugstr_w(lpText),
567 wine_dbgstr_rect(rcText));
568
569 hOldFont = SelectObject (hdc, infoPtr->hFont);
570 if ((state & CDIS_HOT) && (dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
571 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
572 }
573 else if (state & CDIS_DISABLED) {
574 clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
575 OffsetRect (rcText, 1, 1);
576 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
577 SetTextColor (hdc, comctl32_color.clr3dShadow);
578 OffsetRect (rcText, -1, -1);
579 }
580 else if (state & CDIS_INDETERMINATE) {
581 clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
582 }
583 else if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK)) {
584 clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
585 clrOldBk = SetBkColor (hdc, tbcd->clrMark);
586 oldBkMode = SetBkMode (hdc, tbcd->nHLStringBkMode);
587 }
588 else {
589 clrOld = SetTextColor (hdc, tbcd->clrText);
590 }
591
592 DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
593 SetTextColor (hdc, clrOld);
594 if ((state & CDIS_MARKED) && !(dwItemCDFlag & TBCDRF_NOMARK))
595 {
596 SetBkColor (hdc, clrOldBk);
597 SetBkMode (hdc, oldBkMode);
598 }
599 SelectObject (hdc, hOldFont);
600 }
601 }
602
603
604 static void
605 TOOLBAR_DrawPattern (const RECT *lpRect, const NMTBCUSTOMDRAW *tbcd)
606 {
607 HDC hdc = tbcd->nmcd.hdc;
608 HBRUSH hbr = SelectObject (hdc, tbcd->hbrMonoDither);
609 COLORREF clrTextOld;
610 COLORREF clrBkOld;
611 INT cx = lpRect->right - lpRect->left;
612 INT cy = lpRect->bottom - lpRect->top;
613 INT cxEdge = GetSystemMetrics(SM_CXEDGE);
614 INT cyEdge = GetSystemMetrics(SM_CYEDGE);
615 clrTextOld = SetTextColor(hdc, tbcd->clrBtnHighlight);
616 clrBkOld = SetBkColor(hdc, tbcd->clrBtnFace);
617 PatBlt (hdc, lpRect->left + cxEdge, lpRect->top + cyEdge,
618 cx - (2 * cxEdge), cy - (2 * cyEdge), PATCOPY);
619 SetBkColor(hdc, clrBkOld);
620 SetTextColor(hdc, clrTextOld);
621 SelectObject (hdc, hbr);
622 }
623
624
625 static void TOOLBAR_DrawMasked(HIMAGELIST himl, int index, HDC hdc, INT x, INT y, UINT draw_flags)
626 {
627 INT cx, cy;
628 HBITMAP hbmMask, hbmImage;
629 HDC hdcMask, hdcImage;
630
631 ImageList_GetIconSize(himl, &cx, &cy);
632
633 /* Create src image */
634 hdcImage = CreateCompatibleDC(hdc);
635 hbmImage = CreateCompatibleBitmap(hdc, cx, cy);
636 SelectObject(hdcImage, hbmImage);
637 ImageList_DrawEx(himl, index, hdcImage, 0, 0, cx, cy,
638 RGB(0xff, 0xff, 0xff), RGB(0,0,0), draw_flags);
639
640 /* Create Mask */
641 hdcMask = CreateCompatibleDC(0);
642 hbmMask = CreateBitmap(cx, cy, 1, 1, NULL);
643 SelectObject(hdcMask, hbmMask);
644
645 /* Remove the background and all white pixels */
646 ImageList_DrawEx(himl, index, hdcMask, 0, 0, cx, cy,
647 RGB(0xff, 0xff, 0xff), RGB(0,0,0), ILD_MASK);
648 SetBkColor(hdcImage, RGB(0xff, 0xff, 0xff));
649 BitBlt(hdcMask, 0, 0, cx, cy, hdcImage, 0, 0, NOTSRCERASE);
650
651 /* draw the new mask 'etched' to hdc */
652 SetBkColor(hdc, RGB(255, 255, 255));
653 SelectObject(hdc, GetSysColorBrush(COLOR_3DHILIGHT));
654 /* E20746 op code is (Dst ^ (Src & (Pat ^ Dst))) */
655 BitBlt(hdc, x + 1, y + 1, cx, cy, hdcMask, 0, 0, 0xE20746);
656 SelectObject(hdc, GetSysColorBrush(COLOR_3DSHADOW));
657 BitBlt(hdc, x, y, cx, cy, hdcMask, 0, 0, 0xE20746);
658
659 /* Cleanup */
660 DeleteObject(hbmImage);
661 DeleteDC(hdcImage);
662 DeleteObject (hbmMask);
663 DeleteDC(hdcMask);
664 }
665
666
667 static UINT
668 TOOLBAR_TranslateState(const TBUTTON_INFO *btnPtr)
669 {
670 UINT retstate = 0;
671
672 retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED : 0;
673 retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
674 retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
675 retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED : 0;
676 retstate |= (btnPtr->bHot ) ? CDIS_HOT : 0;
677 retstate |= ((btnPtr->fsState & (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) == (TBSTATE_ENABLED|TBSTATE_INDETERMINATE)) ? CDIS_INDETERMINATE : 0;
678 /* NOTE: we don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT */
679 return retstate;
680 }
681
682 /* draws the image on a toolbar button */
683 static void
684 TOOLBAR_DrawImage(const TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr, INT left, INT top,
685 const NMTBCUSTOMDRAW *tbcd, DWORD dwItemCDFlag)
686 {
687 HIMAGELIST himl = NULL;
688 BOOL draw_masked = FALSE;
689 INT index;
690 INT offset = 0;
691 UINT draw_flags = ILD_TRANSPARENT;
692
693 if (tbcd->nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
694 {
695 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DISABLED, &index);
696 if (!himl)
697 {
698 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
699 draw_masked = TRUE;
700 }
701 }
702 else if (tbcd->nmcd.uItemState & CDIS_CHECKED ||
703 ((tbcd->nmcd.uItemState & CDIS_HOT)
704 && ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))))
705 {
706 /* if hot, attempt to draw with hot image list, if fails,
707 use default image list */
708 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_HOT, &index);
709 if (!himl)
710 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
711 }
712 else
713 himl = TOOLBAR_GetImageListForDrawing(infoPtr, btnPtr, IMAGE_LIST_DEFAULT, &index);
714
715 if (!himl)
716 return;
717
718 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
719 (tbcd->nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED)))
720 offset = 1;
721
722 if (!(dwItemCDFlag & TBCDRF_NOMARK) &&
723 (tbcd->nmcd.uItemState & CDIS_MARKED))
724 draw_flags |= ILD_BLEND50;
725
726 TRACE("drawing index=%d, himl=%p, left=%d, top=%d, offset=%d\n",
727 index, himl, left, top, offset);
728
729 if (draw_masked)
730 TOOLBAR_DrawMasked (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
731 else
732 ImageList_Draw (himl, index, tbcd->nmcd.hdc, left + offset, top + offset, draw_flags);
733 }
734
735 /* draws a blank frame for a toolbar button */
736 static void
737 TOOLBAR_DrawFrame(const TOOLBAR_INFO *infoPtr, const NMTBCUSTOMDRAW *tbcd, 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 RECT rcsep = rc;
848 InflateRect(&rcsep, -infoPtr->szPadding.cx, -infoPtr->szPadding.cy);
849 TOOLBAR_DrawFlatHorizontalSeparator (&rcsep, hdc, infoPtr);
850 }
851 else
852 TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
853 }
854 else if (btnPtr->fsStyle != BTNS_SEP) {
855 FIXME("Draw some kind of separator: fsStyle=%x\n",
856 btnPtr->fsStyle);
857 }
858 return;
859 }
860
861 /* get a pointer to the text */
862 lpText = TOOLBAR_GetText(infoPtr, btnPtr);
863
864 if (hasDropDownArrow)
865 {
866 int right;
867
868 if (dwStyle & TBSTYLE_FLAT)
869 right = max(rc.left, rc.right - DDARROW_WIDTH);
870 else
871 right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
872
873 if (drawSepDropDownArrow)
874 rc.right = right;
875
876 rcArrow.left = right;
877 }
878
879 /* copy text & bitmap rects after adjusting for drop-down arrow
880 * so that text & bitmap is centered in the rectangle not containing
881 * the arrow */
882 CopyRect(&rcText, &rc);
883 CopyRect(&rcBitmap, &rc);
884
885 /* Center the bitmap horizontally and vertically */
886 if (dwStyle & TBSTYLE_LIST)
887 {
888 if (lpText &&
889 infoPtr->nMaxTextRows > 0 &&
890 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
891 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
892 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->szPadding.cx / 2;
893 else
894 rcBitmap.left += GetSystemMetrics(SM_CXEDGE) + infoPtr->iListGap / 2;
895 }
896 else
897 rcBitmap.left += ((rc.right - rc.left) - infoPtr->nBitmapWidth) / 2;
898
899 rcBitmap.top += infoPtr->szPadding.cy / 2;
900
901 TRACE("iBitmap=%d, start=(%d,%d) w=%d, h=%d\n",
902 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
903 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
904 TRACE("Text=%s\n", debugstr_w(lpText));
905 TRACE("iListGap=%d, padding = { %d, %d }\n", infoPtr->iListGap, infoPtr->szPadding.cx, infoPtr->szPadding.cy);
906
907 /* calculate text position */
908 if (lpText)
909 {
910 rcText.left += GetSystemMetrics(SM_CXEDGE);
911 rcText.right -= GetSystemMetrics(SM_CXEDGE);
912 if (dwStyle & TBSTYLE_LIST)
913 {
914 rcText.left += infoPtr->nBitmapWidth + infoPtr->iListGap + 2;
915 }
916 else
917 {
918 if (ImageList_GetImageCount(GETDEFIMAGELIST(infoPtr, 0)) > 0)
919 rcText.top += infoPtr->szPadding.cy/2 + infoPtr->nBitmapHeight + 1;
920 else
921 rcText.top += infoPtr->szPadding.cy/2 + 2;
922 }
923 }
924
925 /* Initialize fields in all cases, because we use these later
926 * NOTE: applications can and do alter these to customize their
927 * toolbars */
928 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
929 tbcd.clrText = comctl32_color.clrBtnText;
930 tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
931 tbcd.clrBtnFace = comctl32_color.clrBtnFace;
932 tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
933 tbcd.clrMark = comctl32_color.clrHighlight;
934 tbcd.clrHighlightHotTrack = 0;
935 tbcd.nStringBkMode = TRANSPARENT;
936 tbcd.nHLStringBkMode = OPAQUE;
937 tbcd.rcText.left = 0;
938 tbcd.rcText.top = 0;
939 tbcd.rcText.right = rcText.right - rc.left;
940 tbcd.rcText.bottom = rcText.bottom - rc.top;
941 tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
942 tbcd.nmcd.hdc = hdc;
943 tbcd.nmcd.rc = rc;
944 tbcd.hbrMonoDither = COMCTL32_hPattern55AABrush;
945
946 /* FIXME: what are these used for? */
947 tbcd.hbrLines = 0;
948 tbcd.hpenLines = 0;
949
950 /* Issue Item Prepaint notify */
951 dwItemCustDraw = 0;
952 dwItemCDFlag = 0;
953 if (dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
954 {
955 tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
956 tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
957 tbcd.nmcd.lItemlParam = btnPtr->dwData;
958 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
959 /* reset these fields so the user can't alter the behaviour like native */
960 tbcd.nmcd.hdc = hdc;
961 tbcd.nmcd.rc = rc;
962
963 dwItemCustDraw = ntfret & 0xffff;
964 dwItemCDFlag = ntfret & 0xffff0000;
965 if (dwItemCustDraw & CDRF_SKIPDEFAULT)
966 return;
967 /* save the only part of the rect that the user can change */
968 rcText.right = tbcd.rcText.right + rc.left;
969 rcText.bottom = tbcd.rcText.bottom + rc.top;
970 }
971
972 if (!(dwItemCDFlag & TBCDRF_NOOFFSET) &&
973 (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED)))
974 OffsetRect(&rcText, 1, 1);
975
976 if (!(tbcd.nmcd.uItemState & CDIS_HOT) &&
977 ((tbcd.nmcd.uItemState & CDIS_CHECKED) || (tbcd.nmcd.uItemState & CDIS_INDETERMINATE)))
978 TOOLBAR_DrawPattern (&rc, &tbcd);
979
980 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
981 && (tbcd.nmcd.uItemState & CDIS_HOT))
982 {
983 if ( dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
984 {
985 COLORREF oldclr;
986
987 oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
988 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
989 if (hasDropDownArrow)
990 ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
991 SetBkColor(hdc, oldclr);
992 }
993 }
994
995 if (theme)
996 {
997 int partId = drawSepDropDownArrow ? TP_SPLITBUTTON : TP_BUTTON;
998 int stateId = TS_NORMAL;
999
1000 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1001 stateId = TS_DISABLED;
1002 else if (tbcd.nmcd.uItemState & CDIS_SELECTED)
1003 stateId = TS_PRESSED;
1004 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1005 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1006 else if ((tbcd.nmcd.uItemState & CDIS_HOT)
1007 || (drawSepDropDownArrow && btnPtr->bDropDownPressed))
1008 stateId = TS_HOT;
1009
1010 DrawThemeBackground (theme, hdc, partId, stateId, &tbcd.nmcd.rc, NULL);
1011 }
1012 else
1013 TOOLBAR_DrawFrame(infoPtr, &tbcd, dwItemCDFlag);
1014
1015 if (drawSepDropDownArrow)
1016 {
1017 if (theme)
1018 {
1019 int stateId = TS_NORMAL;
1020
1021 if (tbcd.nmcd.uItemState & CDIS_DISABLED)
1022 stateId = TS_DISABLED;
1023 else if (btnPtr->bDropDownPressed || (tbcd.nmcd.uItemState & CDIS_SELECTED))
1024 stateId = TS_PRESSED;
1025 else if (tbcd.nmcd.uItemState & CDIS_CHECKED)
1026 stateId = (tbcd.nmcd.uItemState & CDIS_HOT) ? TS_HOTCHECKED : TS_HOT;
1027 else if (tbcd.nmcd.uItemState & CDIS_HOT)
1028 stateId = TS_HOT;
1029
1030 DrawThemeBackground (theme, hdc, TP_DROPDOWNBUTTON, stateId, &rcArrow, NULL);
1031 DrawThemeBackground (theme, hdc, TP_SPLITBUTTONDROPDOWN, stateId, &rcArrow, NULL);
1032 }
1033 else
1034 TOOLBAR_DrawSepDDArrow(infoPtr, &tbcd, &rcArrow, btnPtr->bDropDownPressed, dwItemCDFlag);
1035 }
1036
1037 oldBkMode = SetBkMode (hdc, tbcd.nStringBkMode);
1038 if (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) || (btnPtr->fsStyle & BTNS_SHOWTEXT))
1039 TOOLBAR_DrawString (infoPtr, &rcText, lpText, &tbcd, dwItemCDFlag);
1040 SetBkMode (hdc, oldBkMode);
1041
1042 TOOLBAR_DrawImage(infoPtr, btnPtr, rcBitmap.left, rcBitmap.top, &tbcd, dwItemCDFlag);
1043
1044 if (hasDropDownArrow && !drawSepDropDownArrow)
1045 {
1046 if (tbcd.nmcd.uItemState & (CDIS_DISABLED | CDIS_INDETERMINATE))
1047 {
1048 TOOLBAR_DrawArrow(hdc, rcArrow.left+1, rcArrow.top+1 + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnHighlight);
1049 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clr3dShadow);
1050 }
1051 else if (tbcd.nmcd.uItemState & (CDIS_SELECTED | CDIS_CHECKED))
1052 {
1053 offset = (dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
1054 TOOLBAR_DrawArrow(hdc, rcArrow.left + offset, rcArrow.top + offset + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1055 }
1056 else
1057 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top + (rcArrow.bottom - rcArrow.top - ARROW_HEIGHT) / 2, comctl32_color.clrBtnText);
1058 }
1059
1060 if (dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
1061 {
1062 tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
1063 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1064 }
1065
1066 }
1067
1068
1069 static void
1070 TOOLBAR_Refresh (TOOLBAR_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1071 {
1072 TBUTTON_INFO *btnPtr;
1073 INT i;
1074 RECT rcTemp, rcClient;
1075 NMTBCUSTOMDRAW tbcd;
1076 DWORD ntfret;
1077 DWORD dwBaseCustDraw;
1078
1079 /* the app has told us not to redraw the toolbar */
1080 if (!infoPtr->bDoRedraw)
1081 return;
1082
1083 /* if imagelist belongs to the app, it can be changed
1084 by the app after setting it */
1085 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt)
1086 {
1087 infoPtr->nNumBitmaps = 0;
1088 for (i = 0; i < infoPtr->cimlDef; i++)
1089 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
1090 }
1091
1092 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1093
1094 /* change the imagelist icon size if we manage the list and it is necessary */
1095 TOOLBAR_CheckImageListIconSize(infoPtr);
1096
1097 /* Send initial notify */
1098 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1099 tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
1100 tbcd.nmcd.hdc = hdc;
1101 tbcd.nmcd.rc = ps->rcPaint;
1102 ntfret = TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1103 dwBaseCustDraw = ntfret & 0xffff;
1104
1105 GetClientRect(infoPtr->hwndSelf, &rcClient);
1106
1107 /* redraw necessary buttons */
1108 btnPtr = infoPtr->buttons;
1109 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
1110 {
1111 BOOL bDraw;
1112 if (!RectVisible(hdc, &btnPtr->rect))
1113 continue;
1114 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
1115 {
1116 IntersectRect(&rcTemp, &rcClient, &btnPtr->rect);
1117 bDraw = EqualRect(&rcTemp, &btnPtr->rect);
1118 }
1119 else
1120 bDraw = TRUE;
1121 bDraw &= IntersectRect(&rcTemp, &(ps->rcPaint), &(btnPtr->rect));
1122 bDraw = (btnPtr->fsState & TBSTATE_HIDDEN) ? FALSE : bDraw;
1123 if (bDraw)
1124 TOOLBAR_DrawButton(infoPtr, btnPtr, hdc, dwBaseCustDraw);
1125 }
1126
1127 /* draw insert mark if required */
1128 if (infoPtr->tbim.iButton != -1)
1129 {
1130 RECT rcButton = infoPtr->buttons[infoPtr->tbim.iButton].rect;
1131 RECT rcInsertMark;
1132 rcInsertMark.top = rcButton.top;
1133 rcInsertMark.bottom = rcButton.bottom;
1134 if (infoPtr->tbim.dwFlags & TBIMHT_AFTER)
1135 rcInsertMark.left = rcInsertMark.right = rcButton.right;
1136 else
1137 rcInsertMark.left = rcInsertMark.right = rcButton.left - INSERTMARK_WIDTH;
1138 COMCTL32_DrawInsertMark(hdc, &rcInsertMark, infoPtr->clrInsertMark, FALSE);
1139 }
1140
1141 if (dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
1142 {
1143 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
1144 tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
1145 tbcd.nmcd.hdc = hdc;
1146 tbcd.nmcd.rc = ps->rcPaint;
1147 TOOLBAR_SendNotify(&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
1148 }
1149 }
1150
1151 /***********************************************************************
1152 * TOOLBAR_MeasureString
1153 *
1154 * This function gets the width and height of a string in pixels. This
1155 * is done first by using GetTextExtentPoint to get the basic width
1156 * and height. The DrawText is called with DT_CALCRECT to get the exact
1157 * width. The reason is because the text may have more than one "&" (or
1158 * prefix characters as M$ likes to call them). The prefix character
1159 * indicates where the underline goes, except for the string "&&" which
1160 * is reduced to a single "&". GetTextExtentPoint does not process these
1161 * only DrawText does. Note that the BTNS_NOPREFIX is handled here.
1162 */
1163 static void
1164 TOOLBAR_MeasureString(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *btnPtr,
1165 HDC hdc, LPSIZE lpSize)
1166 {
1167 RECT myrect;
1168
1169 lpSize->cx = 0;
1170 lpSize->cy = 0;
1171
1172 if (infoPtr->nMaxTextRows > 0 &&
1173 !(btnPtr->fsState & TBSTATE_HIDDEN) &&
1174 (!(infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1175 (btnPtr->fsStyle & BTNS_SHOWTEXT)) )
1176 {
1177 LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
1178
1179 if(lpText != NULL) {
1180 /* first get size of all the text */
1181 GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
1182
1183 /* feed above size into the rectangle for DrawText */
1184 myrect.left = myrect.top = 0;
1185 myrect.right = lpSize->cx;
1186 myrect.bottom = lpSize->cy;
1187
1188 /* Use DrawText to get true size as drawn (less pesky "&") */
1189 DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
1190 DT_CALCRECT | ((btnPtr->fsStyle & BTNS_NOPREFIX) ?
1191 DT_NOPREFIX : 0));
1192
1193 /* feed back to caller */
1194 lpSize->cx = myrect.right;
1195 lpSize->cy = myrect.bottom;
1196 }
1197 }
1198
1199 TRACE("string size %d x %d!\n", lpSize->cx, lpSize->cy);
1200 }
1201
1202 /***********************************************************************
1203 * TOOLBAR_CalcStrings
1204 *
1205 * This function walks through each string and measures it and returns
1206 * the largest height and width to caller.
1207 */
1208 static void
1209 TOOLBAR_CalcStrings (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
1210 {
1211 TBUTTON_INFO *btnPtr;
1212 INT i;
1213 SIZE sz;
1214 HDC hdc;
1215 HFONT hOldFont;
1216
1217 lpSize->cx = 0;
1218 lpSize->cy = 0;
1219
1220 if (infoPtr->nMaxTextRows == 0)
1221 return;
1222
1223 hdc = GetDC (infoPtr->hwndSelf);
1224 hOldFont = SelectObject (hdc, infoPtr->hFont);
1225
1226 if (infoPtr->nNumButtons == 0 && infoPtr->nNumStrings > 0)
1227 {
1228 TEXTMETRICW tm;
1229
1230 GetTextMetricsW(hdc, &tm);
1231 lpSize->cy = tm.tmHeight;
1232 }
1233
1234 btnPtr = infoPtr->buttons;
1235 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1236 if(TOOLBAR_GetText(infoPtr, btnPtr))
1237 {
1238 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1239 if (sz.cx > lpSize->cx)
1240 lpSize->cx = sz.cx;
1241 if (sz.cy > lpSize->cy)
1242 lpSize->cy = sz.cy;
1243 }
1244 }
1245
1246 SelectObject (hdc, hOldFont);
1247 ReleaseDC (infoPtr->hwndSelf, hdc);
1248
1249 TRACE("max string size %d x %d!\n", lpSize->cx, lpSize->cy);
1250 }
1251
1252 /***********************************************************************
1253 * TOOLBAR_WrapToolbar
1254 *
1255 * This function walks through the buttons and separators in the
1256 * toolbar, and sets the TBSTATE_WRAP flag only on those items where
1257 * wrapping should occur based on the width of the toolbar window.
1258 * It does *not* calculate button placement itself. That task
1259 * takes place in TOOLBAR_CalcToolbar. If the program wants to manage
1260 * the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
1261 * flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
1262 *
1263 * Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_VERTICAL can be used also to allow
1264 * vertical toolbar lists.
1265 */
1266
1267 static void
1268 TOOLBAR_WrapToolbar(TOOLBAR_INFO *infoPtr)
1269 {
1270 TBUTTON_INFO *btnPtr;
1271 INT x, cx, i, j;
1272 RECT rc;
1273 BOOL bButtonWrap;
1274
1275 /* When the toolbar window style is not TBSTYLE_WRAPABLE, */
1276 /* no layout is necessary. Applications may use this style */
1277 /* to perform their own layout on the toolbar. */
1278 if( !(infoPtr->dwStyle & TBSTYLE_WRAPABLE) &&
1279 !(infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL) ) return;
1280
1281 btnPtr = infoPtr->buttons;
1282 x = infoPtr->nIndent;
1283
1284 if (GetParent(infoPtr->hwndSelf))
1285 {
1286 /* this can get the parents width, to know how far we can extend
1287 * this toolbar. We cannot use its height, as there may be multiple
1288 * toolbars in a rebar control
1289 */
1290 GetClientRect( GetParent(infoPtr->hwndSelf), &rc );
1291 infoPtr->nWidth = rc.right - rc.left;
1292 }
1293 else
1294 {
1295 GetWindowRect( infoPtr->hwndSelf, &rc );
1296 infoPtr->nWidth = rc.right - rc.left;
1297 }
1298
1299 bButtonWrap = FALSE;
1300
1301 TRACE("start ButtonWidth=%d, BitmapWidth=%d, nWidth=%d, nIndent=%d\n",
1302 infoPtr->nButtonWidth, infoPtr->nBitmapWidth, infoPtr->nWidth,
1303 infoPtr->nIndent);
1304
1305 for (i = 0; i < infoPtr->nNumButtons; i++ )
1306 {
1307 btnPtr[i].fsState &= ~TBSTATE_WRAP;
1308
1309 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
1310 continue;
1311
1312 if (btnPtr[i].cx > 0)
1313 cx = btnPtr[i].cx;
1314 /* horizontal separators are treated as buttons for width */
1315 else if ((btnPtr[i].fsStyle & BTNS_SEP) &&
1316 !(infoPtr->dwStyle & CCS_VERT))
1317 cx = (btnPtr[i].iBitmap > 0) ? btnPtr[i].iBitmap : SEPARATOR_WIDTH;
1318 else
1319 cx = infoPtr->nButtonWidth;
1320
1321 /* Two or more adjacent separators form a separator group. */
1322 /* The first separator in a group should be wrapped to the */
1323 /* next row if the previous wrapping is on a button. */
1324 if( bButtonWrap &&
1325 (btnPtr[i].fsStyle & BTNS_SEP) &&
1326 (i + 1 < infoPtr->nNumButtons ) &&
1327 (btnPtr[i + 1].fsStyle & BTNS_SEP) )
1328 {
1329 TRACE("wrap point 1 btn %d style %02x\n", i, btnPtr[i].fsStyle);
1330 btnPtr[i].fsState |= TBSTATE_WRAP;
1331 x = infoPtr->nIndent;
1332 i++;
1333 bButtonWrap = FALSE;
1334 continue;
1335 }
1336
1337 /* The layout makes sure the bitmap is visible, but not the button. */
1338 /* Test added to also wrap after a button that starts a row but */
1339 /* is bigger than the area. - GA 8/01 */
1340 if (( x + cx - (infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2
1341 > infoPtr->nWidth ) ||
1342 ((x == infoPtr->nIndent) && (cx > infoPtr->nWidth)))
1343 {
1344 BOOL bFound = FALSE;
1345
1346 /* If the current button is a separator and not hidden, */
1347 /* go to the next until it reaches a non separator. */
1348 /* Wrap the last separator if it is before a button. */
1349 while( ( ((btnPtr[i].fsStyle & BTNS_SEP) &&
1350 !(btnPtr[i].fsStyle & BTNS_DROPDOWN)) ||
1351 (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
1352 i < infoPtr->nNumButtons )
1353 {
1354 i++;
1355 bFound = TRUE;
1356 }
1357
1358 if( bFound && i < infoPtr->nNumButtons )
1359 {
1360 i--;
1361 TRACE("wrap point 2 btn %d style %02x, x=%d, cx=%d\n",
1362 i, btnPtr[i].fsStyle, x, cx);
1363 btnPtr[i].fsState |= TBSTATE_WRAP;
1364 x = infoPtr->nIndent;
1365 bButtonWrap = FALSE;
1366 continue;
1367 }
1368 else if ( i >= infoPtr->nNumButtons)
1369 break;
1370
1371 /* If the current button is not a separator, find the last */
1372 /* separator and wrap it. */
1373 for ( j = i - 1; j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1374 {
1375 if ((btnPtr[j].fsStyle & BTNS_SEP) &&
1376 !(btnPtr[j].fsState & TBSTATE_HIDDEN))
1377 {
1378 bFound = TRUE;
1379 i = j;
1380 TRACE("wrap point 3 btn %d style %02x, x=%d, cx=%d\n",
1381 i, btnPtr[i].fsStyle, x, cx);
1382 x = infoPtr->nIndent;
1383 btnPtr[j].fsState |= TBSTATE_WRAP;
1384 bButtonWrap = FALSE;
1385 break;
1386 }
1387 }
1388
1389 /* If no separator available for wrapping, wrap one of */
1390 /* non-hidden previous button. */
1391 if (!bFound)
1392 {
1393 for ( j = i - 1;
1394 j >= 0 && !(btnPtr[j].fsState & TBSTATE_WRAP); j--)
1395 {
1396 if (btnPtr[j].fsState & TBSTATE_HIDDEN)
1397 continue;
1398
1399 bFound = TRUE;
1400 i = j;
1401 TRACE("wrap point 4 btn %d style %02x, x=%d, cx=%d\n",
1402 i, btnPtr[i].fsStyle, x, cx);
1403 x = infoPtr->nIndent;
1404 btnPtr[j].fsState |= TBSTATE_WRAP;
1405 bButtonWrap = TRUE;
1406 break;
1407 }
1408 }
1409
1410 /* If all above failed, wrap the current button. */
1411 if (!bFound)
1412 {
1413 TRACE("wrap point 5 btn %d style %02x, x=%d, cx=%d\n",
1414 i, btnPtr[i].fsStyle, x, cx);
1415 btnPtr[i].fsState |= TBSTATE_WRAP;
1416 x = infoPtr->nIndent;
1417 if (btnPtr[i].fsStyle & BTNS_SEP )
1418 bButtonWrap = FALSE;
1419 else
1420 bButtonWrap = TRUE;
1421 }
1422 }
1423 else {
1424 TRACE("wrap point 6 btn %d style %02x, x=%d, cx=%d\n",
1425 i, btnPtr[i].fsStyle, x, cx);
1426 x += cx;
1427 }
1428 }
1429 }
1430
1431
1432 /***********************************************************************
1433 * TOOLBAR_MeasureButton
1434 *
1435 * Calculates the width and height required for a button. Used in
1436 * TOOLBAR_CalcToolbar to set the all-button width and height and also for
1437 * the width of buttons that are autosized.
1438 *
1439 * Note that it would have been rather elegant to use one piece of code for
1440 * both the laying out of the toolbar and for controlling where button parts
1441 * are drawn, but the native control has inconsistencies between the two that
1442 * prevent this from being effectively. These inconsistencies can be seen as
1443 * artefacts where parts of the button appear outside of the bounding button
1444 * rectangle.
1445 *
1446 * There are several cases for the calculation of the button dimensions and
1447 * button part positioning:
1448 *
1449 * List
1450 * ====
1451 *
1452 * With Bitmap:
1453 *
1454 * +--------------------------------------------------------+ ^
1455 * | ^ ^ | |
1456 * | | pad.cy / 2 | centered | |
1457 * | pad.cx/2 + cxedge +--------------+ +------------+ | | DEFPAD_CY +
1458 * |<----------------->| nBitmapWidth | | Text | | | max(nBitmapHeight, szText.cy)
1459 * | |<------------>| | | | |
1460 * | +--------------+ +------------+ | |
1461 * |<-------------------------------------->| | |
1462 * | cxedge + iListGap + nBitmapWidth + 2 |<-----------> | |
1463 * | szText.cx | |
1464 * +--------------------------------------------------------+ -
1465 * <-------------------------------------------------------->
1466 * 2*cxedge + nBitmapWidth + iListGap + szText.cx + pad.cx
1467 *
1468 * Without Bitmap (I_IMAGENONE):
1469 *
1470 * +-----------------------------------+ ^
1471 * | ^ | |
1472 * | | centered | | LISTPAD_CY +
1473 * | +------------+ | | szText.cy
1474 * | | Text | | |
1475 * | | | | |
1476 * | +------------+ | |
1477 * |<----------------->| | |
1478 * | cxedge |<-----------> | |
1479 * | szText.cx | |
1480 * +-----------------------------------+ -
1481 * <----------------------------------->
1482 * szText.cx + pad.cx
1483 *
1484 * Without text:
1485 *
1486 * +--------------------------------------+ ^
1487 * | ^ | |
1488 * | | padding.cy/2 | | DEFPAD_CY +
1489 * | +------------+ | | nBitmapHeight
1490 * | | Bitmap | | |
1491 * | | | | |
1492 * | +------------+ | |
1493 * |<------------------->| | |
1494 * | cxedge + iListGap/2 |<-----------> | |
1495 * | nBitmapWidth | |
1496 * +--------------------------------------+ -
1497 * <-------------------------------------->
1498 * 2*cxedge + nBitmapWidth + iListGap
1499 *
1500 * Non-List
1501 * ========
1502 *
1503 * With bitmap:
1504 *
1505 * +-----------------------------------+ ^
1506 * | ^ | |
1507 * | | pad.cy / 2 | | nBitmapHeight +
1508 * | - | | szText.cy +
1509 * | +------------+ | | DEFPAD_CY + 1
1510 * | centered | Bitmap | | |
1511 * |<----------------->| | | |
1512 * | +------------+ | |
1513 * | ^ | |
1514 * | 1 | | |
1515 * | - | |
1516 * | centered +---------------+ | |
1517 * |<--------------->| Text | | |
1518 * | +---------------+ | |
1519 * +-----------------------------------+ -
1520 * <----------------------------------->
1521 * pad.cx + max(nBitmapWidth, szText.cx)
1522 *
1523 * Without bitmaps (NULL imagelist or ImageList_GetImageCount() = 0):
1524 *
1525 * +---------------------------------------+ ^
1526 * | ^ | |
1527 * | | 2 + pad.cy / 2 | |
1528 * | - | | szText.cy +
1529 * | centered +-----------------+ | | pad.cy + 2
1530 * |<--------------->| Text | | |
1531 * | +-----------------+ | |
1532 * | | |
1533 * +---------------------------------------+ -
1534 * <--------------------------------------->
1535 * 2*cxedge + pad.cx + szText.cx
1536 *
1537 * Without text:
1538 * As for with bitmaps, but with szText.cx zero.
1539 */
1540 static inline SIZE TOOLBAR_MeasureButton(const TOOLBAR_INFO *infoPtr, SIZE sizeString,
1541 BOOL bHasBitmap, BOOL bValidImageList)
1542 {
1543 SIZE sizeButton;
1544 if (infoPtr->dwStyle & TBSTYLE_LIST)
1545 {
1546 /* set button height from bitmap / text height... */
1547 sizeButton.cy = max((bHasBitmap ? infoPtr->nBitmapHeight : 0),
1548 sizeString.cy);
1549
1550 /* ... add on the necessary padding */
1551 if (bValidImageList)
1552 {
1553 if (bHasBitmap)
1554 sizeButton.cy += DEFPAD_CY;
1555 else
1556 sizeButton.cy += LISTPAD_CY;
1557 }
1558 else
1559 sizeButton.cy += infoPtr->szPadding.cy;
1560
1561 /* calculate button width */
1562 sizeButton.cx = 2*GetSystemMetrics(SM_CXEDGE) +
1563 infoPtr->nBitmapWidth + infoPtr->iListGap;
1564 if (sizeString.cx > 0)
1565 sizeButton.cx += sizeString.cx + infoPtr->szPadding.cx;
1566
1567 }
1568 else
1569 {
1570 if (bHasBitmap)
1571 {
1572 sizeButton.cy = infoPtr->nBitmapHeight + DEFPAD_CY;
1573 if (sizeString.cy > 0)
1574 sizeButton.cy += 1 + sizeString.cy;
1575 sizeButton.cx = infoPtr->szPadding.cx +
1576 max(sizeString.cx, infoPtr->nBitmapWidth);
1577 }
1578 else
1579 {
1580 sizeButton.cy = sizeString.cy + infoPtr->szPadding.cy +
1581 NONLIST_NOTEXT_OFFSET;
1582 sizeButton.cx = infoPtr->szPadding.cx +
1583 max(2*GetSystemMetrics(SM_CXEDGE) + sizeString.cx, infoPtr->nBitmapWidth);
1584 }
1585 }
1586 return sizeButton;
1587 }
1588
1589
1590 /***********************************************************************
1591 * TOOLBAR_CalcToolbar
1592 *
1593 * This function calculates button and separator placement. It first
1594 * calculates the button sizes, gets the toolbar window width and then
1595 * calls TOOLBAR_WrapToolbar to determine which buttons we need to wrap
1596 * on. It assigns a new location to each item and sends this location to
1597 * the tooltip window if appropriate. Finally, it updates the rcBound
1598 * rect and calculates the new required toolbar window height.
1599 */
1600 static void
1601 TOOLBAR_CalcToolbar (TOOLBAR_INFO *infoPtr)
1602 {
1603 SIZE sizeString, sizeButton;
1604 BOOL validImageList = FALSE;
1605
1606 TOOLBAR_CalcStrings (infoPtr, &sizeString);
1607
1608 TOOLBAR_DumpToolbar (infoPtr, __LINE__);
1609
1610 if (TOOLBAR_IsValidImageList(infoPtr, 0))
1611 validImageList = TRUE;
1612 sizeButton = TOOLBAR_MeasureButton(infoPtr, sizeString, TRUE, validImageList);
1613 infoPtr->nButtonWidth = sizeButton.cx;
1614 infoPtr->nButtonHeight = sizeButton.cy;
1615 infoPtr->iTopMargin = default_top_margin(infoPtr);
1616
1617 if ( infoPtr->cxMin >= 0 && infoPtr->nButtonWidth < infoPtr->cxMin )
1618 infoPtr->nButtonWidth = infoPtr->cxMin;
1619 if ( infoPtr->cxMax > 0 && infoPtr->nButtonWidth > infoPtr->cxMax )
1620 infoPtr->nButtonWidth = infoPtr->cxMax;
1621
1622 TOOLBAR_LayoutToolbar(infoPtr);
1623 }
1624
1625 static void
1626 TOOLBAR_LayoutToolbar(TOOLBAR_INFO *infoPtr)
1627 {
1628 TBUTTON_INFO *btnPtr;
1629 SIZE sizeButton;
1630 INT i, nRows, nSepRows;
1631 INT x, y, cx, cy;
1632 BOOL bWrap;
1633 BOOL validImageList = TOOLBAR_IsValidImageList(infoPtr, 0);
1634 BOOL hasDropDownArrows = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle);
1635
1636 TOOLBAR_WrapToolbar(infoPtr);
1637
1638 x = infoPtr->nIndent;
1639 y = infoPtr->iTopMargin;
1640 cx = infoPtr->nButtonWidth;
1641 cy = infoPtr->nButtonHeight;
1642
1643 nRows = nSepRows = 0;
1644
1645 infoPtr->rcBound.top = y;
1646 infoPtr->rcBound.left = x;
1647 infoPtr->rcBound.bottom = y + cy;
1648 infoPtr->rcBound.right = x;
1649
1650 btnPtr = infoPtr->buttons;
1651
1652 TRACE("cy=%d\n", cy);
1653
1654 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++ )
1655 {
1656 bWrap = FALSE;
1657 if (btnPtr->fsState & TBSTATE_HIDDEN)
1658 {
1659 SetRectEmpty (&btnPtr->rect);
1660 continue;
1661 }
1662
1663 cy = infoPtr->nButtonHeight;
1664
1665 if (btnPtr->fsStyle & BTNS_SEP) {
1666 if (infoPtr->dwStyle & CCS_VERT) {
1667 cy = (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1668 cx = (btnPtr->cx > 0) ? btnPtr->cx : infoPtr->nButtonWidth;
1669 }
1670 else
1671 cx = (btnPtr->cx > 0) ? btnPtr->cx :
1672 (btnPtr->iBitmap > 0) ? btnPtr->iBitmap : SEPARATOR_WIDTH;
1673 }
1674 else
1675 {
1676 if (btnPtr->cx)
1677 cx = btnPtr->cx;
1678 else if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ||
1679 (btnPtr->fsStyle & BTNS_AUTOSIZE))
1680 {
1681 SIZE sz;
1682 HDC hdc;
1683 HFONT hOldFont;
1684
1685 hdc = GetDC (infoPtr->hwndSelf);
1686 hOldFont = SelectObject (hdc, infoPtr->hFont);
1687
1688 TOOLBAR_MeasureString(infoPtr, btnPtr, hdc, &sz);
1689
1690 SelectObject (hdc, hOldFont);
1691 ReleaseDC (infoPtr->hwndSelf, hdc);
1692
1693 sizeButton = TOOLBAR_MeasureButton(infoPtr, sz,
1694 TOOLBAR_IsValidBitmapIndex(infoPtr, infoPtr->buttons[i].iBitmap),
1695 validImageList);
1696 cx = sizeButton.cx;
1697 }
1698 else
1699 cx = infoPtr->nButtonWidth;
1700
1701 /* if size has been set manually then don't add on extra space
1702 * for the drop down arrow */
1703 if (!btnPtr->cx && hasDropDownArrows &&
1704 ((btnPtr->fsStyle & BTNS_DROPDOWN) || (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)))
1705 cx += DDARROW_WIDTH;
1706 }
1707 if (btnPtr->fsState & TBSTATE_WRAP )
1708 bWrap = TRUE;
1709
1710 SetRect (&btnPtr->rect, x, y, x + cx, y + cy);
1711
1712 if (infoPtr->rcBound.left > x)
1713 infoPtr->rcBound.left = x;
1714 if (infoPtr->rcBound.right < x + cx)
1715 infoPtr->rcBound.right = x + cx;
1716 if (infoPtr->rcBound.bottom < y + cy)
1717 infoPtr->rcBound.bottom = y + cy;
1718
1719 TOOLBAR_TooltipSetRect(infoPtr, btnPtr);
1720
1721 /* btnPtr->nRow is zero based. The space between the rows is */
1722 /* also considered as a row. */
1723 btnPtr->nRow = nRows + nSepRows;
1724
1725 TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
1726 i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
1727 x, y, x+cx, y+cy);
1728
1729 if( bWrap )
1730 {
1731 if ( !(btnPtr->fsStyle & BTNS_SEP) )
1732 y += cy;
1733 else
1734 {
1735 if ( !(infoPtr->dwStyle & CCS_VERT))
1736 y += cy + ( (btnPtr->cx > 0 ) ?
1737 btnPtr->cx : SEPARATOR_WIDTH) * 2 /3;
1738 else
1739 y += cy;
1740
1741 /* nSepRows is used to calculate the extra height following */
1742 /* the last row. */
1743 nSepRows++;
1744 }
1745 x = infoPtr->nIndent;
1746
1747 /* Increment row number unless this is the last button */
1748 /* and it has Wrap set. */
1749 if (i != infoPtr->nNumButtons-1)
1750 nRows++;
1751 }
1752 else
1753 x += cx;
1754 }
1755
1756 /* infoPtr->nRows is the number of rows on the toolbar */
1757 infoPtr->nRows = nRows + nSepRows + 1;
1758
1759 TRACE("toolbar button width %d\n", infoPtr->nButtonWidth);
1760 }
1761
1762
1763 static INT
1764 TOOLBAR_InternalHitTest (const TOOLBAR_INFO *infoPtr, const POINT *lpPt, BOOL *button)
1765 {
1766 TBUTTON_INFO *btnPtr;
1767 INT i;
1768
1769 if (button)
1770 *button = FALSE;
1771
1772 btnPtr = infoPtr->buttons;
1773 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1774 if (btnPtr->fsState & TBSTATE_HIDDEN)
1775 continue;
1776
1777 if (btnPtr->fsStyle & BTNS_SEP) {
1778 if (PtInRect (&btnPtr->rect, *lpPt)) {
1779 TRACE(" ON SEPARATOR %d!\n", i);
1780 return -i;
1781 }
1782 }
1783 else {
1784 if (PtInRect (&btnPtr->rect, *lpPt)) {
1785 TRACE(" ON BUTTON %d!\n", i);
1786 if (button)
1787 *button = TRUE;
1788 return i;
1789 }
1790 }
1791 }
1792
1793 TRACE(" NOWHERE!\n");
1794 return TOOLBAR_NOWHERE;
1795 }
1796
1797
1798 /* worker for TB_ADDBUTTONS and TB_INSERTBUTTON */
1799 static BOOL
1800 TOOLBAR_InternalInsertButtonsT(TOOLBAR_INFO *infoPtr, INT iIndex, UINT nAddButtons, const TBBUTTON *lpTbb, BOOL fUnicode)
1801 {
1802 INT nOldButtons, nNewButtons, iButton;
1803 BOOL fHasString = FALSE;
1804
1805 if (iIndex < 0) /* iIndex can be negative, what means adding at the end */
1806 iIndex = infoPtr->nNumButtons;
1807
1808 nOldButtons = infoPtr->nNumButtons;
1809 nNewButtons = nOldButtons + nAddButtons;
1810
1811 infoPtr->buttons = ReAlloc(infoPtr->buttons, sizeof(TBUTTON_INFO)*nNewButtons);
1812 memmove(&infoPtr->buttons[iIndex + nAddButtons], &infoPtr->buttons[iIndex],
1813 (nOldButtons - iIndex) * sizeof(TBUTTON_INFO));
1814 infoPtr->nNumButtons += nAddButtons;
1815
1816 /* insert new buttons data */
1817 for (iButton = 0; iButton < nAddButtons; iButton++) {
1818 TBUTTON_INFO *btnPtr = &infoPtr->buttons[iIndex + iButton];
1819
1820 TOOLBAR_DumpTBButton(lpTbb + iButton, fUnicode);
1821
1822 ZeroMemory(btnPtr, sizeof(*btnPtr));
1823
1824 btnPtr->iBitmap = lpTbb[iButton].iBitmap;
1825 btnPtr->idCommand = lpTbb[iButton].idCommand;
1826 btnPtr->fsState = lpTbb[iButton].fsState;
1827 btnPtr->fsStyle = lpTbb[iButton].fsStyle;
1828 btnPtr->dwData = lpTbb[iButton].dwData;
1829 if (btnPtr->fsStyle & BTNS_SEP)
1830 btnPtr->iString = -1;
1831 else if(!IS_INTRESOURCE(lpTbb[iButton].iString) && lpTbb[iButton].iString != -1)
1832 {
1833 if (fUnicode)
1834 Str_SetPtrW((LPWSTR*)&btnPtr->iString, (LPWSTR)lpTbb[iButton].iString );
1835 else
1836 Str_SetPtrAtoW((LPWSTR*)&btnPtr->iString, (LPSTR)lpTbb[iButton].iString);
1837 fHasString = TRUE;
1838 }
1839 else
1840 btnPtr->iString = lpTbb[iButton].iString;
1841
1842 TOOLBAR_TooltipAddTool(infoPtr, btnPtr);
1843 }
1844
1845 if (infoPtr->nNumStrings > 0 || fHasString)
1846 TOOLBAR_CalcToolbar(infoPtr);
1847 else
1848 TOOLBAR_LayoutToolbar(infoPtr);
1849 TOOLBAR_AutoSize(infoPtr);
1850
1851 TOOLBAR_DumpToolbar(infoPtr, __LINE__);
1852 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1853 return TRUE;
1854 }
1855
1856
1857 static INT
1858 TOOLBAR_GetButtonIndex (const TOOLBAR_INFO *infoPtr, INT idCommand, BOOL CommandIsIndex)
1859 {
1860 TBUTTON_INFO *btnPtr;
1861 INT i;
1862
1863 if (CommandIsIndex) {
1864 TRACE("command is really index command=%d\n", idCommand);
1865 if (idCommand >= infoPtr->nNumButtons) return -1;
1866 return idCommand;
1867 }
1868 btnPtr = infoPtr->buttons;
1869 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++) {
1870 if (btnPtr->idCommand == idCommand) {
1871 TRACE("command=%d index=%d\n", idCommand, i);
1872 return i;
1873 }
1874 }
1875 TRACE("no index found for command=%d\n", idCommand);
1876 return -1;
1877 }
1878
1879
1880 static INT
1881 TOOLBAR_GetCheckedGroupButtonIndex (const TOOLBAR_INFO *infoPtr, INT nIndex)
1882 {
1883 TBUTTON_INFO *btnPtr;
1884 INT nRunIndex;
1885
1886 if ((nIndex < 0) || (nIndex > infoPtr->nNumButtons))
1887 return -1;
1888
1889 /* check index button */
1890 btnPtr = &infoPtr->buttons[nIndex];
1891 if ((btnPtr->fsStyle & BTNS_CHECKGROUP) == BTNS_CHECKGROUP) {
1892 if (btnPtr->fsState & TBSTATE_CHECKED)
1893 return nIndex;
1894 }
1895
1896 /* check previous buttons */
1897 nRunIndex = nIndex - 1;
1898 while (nRunIndex >= 0) {
1899 btnPtr = &infoPtr->buttons[nRunIndex];
1900 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1901 if (btnPtr->fsState & TBSTATE_CHECKED)
1902 return nRunIndex;
1903 }
1904 else
1905 break;
1906 nRunIndex--;
1907 }
1908
1909 /* check next buttons */
1910 nRunIndex = nIndex + 1;
1911 while (nRunIndex < infoPtr->nNumButtons) {
1912 btnPtr = &infoPtr->buttons[nRunIndex];
1913 if ((btnPtr->fsStyle & BTNS_GROUP) == BTNS_GROUP) {
1914 if (btnPtr->fsState & TBSTATE_CHECKED)
1915 return nRunIndex;
1916 }
1917 else
1918 break;
1919 nRunIndex++;
1920 }
1921
1922 return -1;
1923 }
1924
1925
1926 static VOID
1927 TOOLBAR_RelayEvent (HWND hwndTip, HWND hwndMsg, UINT uMsg,
1928 WPARAM wParam, LPARAM lParam)
1929 {
1930 MSG msg;
1931
1932 msg.hwnd = hwndMsg;
1933 msg.message = uMsg;
1934 msg.wParam = wParam;
1935 msg.lParam = lParam;
1936 msg.time = GetMessageTime ();
1937 msg.pt.x = (short)LOWORD(GetMessagePos ());
1938 msg.pt.y = (short)HIWORD(GetMessagePos ());
1939
1940 SendMessageW (hwndTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
1941 }
1942
1943 static void
1944 TOOLBAR_TooltipAddTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1945 {
1946 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP)) {
1947 TTTOOLINFOW ti;
1948
1949 ZeroMemory(&ti, sizeof(TTTOOLINFOW));
1950 ti.cbSize = sizeof (TTTOOLINFOW);
1951 ti.hwnd = infoPtr->hwndSelf;
1952 ti.uId = button->idCommand;
1953 ti.hinst = 0;
1954 ti.lpszText = LPSTR_TEXTCALLBACKW;
1955 /* ti.lParam = random value from the stack? */
1956
1957 SendMessageW(infoPtr->hwndToolTip, TTM_ADDTOOLW,
1958 0, (LPARAM)&ti);
1959 }
1960 }
1961
1962 static void
1963 TOOLBAR_TooltipDelTool(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1964 {
1965 if ((infoPtr->hwndToolTip) && !(button->fsStyle & BTNS_SEP)) {
1966 TTTOOLINFOW ti;
1967
1968 ZeroMemory(&ti, sizeof(ti));
1969 ti.cbSize = sizeof(ti);
1970 ti.hwnd = infoPtr->hwndSelf;
1971 ti.uId = button->idCommand;
1972
1973 SendMessageW(infoPtr->hwndToolTip, TTM_DELTOOLW, 0, (LPARAM)&ti);
1974 }
1975 }
1976
1977 static void TOOLBAR_TooltipSetRect(const TOOLBAR_INFO *infoPtr, const TBUTTON_INFO *button)
1978 {
1979 /* Set the toolTip only for non-hidden, non-separator button */
1980 if (infoPtr->hwndToolTip && !(button->fsStyle & BTNS_SEP))
1981 {
1982 TTTOOLINFOW ti;
1983
1984 ZeroMemory(&ti, sizeof(ti));
1985 ti.cbSize = sizeof(ti);
1986 ti.hwnd = infoPtr->hwndSelf;
1987 ti.uId = button->idCommand;
1988 ti.rect = button->rect;
1989 SendMessageW(infoPtr->hwndToolTip, TTM_NEWTOOLRECTW, 0, (LPARAM)&ti);
1990 }
1991 }
1992
1993 /* Creates the tooltip control */
1994 static void
1995 TOOLBAR_TooltipCreateControl(TOOLBAR_INFO *infoPtr)
1996 {
1997 int i;
1998 NMTOOLTIPSCREATED nmttc;
1999
2000 infoPtr->hwndToolTip = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, WS_POPUP,
2001 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2002 infoPtr->hwndSelf, 0, 0, 0);
2003
2004 if (!infoPtr->hwndToolTip)
2005 return;
2006
2007 /* Send NM_TOOLTIPSCREATED notification */
2008 nmttc.hwndToolTips = infoPtr->hwndToolTip;
2009 TOOLBAR_SendNotify(&nmttc.hdr, infoPtr, NM_TOOLTIPSCREATED);
2010
2011 for (i = 0; i < infoPtr->nNumButtons; i++)
2012 {
2013 TOOLBAR_TooltipAddTool(infoPtr, &infoPtr->buttons[i]);
2014 TOOLBAR_TooltipSetRect(infoPtr, &infoPtr->buttons[i]);
2015 }
2016 }
2017
2018 /* keeps available button list box sorted by button id */
2019 static void TOOLBAR_Cust_InsertAvailButton(HWND hwnd, PCUSTOMBUTTON btnInfoNew)
2020 {
2021 int i;
2022 int count;
2023 PCUSTOMBUTTON btnInfo;
2024 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2025
2026 TRACE("button %s, idCommand %d\n", debugstr_w(btnInfoNew->text), btnInfoNew->btn.idCommand);
2027
2028 count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2029
2030 /* position 0 is always separator */
2031 for (i = 1; i < count; i++)
2032 {
2033 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, i, 0);
2034 if (btnInfoNew->btn.idCommand < btnInfo->btn.idCommand)
2035 {
2036 i = SendMessageW(hwndAvail, LB_INSERTSTRING, i, 0);
2037 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2038 return;
2039 }
2040 }
2041 /* id higher than all others add to end */
2042 i = SendMessageW(hwndAvail, LB_ADDSTRING, 0, 0);
2043 SendMessageW(hwndAvail, LB_SETITEMDATA, i, (LPARAM)btnInfoNew);
2044 }
2045
2046 static void TOOLBAR_Cust_MoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexFrom, INT nIndexTo)
2047 {
2048 NMTOOLBARW nmtb;
2049
2050 TRACE("index from %d, index to %d\n", nIndexFrom, nIndexTo);
2051
2052 if (nIndexFrom == nIndexTo)
2053 return;
2054
2055 /* MSDN states that iItem is the index of the button, rather than the
2056 * command ID as used by every other NMTOOLBAR notification */
2057 nmtb.iItem = nIndexFrom;
2058 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2059 {
2060 PCUSTOMBUTTON btnInfo;
2061 NMHDR hdr;
2062 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2063 int count = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2064
2065 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, nIndexFrom, 0);
2066
2067 SendMessageW(hwndList, LB_DELETESTRING, nIndexFrom, 0);
2068 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2069 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2070 SendMessageW(hwndList, LB_SETCURSEL, nIndexTo, 0);
2071
2072 if (nIndexTo <= 0)
2073 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), FALSE);
2074 else
2075 EnableWindow(GetDlgItem(hwnd,IDC_MOVEUP_BTN), TRUE);
2076
2077 /* last item is always separator, so -2 instead of -1 */
2078 if (nIndexTo >= (count - 2))
2079 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), FALSE);
2080 else
2081 EnableWindow(GetDlgItem(hwnd,IDC_MOVEDN_BTN), TRUE);
2082
2083 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, nIndexFrom, 0);
2084 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2085
2086 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2087 }
2088 }
2089
2090 static void TOOLBAR_Cust_AddButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT nIndexAvail, INT nIndexTo)
2091 {
2092 NMTOOLBARW nmtb;
2093
2094 TRACE("Add: nIndexAvail %d, nIndexTo %d\n", nIndexAvail, nIndexTo);
2095
2096 /* MSDN states that iItem is the index of the button, rather than the
2097 * command ID as used by every other NMTOOLBAR notification */
2098 nmtb.iItem = nIndexAvail;
2099 if (TOOLBAR_SendNotify(&nmtb.hdr, custInfo->tbInfo, TBN_QUERYINSERT))
2100 {
2101 PCUSTOMBUTTON btnInfo;
2102 NMHDR hdr;
2103 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2104 HWND hwndAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2105 int count = SendMessageW(hwndAvail, LB_GETCOUNT, 0, 0);
2106
2107 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndAvail, LB_GETITEMDATA, nIndexAvail, 0);
2108
2109 if (nIndexAvail != 0) /* index == 0 indicates separator */
2110 {
2111 /* remove from 'available buttons' list */
2112 SendMessageW(hwndAvail, LB_DELETESTRING, nIndexAvail, 0);
2113 if (nIndexAvail == count-1)
2114 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail-1 , 0);
2115 else
2116 SendMessageW(hwndAvail, LB_SETCURSEL, nIndexAvail , 0);
2117 }
2118 else
2119 {
2120 PCUSTOMBUTTON btnNew;
2121
2122 /* duplicate 'separator' button */
2123 btnNew = Alloc(sizeof(CUSTOMBUTTON));
2124 *btnNew = *btnInfo;
2125 btnInfo = btnNew;
2126 }
2127
2128 /* insert into 'toolbar button' list */
2129 SendMessageW(hwndList, LB_INSERTSTRING, nIndexTo, 0);
2130 SendMessageW(hwndList, LB_SETITEMDATA, nIndexTo, (LPARAM)btnInfo);
2131
2132 SendMessageW(custInfo->tbHwnd, TB_INSERTBUTTONW, nIndexTo, (LPARAM)&(btnInfo->btn));
2133
2134 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2135 }
2136 }
2137
2138 static void TOOLBAR_Cust_RemoveButton(const CUSTDLG_INFO *custInfo, HWND hwnd, INT index)
2139 {
2140 PCUSTOMBUTTON btnInfo;
2141 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2142
2143 TRACE("Remove: index %d\n", index);
2144
2145 btnInfo = (PCUSTOMBUTTON)SendMessageW(hwndList, LB_GETITEMDATA, index, 0);
2146
2147 /* send TBN_QUERYDELETE notification */
2148 if (TOOLBAR_IsButtonRemovable(custInfo->tbInfo, index, btnInfo))
2149 {
2150 NMHDR hdr;
2151
2152 SendMessageW(hwndList, LB_DELETESTRING, index, 0);
2153 SendMessageW(hwndList, LB_SETCURSEL, index , 0);
2154
2155 SendMessageW(custInfo->tbHwnd, TB_DELETEBUTTON, index, 0);
2156
2157 /* insert into 'available button' list */
2158 if (!(btnInfo->btn.fsStyle & BTNS_SEP))
2159 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2160 else
2161 Free(btnInfo);
2162
2163 TOOLBAR_SendNotify(&hdr, custInfo->tbInfo, TBN_TOOLBARCHANGE);
2164 }
2165 }
2166
2167 /* drag list notification function for toolbar buttons list box */
2168 static LRESULT TOOLBAR_Cust_ToolbarDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2169 const DRAGLISTINFO *pDLI)
2170 {
2171 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2172 switch (pDLI->uNotification)
2173 {
2174 case DL_BEGINDRAG:
2175 {
2176 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2177 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2178 /* no dragging for last item (separator) */
2179 if (nCurrentItem >= (nCount - 1)) return FALSE;
2180 return TRUE;
2181 }
2182 case DL_DRAGGING:
2183 {
2184 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2185 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2186 /* no dragging past last item (separator) */
2187 if ((nCurrentItem >= 0) && (nCurrentItem < (nCount - 1)))
2188 {
2189 DrawInsert(hwnd, hwndList, nCurrentItem);
2190 /* FIXME: native uses "move button" cursor */
2191 return DL_COPYCURSOR;
2192 }
2193
2194 /* not over toolbar buttons list */
2195 if (nCurrentItem < 0)
2196 {
2197 POINT ptWindow = pDLI->ptCursor;
2198 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2199 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2200 /* over available buttons list? */
2201 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2202 /* FIXME: native uses "move button" cursor */
2203 return DL_COPYCURSOR;
2204 }
2205 /* clear drag arrow */
2206 DrawInsert(hwnd, hwndList, -1);
2207 return DL_STOPCURSOR;
2208 }
2209 case DL_DROPPED:
2210 {
2211 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2212 INT nIndexFrom = SendMessageW(hwndList, LB_GETCURSEL, 0, 0);
2213 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2214 if ((nIndexTo >= 0) && (nIndexTo < (nCount - 1)))
2215 {
2216 /* clear drag arrow */
2217 DrawInsert(hwnd, hwndList, -1);
2218 /* move item */
2219 TOOLBAR_Cust_MoveButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2220 }
2221 /* not over toolbar buttons list */
2222 if (nIndexTo < 0)
2223 {
2224 POINT ptWindow = pDLI->ptCursor;
2225 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2226 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2227 /* over available buttons list? */
2228 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2229 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, nIndexFrom);
2230 }
2231 break;
2232 }
2233 case DL_CANCELDRAG:
2234 /* Clear drag arrow */
2235 DrawInsert(hwnd, hwndList, -1);
2236 break;
2237 }
2238
2239 return 0;
2240 }
2241
2242 /* drag list notification function for available buttons list box */
2243 static LRESULT TOOLBAR_Cust_AvailDragListNotification(const CUSTDLG_INFO *custInfo, HWND hwnd,
2244 const DRAGLISTINFO *pDLI)
2245 {
2246 HWND hwndList = GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX);
2247 switch (pDLI->uNotification)
2248 {
2249 case DL_BEGINDRAG:
2250 return TRUE;
2251 case DL_DRAGGING:
2252 {
2253 INT nCurrentItem = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2254 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2255 /* no dragging past last item (separator) */
2256 if ((nCurrentItem >= 0) && (nCurrentItem < nCount))
2257 {
2258 DrawInsert(hwnd, hwndList, nCurrentItem);
2259 /* FIXME: native uses "move button" cursor */
2260 return DL_COPYCURSOR;
2261 }
2262
2263 /* not over toolbar buttons list */
2264 if (nCurrentItem < 0)
2265 {
2266 POINT ptWindow = pDLI->ptCursor;
2267 HWND hwndListAvail = GetDlgItem(hwnd, IDC_AVAILBTN_LBOX);
2268 MapWindowPoints(NULL, hwnd, &ptWindow, 1);
2269 /* over available buttons list? */
2270 if (ChildWindowFromPoint(hwnd, ptWindow) == hwndListAvail)
2271 /* FIXME: native uses "move button" cursor */
2272 return DL_COPYCURSOR;
2273 }
2274 /* clear drag arrow */
2275 DrawInsert(hwnd, hwndList, -1);
2276 return DL_STOPCURSOR;
2277 }
2278 case DL_DROPPED:
2279 {
2280 INT nIndexTo = LBItemFromPt(hwndList, pDLI->ptCursor, TRUE);
2281 INT nCount = SendMessageW(hwndList, LB_GETCOUNT, 0, 0);
2282 INT nIndexFrom = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2283 if ((nIndexTo >= 0) && (nIndexTo < nCount))
2284 {
2285 /* clear drag arrow */
2286 DrawInsert(hwnd, hwndList, -1);
2287 /* add item */
2288 TOOLBAR_Cust_AddButton(custInfo, hwnd, nIndexFrom, nIndexTo);
2289 }
2290 }
2291 case DL_CANCELDRAG:
2292 /* Clear drag arrow */
2293 DrawInsert(hwnd, hwndList, -1);
2294 break;
2295 }
2296 return 0;
2297 }
2298
2299 extern UINT uDragListMessage DECLSPEC_HIDDEN;
2300
2301 /***********************************************************************
2302 * TOOLBAR_CustomizeDialogProc
2303 * This function implements the toolbar customization dialog.
2304 */
2305 static INT_PTR CALLBACK
2306 TOOLBAR_CustomizeDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2307 {
2308 PCUSTDLG_INFO custInfo = (PCUSTDLG_INFO)GetWindowLongPtrW (hwnd, DWLP_USER);
2309 PCUSTOMBUTTON btnInfo;
2310 NMTOOLBARA nmtb;
2311 TOOLBAR_INFO *infoPtr = custInfo ? custInfo->tbInfo : NULL;
2312
2313 switch (uMsg)
2314 {
2315 case WM_INITDIALOG:
2316 custInfo = (PCUSTDLG_INFO)lParam;
2317 SetWindowLongPtrW (hwnd, DWLP_USER, (LONG_PTR)custInfo);
2318
2319 if (custInfo)
2320 {
2321 WCHAR Buffer[256];
2322 int i = 0;
2323 int index;
2324 NMTBINITCUSTOMIZE nmtbic;
2325
2326 infoPtr = custInfo->tbInfo;
2327
2328 /* send TBN_QUERYINSERT notification */
2329 nmtb.iItem = custInfo->tbInfo->nNumButtons;
2330
2331 if (!TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT))
2332 return FALSE;
2333
2334 nmtbic.hwndDialog = hwnd;
2335 /* Send TBN_INITCUSTOMIZE notification */
2336 if (TOOLBAR_SendNotify (&nmtbic.hdr, infoPtr, TBN_INITCUSTOMIZE) ==
2337 TBNRF_HIDEHELP)
2338 {
2339 TRACE("TBNRF_HIDEHELP requested\n");
2340 ShowWindow(GetDlgItem(hwnd, IDC_HELP_BTN), SW_HIDE);
2341 }
2342
2343 /* add items to 'toolbar buttons' list and check if removable */
2344 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++)
2345 {
2346 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2347 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2348 btnInfo->btn.fsStyle = BTNS_SEP;
2349 btnInfo->bVirtual = FALSE;
2350 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2351
2352 /* send TBN_QUERYDELETE notification */
2353 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo);
2354
2355 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0);
2356 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2357 }
2358
2359 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2360
2361 /* insert separator button into 'available buttons' list */
2362 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2363 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2364 btnInfo->btn.fsStyle = BTNS_SEP;
2365 btnInfo->bVirtual = FALSE;
2366 btnInfo->bRemovable = TRUE;
2367 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2368 index = (int)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2369 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2370
2371 /* insert all buttons into dsa */
2372 for (i = 0;; i++)
2373 {
2374 /* send TBN_GETBUTTONINFO notification */
2375 NMTOOLBARW nmtb;
2376 nmtb.iItem = i;
2377 nmtb.pszText = Buffer;
2378 nmtb.cchText = 256;
2379
2380 /* Clear previous button's text */
2381 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR));
2382
2383 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb))
2384 break;
2385
2386 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%ld) %s\n",
2387 nmtb.tbButton.fsStyle, i,
2388 nmtb.tbButton.idCommand,
2389 nmtb.tbButton.iString,
2390 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString])
2391 : "");
2392
2393 /* insert button into the appropriate list */
2394 index = TOOLBAR_GetButtonIndex (custInfo->tbInfo, nmtb.tbButton.idCommand, FALSE);
2395 if (index == -1)
2396 {
2397 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2398 btnInfo->bVirtual = FALSE;
2399 btnInfo->bRemovable = TRUE;
2400 }
2401 else
2402 {
2403 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd,
2404 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2405 }
2406
2407 btnInfo->btn = nmtb.tbButton;
2408 if (!(nmtb.tbButton.fsStyle & BTNS_SEP))
2409 {
2410 if (lstrlenW(nmtb.pszText))
2411 lstrcpyW(btnInfo->text, nmtb.pszText);
2412 else if (nmtb.tbButton.iString >= 0 &&
2413 nmtb.tbButton.iString < infoPtr->nNumStrings)
2414 {
2415 lstrcpyW(btnInfo->text,
2416 infoPtr->strings[nmtb.tbButton.iString]);
2417 }
2418 }
2419
2420 if (index == -1)
2421 TOOLBAR_Cust_InsertAvailButton(hwnd, btnInfo);
2422 }
2423
2424 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMHEIGHT, 0, infoPtr->nBitmapHeight + 8);
2425
2426 /* select first item in the 'available' list */
2427 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETCURSEL, 0, 0);
2428
2429 /* append 'virtual' separator button to the 'toolbar buttons' list */
2430 btnInfo = Alloc(sizeof(CUSTOMBUTTON));
2431 memset (&btnInfo->btn, 0, sizeof(TBBUTTON));
2432 btnInfo->btn.fsStyle = BTNS_SEP;
2433 btnInfo->bVirtual = TRUE;
2434 btnInfo->bRemovable = FALSE;
2435 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);
2436 index = (int)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo);
2437 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo);
2438
2439 /* select last item in the 'toolbar' list */
2440 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETCURSEL, index, 0);
2441 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETTOPINDEX, index, 0);
2442
2443 MakeDragList(GetDlgItem(hwnd, IDC_TOOLBARBTN_LBOX));
2444 MakeDragList(GetDlgItem(hwnd, IDC_AVAILBTN_LBOX));
2445
2446 /* set focus and disable buttons */
2447 PostMessageW (hwnd, WM_USER, 0, 0);
2448 }
2449 return TRUE;
2450
2451 case WM_USER:
2452 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2453 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2454 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), FALSE);
2455 SetFocus (GetDlgItem (hwnd, IDC_TOOLBARBTN_LBOX));
2456 return TRUE;
2457
2458 case WM_CLOSE:
2459 EndDialog(hwnd, FALSE);
2460 return TRUE;
2461
2462 case WM_COMMAND:
2463 switch (LOWORD(wParam))
2464 {
2465 case IDC_TOOLBARBTN_LBOX:
2466 if (HIWORD(wParam) == LBN_SELCHANGE)
2467 {
2468 PCUSTOMBUTTON btnInfo;
2469 NMTOOLBARA nmtb;
2470 int count;
2471 int index;
2472
2473 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2474 index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2475
2476 /* send TBN_QUERYINSERT notification */
2477 nmtb.iItem = index;
2478 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYINSERT);
2479
2480 /* get list box item */
2481 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0);
2482
2483 if (index == (count - 1))
2484 {
2485 /* last item (virtual separator) */
2486 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2487 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2488 }
2489 else if (index == (count - 2))
2490 {
2491 /* second last item (last non-virtual item) */
2492 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2493 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), FALSE);
2494 }
2495 else if (index == 0)
2496 {
2497 /* first item */
2498 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), FALSE);
2499 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2500 }
2501 else
2502 {
2503 EnableWindow (GetDlgItem (hwnd,IDC_MOVEUP_BTN), TRUE);
2504 EnableWindow (GetDlgItem (hwnd,IDC_MOVEDN_BTN), TRUE);
2505 }
2506
2507 EnableWindow (GetDlgItem (hwnd,IDC_REMOVE_BTN), btnInfo->bRemovable);
2508 }
2509 break;
2510
2511 case IDC_MOVEUP_BTN:
2512 {
2513 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2514 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index-1);
2515 }
2516 break;
2517
2518 case IDC_MOVEDN_BTN: /* move down */
2519 {
2520 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2521 TOOLBAR_Cust_MoveButton(custInfo, hwnd, index, index+1);
2522 }
2523 break;
2524
2525 case IDC_REMOVE_BTN: /* remove button */
2526 {
2527 int index = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2528
2529 if (LB_ERR == index)
2530 break;
2531
2532 TOOLBAR_Cust_RemoveButton(custInfo, hwnd, index);
2533 }
2534 break;
2535 case IDC_HELP_BTN:
2536 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_CUSTHELP);
2537 break;
2538 case IDC_RESET_BTN:
2539 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_RESET);
2540 break;
2541
2542 case IDOK: /* Add button */
2543 {
2544 int index;
2545 int indexto;
2546
2547 index = SendDlgItemMessageW(hwnd, IDC_AVAILBTN_LBOX, LB_GETCURSEL, 0, 0);
2548 indexto = SendDlgItemMessageW(hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0);
2549
2550 TOOLBAR_Cust_AddButton(custInfo, hwnd, index, indexto);
2551 }
2552 break;
2553
2554 case IDCANCEL:
2555 EndDialog(hwnd, FALSE);
2556 break;
2557 }
2558 return TRUE;
2559
2560 case WM_DESTROY:
2561 {
2562 int count;
2563 int i;
2564
2565 /* delete items from 'toolbar buttons' listbox*/
2566 count = SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCOUNT, 0, 0);
2567 for (i = 0; i < count; i++)
2568 {
2569 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, i, 0);
2570 Free(btnInfo);
2571 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, 0, 0);
2572 }
2573 SendDlgItemMessageW (hwnd, IDC_TOOLBARBTN_LBOX, LB_RESETCONTENT, 0, 0);
2574
2575
2576 /* delete items from 'available buttons' listbox*/
2577 count = SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETCOUNT, 0, 0);
2578 for (i = 0; i < count; i++)
2579 {
2580 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_GETITEMDATA, i, 0);
2581 Free(btnInfo);
2582 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, i, 0);
2583 }
2584 SendDlgItemMessageW (hwnd, IDC_AVAILBTN_LBOX, LB_RESETCONTENT, 0, 0);
2585 }
2586 return TRUE;
2587
2588 case WM_DRAWITEM:
2589 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2590 {
2591 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
2592 RECT rcButton;
2593 RECT rcText;
2594 HPEN hPen, hOldPen;
2595 HBRUSH hOldBrush;
2596 COLORREF oldText = 0;
2597 COLORREF oldBk = 0;
2598
2599 /* get item data */
2600 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageW (hwnd, wParam, LB_GETITEMDATA, lpdis->itemID, 0);
2601 if (btnInfo == NULL)
2602 {
2603 FIXME("btnInfo invalid!\n");
2604 return TRUE;
2605 }
2606
2607 /* set colors and select objects */
2608 oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2609 if (btnInfo->bVirtual)
2610 oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
2611 else
2612 oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
2613 hPen = CreatePen( PS_SOLID, 1,
2614 (lpdis->itemState & ODS_SELECTED)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
2615 hOldPen = SelectObject (lpdis->hDC, hPen );
2616 hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
2617
2618 /* fill background rectangle */
2619 Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
2620 lpdis->rcItem.right, lpdis->rcItem.bottom);
2621
2622 /* calculate button and text rectangles */
2623 CopyRect (&rcButton, &lpdis->rcItem);
2624 InflateRect (&rcButton, -1, -1);
2625 CopyRect (&rcText, &rcButton);
2626 rcButton.right = rcButton.left + custInfo->tbInfo->nBitmapWidth + 6;
2627 rcText.left = rcButton.right + 2;
2628
2629 /* draw focus rectangle */
2630 if (lpdis->itemState & ODS_FOCUS)
2631 DrawFocusRect (lpdis->hDC, &lpdis->rcItem);
2632
2633 /* draw button */
2634 if (!(infoPtr->dwStyle & TBSTYLE_FLAT))
2635 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT);
2636
2637 /* draw image and text */
2638 if ((btnInfo->btn.fsStyle & BTNS_SEP) == 0) {
2639 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr,
2640 btnInfo->btn.iBitmap));
2641 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap),
2642 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL);
2643 }
2644 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText,
2645 DT_LEFT | DT_VCENTER | DT_SINGLELINE);
2646
2647 /* delete objects and reset colors */
2648 SelectObject (lpdis->hDC, hOldBrush);
2649 SelectObject (lpdis->hDC, hOldPen);
2650 SetBkColor (lpdis->hDC, oldBk);
2651 SetTextColor (lpdis->hDC, oldText);
2652 DeleteObject( hPen );
2653 return TRUE;
2654 }
2655 return FALSE;
2656
2657 case WM_MEASUREITEM:
2658 if (wParam == IDC_AVAILBTN_LBOX || wParam == IDC_TOOLBARBTN_LBOX)
2659 {
2660 MEASUREITEMSTRUCT *lpmis = (MEASUREITEMSTRUCT*)lParam;
2661
2662 lpmis->itemHeight = 15 + 8; /* default height */
2663
2664 return TRUE;
2665 }
2666 return FALSE;
2667
2668 default:
2669 if (uDragListMessage && (uMsg == uDragListMessage))
2670 {
2671 if (wParam == IDC_TOOLBARBTN_LBOX)
2672 {
2673 LRESULT res = TOOLBAR_Cust_ToolbarDragListNotification(
2674 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2675 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2676 return TRUE;
2677 }
2678 else if (wParam == IDC_AVAILBTN_LBOX)
2679 {
2680 LRESULT res = TOOLBAR_Cust_AvailDragListNotification(
2681 custInfo, hwnd, (DRAGLISTINFO *)lParam);
2682 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, res);
2683 return TRUE;
2684 }
2685 }
2686 return FALSE;
2687 }
2688 }
2689
2690 static BOOL
2691 TOOLBAR_AddBitmapToImageList(TOOLBAR_INFO *infoPtr, HIMAGELIST himlDef, const TBITMAP_INFO *bitmap)
2692 {
2693 HBITMAP hbmLoad;
2694 INT nCountBefore = ImageList_GetImageCount(himlDef);
2695 INT nCountAfter;
2696 INT cxIcon, cyIcon;
2697 INT nAdded;
2698 INT nIndex;
2699
2700 TRACE("adding hInst=%p nID=%d nButtons=%d\n", bitmap->hInst, bitmap->nID, bitmap->nButtons);
2701 /* Add bitmaps to the default image list */
2702 if (bitmap->hInst == NULL) /* a handle was passed */
2703 hbmLoad = CopyImage(ULongToHandle(bitmap->nID), IMAGE_BITMAP, 0, 0, 0);
2704 else if (bitmap->hInst == COMCTL32_hModule)
2705 hbmLoad = LoadImageW( bitmap->hInst, MAKEINTRESOURCEW(bitmap->nID),
2706 IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
2707 else
2708 hbmLoad = CreateMappedBitmap(bitmap->hInst, bitmap->nID, 0, NULL, 0);
2709
2710 /* enlarge the bitmap if needed */
2711 ImageList_GetIconSize(himlDef, &cxIcon, &cyIcon);
2712 if (bitmap->hInst != COMCTL32_hModule)
2713 COMCTL32_EnsureBitmapSize(&hbmLoad, cxIcon*(INT)bitmap->nButtons, cyIcon, comctl32_color.clrBtnFace);
2714
2715 nIndex = ImageList_AddMasked(himlDef, hbmLoad, comctl32_color.clrBtnFace);
2716 DeleteObject(hbmLoad);
2717 if (nIndex == -1)
2718 return FALSE;
2719
2720 nCountAfter = ImageList_GetImageCount(himlDef);
2721 nAdded = nCountAfter - nCountBefore;
2722 if (bitmap->nButtons == 0) /* wParam == 0 is special and means add only one image */
2723 {
2724 ImageList_SetImageCount(himlDef, nCountBefore + 1);
2725 } else if (nAdded > (INT)bitmap->nButtons) {
2726 TRACE("Added more images than wParam: Previous image number %i added %i while wParam %i. Images in list %i\n",
2727 nCountBefore, nAdded, bitmap->nButtons, nCountAfter);
2728 }
2729
2730 infoPtr->nNumBitmaps += nAdded;
2731 return TRUE;
2732 }
2733
2734 static void
2735 TOOLBAR_CheckImageListIconSize(TOOLBAR_INFO *infoPtr)
2736 {
2737 HIMAGELIST himlDef;
2738 HIMAGELIST himlNew;
2739 INT cx, cy;
2740 INT i;
2741
2742 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2743 if (himlDef == NULL || himlDef != infoPtr->himlInt)
2744 return;
2745 if (!ImageList_GetIconSize(himlDef, &cx, &cy))
2746 return;
2747 if (cx == infoPtr->nBitmapWidth && cy == infoPtr->nBitmapHeight)
2748 return;
2749
2750 TRACE("Update icon size: %dx%d -> %dx%d\n",
2751 cx, cy, infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
2752
2753 himlNew = ImageList_Create(infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2754 ILC_COLOR32|ILC_MASK, 8, 2);
2755 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2756 TOOLBAR_AddBitmapToImageList(infoPtr, himlNew, &infoPtr->bitmaps[i]);
2757 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlNew, 0);
2758 infoPtr->himlInt = himlNew;
2759
2760 infoPtr->nNumBitmaps -= ImageList_GetImageCount(himlDef);
2761 ImageList_Destroy(himlDef);
2762 }
2763
2764 /***********************************************************************
2765 * TOOLBAR_AddBitmap: Add the bitmaps to the default image list.
2766 *
2767 */
2768 static LRESULT
2769 TOOLBAR_AddBitmap (TOOLBAR_INFO *infoPtr, INT count, const TBADDBITMAP *lpAddBmp)
2770 {
2771 TBITMAP_INFO info;
2772 INT iSumButtons, i;
2773 HIMAGELIST himlDef;
2774
2775 TRACE("hwnd=%p count=%d lpAddBmp=%p\n", infoPtr->hwndSelf, count, lpAddBmp);
2776 if (!lpAddBmp)
2777 return -1;
2778
2779 if (lpAddBmp->hInst == HINST_COMMCTRL)
2780 {
2781 info.hInst = COMCTL32_hModule;
2782 switch (lpAddBmp->nID)
2783 {
2784 case IDB_STD_SMALL_COLOR:
2785 info.nButtons = 15;
2786 info.nID = IDB_STD_SMALL;
2787 break;
2788 case IDB_STD_LARGE_COLOR:
2789 info.nButtons = 15;
2790 info.nID = IDB_STD_LARGE;
2791 break;
2792 case IDB_VIEW_SMALL_COLOR:
2793 info.nButtons = 12;
2794 info.nID = IDB_VIEW_SMALL;
2795 break;
2796 case IDB_VIEW_LARGE_COLOR:
2797 info.nButtons = 12;
2798 info.nID = IDB_VIEW_LARGE;
2799 break;
2800 case IDB_HIST_SMALL_COLOR:
2801 info.nButtons = 5;
2802 info.nID = IDB_HIST_SMALL;
2803 break;
2804 case IDB_HIST_LARGE_COLOR:
2805 info.nButtons = 5;
2806 info.nID = IDB_HIST_LARGE;
2807 break;
2808 default:
2809 return -1;
2810 }
2811
2812 TRACE ("adding %d internal bitmaps!\n", info.nButtons);
2813
2814 /* Windows resize all the buttons to the size of a newly added standard image */
2815 if (lpAddBmp->nID & 1)
2816 {
2817 /* large icons: 24x24. Will make the button 31x30 */
2818 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(24, 24));
2819 }
2820 else
2821 {
2822 /* small icons: 16x16. Will make the buttons 23x22 */
2823 SendMessageW (infoPtr->hwndSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(16, 16));
2824 }
2825
2826 TOOLBAR_CalcToolbar (infoPtr);
2827 }
2828 else
2829 {
2830 info.nButtons = count;
2831 info.hInst = lpAddBmp->hInst;
2832 info.nID = lpAddBmp->nID;
2833 TRACE("adding %d bitmaps!\n", info.nButtons);
2834 }
2835
2836 /* check if the bitmap is already loaded and compute iSumButtons */
2837 iSumButtons = 0;
2838 for (i = 0; i < infoPtr->nNumBitmapInfos; i++)
2839 {
2840 if (infoPtr->bitmaps[i].hInst == info.hInst &&
2841 infoPtr->bitmaps[i].nID == info.nID)
2842 return iSumButtons;
2843 iSumButtons += infoPtr->bitmaps[i].nButtons;
2844 }
2845
2846 if (!infoPtr->cimlDef) {
2847 /* create new default image list */
2848 TRACE ("creating default image list!\n");
2849
2850 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
2851 ILC_COLOR32 | ILC_MASK, info.nButtons, 2);
2852 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0);
2853 infoPtr->himlInt = himlDef;
2854 }
2855 else {
2856 himlDef = GETDEFIMAGELIST(infoPtr, 0);
2857 }
2858
2859 if (!himlDef) {
2860 WARN("No default image list available\n");
2861 return -1;
2862 }
2863
2864 if (!TOOLBAR_AddBitmapToImageList(infoPtr, himlDef, &info))
2865 return -1;
2866
2867 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2868 infoPtr->bitmaps = ReAlloc(infoPtr->bitmaps, (infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
2869 infoPtr->bitmaps[infoPtr->nNumBitmapInfos] = info;
2870 infoPtr->nNumBitmapInfos++;
2871 TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
2872
2873 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2874 return iSumButtons;
2875 }
2876
2877
2878 static LRESULT
2879 TOOLBAR_AddButtonsT(TOOLBAR_INFO *infoPtr, INT nAddButtons, const TBBUTTON* lpTbb, BOOL fUnicode)
2880 {
2881 TRACE("adding %d buttons (unicode=%d)!\n", nAddButtons, fUnicode);
2882
2883 return TOOLBAR_InternalInsertButtonsT(infoPtr, -1, nAddButtons, lpTbb, fUnicode);
2884 }
2885
2886
2887 static LRESULT
2888 TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2889 {
2890 #define MAX_RESOURCE_STRING_LENGTH 512
2891 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2892 INT nIndex = infoPtr->nNumStrings;
2893
2894 TRACE("%p, %lx\n", hInstance, lParam);
2895
2896 if (IS_INTRESOURCE(lParam)) {
2897 WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
2898 WCHAR delimiter;
2899 WCHAR *next_delim;
2900 HRSRC hrsrc;
2901 WCHAR *p;
2902 INT len;
2903
2904 TRACE("adding string from resource\n");
2905
2906 if (!hInstance) return -1;
2907
2908 hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
2909 (LPWSTR)RT_STRING );
2910 if (!hrsrc)
2911 {
2912 TRACE("string not found in resources\n");
2913 return -1;
2914 }
2915
2916 len = LoadStringW (hInstance, (UINT)lParam,
2917 szString, MAX_RESOURCE_STRING_LENGTH);
2918
2919 TRACE("len=%d %s\n", len, debugstr_w(szString));
2920 if (len == 0 || len == 1)
2921 return nIndex;
2922
2923 TRACE("delimiter: 0x%x\n", *szString);
2924 delimiter = *szString;
2925 p = szString + 1;
2926
2927 while ((next_delim = strchrW(p, delimiter)) != NULL) {
2928 *next_delim = 0;
2929 if (next_delim + 1 >= szString + len)
2930 {
2931 /* this may happen if delimiter == '\0' or if the last char is a
2932 * delimiter (then it is ignored like the native does) */
2933 break;
2934 }
2935
2936 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2937 Str_SetPtrW(&infoPtr->strings[infoPtr->nNumStrings], p);
2938 infoPtr->nNumStrings++;
2939
2940 p = next_delim + 1;
2941 }
2942 }
2943 else {
2944 LPWSTR p = (LPWSTR)lParam;
2945 INT len;
2946
2947 if (p == NULL)
2948 return -1;
2949 TRACE("adding string(s) from array\n");
2950 while (*p) {
2951 len = strlenW (p);
2952
2953 TRACE("len=%d %s\n", len, debugstr_w(p));
2954 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2955 Str_SetPtrW (&infoPtr->strings[infoPtr->nNumStrings], p);
2956 infoPtr->nNumStrings++;
2957
2958 p += (len+1);
2959 }
2960 }
2961
2962 if (fFirstString)
2963 TOOLBAR_CalcToolbar(infoPtr);
2964 return nIndex;
2965 }
2966
2967
2968 static LRESULT
2969 TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
2970 {
2971 BOOL fFirstString = (infoPtr->nNumStrings == 0);
2972 LPSTR p;
2973 INT nIndex;
2974 INT len;
2975
2976 TRACE("%p, %lx\n", hInstance, lParam);
2977
2978 if (IS_INTRESOURCE(lParam)) /* load from resources */
2979 return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
2980
2981 p = (LPSTR)lParam;
2982 if (p == NULL)
2983 return -1;
2984
2985 TRACE("adding string(s) from array\n");
2986 nIndex = infoPtr->nNumStrings;
2987 while (*p) {
2988 len = strlen (p);
2989 TRACE("len=%d \"%s\"\n", len, p);
2990
2991 infoPtr->strings = ReAlloc(infoPtr->strings, sizeof(LPWSTR)*(infoPtr->nNumStrings+1));
2992 Str_SetPtrAtoW(&infoPtr->strings[infoPtr->nNumStrings], p);
2993 infoPtr->nNumStrings++;
2994
2995 p += (len+1);
2996 }
2997
2998 if (fFirstString)
2999 TOOLBAR_CalcToolbar(infoPtr);
3000 return nIndex;
3001 }
3002
3003
3004 static LRESULT
3005 TOOLBAR_AutoSize (TOOLBAR_INFO *infoPtr)
3006 {
3007 RECT parent_rect;
3008 HWND parent;
3009 INT x, y;
3010 INT cx, cy;
3011
3012 TRACE("auto sizing, style=%x!\n", infoPtr->dwStyle);
3013
3014 parent = GetParent (infoPtr->hwndSelf);
3015
3016 if (!parent || !infoPtr->bDoRedraw)
3017 return 0;
3018
3019 GetClientRect(parent, &parent_rect);
3020
3021 x = parent_rect.left;
3022 y = parent_rect.top;
3023
3024 TRACE("nRows: %d, infoPtr->nButtonHeight: %d\n", infoPtr->nRows, infoPtr->nButtonHeight);
3025
3026 cy = TOP_BORDER + infoPtr->nRows * infoPtr->nButtonHeight + BOTTOM_BORDER;
3027 cx = parent_rect.right - parent_rect.left;
3028
3029 if ((infoPtr->dwStyle & TBSTYLE_WRAPABLE) || (infoPtr->dwExStyle & TBSTYLE_EX_VERTICAL))
3030 {
3031 TOOLBAR_LayoutToolbar(infoPtr);
3032 InvalidateRect( infoPtr->hwndSelf, NULL, TRUE );
3033 }
3034
3035 if (!(infoPtr->dwStyle & CCS_NORESIZE))
3036 {
3037 RECT window_rect;
3038 UINT uPosFlags = SWP_NOZORDER | SWP_NOACTIVATE;
3039
3040 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_NOMOVEY)
3041 {
3042 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3043 MapWindowPoints( 0, parent, (POINT *)&window_rect, 2 );
3044 y = window_rect.top;
3045 }
3046 if ((infoPtr->dwStyle & CCS_BOTTOM) == CCS_BOTTOM)
3047 {
3048 GetWindowRect(infoPtr->hwndSelf, &window_rect);
3049 y = parent_rect.bottom - ( window_rect.bottom - window_rect.top);
3050 }
3051
3052 if (infoPtr->dwStyle & CCS_NOPARENTALIGN)
3053 uPosFlags |= SWP_NOMOVE;
3054
3055 if (!(infoPtr->dwStyle & CCS_NODIVIDER))
3056 cy += GetSystemMetrics(SM_CYEDGE);
3057
3058 if (infoPtr->dwStyle & WS_BORDER)
3059 {
3060 cx += 2 * GetSystemMetrics(SM_CXBORDER);
3061 cy += 2 * GetSystemMetrics(SM_CYBORDER);
3062 }
3063
3064 SetWindowPos(infoPtr->hwndSelf, NULL, x, y, cx, cy, uPosFlags);
3065 }
3066
3067 return 0;
3068 }
3069
3070
3071 static inline LRESULT
3072 TOOLBAR_ButtonCount (const TOOLBAR_INFO *infoPtr)
3073 {
3074 return infoPtr->nNumButtons;
3075 }
3076
3077
3078 static inline LRESULT
3079 TOOLBAR_ButtonStructSize (TOOLBAR_INFO *infoPtr, DWORD Size)
3080 {
3081 infoPtr->dwStructSize = Size;
3082
3083 return 0;
3084 }
3085
3086
3087 static LRESULT
3088 TOOLBAR_ChangeBitmap (TOOLBAR_INFO *infoPtr, INT Id, INT Index)
3089 {
3090 TBUTTON_INFO *btnPtr;
3091 INT nIndex;
3092
3093 TRACE("button %d, iBitmap now %d\n", Id, Index);
3094
3095 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3096 if (nIndex == -1)
3097 return FALSE;
3098
3099 btnPtr = &infoPtr->buttons[nIndex];
3100 btnPtr->iBitmap = Index;
3101
3102 /* we HAVE to erase the background, the new bitmap could be */
3103 /* transparent */
3104 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3105
3106 return TRUE;
3107 }
3108
3109
3110 static LRESULT
3111 TOOLBAR_CheckButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3112 {
3113 TBUTTON_INFO *btnPtr;
3114 INT nIndex;
3115 INT nOldIndex = -1;
3116 BOOL bChecked = FALSE;
3117
3118 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3119
3120 TRACE("hwnd=%p, btn index=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, nIndex, lParam);
3121
3122 if (nIndex == -1)
3123 return FALSE;
3124
3125 btnPtr = &infoPtr->buttons[nIndex];
3126
3127 bChecked = (btnPtr->fsState & TBSTATE_CHECKED) != 0;
3128
3129 if (LOWORD(lParam) == FALSE)
3130 btnPtr->fsState &= ~TBSTATE_CHECKED;
3131 else {
3132 if (btnPtr->fsStyle & BTNS_GROUP) {
3133 nOldIndex =
3134 TOOLBAR_GetCheckedGroupButtonIndex (infoPtr, nIndex);
3135 if (nOldIndex == nIndex)
3136 return 0;
3137 if (nOldIndex != -1)
3138 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
3139 }
3140 btnPtr->fsState |= TBSTATE_CHECKED;
3141 }
3142
3143 if( bChecked != LOWORD(lParam) )
3144 {
3145 if (nOldIndex != -1)
3146 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
3147 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3148 }
3149
3150 /* FIXME: Send a WM_NOTIFY?? */
3151
3152 return TRUE;
3153 }
3154
3155
3156 static LRESULT
3157 TOOLBAR_CommandToIndex (const TOOLBAR_INFO *infoPtr, INT Id)
3158 {
3159 return TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3160 }
3161
3162
3163 static LRESULT
3164 TOOLBAR_Customize (TOOLBAR_INFO *infoPtr)
3165 {
3166 CUSTDLG_INFO custInfo;
3167 LRESULT ret;
3168 NMHDR nmhdr;
3169
3170 custInfo.tbInfo = infoPtr;
3171 custInfo.tbHwnd = infoPtr->hwndSelf;
3172
3173 /* send TBN_BEGINADJUST notification */
3174 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_BEGINADJUST);
3175
3176 ret = DialogBoxParamW (COMCTL32_hModule, MAKEINTRESOURCEW(IDD_TBCUSTOMIZE),
3177 infoPtr->hwndSelf, TOOLBAR_CustomizeDialogProc, (LPARAM)&custInfo);
3178
3179 /* send TBN_ENDADJUST notification */
3180 TOOLBAR_SendNotify (&nmhdr, infoPtr, TBN_ENDADJUST);
3181
3182 return ret;
3183 }
3184
3185
3186 static LRESULT
3187 TOOLBAR_DeleteButton (TOOLBAR_INFO *infoPtr, INT nIndex)
3188 {
3189 NMTOOLBARW nmtb;
3190 TBUTTON_INFO *btnPtr = &infoPtr->buttons[nIndex];
3191
3192 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3193 return FALSE;
3194
3195 memset(&nmtb, 0, sizeof(nmtb));
3196 nmtb.iItem = btnPtr->idCommand;
3197 nmtb.tbButton.iBitmap = btnPtr->iBitmap;
3198 nmtb.tbButton.idCommand = btnPtr->idCommand;
3199 nmtb.tbButton.fsState = btnPtr->fsState;
3200 nmtb.tbButton.fsStyle = btnPtr->fsStyle;
3201 nmtb.tbButton.dwData = btnPtr->dwData;
3202 nmtb.tbButton.iString = btnPtr->iString;
3203 TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_DELETINGBUTTON);
3204
3205 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[nIndex]);
3206
3207 if (infoPtr->nNumButtons == 1) {
3208 TRACE(" simple delete!\n");
3209 if (TOOLBAR_ButtonHasString(infoPtr->buttons))
3210 Free((LPWSTR)infoPtr->buttons[0].iString);
3211 Free (infoPtr->buttons);
3212 infoPtr->buttons = NULL;
3213 infoPtr->nNumButtons = 0;
3214 }
3215 else {
3216 TBUTTON_INFO *oldButtons = infoPtr->buttons;
3217 TRACE("complex delete! [nIndex=%d]\n", nIndex);
3218
3219 infoPtr->nNumButtons--;
3220 infoPtr->buttons = Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
3221 if (nIndex > 0) {
3222 memcpy (&infoPtr->buttons[0], &oldButtons[0],
3223 nIndex * sizeof(TBUTTON_INFO));
3224 }
3225
3226 if (nIndex < infoPtr->nNumButtons) {
3227 memcpy (&infoPtr->buttons[nIndex], &oldButtons[nIndex+1],
3228 (infoPtr->nNumButtons - nIndex) * sizeof(TBUTTON_INFO));
3229 }
3230
3231 if (TOOLBAR_ButtonHasString(&oldButtons[nIndex]))
3232 Free((LPWSTR)oldButtons[nIndex].iString);
3233 Free (oldButtons);
3234 }
3235
3236 TOOLBAR_LayoutToolbar(infoPtr);
3237
3238 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3239
3240 return TRUE;
3241 }
3242
3243
3244 static LRESULT
3245 TOOLBAR_EnableButton (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
3246 {
3247 TBUTTON_INFO *btnPtr;
3248 INT nIndex;
3249 DWORD bState;
3250
3251 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3252
3253 TRACE("hwnd=%p, btn id=%d, lParam=0x%08lx\n", infoPtr->hwndSelf, Id, lParam);
3254
3255 if (nIndex == -1)
3256 return FALSE;
3257
3258 btnPtr = &infoPtr->buttons[nIndex];
3259
3260 bState = btnPtr->fsState & TBSTATE_ENABLED;
3261
3262 /* update the toolbar button state */
3263 if(LOWORD(lParam) == FALSE) {
3264 btnPtr->fsState &= ~(TBSTATE_ENABLED | TBSTATE_PRESSED);
3265 } else {
3266 btnPtr->fsState |= TBSTATE_ENABLED;
3267 }
3268
3269 /* redraw the button only if the state of the button changed */
3270 if(bState != (btnPtr->fsState & TBSTATE_ENABLED))
3271 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3272
3273 return TRUE;
3274 }
3275
3276
3277 static inline LRESULT
3278 TOOLBAR_GetAnchorHighlight (const TOOLBAR_INFO *infoPtr)
3279 {
3280 return infoPtr->bAnchor;
3281 }
3282
3283
3284 static LRESULT
3285 TOOLBAR_GetBitmap (const TOOLBAR_INFO *infoPtr, INT Id)
3286 {
3287 INT nIndex;
3288
3289 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3290 if (nIndex == -1)
3291 return -1;
3292
3293 return infoPtr->buttons[nIndex].iBitmap;
3294 }
3295
3296
3297 static inline LRESULT
3298 TOOLBAR_GetBitmapFlags (void)
3299 {
3300 return (GetDeviceCaps (0, LOGPIXELSX) >= 120) ? TBBF_LARGE : 0;
3301 }
3302
3303
3304 static LRESULT
3305 TOOLBAR_GetButton (const TOOLBAR_INFO *infoPtr, INT nIndex, TBBUTTON *lpTbb)
3306 {
3307 TBUTTON_INFO *btnPtr;
3308
3309 if (lpTbb == NULL)
3310 return FALSE;
3311
3312 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3313 return FALSE;
3314
3315 btnPtr = &infoPtr->buttons[nIndex];
3316 lpTbb->iBitmap = btnPtr->iBitmap;
3317 lpTbb->idCommand = btnPtr->idCommand;
3318 lpTbb->fsState = btnPtr->fsState;
3319 lpTbb->fsStyle = btnPtr->fsStyle;
3320 lpTbb->bReserved[0] = 0;
3321 lpTbb->bReserved[1] = 0;
3322 lpTbb->dwData = btnPtr->dwData;
3323 lpTbb->iString = btnPtr->iString;
3324
3325 return TRUE;
3326 }
3327
3328
3329 static LRESULT
3330 TOOLBAR_GetButtonInfoT(const TOOLBAR_INFO *infoPtr, INT Id, LPTBBUTTONINFOW lpTbInfo, BOOL bUnicode)
3331 {
3332 /* TBBUTTONINFOW and TBBUTTONINFOA have the same layout*/
3333 TBUTTON_INFO *btnPtr;
3334 INT nIndex;
3335
3336 if (lpTbInfo == NULL)
3337 return -1;
3338
3339 /* MSDN documents an iImageLabel field added in Vista but it is not present in
3340 * the headers and tests shows that even with comctl 6 Vista accepts only the
3341 * original TBBUTTONINFO size
3342 */
3343 if (lpTbInfo->cbSize != sizeof(TBBUTTONINFOW))
3344 {
3345 WARN("Invalid button size\n");
3346 return -1;
3347 }
3348
3349 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lpTbInfo->dwMask & TBIF_BYINDEX);
3350 if (nIndex == -1)
3351 return -1;
3352
3353 if (!(btnPtr = &infoPtr->buttons[nIndex])) return -1;
3354
3355 if (lpTbInfo->dwMask & TBIF_COMMAND)
3356 lpTbInfo->idCommand = btnPtr->idCommand;
3357 if (lpTbInfo->dwMask & TBIF_IMAGE)
3358 lpTbInfo->iImage = btnPtr->iBitmap;
3359 if (lpTbInfo->dwMask & TBIF_LPARAM)
3360 lpTbInfo->lParam = btnPtr->dwData;
3361 if (lpTbInfo->dwMask & TBIF_SIZE)
3362 /* tests show that for separators TBIF_SIZE returns not calculated width,
3363 but cx property, that differs from 0 only if application have
3364 specifically set it */
3365 lpTbInfo->cx = (btnPtr->fsStyle & BTNS_SEP)
3366 ? btnPtr->cx : (WORD)(btnPtr->rect.right - btnPtr->rect.left);
3367 if (lpTbInfo->dwMask & TBIF_STATE)
3368 lpTbInfo->fsState = btnPtr->fsState;
3369 if (lpTbInfo->dwMask & TBIF_STYLE)
3370 lpTbInfo->fsStyle = btnPtr->fsStyle;
3371 if (lpTbInfo->dwMask & TBIF_TEXT) {
3372 /* TB_GETBUTTONINFO doesn't retrieve text from the string list, so we
3373 can't use TOOLBAR_GetText here */
3374 if (!IS_INTRESOURCE(btnPtr->iString) && (btnPtr->iString != -1)) {
3375 LPWSTR lpText = (LPWSTR)btnPtr->iString;
3376 if (bUnicode)
3377 Str_GetPtrW(lpText, lpTbInfo->pszText, lpTbInfo->cchText);
3378 else
3379 Str_GetPtrWtoA(lpText, (LPSTR)lpTbInfo->pszText, lpTbInfo->cchText);
3380 } else
3381 lpTbInfo->pszText[0] = '\0';
3382 }
3383 return nIndex;
3384 }
3385
3386
3387 static inline LRESULT
3388 TOOLBAR_GetButtonSize (const TOOLBAR_INFO *infoPtr)
3389 {
3390 return MAKELONG((WORD)infoPtr->nButtonWidth,
3391 (WORD)infoPtr->nButtonHeight);
3392 }
3393
3394
3395 static LRESULT
3396 TOOLBAR_GetButtonText (const TOOLBAR_INFO *infoPtr, INT Id, LPWSTR lpStr, BOOL isW)
3397 {
3398 INT nIndex;
3399 LPWSTR lpText;
3400 LRESULT ret = 0;
3401
3402 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3403 if (nIndex == -1)
3404 return -1;
3405
3406 lpText = TOOLBAR_GetText(infoPtr,&infoPtr->buttons[nIndex]);
3407
3408 if (isW)
3409 {
3410 if (lpText)
3411 {
3412 ret = strlenW (lpText);
3413 if (lpStr) strcpyW (lpStr, lpText);
3414 }
3415 }
3416 else
3417 ret = WideCharToMultiByte( CP_ACP, 0, lpText, -1,
3418 (LPSTR)lpStr, lpStr ? 0x7fffffff : 0, NULL, NULL ) - 1;
3419 return ret;
3420 }
3421
3422
3423 static LRESULT
3424 TOOLBAR_GetDisabledImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3425 {
3426 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3427 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3428 return (LRESULT)GETDISIMAGELIST(infoPtr, wParam);
3429 }
3430
3431
3432 static inline LRESULT
3433 TOOLBAR_GetExtendedStyle (const TOOLBAR_INFO *infoPtr)
3434 {
3435 TRACE("\n");
3436
3437 return infoPtr->dwExStyle;
3438 }
3439
3440
3441 static LRESULT
3442 TOOLBAR_GetHotImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3443 {
3444 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3445 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3446 return (LRESULT)GETHOTIMAGELIST(infoPtr, wParam);
3447 }
3448
3449
3450 static LRESULT
3451 TOOLBAR_GetHotItem (const TOOLBAR_INFO *infoPtr)
3452 {
3453 if (!((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)))
3454 return -1;
3455
3456 if (infoPtr->nHotItem < 0)
3457 return -1;
3458
3459 return (LRESULT)infoPtr->nHotItem;
3460 }
3461
3462
3463 static LRESULT
3464 TOOLBAR_GetDefImageList (const TOOLBAR_INFO *infoPtr, WPARAM wParam)
3465 {
3466 TRACE("hwnd=%p, wParam=%ld\n", infoPtr->hwndSelf, wParam);
3467 /* UNDOCUMENTED: wParam is actually the ID of the image list to return */
3468 return (LRESULT) GETDEFIMAGELIST(infoPtr, wParam);
3469 }
3470
3471
3472 static LRESULT
3473 TOOLBAR_GetInsertMark (const TOOLBAR_INFO *infoPtr, TBINSERTMARK *lptbim)
3474 {
3475 TRACE("hwnd = %p, lptbim = %p\n", infoPtr->hwndSelf, lptbim);
3476
3477 *lptbim = infoPtr->tbim;
3478
3479 return 0;
3480 }
3481
3482
3483 static inline LRESULT
3484 TOOLBAR_GetInsertMarkColor (const TOOLBAR_INFO *infoPtr)
3485 {
3486 TRACE("hwnd = %p\n", infoPtr->hwndSelf);
3487
3488 return (LRESULT)infoPtr->clrInsertMark;
3489 }
3490
3491
3492 static LRESULT
3493 TOOLBAR_GetItemRect (const TOOLBAR_INFO *infoPtr, INT nIndex, LPRECT lpRect)
3494 {
3495 TBUTTON_INFO *btnPtr;
3496
3497 btnPtr = &infoPtr->buttons[nIndex];
3498 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3499 return FALSE;
3500
3501 if (lpRect == NULL)
3502 return FALSE;
3503 if (btnPtr->fsState & TBSTATE_HIDDEN)
3504 return FALSE;
3505
3506 lpRect->left = btnPtr->rect.left;
3507 lpRect->right = btnPtr->rect.right;
3508 lpRect->bottom = btnPtr->rect.bottom;
3509 lpRect->top = btnPtr->rect.top;
3510
3511 return TRUE;
3512 }
3513
3514
3515 static LRESULT
3516 TOOLBAR_GetMaxSize (const TOOLBAR_INFO *infoPtr, LPSIZE lpSize)
3517 {
3518 if (lpSize == NULL)
3519 return FALSE;
3520
3521 lpSize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
3522 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
3523
3524 TRACE("maximum size %d x %d\n",
3525 infoPtr->rcBound.right - infoPtr->rcBound.left,
3526 infoPtr->rcBound.bottom - infoPtr->rcBound.top);
3527
3528 return TRUE;
3529 }
3530
3531
3532 /* << TOOLBAR_GetObject >> */
3533
3534
3535 static inline LRESULT
3536 TOOLBAR_GetPadding (const TOOLBAR_INFO *infoPtr)
3537 {
3538 return MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
3539 }
3540
3541
3542 static LRESULT
3543 TOOLBAR_GetRect (const TOOLBAR_INFO *infoPtr, INT Id, LPRECT lpRect)
3544 {
3545 TBUTTON_INFO *btnPtr;
3546 INT nIndex;
3547
3548 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3549 btnPtr = &infoPtr->buttons[nIndex];
3550 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
3551 return FALSE;
3552
3553 if (lpRect == NULL)
3554 return FALSE;
3555
3556 lpRect->left = btnPtr->rect.left;
3557 lpRect->right = btnPtr->rect.right;
3558 lpRect->bottom = btnPtr->rect.bottom;
3559 lpRect->top = btnPtr->rect.top;
3560
3561 return TRUE;
3562 }
3563
3564
3565 static inline LRESULT
3566 TOOLBAR_GetRows (const TOOLBAR_INFO *infoPtr)
3567 {
3568 return infoPtr->nRows;
3569 }
3570
3571
3572 static LRESULT
3573 TOOLBAR_GetState (const TOOLBAR_INFO *infoPtr, INT Id)
3574 {
3575 INT nIndex;
3576
3577 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3578 if (nIndex == -1)
3579 return -1;
3580
3581 return infoPtr->buttons[nIndex].fsState;
3582 }
3583
3584
3585 static inline LRESULT
3586 TOOLBAR_GetStyle (const TOOLBAR_INFO *infoPtr)
3587 {
3588 return infoPtr->dwStyle;
3589 }
3590
3591
3592 static inline LRESULT
3593 TOOLBAR_GetTextRows (const TOOLBAR_INFO *infoPtr)
3594 {
3595 return infoPtr->nMaxTextRows;
3596 }
3597
3598
3599 static LRESULT
3600 TOOLBAR_GetToolTips (TOOLBAR_INFO *infoPtr)
3601 {
3602 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
3603 TOOLBAR_TooltipCreateControl(infoPtr);
3604 return (LRESULT)infoPtr->hwndToolTip;
3605 }
3606
3607
3608 static LRESULT
3609 TOOLBAR_GetUnicodeFormat (const TOOLBAR_INFO *infoPtr)
3610 {
3611 TRACE("%s hwnd=%p\n",
3612 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
3613
3614 return infoPtr->bUnicode;
3615 }
3616
3617
3618 static inline LRESULT
3619 TOOLBAR_GetVersion (const TOOLBAR_INFO *infoPtr)
3620 {
3621 return infoPtr->iVersion;
3622 }
3623
3624
3625 static LRESULT
3626 TOOLBAR_HideButton (TOOLBAR_INFO *infoPtr, INT Id, BOOL fHide)
3627 {
3628 TBUTTON_INFO *btnPtr;
3629 BYTE oldState;
3630 INT nIndex;
3631
3632 TRACE("\n");
3633
3634 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3635 if (nIndex == -1)
3636 return FALSE;
3637
3638 btnPtr = &infoPtr->buttons[nIndex];
3639 oldState = btnPtr->fsState;
3640
3641 if (fHide)
3642 btnPtr->fsState |= TBSTATE_HIDDEN;
3643 else
3644 btnPtr->fsState &= ~TBSTATE_HIDDEN;
3645
3646 if (oldState != btnPtr->fsState) {
3647 TOOLBAR_LayoutToolbar (infoPtr);
3648 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3649 }
3650
3651 return TRUE;
3652 }
3653
3654
3655 static inline LRESULT
3656 TOOLBAR_HitTest (const TOOLBAR_INFO *infoPtr, const POINT* lpPt)
3657 {
3658 return TOOLBAR_InternalHitTest (infoPtr, lpPt, NULL);
3659 }
3660
3661
3662 static LRESULT
3663 TOOLBAR_Indeterminate (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fIndeterminate)
3664 {
3665 TBUTTON_INFO *btnPtr;
3666 INT nIndex;
3667 DWORD oldState;
3668
3669 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3670 if (nIndex == -1)
3671 return FALSE;
3672
3673 btnPtr = &infoPtr->buttons[nIndex];
3674 oldState = btnPtr->fsState;
3675
3676 if (fIndeterminate)
3677 btnPtr->fsState |= TBSTATE_INDETERMINATE;
3678 else
3679 btnPtr->fsState &= ~TBSTATE_INDETERMINATE;
3680
3681 if(oldState != btnPtr->fsState)
3682 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3683
3684 return TRUE;
3685 }
3686
3687
3688 static LRESULT
3689 TOOLBAR_InsertButtonT(TOOLBAR_INFO *infoPtr, INT nIndex, const TBBUTTON *lpTbb, BOOL fUnicode)
3690 {
3691 if (lpTbb == NULL)
3692 return FALSE;
3693
3694 if (nIndex == -1) {
3695 /* EPP: this seems to be an undocumented call (from my IE4)
3696 * I assume in that case that:
3697 * - index of insertion is at the end of existing buttons
3698 * I only see this happen with nIndex == -1, but it could have a special
3699 * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
3700 */
3701 nIndex = infoPtr->nNumButtons;
3702
3703 } else if (nIndex < 0)
3704 return FALSE;
3705
3706 TRACE("inserting button index=%d\n", nIndex);
3707 if (nIndex > infoPtr->nNumButtons) {
3708 nIndex = infoPtr->nNumButtons;
3709 TRACE("adjust index=%d\n", nIndex);
3710 }
3711
3712 return TOOLBAR_InternalInsertButtonsT(infoPtr, nIndex, 1, lpTbb, fUnicode);
3713 }
3714
3715 /* << TOOLBAR_InsertMarkHitTest >> */
3716
3717
3718 static LRESULT
3719 TOOLBAR_IsButtonChecked (const TOOLBAR_INFO *infoPtr, INT Id)
3720 {
3721 INT nIndex;
3722
3723 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3724 if (nIndex == -1)
3725 return -1;
3726
3727 return (infoPtr->buttons[nIndex].fsState & TBSTATE_CHECKED);
3728 }
3729
3730
3731 static LRESULT
3732 TOOLBAR_IsButtonEnabled (const TOOLBAR_INFO *infoPtr, INT Id)
3733 {
3734 INT nIndex;
3735
3736 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3737 if (nIndex == -1)
3738 return -1;
3739
3740 return (infoPtr->buttons[nIndex].fsState & TBSTATE_ENABLED);
3741 }
3742
3743
3744 static LRESULT
3745 TOOLBAR_IsButtonHidden (const TOOLBAR_INFO *infoPtr, INT Id)
3746 {
3747 INT nIndex;
3748
3749 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3750 if (nIndex == -1)
3751 return -1;
3752
3753 return (infoPtr->buttons[nIndex].fsState & TBSTATE_HIDDEN);
3754 }
3755
3756
3757 static LRESULT
3758 TOOLBAR_IsButtonHighlighted (const TOOLBAR_INFO *infoPtr, INT Id)
3759 {
3760 INT nIndex;
3761
3762 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3763 if (nIndex == -1)
3764 return -1;
3765
3766 return (infoPtr->buttons[nIndex].fsState & TBSTATE_MARKED);
3767 }
3768
3769
3770 static LRESULT
3771 TOOLBAR_IsButtonIndeterminate (const TOOLBAR_INFO *infoPtr, INT Id)
3772 {
3773 INT nIndex;
3774
3775 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3776 if (nIndex == -1)
3777 return -1;
3778
3779 return (infoPtr->buttons[nIndex].fsState & TBSTATE_INDETERMINATE);
3780 }
3781
3782
3783 static LRESULT
3784 TOOLBAR_IsButtonPressed (const TOOLBAR_INFO *infoPtr, INT Id)
3785 {
3786 INT nIndex;
3787
3788 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3789 if (nIndex == -1)
3790 return -1;
3791
3792 return (infoPtr->buttons[nIndex].fsState & TBSTATE_PRESSED);
3793 }
3794
3795
3796 static LRESULT
3797 TOOLBAR_LoadImages (TOOLBAR_INFO *infoPtr, WPARAM wParam, HINSTANCE hInstance)
3798 {
3799 TBADDBITMAP tbab;
3800 tbab.hInst = hInstance;
3801 tbab.nID = wParam;
3802
3803 TRACE("hwnd = %p, hInst = %p, nID = %lu\n", infoPtr->hwndSelf, tbab.hInst, tbab.nID);
3804
3805 return TOOLBAR_AddBitmap(infoPtr, 0, &tbab);
3806 }
3807
3808
3809 static LRESULT
3810 TOOLBAR_MapAccelerator (const TOOLBAR_INFO *infoPtr, WCHAR wAccel, UINT *pIDButton)
3811 {
3812 WCHAR wszAccel[] = {'&',wAccel,0};
3813 int i;
3814
3815 TRACE("hwnd = %p, wAccel = %x(%s), pIDButton = %p\n",
3816 infoPtr->hwndSelf, wAccel, debugstr_wn(&wAccel,1), pIDButton);
3817
3818 for (i = 0; i < infoPtr->nNumButtons; i++)
3819 {
3820 TBUTTON_INFO *btnPtr = infoPtr->buttons+i;
3821 if (!(btnPtr->fsStyle & BTNS_NOPREFIX) &&
3822 !(btnPtr->fsState & TBSTATE_HIDDEN))
3823 {
3824 int iLen = strlenW(wszAccel);
3825 LPCWSTR lpszStr = TOOLBAR_GetText(infoPtr, btnPtr);
3826
3827 if (!lpszStr)
3828 continue;
3829
3830 while (*lpszStr)
3831 {
3832 if ((lpszStr[0] == '&') && (lpszStr[1] == '&'))
3833 {
3834 lpszStr += 2;
3835 continue;
3836 }
3837 if (!strncmpiW(lpszStr, wszAccel, iLen))
3838 {
3839 *pIDButton = btnPtr->idCommand;
3840 return TRUE;
3841 }
3842 lpszStr++;
3843 }
3844 }
3845 }
3846 return FALSE;
3847 }
3848
3849
3850 static LRESULT
3851 TOOLBAR_MarkButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fMark)
3852 {
3853 INT nIndex;
3854 DWORD oldState;
3855 TBUTTON_INFO *btnPtr;
3856
3857 TRACE("hwnd = %p, Id = %d, fMark = 0%d\n", infoPtr->hwndSelf, Id, fMark);
3858
3859 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3860 if (nIndex == -1)
3861 return FALSE;
3862
3863 btnPtr = &infoPtr->buttons[nIndex];
3864 oldState = btnPtr->fsState;
3865
3866 if (fMark)
3867 btnPtr->fsState |= TBSTATE_MARKED;
3868 else
3869 btnPtr->fsState &= ~TBSTATE_MARKED;
3870
3871 if(oldState != btnPtr->fsState)
3872 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3873
3874 return TRUE;
3875 }
3876
3877
3878 /* fixes up an index of a button affected by a move */
3879 static inline void TOOLBAR_MoveFixupIndex(INT* pIndex, INT nIndex, INT nMoveIndex, BOOL bMoveUp)
3880 {
3881 if (bMoveUp)
3882 {
3883 if (*pIndex > nIndex && *pIndex <= nMoveIndex)
3884 (*pIndex)--;
3885 else if (*pIndex == nIndex)
3886 *pIndex = nMoveIndex;
3887 }
3888 else
3889 {
3890 if (*pIndex >= nMoveIndex && *pIndex < nIndex)
3891 (*pIndex)++;
3892 else if (*pIndex == nIndex)
3893 *pIndex = nMoveIndex;
3894 }
3895 }
3896
3897
3898 static LRESULT
3899 TOOLBAR_MoveButton (TOOLBAR_INFO *infoPtr, INT Id, INT nMoveIndex)
3900 {
3901 INT nIndex;
3902 INT nCount;
3903 TBUTTON_INFO button;
3904
3905 TRACE("hwnd=%p, Id=%d, nMoveIndex=%d\n", infoPtr->hwndSelf, Id, nMoveIndex);
3906
3907 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, TRUE);
3908 if ((nIndex == -1) || (nMoveIndex < 0))
3909 return FALSE;
3910
3911 if (nMoveIndex > infoPtr->nNumButtons - 1)
3912 nMoveIndex = infoPtr->nNumButtons - 1;
3913
3914 button = infoPtr->buttons[nIndex];
3915
3916 /* move button right */
3917 if (nIndex < nMoveIndex)
3918 {
3919 nCount = nMoveIndex - nIndex;
3920 memmove(&infoPtr->buttons[nIndex], &infoPtr->buttons[nIndex+1], nCount*sizeof(TBUTTON_INFO));
3921 infoPtr->buttons[nMoveIndex] = button;
3922
3923 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, TRUE);
3924 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, TRUE);
3925 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, TRUE);
3926 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, TRUE);
3927 }
3928 else if (nIndex > nMoveIndex) /* move button left */
3929 {
3930 nCount = nIndex - nMoveIndex;
3931 memmove(&infoPtr->buttons[nMoveIndex+1], &infoPtr->buttons[nMoveIndex], nCount*sizeof(TBUTTON_INFO));
3932 infoPtr->buttons[nMoveIndex] = button;
3933
3934 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDown, nIndex, nMoveIndex, FALSE);
3935 TOOLBAR_MoveFixupIndex(&infoPtr->nButtonDrag, nIndex, nMoveIndex, FALSE);
3936 TOOLBAR_MoveFixupIndex(&infoPtr->nOldHit, nIndex, nMoveIndex, FALSE);
3937 TOOLBAR_MoveFixupIndex(&infoPtr->nHotItem, nIndex, nMoveIndex, FALSE);
3938 }
3939
3940 TOOLBAR_LayoutToolbar(infoPtr);
3941 TOOLBAR_AutoSize(infoPtr);
3942 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3943
3944 return TRUE;
3945 }
3946
3947
3948 static LRESULT
3949 TOOLBAR_PressButton (const TOOLBAR_INFO *infoPtr, INT Id, BOOL fPress)
3950 {
3951 TBUTTON_INFO *btnPtr;
3952 INT nIndex;
3953 DWORD oldState;
3954
3955 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
3956 if (nIndex == -1)
3957 return FALSE;
3958
3959 btnPtr = &infoPtr->buttons[nIndex];
3960 oldState = btnPtr->fsState;
3961
3962 if (fPress)
3963 btnPtr->fsState |= TBSTATE_PRESSED;
3964 else
3965 btnPtr->fsState &= ~TBSTATE_PRESSED;
3966
3967 if(oldState != btnPtr->fsState)
3968 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
3969
3970 return TRUE;
3971 }
3972
3973 /* FIXME: there might still be some confusion her between number of buttons
3974 * and number of bitmaps */
3975 static LRESULT
3976 TOOLBAR_ReplaceBitmap (TOOLBAR_INFO *infoPtr, const TBREPLACEBITMAP *lpReplace)
3977 {
3978 HBITMAP hBitmap;
3979 int i = 0, nOldButtons = 0, pos = 0;
3980 int nOldBitmaps, nNewBitmaps = 0;
3981 HIMAGELIST himlDef = 0;
3982
3983 TRACE("hInstOld %p nIDOld %lx hInstNew %p nIDNew %lx nButtons %x\n",
3984 lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
3985 lpReplace->nButtons);
3986
3987 if (lpReplace->hInstOld == HINST_COMMCTRL)
3988 {
3989 FIXME("changing standard bitmaps not implemented\n");
3990 return FALSE;
3991 }
3992 else if (lpReplace->hInstOld != 0 && lpReplace->hInstOld != lpReplace->hInstNew)
3993 FIXME("resources not in the current module not implemented\n");
3994
3995 TRACE("To be replaced hInstOld %p nIDOld %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
3996 for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
3997 TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
3998 TRACE("tbimapinfo %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
3999 if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
4000 {
4001 TRACE("Found: nButtons %d hInst %p nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
4002 nOldButtons = tbi->nButtons;
4003 tbi->nButtons = lpReplace->nButtons;
4004 tbi->hInst = lpReplace->hInstNew;
4005 tbi->nID = lpReplace->nIDNew;
4006 TRACE("tbimapinfo changed %d hInstOld %p nIDOld %x\n", i, tbi->hInst, tbi->nID);
4007 break;
4008 }
4009 pos += tbi->nButtons;
4010 }
4011
4012 if (nOldButtons == 0)
4013 {
4014 WARN("No hinst/bitmap found! hInst %p nID %lx\n", lpReplace->hInstOld, lpReplace->nIDOld);
4015 return FALSE;
4016 }
4017
4018 /* copy the bitmap before adding it as ImageList_AddMasked modifies the
4019 * bitmap
4020 */
4021 if (lpReplace->hInstNew)
4022 hBitmap = LoadBitmapW(lpReplace->hInstNew,(LPWSTR)lpReplace->nIDNew);
4023 else
4024 hBitmap = CopyImage((HBITMAP)lpReplace->nIDNew, IMAGE_BITMAP, 0, 0, 0);
4025
4026 himlDef = GETDEFIMAGELIST(infoPtr, 0); /* fixme: correct? */
4027 nOldBitmaps = ImageList_GetImageCount(himlDef);
4028
4029 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */
4030
4031 for (i = pos + nOldBitmaps - 1; i >= pos; i--)
4032 ImageList_Remove(himlDef, i);
4033
4034 if (hBitmap)
4035 {
4036 ImageList_AddMasked (himlDef, hBitmap, comctl32_color.clrBtnFace);
4037 nNewBitmaps = ImageList_GetImageCount(himlDef);
4038 DeleteObject(hBitmap);
4039 }
4040
4041 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldBitmaps + nNewBitmaps;
4042
4043 TRACE(" pos %d %d old bitmaps replaced by %d new ones.\n",
4044 pos, nOldBitmaps, nNewBitmaps);
4045
4046 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4047 return TRUE;
4048 }
4049
4050
4051 /* helper for TOOLBAR_SaveRestoreW */
4052 static BOOL
4053 TOOLBAR_Save(const TBSAVEPARAMSW *lpSave)
4054 {
4055 FIXME("save to %s %s\n", debugstr_w(lpSave->pszSubKey),
4056 debugstr_w(lpSave->pszValueName));
4057
4058 return FALSE;
4059 }
4060
4061
4062 /* helper for TOOLBAR_Restore */
4063 static void
4064 TOOLBAR_DeleteAllButtons(TOOLBAR_INFO *infoPtr)
4065 {
4066 INT i;
4067
4068 for (i = 0; i < infoPtr->nNumButtons; i++)
4069 {
4070 TOOLBAR_TooltipDelTool(infoPtr, &infoPtr->buttons[i]);
4071 }
4072
4073 Free(infoPtr->buttons);
4074 infoPtr->buttons = NULL;
4075 infoPtr->nNumButtons = 0;
4076 }
4077
4078
4079 /* helper for TOOLBAR_SaveRestoreW */
4080 static BOOL
4081 TOOLBAR_Restore(TOOLBAR_INFO *infoPtr, const TBSAVEPARAMSW *lpSave)
4082 {
4083 LONG res;
4084 HKEY hkey = NULL;
4085 BOOL ret = FALSE;
4086 DWORD dwType;
4087 DWORD dwSize = 0;
4088 NMTBRESTORE nmtbr;
4089
4090 /* restore toolbar information */
4091 TRACE("restore from %s %s\n", debugstr_w(lpSave->pszSubKey),
4092 debugstr_w(lpSave->pszValueName));
4093
4094 memset(&nmtbr, 0, sizeof(nmtbr));
4095
4096 res = RegOpenKeyExW(lpSave->hkr, lpSave->pszSubKey, 0,
4097 KEY_QUERY_VALUE, &hkey);
4098 if (!res)
4099 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4100 NULL, &dwSize);
4101 if (!res && dwType != REG_BINARY)
4102 res = ERROR_FILE_NOT_FOUND;
4103 if (!res)
4104 {
4105 nmtbr.pData = Alloc(dwSize);
4106 nmtbr.cbData = dwSize;
4107 if (!nmtbr.pData) res = ERROR_OUTOFMEMORY;
4108 }
4109 if (!res)
4110 res = RegQueryValueExW(hkey, lpSave->pszValueName, NULL, &dwType,
4111 (LPBYTE)nmtbr.pData, &dwSize);
4112 if (!res)
4113 {
4114 nmtbr.pCurrent = nmtbr.pData;
4115 nmtbr.iItem = -1;
4116 nmtbr.cbBytesPerRecord = sizeof(DWORD);
4117 nmtbr.cButtons = nmtbr.cbData / nmtbr.cbBytesPerRecord;
4118
4119 if (!TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE))
4120 {
4121 INT i;
4122
4123 /* remove all existing buttons as this function is designed to
4124 * restore the toolbar to a previously saved state */
4125 TOOLBAR_DeleteAllButtons(infoPtr);
4126
4127 for (i = 0; i < nmtbr.cButtons; i++)
4128 {
4129 nmtbr.iItem = i;
4130 nmtbr.tbButton.iBitmap = -1;
4131 nmtbr.tbButton.fsState = 0;
4132 nmtbr.tbButton.fsStyle = 0;
4133 nmtbr.tbButton.idCommand = 0;
4134 if (*nmtbr.pCurrent == (DWORD)-1)
4135 {
4136 /* separator */
4137 nmtbr.tbButton.fsStyle = TBSTYLE_SEP;
4138 /* when inserting separators, iBitmap controls its size.
4139 0 sets default size (width) */
4140 nmtbr.tbButton.iBitmap = 0;
4141 }
4142 else if (*nmtbr.pCurrent == (DWORD)-2)
4143 /* hidden button */
4144 nmtbr.tbButton.fsState = TBSTATE_HIDDEN;
4145 else
4146 nmtbr.tbButton.idCommand = (int)*nmtbr.pCurrent;
4147
4148 nmtbr.pCurrent++;
4149
4150 TOOLBAR_SendNotify(&nmtbr.hdr, infoPtr, TBN_RESTORE);
4151
4152 /* can't contain real string as we don't know whether
4153 * the client put an ANSI or Unicode string in there */
4154 if (!IS_INTRESOURCE(nmtbr.tbButton.iString))
4155 nmtbr.tbButton.iString = 0;
4156
4157 TOOLBAR_InsertButtonT(infoPtr, -1, &nmtbr.tbButton, TRUE);
4158 }
4159
4160 /* do legacy notifications */
4161 if (infoPtr->iVersion < 5)
4162 {
4163 /* FIXME: send TBN_BEGINADJUST */
4164 FIXME("send TBN_GETBUTTONINFO for each button\n");
4165 /* FIXME: send TBN_ENDADJUST */
4166 }
4167
4168 /* remove all uninitialised buttons
4169 * note: loop backwards to avoid having to fixup i on a
4170 * delete */
4171 for (i = infoPtr->nNumButtons - 1; i >= 0; i--)
4172 if (infoPtr->buttons[i].iBitmap == -1)
4173 TOOLBAR_DeleteButton(infoPtr, i);
4174
4175 /* only indicate success if at least one button survived */
4176 if (infoPtr->nNumButtons > 0) ret = TRUE;
4177 }
4178 }
4179 Free (nmtbr.pData);
4180 RegCloseKey(hkey);
4181
4182 return ret;
4183 }
4184
4185
4186 static LRESULT
4187 TOOLBAR_SaveRestoreW (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSW *lpSave)
4188 {
4189 if (lpSave == NULL) return 0;
4190
4191 if (wParam)
4192 return TOOLBAR_Save(lpSave);
4193 else
4194 return TOOLBAR_Restore(infoPtr, lpSave);
4195 }
4196
4197
4198 static LRESULT
4199 TOOLBAR_SaveRestoreA (TOOLBAR_INFO *infoPtr, WPARAM wParam, const TBSAVEPARAMSA *lpSave)
4200 {
4201 LPWSTR pszValueName = 0, pszSubKey = 0;
4202 TBSAVEPARAMSW SaveW;
4203 LRESULT result = 0;
4204 int len;
4205
4206 if (lpSave == NULL) return 0;
4207
4208 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, NULL, 0);
4209 pszSubKey = Alloc(len * sizeof(WCHAR));
4210 if (pszSubKey) goto exit;
4211 MultiByteToWideChar(CP_ACP, 0, lpSave->pszSubKey, -1, pszSubKey, len);
4212
4213 len = MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, NULL, 0);
4214 pszValueName = Alloc(len * sizeof(WCHAR));
4215 if (!pszValueName) goto exit;
4216 MultiByteToWideChar(CP_ACP, 0, lpSave->pszValueName, -1, pszValueName, len);
4217
4218 SaveW.pszValueName = pszValueName;
4219 SaveW.pszSubKey = pszSubKey;
4220 SaveW.hkr = lpSave->hkr;
4221 result = TOOLBAR_SaveRestoreW(infoPtr, wParam, &SaveW);
4222
4223 exit:
4224 Free (pszValueName);
4225 Free (pszSubKey);
4226
4227 return result;
4228 }
4229
4230
4231 static LRESULT
4232 TOOLBAR_SetAnchorHighlight (TOOLBAR_INFO *infoPtr, BOOL bAnchor)
4233 {
4234 BOOL bOldAnchor = infoPtr->bAnchor;
4235
4236 TRACE("hwnd=%p, bAnchor = %s\n", infoPtr->hwndSelf, bAnchor ? "TRUE" : "FALSE");
4237
4238 infoPtr->bAnchor = bAnchor;
4239
4240 /* Native does not remove the hot effect from an already hot button */
4241
4242 return (LRESULT)bOldAnchor;
4243 }
4244
4245
4246 static LRESULT
4247 TOOLBAR_SetBitmapSize (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4248 {
4249 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0);
4250 short width = (short)LOWORD(lParam);
4251 short height = (short)HIWORD(lParam);
4252
4253 TRACE("hwnd=%p, wParam=%ld, lParam=%ld\n", infoPtr->hwndSelf, wParam, lParam);
4254
4255 if (wParam != 0)
4256 FIXME("wParam is %ld. Perhaps image list index?\n", wParam);
4257
4258 /* 0 width or height is changed to 1 */
4259 if (width == 0)
4260 width = 1;
4261 if (height == 0)
4262 height = 1;
4263
4264 if (infoPtr->nNumButtons > 0)
4265 TRACE("%d buttons, undoc change to bitmap size : %d-%d -> %d-%d\n",
4266 infoPtr->nNumButtons,
4267 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, width, height);
4268
4269 if (width < -1 || height < -1)
4270 {
4271 /* Windows destroys the imagelist and seems to actually use negative
4272 * values to compute button sizes */
4273 FIXME("Negative bitmap sizes not supported (%d, %d)\n", width, height);
4274 return FALSE;
4275 }
4276
4277 /* width or height of -1 means no change */
4278 if (width != -1)
4279 infoPtr->nBitmapWidth = width;
4280 if (height != -1)
4281 infoPtr->nBitmapHeight = height;
4282
4283 if ((himlDef == infoPtr->himlInt) &&
4284 (ImageList_GetImageCount(infoPtr->himlInt) == 0))
4285 {
4286 ImageList_SetIconSize(infoPtr->himlInt, infoPtr->nBitmapWidth,
4287 infoPtr->nBitmapHeight);
4288 }
4289
4290 TOOLBAR_CalcToolbar(infoPtr);
4291 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4292 return TRUE;
4293 }
4294
4295
4296 static LRESULT
4297 TOOLBAR_SetButtonInfo (TOOLBAR_INFO *infoPtr, INT Id,
4298 const TBBUTTONINFOW *lptbbi, BOOL isW)
4299 {
4300 TBUTTON_INFO *btnPtr;
4301 INT nIndex;
4302 RECT oldBtnRect;
4303
4304 if (lptbbi == NULL)
4305 return FALSE;
4306 if (lptbbi->cbSize < sizeof(TBBUTTONINFOW))
4307 return FALSE;
4308
4309 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, lptbbi->dwMask & TBIF_BYINDEX);
4310 if (nIndex == -1)
4311 return FALSE;
4312
4313 btnPtr = &infoPtr->buttons[nIndex];
4314 if (lptbbi->dwMask & TBIF_COMMAND)
4315 btnPtr->idCommand = lptbbi->idCommand;
4316 if (lptbbi->dwMask & TBIF_IMAGE)
4317 btnPtr->iBitmap = lptbbi->iImage;
4318 if (lptbbi->dwMask & TBIF_LPARAM)
4319 btnPtr->dwData = lptbbi->lParam;
4320 if (lptbbi->dwMask & TBIF_SIZE)
4321 btnPtr->cx = lptbbi->cx;
4322 if (lptbbi->dwMask & TBIF_STATE)
4323 btnPtr->fsState = lptbbi->fsState;
4324 if (lptbbi->dwMask & TBIF_STYLE)
4325 btnPtr->fsStyle = lptbbi->fsStyle;
4326
4327 if ((lptbbi->dwMask & TBIF_TEXT) && ((INT_PTR)lptbbi->pszText != -1)) {
4328 /* iString is index, zero it to make Str_SetPtr succeed */
4329 if (!TOOLBAR_ButtonHasString(btnPtr)) btnPtr->iString = 0;
4330
4331 if (isW)
4332 Str_SetPtrW ((LPWSTR *)&btnPtr->iString, lptbbi->pszText);
4333 else
4334 Str_SetPtrAtoW ((LPWSTR *)&btnPtr->iString, (LPSTR)lptbbi->pszText);
4335 }
4336
4337 /* save the button rect to see if we need to redraw the whole toolbar */
4338 oldBtnRect = btnPtr->rect;
4339 TOOLBAR_LayoutToolbar(infoPtr);
4340
4341 if (!EqualRect(&oldBtnRect, &btnPtr->rect))
4342 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4343 else
4344 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4345
4346 return TRUE;
4347 }
4348
4349
4350 static LRESULT
4351 TOOLBAR_SetButtonSize (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4352 {
4353 INT cx = (short)LOWORD(lParam), cy = (short)HIWORD(lParam);
4354
4355 if ((cx < 0) || (cy < 0))
4356 {
4357 ERR("invalid parameter 0x%08x\n", (DWORD)lParam);
4358 return FALSE;
4359 }
4360
4361 TRACE("%p, cx = %d, cy = %d\n", infoPtr->hwndSelf, cx, cy);
4362
4363 /* The documentation claims you can only change the button size before
4364 * any button has been added. But this is wrong.
4365 * WINZIP32.EXE (ver 8) calls this on one of its buttons after adding
4366 * it to the toolbar, and it checks that the return value is nonzero - mjm
4367 * Further testing shows that we must actually perform the change too.
4368 */
4369 /*
4370 * The documentation also does not mention that if 0 is supplied for
4371 * either size, the system changes it to the default of 24 wide and
4372 * 22 high. Demonstrated in ControlSpy Toolbar. GLA 3/02
4373 */
4374 if (cx == 0) cx = 24;
4375 if (cy == 0) cy = 22;
4376
4377 cx = max(cx, infoPtr->szPadding.cx + infoPtr->nBitmapWidth);
4378 cy = max(cy, infoPtr->szPadding.cy + infoPtr->nBitmapHeight);
4379
4380 infoPtr->nButtonWidth = cx;
4381 infoPtr->nButtonHeight = cy;
4382
4383 infoPtr->iTopMargin = default_top_margin(infoPtr);
4384 TOOLBAR_LayoutToolbar(infoPtr);
4385 return TRUE;
4386 }
4387
4388
4389 static LRESULT
4390 TOOLBAR_SetButtonWidth (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4391 {
4392 /* if setting to current values, ignore */
4393 if ((infoPtr->cxMin == (short)LOWORD(lParam)) &&
4394 (infoPtr->cxMax == (short)HIWORD(lParam))) {
4395 TRACE("matches current width, min=%d, max=%d, no recalc\n",
4396 infoPtr->cxMin, infoPtr->cxMax);
4397 return TRUE;
4398 }
4399
4400 /* save new values */
4401 infoPtr->cxMin = (short)LOWORD(lParam);
4402 infoPtr->cxMax = (short)HIWORD(lParam);
4403
4404 /* otherwise we need to recalc the toolbar and in some cases
4405 recalc the bounding rectangle (does DrawText w/ DT_CALCRECT
4406 which doesn't actually draw - GA). */
4407 TRACE("number of buttons %d, cx=%d, cy=%d, recalcing\n",
4408 infoPtr->nNumButtons, infoPtr->cxMin, infoPtr->cxMax);
4409
4410 TOOLBAR_CalcToolbar (infoPtr);
4411
4412 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
4413
4414 return TRUE;
4415 }
4416
4417
4418 static LRESULT
4419 TOOLBAR_SetCmdId (TOOLBAR_INFO *infoPtr, INT nIndex, INT nId)
4420 {
4421 if ((nIndex < 0) || (nIndex >= infoPtr->nNumButtons))
4422 return FALSE;
4423
4424 infoPtr->buttons[nIndex].idCommand = nId;
4425
4426 if (infoPtr->hwndToolTip) {
4427
4428 FIXME("change tool tip!\n");
4429
4430 }
4431
4432 return TRUE;
4433 }
4434
4435
4436 static LRESULT
4437 TOOLBAR_SetDisabledImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4438 {
4439 HIMAGELIST himlTemp;
4440 INT id = 0;
4441
4442 if (infoPtr->iVersion >= 5)
4443 id = wParam;
4444
4445 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis,
4446 &infoPtr->cimlDis, himl, id);
4447
4448 /* FIXME: redraw ? */
4449
4450 return (LRESULT)himlTemp;
4451 }
4452
4453
4454 static LRESULT
4455 TOOLBAR_SetDrawTextFlags (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4456 {
4457 DWORD dwTemp;
4458
4459 TRACE("hwnd = %p, dwMask = 0x%08x, dwDTFlags = 0x%08x\n", infoPtr->hwndSelf, (DWORD)wParam, (DWORD)lParam);
4460
4461 dwTemp = infoPtr->dwDTFlags;
4462 infoPtr->dwDTFlags =
4463 (infoPtr->dwDTFlags & (DWORD)wParam) | (DWORD)lParam;
4464
4465 return (LRESULT)dwTemp;
4466 }
4467
4468 /* This function differs a bit from what MSDN says it does:
4469 * 1. lParam contains extended style flags to OR with current style
4470 * (MSDN isn't clear on the OR bit)
4471 * 2. wParam appears to contain extended style flags to be reset
4472 * (MSDN says that this parameter is reserved)
4473 */
4474 static LRESULT
4475 TOOLBAR_SetExtendedStyle (TOOLBAR_INFO *infoPtr, DWORD mask, DWORD style)
4476 {
4477 DWORD old_style = infoPtr->dwExStyle;
4478
4479 TRACE("mask=0x%08x, style=0x%08x\n", mask, style);
4480
4481 if (mask)
4482 infoPtr->dwExStyle = (old_style & ~mask) | (style & mask);
4483 else
4484 infoPtr->dwExStyle = style;
4485
4486 if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
4487 FIXME("Unknown Toolbar Extended Style 0x%08x. Please report.\n",
4488 (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
4489
4490 if ((old_style ^ infoPtr->dwExStyle) & TBSTYLE_EX_MIXEDBUTTONS)
4491 TOOLBAR_CalcToolbar(infoPtr);
4492 else
4493 TOOLBAR_LayoutToolbar(infoPtr);
4494
4495 TOOLBAR_AutoSize(infoPtr);
4496 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4497
4498 return old_style;
4499 }
4500
4501
4502 static LRESULT
4503 TOOLBAR_SetHotImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4504 {
4505 HIMAGELIST himlTemp;
4506 INT id = 0;
4507
4508 if (infoPtr->iVersion >= 5)
4509 id = wParam;
4510
4511 TRACE("hwnd = %p, himl = %p, id = %d\n", infoPtr->hwndSelf, himl, id);
4512
4513 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot,
4514 &infoPtr->cimlHot, himl, id);
4515
4516 /* FIXME: redraw ? */
4517
4518 return (LRESULT)himlTemp;
4519 }
4520
4521
4522 /* Makes previous hot button no longer hot, makes the specified
4523 * button hot and sends appropriate notifications. dwReason is one or
4524 * more HICF_ flags. Specify nHit < 0 to make no buttons hot.
4525 * NOTE 1: this function does not validate nHit
4526 * NOTE 2: the name of this function is completely made up and
4527 * not based on any documentation from Microsoft. */
4528 static void
4529 TOOLBAR_SetHotItemEx (TOOLBAR_INFO *infoPtr, INT nHit, DWORD dwReason)
4530 {
4531 if (infoPtr->nHotItem != nHit)
4532 {
4533 NMTBHOTITEM nmhotitem;
4534 TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
4535
4536 nmhotitem.dwFlags = dwReason;
4537 if(infoPtr->nHotItem >= 0)
4538 {
4539 oldBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
4540 nmhotitem.idOld = oldBtnPtr->idCommand;
4541 }
4542 else
4543 {
4544 nmhotitem.dwFlags |= HICF_ENTERING;
4545 nmhotitem.idOld = 0;
4546 }
4547
4548 if (nHit >= 0)
4549 {
4550 btnPtr = &infoPtr->buttons[nHit];
4551 nmhotitem.idNew = btnPtr->idCommand;
4552 }
4553 else
4554 {
4555 nmhotitem.dwFlags |= HICF_LEAVING;
4556 nmhotitem.idNew = 0;
4557 }
4558
4559 /* now change the hot and invalidate the old and new buttons - if the
4560 * parent agrees */
4561 if (!TOOLBAR_SendNotify(&nmhotitem.hdr, infoPtr, TBN_HOTITEMCHANGE))
4562 {
4563 if (oldBtnPtr) {
4564 oldBtnPtr->bHot = FALSE;
4565 InvalidateRect(infoPtr->hwndSelf, &oldBtnPtr->rect, TRUE);
4566 }
4567 /* setting disabled buttons as hot fails even if the notify contains the button id */
4568 if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED)) {
4569 btnPtr->bHot = TRUE;
4570 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4571 infoPtr->nHotItem = nHit;
4572 }
4573 else
4574 infoPtr->nHotItem = -1;
4575 }
4576 }
4577 }
4578
4579 static LRESULT
4580 TOOLBAR_SetHotItem (TOOLBAR_INFO *infoPtr, INT nHotItem)
4581 {
4582 INT nOldHotItem = infoPtr->nHotItem;
4583
4584 TRACE("hwnd = %p, nHotItem = %d\n", infoPtr->hwndSelf, nHotItem);
4585
4586 if (nHotItem >= infoPtr->nNumButtons)
4587 return infoPtr->nHotItem;
4588
4589 if (nHotItem < 0)
4590 nHotItem = -1;
4591
4592 /* NOTE: an application can still remove the hot item even if anchor
4593 * highlighting is enabled */
4594
4595 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, HICF_OTHER);
4596
4597 if (nOldHotItem < 0)
4598 return -1;
4599
4600 return (LRESULT)nOldHotItem;
4601 }
4602
4603
4604 static LRESULT
4605 TOOLBAR_SetImageList (TOOLBAR_INFO *infoPtr, WPARAM wParam, HIMAGELIST himl)
4606 {
4607 HIMAGELIST himlTemp;
4608 INT oldButtonWidth = infoPtr->nButtonWidth;
4609 INT oldBitmapWidth = infoPtr->nBitmapWidth;
4610 INT oldBitmapHeight = infoPtr->nBitmapHeight;
4611 INT i, id = 0;
4612
4613 if (infoPtr->iVersion >= 5)
4614 id = wParam;
4615
4616 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef,
4617 &infoPtr->cimlDef, himl, id);
4618
4619 infoPtr->nNumBitmaps = 0;
4620 for (i = 0; i < infoPtr->cimlDef; i++)
4621 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl);
4622
4623 if (!ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth,
4624 &infoPtr->nBitmapHeight))
4625 {
4626 infoPtr->nBitmapWidth = 1;
4627 infoPtr->nBitmapHeight = 1;
4628 }
4629 if ((oldBitmapWidth != infoPtr->nBitmapWidth) || (oldBitmapHeight != infoPtr->nBitmapHeight))
4630 {
4631 TOOLBAR_CalcToolbar(infoPtr);
4632 if (infoPtr->nButtonWidth < oldButtonWidth)
4633 TOOLBAR_SetButtonSize(infoPtr, MAKELONG(oldButtonWidth, infoPtr->nButtonHeight));
4634 }
4635
4636 TRACE("hwnd %p, new himl=%p, id = %d, count=%d, bitmap w=%d, h=%d\n",
4637 infoPtr->hwndSelf, infoPtr->himlDef, id, infoPtr->nNumBitmaps,
4638 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
4639
4640 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4641
4642 return (LRESULT)himlTemp;
4643 }
4644
4645
4646 static LRESULT
4647 TOOLBAR_SetIndent (TOOLBAR_INFO *infoPtr, INT nIndent)
4648 {
4649 infoPtr->nIndent = nIndent;
4650
4651 TRACE("\n");
4652
4653 /* process only on indent changing */
4654 if(infoPtr->nIndent != nIndent)
4655 {
4656 infoPtr->nIndent = nIndent;
4657 TOOLBAR_CalcToolbar (infoPtr);
4658 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
4659 }
4660
4661 return TRUE;
4662 }
4663
4664
4665 static LRESULT
4666 TOOLBAR_SetInsertMark (TOOLBAR_INFO *infoPtr, const TBINSERTMARK *lptbim)
4667 {
4668 TRACE("hwnd = %p, lptbim = { %d, 0x%08x}\n", infoPtr->hwndSelf, lptbim->iButton, lptbim->dwFlags);
4669
4670 if ((lptbim->dwFlags & ~TBIMHT_AFTER) != 0)
4671 {
4672 FIXME("Unrecognized flag(s): 0x%08x\n", (lptbim->dwFlags & ~TBIMHT_AFTER));
4673 return 0;
4674 }
4675
4676 if ((lptbim->iButton == -1) ||
4677 ((lptbim->iButton < infoPtr->nNumButtons) &&
4678 (lptbim->iButton >= 0)))
4679 {
4680 infoPtr->tbim = *lptbim;
4681 /* FIXME: don't need to update entire toolbar */
4682 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4683 }
4684 else
4685 ERR("Invalid button index %d\n", lptbim->iButton);
4686
4687 return 0;
4688 }
4689
4690
4691 static LRESULT
4692 TOOLBAR_SetInsertMarkColor (TOOLBAR_INFO *infoPtr, COLORREF clr)
4693 {
4694 infoPtr->clrInsertMark = clr;
4695
4696 /* FIXME: don't need to update entire toolbar */
4697 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4698
4699 return 0;
4700 }
4701
4702
4703 static LRESULT
4704 TOOLBAR_SetMaxTextRows (TOOLBAR_INFO *infoPtr, INT nMaxRows)
4705 {
4706 infoPtr->nMaxTextRows = nMaxRows;
4707
4708 TOOLBAR_CalcToolbar(infoPtr);
4709 return TRUE;
4710 }
4711
4712
4713 /* MSDN gives slightly wrong info on padding.
4714 * 1. It is not only used on buttons with the BTNS_AUTOSIZE style
4715 * 2. It is not used to create a blank area between the edge of the button
4716 * and the text or image if TBSTYLE_LIST is set. It is used to control
4717 * the gap between the image and text.
4718 * 3. It is not applied to both sides. If TBSTYLE_LIST is set it is used
4719 * to control the bottom and right borders [with the border being
4720 * szPadding.cx - (GetSystemMetrics(SM_CXEDGE)+1)], otherwise the padding
4721 * is shared evenly on both sides of the button.
4722 * See blueprints in comments above TOOLBAR_MeasureButton for more info.
4723 */
4724 static LRESULT
4725 TOOLBAR_SetPadding (TOOLBAR_INFO *infoPtr, LPARAM lParam)
4726 {
4727 DWORD oldPad;
4728
4729 oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4730 infoPtr->szPadding.cx = min(LOWORD((DWORD)lParam), GetSystemMetrics(SM_CXEDGE));
4731 infoPtr->szPadding.cy = min(HIWORD((DWORD)lParam), GetSystemMetrics(SM_CYEDGE));
4732 TRACE("cx=%d, cy=%d\n",
4733 infoPtr->szPadding.cx, infoPtr->szPadding.cy);
4734 return (LRESULT) oldPad;
4735 }
4736
4737
4738 static LRESULT
4739 TOOLBAR_SetParent (TOOLBAR_INFO *infoPtr, HWND hParent)
4740 {
4741 HWND hwndOldNotify;
4742
4743 TRACE("\n");
4744
4745 hwndOldNotify = infoPtr->hwndNotify;
4746 infoPtr->hwndNotify = hParent;
4747
4748 return (LRESULT)hwndOldNotify;
4749 }
4750
4751
4752 static LRESULT
4753 TOOLBAR_SetRows (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPRECT lprc)
4754 {
4755 int rows = LOWORD(wParam);
4756 BOOL bLarger = HIWORD(wParam);
4757
4758 TRACE("\n");
4759
4760 TRACE("Setting rows to %d (%d)\n", rows, bLarger);
4761
4762 if(infoPtr->nRows != rows)
4763 {
4764 TBUTTON_INFO *btnPtr = infoPtr->buttons;
4765 int curColumn = 0; /* Current column */
4766 int curRow = 0; /* Current row */
4767 int hidden = 0; /* Number of hidden buttons */
4768 int seps = 0; /* Number of separators */
4769 int idealWrap = 0; /* Ideal wrap point */
4770 int i;
4771 BOOL wrap;
4772
4773 /*
4774 Calculate new size and wrap points - Under windows, setrows will
4775 change the dimensions if needed to show the number of requested
4776 rows (if CCS_NORESIZE is set), or will take up the whole window
4777 (if no CCS_NORESIZE).
4778
4779 Basic algorithm - If N buttons, and y rows requested, each row
4780 contains N/y buttons.
4781
4782 FIXME: Handling of separators not obvious from testing results
4783 FIXME: Take width of window into account?
4784 */
4785
4786 /* Loop through the buttons one by one counting key items */
4787 for (i = 0; i < infoPtr->nNumButtons; i++ )
4788 {
4789 btnPtr[i].fsState &= ~TBSTATE_WRAP;
4790 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4791 hidden++;
4792 else if (btnPtr[i].fsStyle & BTNS_SEP)
4793 seps++;
4794 }
4795
4796 /* FIXME: Separators make this quite complex */
4797 if (seps) FIXME("Separators unhandled\n");
4798
4799 /* Round up so more per line, i.e., less rows */
4800 idealWrap = (infoPtr->nNumButtons - hidden + (rows-1)) / (rows ? rows : 1);
4801
4802 /* Calculate ideal wrap point if we are allowed to grow, but cannot
4803 achieve the requested number of rows. */
4804 if (bLarger && idealWrap > 1)
4805 {
4806 int resRows = (infoPtr->nNumButtons + (idealWrap-1)) / idealWrap;
4807 int moreRows = (infoPtr->nNumButtons + (idealWrap-2)) / (idealWrap-1);
4808
4809 if (resRows < rows && moreRows > rows)
4810 {
4811 idealWrap--;
4812 TRACE("Changing idealWrap due to bLarger (now %d)\n", idealWrap);
4813 }
4814 }
4815
4816 curColumn = curRow = 0;
4817 wrap = FALSE;
4818 TRACE("Trying to wrap at %d (%d,%d,%d)\n", idealWrap,
4819 infoPtr->nNumButtons, hidden, rows);
4820
4821 for (i = 0; i < infoPtr->nNumButtons; i++ )
4822 {
4823 if (btnPtr[i].fsState & TBSTATE_HIDDEN)
4824 continue;
4825
4826 /* Step on, wrap if necessary or flag next to wrap */
4827 if (!wrap) {
4828 curColumn++;
4829 } else {
4830 wrap = FALSE;
4831 curColumn = 1;
4832 curRow++;
4833 }
4834
4835 if (curColumn > (idealWrap-1)) {
4836 wrap = TRUE;
4837 btnPtr[i].fsState |= TBSTATE_WRAP;
4838 }
4839 }
4840
4841 TRACE("Result - %d rows\n", curRow + 1);
4842
4843 /* recalculate toolbar */
4844 TOOLBAR_CalcToolbar (infoPtr);
4845
4846 /* Resize if necessary (Only if NORESIZE is set - odd, but basically
4847 if NORESIZE is NOT set, then the toolbar will always be resized to
4848 take up the whole window. With it set, sizing needs to be manual. */
4849 if (infoPtr->dwStyle & CCS_NORESIZE) {
4850 SetWindowPos(infoPtr->hwndSelf, NULL, 0, 0,
4851 infoPtr->rcBound.right - infoPtr->rcBound.left,
4852 infoPtr->rcBound.bottom - infoPtr->rcBound.top,
4853 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
4854 }
4855
4856 /* repaint toolbar */
4857 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4858 }
4859
4860 /* return bounding rectangle */
4861 if (lprc) {
4862 lprc->left = infoPtr->rcBound.left;
4863 lprc->right = infoPtr->rcBound.right;
4864 lprc->top = infoPtr->rcBound.top;
4865 lprc->bottom = infoPtr->rcBound.bottom;
4866 }
4867
4868 return 0;
4869 }
4870
4871
4872 static LRESULT
4873 TOOLBAR_SetState (TOOLBAR_INFO *infoPtr, INT Id, LPARAM lParam)
4874 {
4875 TBUTTON_INFO *btnPtr;
4876 INT nIndex;
4877
4878 nIndex = TOOLBAR_GetButtonIndex (infoPtr, Id, FALSE);
4879 if (nIndex == -1)
4880 return FALSE;
4881
4882 btnPtr = &infoPtr->buttons[nIndex];
4883
4884 /* if hidden state has changed the invalidate entire window and recalc */
4885 if ((btnPtr->fsState & TBSTATE_HIDDEN) != (LOWORD(lParam) & TBSTATE_HIDDEN)) {
4886 btnPtr->fsState = LOWORD(lParam);
4887 TOOLBAR_CalcToolbar (infoPtr);
4888 InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
4889 return TRUE;
4890 }
4891
4892 /* process state changing if current state doesn't match new state */
4893 if(btnPtr->fsState != LOWORD(lParam))
4894 {
4895 btnPtr->fsState = LOWORD(lParam);
4896 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
4897 }
4898
4899 return TRUE;
4900 }
4901
4902
4903 static LRESULT
4904 TOOLBAR_SetStyle (TOOLBAR_INFO *infoPtr, DWORD style)
4905 {
4906 infoPtr->dwStyle = style;
4907 return 0;
4908 }
4909
4910
4911 static inline LRESULT
4912 TOOLBAR_SetToolTips (TOOLBAR_INFO *infoPtr, HWND hwndTooltip)
4913 {
4914 TRACE("hwnd=%p, hwndTooltip=%p\n", infoPtr->hwndSelf, hwndTooltip);
4915
4916 infoPtr->hwndToolTip = hwndTooltip;
4917 return 0;
4918 }
4919
4920
4921 static LRESULT
4922 TOOLBAR_SetUnicodeFormat (TOOLBAR_INFO *infoPtr, WPARAM wParam)
4923 {
4924 BOOL bTemp;
4925
4926 TRACE("%s hwnd=%p\n",
4927 ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf);
4928
4929 bTemp = infoPtr->bUnicode;
4930 infoPtr->bUnicode = (BOOL)wParam;
4931
4932 return bTemp;
4933 }
4934
4935
4936 static LRESULT
4937 TOOLBAR_GetColorScheme (const TOOLBAR_INFO *infoPtr, LPCOLORSCHEME lParam)
4938 {
4939 lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
4940 comctl32_color.clrBtnHighlight :
4941 infoPtr->clrBtnHighlight;
4942 lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
4943 comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
4944 return 1;
4945 }
4946
4947
4948 static LRESULT
4949 TOOLBAR_SetColorScheme (TOOLBAR_INFO *infoPtr, const COLORSCHEME *lParam)
4950 {
4951 TRACE("new colors Hl=%x Shd=%x, old colors Hl=%x Shd=%x\n",
4952 lParam->clrBtnHighlight, lParam->clrBtnShadow,
4953 infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
4954
4955 infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
4956 infoPtr->clrBtnShadow = lParam->clrBtnShadow;
4957 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
4958 return 0;
4959 }
4960
4961
4962 static LRESULT
4963 TOOLBAR_SetVersion (TOOLBAR_INFO *infoPtr, INT iVersion)
4964 {
4965 INT iOldVersion = infoPtr->iVersion;
4966
4967 infoPtr->iVersion = iVersion;
4968
4969 if (infoPtr->iVersion >= 5)
4970 TOOLBAR_SetUnicodeFormat(infoPtr, TRUE);
4971
4972 return iOldVersion;
4973 }
4974
4975
4976 static LRESULT
4977 TOOLBAR_GetStringA (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPSTR str)
4978 {
4979 WORD iString = HIWORD(wParam);
4980 WORD buffersize = LOWORD(wParam);
4981 LRESULT ret = -1;
4982
4983 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, buffersize, str);
4984
4985 if (iString < infoPtr->nNumStrings)
4986 {
4987 ret = WideCharToMultiByte(CP_ACP, 0, infoPtr->strings[iString], -1, str, buffersize, NULL, NULL);
4988 ret--;
4989
4990 TRACE("returning %s\n", debugstr_a(str));
4991 }
4992 else
4993 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
4994
4995 return ret;
4996 }
4997
4998
4999 static LRESULT
5000 TOOLBAR_GetStringW (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPWSTR str)
5001 {
5002 WORD iString = HIWORD(wParam);
5003 WORD len = LOWORD(wParam)/sizeof(WCHAR) - 1;
5004 LRESULT ret = -1;
5005
5006 TRACE("hwnd=%p, iString=%d, buffersize=%d, string=%p\n", infoPtr->hwndSelf, iString, LOWORD(wParam), str);
5007
5008 if (iString < infoPtr->nNumStrings)
5009 {
5010 len = min(len, strlenW(infoPtr->strings[iString]));
5011 ret = (len+1)*sizeof(WCHAR);
5012 if (str)
5013 {
5014 memcpy(str, infoPtr->strings[iString], ret);
5015 str[len] = '\0';
5016 }
5017 ret = len;
5018
5019 TRACE("returning %s\n", debugstr_w(str));
5020 }
5021 else
5022 WARN("String index %d out of range (largest is %d)\n", iString, infoPtr->nNumStrings - 1);
5023
5024 return ret;
5025 }
5026
5027 /* UNDOCUMENTED MESSAGE: This appears to set some kind of size. Perhaps it
5028 * is the maximum size of the toolbar? */
5029 static LRESULT TOOLBAR_Unkwn45D(HWND hwnd, WPARAM wParam, LPARAM lParam)
5030 {
5031 SIZE * pSize = (SIZE*)lParam;
5032 FIXME("hwnd=%p, wParam=0x%08lx, size.cx=%d, size.cy=%d stub!\n", hwnd, wParam, pSize->cx, pSize->cy);
5033 return 0;
5034 }
5035
5036
5037 /* This is an extended version of the TB_SETHOTITEM message. It allows the
5038 * caller to specify a reason why the hot item changed (rather than just the
5039 * HICF_OTHER that TB_SETHOTITEM sends). */
5040 static LRESULT
5041 TOOLBAR_SetHotItem2 (TOOLBAR_INFO *infoPtr, INT nHotItem, LPARAM lParam)
5042 {
5043 INT nOldHotItem = infoPtr->nHotItem;
5044
5045 TRACE("old item=%d, new item=%d, flags=%08x\n",
5046 nOldHotItem, nHotItem, (DWORD)lParam);
5047
5048 if (nHotItem < 0 || nHotItem > infoPtr->nNumButtons)
5049 nHotItem = -1;
5050
5051 /* NOTE: an application can still remove the hot item even if anchor
5052 * highlighting is enabled */
5053
5054 TOOLBAR_SetHotItemEx(infoPtr, nHotItem, lParam);
5055
5056 GetFocus();
5057
5058 return (nOldHotItem < 0) ? -1 : (LRESULT)nOldHotItem;
5059 }
5060
5061 /* Sets the toolbar global iListGap parameter which controls the amount of
5062 * spacing between the image and the text of buttons for TBSTYLE_LIST
5063 * toolbars. */
5064 static LRESULT TOOLBAR_SetListGap(TOOLBAR_INFO *infoPtr, INT iListGap)
5065 {
5066 TRACE("hwnd=%p iListGap=%d\n", infoPtr->hwndSelf, iListGap);
5067
5068 infoPtr->iListGap = iListGap;
5069
5070 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
5071
5072 return 0;
5073 }
5074
5075 /* Returns the number of maximum number of image lists associated with the
5076 * various states. */
5077 static LRESULT TOOLBAR_GetImageListCount(const TOOLBAR_INFO *infoPtr)
5078 {
5079 TRACE("hwnd=%p\n", infoPtr->hwndSelf);
5080
5081 return max(infoPtr->cimlDef, max(infoPtr->cimlHot, infoPtr->cimlDis));
5082 }
5083
5084 static LRESULT
5085 TOOLBAR_GetIdealSize (const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5086 {
5087 LPSIZE lpsize = (LPSIZE)lParam;
5088
5089 if (lpsize == NULL)
5090 return FALSE;
5091
5092 /*
5093 * Testing shows the following:
5094 * wParam = 0 adjust cx value
5095 * = 1 set cy value to max size.
5096 * lParam pointer to SIZE structure
5097 *
5098 */
5099 TRACE("wParam %ld, lParam 0x%08lx -> 0x%08x 0x%08x\n",
5100 wParam, lParam, lpsize->cx, lpsize->cy);
5101
5102 switch(wParam) {
5103 case 0:
5104 if (lpsize->cx == -1) {
5105 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5106 }
5107 else if(HIWORD(lpsize->cx)) {
5108 RECT rc;
5109 HWND hwndParent = GetParent(infoPtr->hwndSelf);
5110
5111 GetWindowRect(infoPtr->hwndSelf, &rc);
5112 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
5113 TRACE("mapped to (%s)\n", wine_dbgstr_rect(&rc));
5114 lpsize->cx = max(rc.right-rc.left,
5115 infoPtr->rcBound.right - infoPtr->rcBound.left);
5116 }
5117 else {
5118 lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
5119 }
5120 break;
5121 case 1:
5122 lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
5123 break;
5124 default:
5125 FIXME("Unknown wParam %ld\n", wParam);
5126 return 0;
5127 }
5128 TRACE("set to -> 0x%08x 0x%08x\n",
5129 lpsize->cx, lpsize->cy);
5130 return 1;
5131 }
5132
5133 static LRESULT TOOLBAR_Unkwn464(HWND hwnd, WPARAM wParam, LPARAM lParam)
5134 {
5135 FIXME("hwnd=%p wParam %08lx lParam %08lx\n", hwnd, wParam, lParam);
5136
5137 InvalidateRect(hwnd, NULL, TRUE);
5138 return 1;
5139 }
5140
5141
5142 static LRESULT
5143 TOOLBAR_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
5144 {
5145 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
5146 LOGFONTW logFont;
5147
5148 TRACE("hwnd = %p, style=0x%08x\n", hwnd, lpcs->style);
5149
5150 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5151 GetClientRect(hwnd, &infoPtr->client_rect);
5152 infoPtr->bUnicode = infoPtr->hwndNotify &&
5153 (NFR_UNICODE == SendMessageW(hwnd, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_REQUERY));
5154 infoPtr->hwndToolTip = NULL; /* if needed the tooltip control will be created after a WM_MOUSEMOVE */
5155
5156 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5157 infoPtr->hFont = infoPtr->hDefaultFont = CreateFontIndirectW (&logFont);
5158
5159 OpenThemeData (hwnd, themeClass);
5160
5161 TOOLBAR_CheckStyle (infoPtr);
5162
5163 return 0;
5164 }
5165
5166
5167 static LRESULT
5168 TOOLBAR_Destroy (TOOLBAR_INFO *infoPtr)
5169 {
5170 INT i;
5171
5172 /* delete tooltip control */
5173 if (infoPtr->hwndToolTip)
5174 DestroyWindow (infoPtr->hwndToolTip);
5175
5176 /* delete temporary buffer for tooltip text */
5177 Free (infoPtr->pszTooltipText);
5178 Free (infoPtr->bitmaps); /* bitmaps list */
5179
5180 /* delete button data */
5181 for (i = 0; i < infoPtr->nNumButtons; i++)
5182 if (TOOLBAR_ButtonHasString(&infoPtr->buttons[i]))
5183 Free ((LPWSTR)infoPtr->buttons[i].iString);
5184 Free (infoPtr->buttons);
5185
5186 /* delete strings */
5187 if (infoPtr->strings) {
5188 for (i = 0; i < infoPtr->nNumStrings; i++)
5189 Free (infoPtr->strings[i]);
5190
5191 Free (infoPtr->strings);
5192 }
5193
5194 /* destroy internal image list */
5195 if (infoPtr->himlInt)
5196 ImageList_Destroy (infoPtr->himlInt);
5197
5198 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef);
5199 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis);
5200 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot);
5201
5202 /* delete default font */
5203 DeleteObject (infoPtr->hDefaultFont);
5204
5205 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
5206
5207 /* free toolbar info data */
5208 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
5209 Free (infoPtr);
5210
5211 return 0;
5212 }
5213
5214
5215 static LRESULT
5216 TOOLBAR_EraseBackground (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5217 {
5218 NMTBCUSTOMDRAW tbcd;
5219 INT ret = FALSE;
5220 DWORD ntfret;
5221 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
5222 DWORD dwEraseCustDraw = 0;
5223
5224 /* the app has told us not to redraw the toolbar */
5225 if (!infoPtr->bDoRedraw)
5226 return FALSE;
5227
5228 if (infoPtr->dwStyle & TBSTYLE_CUSTOMERASE) {
5229 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5230 tbcd.nmcd.dwDrawStage = CDDS_PREERASE;
5231 tbcd.nmcd.hdc = (HDC)wParam;
5232 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5233 dwEraseCustDraw = ntfret & 0xffff;
5234
5235 /* FIXME: in general the return flags *can* be or'ed together */
5236 switch (dwEraseCustDraw)
5237 {
5238 case CDRF_DODEFAULT:
5239 break;
5240 case CDRF_SKIPDEFAULT:
5241 return TRUE;
5242 default:
5243 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
5244 infoPtr->hwndSelf, ntfret);
5245 }
5246 }
5247
5248 /* If the toolbar is "transparent" then pass the WM_ERASEBKGND up
5249 * to my parent for processing.
5250 */
5251 if (theme || (infoPtr->dwStyle & TBSTYLE_TRANSPARENT)) {
5252 POINT pt, ptorig;
5253 HDC hdc = (HDC)wParam;
5254 HWND parent;
5255
5256 pt.x = 0;
5257 pt.y = 0;
5258 parent = GetParent(infoPtr->hwndSelf);
5259 MapWindowPoints(infoPtr->hwndSelf, parent, &pt, 1);
5260 OffsetWindowOrgEx (hdc, pt.x, pt.y, &ptorig);
5261 ret = SendMessageW (parent, WM_ERASEBKGND, wParam, lParam);
5262 SetWindowOrgEx (hdc, ptorig.x, ptorig.y, 0);
5263 }
5264 if (!ret)
5265 ret = DefWindowProcW (infoPtr->hwndSelf, WM_ERASEBKGND, wParam, lParam);
5266
5267 if (dwEraseCustDraw & CDRF_NOTIFYPOSTERASE) {
5268 ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
5269 tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
5270 tbcd.nmcd.hdc = (HDC)wParam;
5271 ntfret = TOOLBAR_SendNotify (&tbcd.nmcd.hdr, infoPtr, NM_CUSTOMDRAW);
5272 dwEraseCustDraw = ntfret & 0xffff;
5273 switch (dwEraseCustDraw)
5274 {
5275 case CDRF_DODEFAULT:
5276 break;
5277 case CDRF_SKIPDEFAULT:
5278 return TRUE;
5279 default:
5280 FIXME("[%p] response %d not handled to NM_CUSTOMDRAW (CDDS_POSTERASE)\n",
5281 infoPtr->hwndSelf, ntfret);
5282 }
5283 }
5284 return ret;
5285 }
5286
5287
5288 static inline LRESULT
5289 TOOLBAR_GetFont (const TOOLBAR_INFO *infoPtr)
5290 {
5291 return (LRESULT)infoPtr->hFont;
5292 }
5293
5294
5295 static void
5296 TOOLBAR_SetRelativeHotItem(TOOLBAR_INFO *infoPtr, INT iDirection, DWORD dwReason)
5297 {
5298 INT i;
5299 INT nNewHotItem = infoPtr->nHotItem;
5300
5301 for (i = 0; i < infoPtr->nNumButtons; i++)
5302 {
5303 /* did we wrap? */
5304 if ((nNewHotItem + iDirection < 0) ||
5305 (nNewHotItem + iDirection >= infoPtr->nNumButtons))
5306 {
5307 NMTBWRAPHOTITEM nmtbwhi;
5308 nmtbwhi.idNew = infoPtr->buttons[nNewHotItem].idCommand;
5309 nmtbwhi.iDirection = iDirection;
5310 nmtbwhi.dwReason = dwReason;
5311
5312 if (TOOLBAR_SendNotify(&nmtbwhi.hdr, infoPtr, TBN_WRAPHOTITEM))
5313 return;
5314 }
5315
5316 nNewHotItem += iDirection;
5317 nNewHotItem = (nNewHotItem + infoPtr->nNumButtons) % infoPtr->nNumButtons;
5318
5319 if ((infoPtr->buttons[nNewHotItem].fsState & TBSTATE_ENABLED) &&
5320 !(infoPtr->buttons[nNewHotItem].fsStyle & BTNS_SEP))
5321 {
5322 TOOLBAR_SetHotItemEx(infoPtr, nNewHotItem, dwReason);
5323 break;
5324 }
5325 }
5326 }
5327
5328 static LRESULT
5329 TOOLBAR_KeyDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5330 {
5331 NMKEY nmkey;
5332
5333 nmkey.nVKey = (UINT)wParam;
5334 nmkey.uFlags = HIWORD(lParam);
5335
5336 if (TOOLBAR_SendNotify(&nmkey.hdr, infoPtr, NM_KEYDOWN))
5337 return DefWindowProcW(infoPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
5338
5339 switch ((UINT)wParam)
5340 {
5341 case VK_LEFT:
5342 case VK_UP:
5343 TOOLBAR_SetRelativeHotItem(infoPtr, -1, HICF_ARROWKEYS);
5344 break;
5345 case VK_RIGHT:
5346 case VK_DOWN:
5347 TOOLBAR_SetRelativeHotItem(infoPtr, 1, HICF_ARROWKEYS);
5348 break;
5349 case VK_SPACE:
5350 case VK_RETURN:
5351 if ((infoPtr->nHotItem >= 0) &&
5352 (infoPtr->buttons[infoPtr->nHotItem].fsState & TBSTATE_ENABLED))
5353 {
5354 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5355 MAKEWPARAM(infoPtr->buttons[infoPtr->nHotItem].idCommand, BN_CLICKED),
5356 (LPARAM)infoPtr->hwndSelf);
5357 }
5358 break;
5359 }
5360
5361 return 0;
5362 }
5363
5364
5365 static LRESULT
5366 TOOLBAR_LButtonDblClk (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5367 {
5368 POINT pt;
5369 BOOL button;
5370
5371 pt.x = (short)LOWORD(lParam);
5372 pt.y = (short)HIWORD(lParam);
5373 TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
5374
5375 if (button)
5376 TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
5377 else if (infoPtr->dwStyle & CCS_ADJUSTABLE)
5378 TOOLBAR_Customize (infoPtr);
5379
5380 return 0;
5381 }
5382
5383
5384 static LRESULT
5385 TOOLBAR_LButtonDown (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5386 {
5387 TBUTTON_INFO *btnPtr;
5388 POINT pt;
5389 INT nHit;
5390 NMTOOLBARA nmtb;
5391 NMMOUSE nmmouse;
5392 BOOL bDragKeyPressed;
5393 BOOL button;
5394
5395 TRACE("\n");
5396
5397 if (infoPtr->dwStyle & TBSTYLE_ALTDRAG)
5398 bDragKeyPressed = (GetKeyState(VK_MENU) < 0);
5399 else
5400 bDragKeyPressed = (wParam & MK_SHIFT);
5401
5402 if (infoPtr->hwndToolTip)
5403 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5404 WM_LBUTTONDOWN, wParam, lParam);
5405
5406 pt.x = (short)LOWORD(lParam);
5407 pt.y = (short)HIWORD(lParam);
5408 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
5409
5410 if (button)
5411 btnPtr = &infoPtr->buttons[nHit];
5412
5413 if (button && bDragKeyPressed && (infoPtr->dwStyle & CCS_ADJUSTABLE))
5414 {
5415 infoPtr->nButtonDrag = nHit;
5416 SetCapture (infoPtr->hwndSelf);
5417
5418 /* If drag cursor has not been loaded, load it.
5419 * Note: it doesn't need to be freed */
5420 if (!hCursorDrag)
5421 hCursorDrag = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_MOVEBUTTON);
5422 SetCursor(hCursorDrag);
5423 }
5424 else if (button)
5425 {
5426 RECT arrowRect;
5427 infoPtr->nOldHit = nHit;
5428
5429 CopyRect(&arrowRect, &btnPtr->rect);
5430 arrowRect.left = max(btnPtr->rect.left, btnPtr->rect.right - DDARROW_WIDTH);
5431
5432 /* for EX_DRAWDDARROWS style, click must be in the drop-down arrow rect */
5433 if ((btnPtr->fsState & TBSTATE_ENABLED) &&
5434 ((btnPtr->fsStyle & BTNS_WHOLEDROPDOWN) ||
5435 ((btnPtr->fsStyle & BTNS_DROPDOWN) &&
5436 ((TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) && PtInRect(&arrowRect, pt)) ||
5437 (!TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle))))))
5438 {
5439 LRESULT res;
5440
5441 /* draw in pressed state */
5442 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5443 btnPtr->fsState |= TBSTATE_PRESSED;
5444 else
5445 btnPtr->bDropDownPressed = TRUE;
5446 RedrawWindow(infoPtr->hwndSelf,&btnPtr->rect,0,
5447 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
5448
5449 memset(&nmtb, 0, sizeof(nmtb));
5450 nmtb.iItem = btnPtr->idCommand;
5451 nmtb.rcButton = btnPtr->rect;
5452 res = TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5453 TBN_DROPDOWN);
5454 TRACE("TBN_DROPDOWN responded with %ld\n", res);
5455
5456 if (res != TBDDRET_TREATPRESSED)
5457 {
5458 MSG msg;
5459
5460 /* redraw button in unpressed state */
5461 if (btnPtr->fsStyle & BTNS_WHOLEDROPDOWN)
5462 btnPtr->fsState &= ~TBSTATE_PRESSED;
5463 else
5464 btnPtr->bDropDownPressed = FALSE;
5465 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5466
5467 /* find and set hot item */
5468 GetCursorPos(&pt);
5469 ScreenToClient(infoPtr->hwndSelf, &pt);
5470 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
5471 if (!infoPtr->bAnchor || button)
5472 TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
5473
5474 /* remove any left mouse button down or double-click messages
5475 * so that we can get a toggle effect on the button */
5476 while (PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE) ||
5477 PeekMessageW(&msg, infoPtr->hwndSelf, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_REMOVE))
5478 ;
5479
5480 return 0;
5481 }
5482 /* otherwise drop through and process as pushed */
5483 }
5484 infoPtr->bCaptured = TRUE;
5485 infoPtr->nButtonDown = nHit;
5486 infoPtr->bDragOutSent = FALSE;
5487
5488 btnPtr->fsState |= TBSTATE_PRESSED;
5489
5490 TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
5491
5492 if (btnPtr->fsState & TBSTATE_ENABLED)
5493 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5494 UpdateWindow(infoPtr->hwndSelf);
5495 SetCapture (infoPtr->hwndSelf);
5496 }
5497
5498 if (button)
5499 {
5500 memset(&nmtb, 0, sizeof(nmtb));
5501 nmtb.iItem = btnPtr->idCommand;
5502 TOOLBAR_SendNotify((NMHDR *)&nmtb, infoPtr, TBN_BEGINDRAG);
5503 }
5504
5505 nmmouse.dwHitInfo = nHit;
5506
5507 /* !!! Undocumented - sends NM_LDOWN with the NMMOUSE structure. */
5508 if (!button)
5509 nmmouse.dwItemSpec = -1;
5510 else
5511 {
5512 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5513 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5514 }
5515
5516 ClientToScreen(infoPtr->hwndSelf, &pt);
5517 nmmouse.pt = pt;
5518
5519 if (!TOOLBAR_SendNotify(&nmmouse.hdr, infoPtr, NM_LDOWN))
5520 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONDOWN, wParam, lParam);
5521
5522 return 0;
5523 }
5524
5525 static LRESULT
5526 TOOLBAR_LButtonUp (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5527 {
5528 TBUTTON_INFO *btnPtr;
5529 POINT pt;
5530 INT nHit;
5531 INT nOldIndex = -1;
5532 NMHDR hdr;
5533 NMMOUSE nmmouse;
5534 NMTOOLBARA nmtb;
5535 BOOL button;
5536
5537 if (infoPtr->hwndToolTip)
5538 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5539 WM_LBUTTONUP, wParam, lParam);
5540
5541 pt.x = (short)LOWORD(lParam);
5542 pt.y = (short)HIWORD(lParam);
5543 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
5544
5545 if (!infoPtr->bAnchor || button)
5546 TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
5547
5548 if (infoPtr->nButtonDrag >= 0) {
5549 RECT rcClient;
5550 NMHDR hdr;
5551
5552 btnPtr = &infoPtr->buttons[infoPtr->nButtonDrag];
5553 ReleaseCapture();
5554 /* reset cursor */
5555 SetCursor(LoadCursorW(NULL, (LPCWSTR)IDC_ARROW));
5556
5557 GetClientRect(infoPtr->hwndSelf, &rcClient);
5558 if (PtInRect(&rcClient, pt))
5559 {
5560 INT nButton = -1;
5561 if (nHit >= 0)
5562 nButton = nHit;
5563 else if (nHit < -1)
5564 nButton = -nHit;
5565 else if ((nHit == -1) && PtInRect(&infoPtr->buttons[-nHit].rect, pt))
5566 nButton = -nHit;
5567
5568 if (nButton == infoPtr->nButtonDrag)
5569 {
5570 /* if the button is moved sightly left and we have a
5571 * separator there then remove it */
5572 if (pt.x < (btnPtr->rect.left + (btnPtr->rect.right - btnPtr->rect.left)/2))
5573 {
5574 if ((nButton > 0) && (infoPtr->buttons[nButton-1].fsStyle & BTNS_SEP))
5575 TOOLBAR_DeleteButton(infoPtr, nButton - 1);
5576 }
5577 else /* else insert a separator before the dragged button */
5578 {
5579 TBBUTTON tbb;
5580 memset(&tbb, 0, sizeof(tbb));
5581 tbb.fsStyle = BTNS_SEP;
5582 tbb.iString = -1;
5583 TOOLBAR_InsertButtonT(infoPtr, nButton, &tbb, TRUE);
5584 }
5585 }
5586 else
5587 {
5588 if (nButton == -1)
5589 {
5590 if ((infoPtr->nNumButtons > 0) && (pt.x < infoPtr->buttons[0].rect.left))
5591 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, 0);
5592 else
5593 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, infoPtr->nNumButtons);
5594 }
5595 else
5596 TOOLBAR_MoveButton(infoPtr, infoPtr->nButtonDrag, nButton);
5597 }
5598 }
5599 else
5600 {
5601 TRACE("button %d dragged out of toolbar\n", infoPtr->nButtonDrag);
5602 TOOLBAR_DeleteButton(infoPtr, infoPtr->nButtonDrag);
5603 }
5604
5605 /* button under cursor changed so need to re-set hot item */
5606 TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE | HICF_LMOUSE);
5607 infoPtr->nButtonDrag = -1;
5608
5609 TOOLBAR_SendNotify(&hdr, infoPtr, TBN_TOOLBARCHANGE);
5610 }
5611 else if (infoPtr->nButtonDown >= 0) {
5612 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5613 btnPtr->fsState &= ~TBSTATE_PRESSED;
5614
5615 if (btnPtr->fsStyle & BTNS_CHECK) {
5616 if (btnPtr->fsStyle & BTNS_GROUP) {
5617 nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
5618 nHit);
5619 if ((nOldIndex != nHit) &&
5620 (nOldIndex != -1))
5621 infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
5622 btnPtr->fsState |= TBSTATE_CHECKED;
5623 }
5624 else {
5625 if (btnPtr->fsState & TBSTATE_CHECKED)
5626 btnPtr->fsState &= ~TBSTATE_CHECKED;
5627 else
5628 btnPtr->fsState |= TBSTATE_CHECKED;
5629 }
5630 }
5631
5632 if (nOldIndex != -1)
5633 InvalidateRect(infoPtr->hwndSelf, &infoPtr->buttons[nOldIndex].rect, TRUE);
5634
5635 /*
5636 * now we can ReleaseCapture, which triggers CAPTURECHANGED msg,
5637 * that resets bCaptured and btn TBSTATE_PRESSED flags,
5638 * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
5639 */
5640 if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
5641 ReleaseCapture ();
5642 infoPtr->nButtonDown = -1;
5643
5644 /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
5645 TOOLBAR_SendNotify (&hdr, infoPtr,
5646 NM_RELEASEDCAPTURE);
5647
5648 memset(&nmtb, 0, sizeof(nmtb));
5649 nmtb.iItem = btnPtr->idCommand;
5650 TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr,
5651 TBN_ENDDRAG);
5652
5653 if (btnPtr->fsState & TBSTATE_ENABLED)
5654 {
5655 SendMessageW (infoPtr->hwndNotify, WM_COMMAND,
5656 MAKEWPARAM(infoPtr->buttons[nHit].idCommand, BN_CLICKED), (LPARAM)infoPtr->hwndSelf);
5657
5658 /* In case we have just been destroyed... */
5659 if(!IsWindow(infoPtr->hwndSelf))
5660 return 0;
5661 }
5662 }
5663
5664 /* !!! Undocumented - toolbar at 4.71 level and above sends
5665 * NM_CLICK with the NMMOUSE structure. */
5666 nmmouse.dwHitInfo = nHit;
5667
5668 if (!button)
5669 nmmouse.dwItemSpec = -1;
5670 else
5671 {
5672 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5673 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5674 }
5675
5676 ClientToScreen(infoPtr->hwndSelf, &pt);
5677 nmmouse.pt = pt;
5678
5679 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_CLICK))
5680 return DefWindowProcW(infoPtr->hwndSelf, WM_LBUTTONUP, wParam, lParam);
5681
5682 return 0;
5683 }
5684
5685 static LRESULT
5686 TOOLBAR_RButtonUp(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5687 {
5688 INT nHit;
5689 NMMOUSE nmmouse;
5690 POINT pt;
5691 BOOL button;
5692
5693 pt.x = (short)LOWORD(lParam);
5694 pt.y = (short)HIWORD(lParam);
5695
5696 nHit = TOOLBAR_InternalHitTest(infoPtr, &pt, &button);
5697 nmmouse.dwHitInfo = nHit;
5698
5699 if (!button) {
5700 nmmouse.dwItemSpec = -1;
5701 } else {
5702 nmmouse.dwItemSpec = infoPtr->buttons[nmmouse.dwHitInfo].idCommand;
5703 nmmouse.dwItemData = infoPtr->buttons[nmmouse.dwHitInfo].dwData;
5704 }
5705
5706 ClientToScreen(infoPtr->hwndSelf, &pt);
5707 nmmouse.pt = pt;
5708
5709 if (!TOOLBAR_SendNotify((LPNMHDR)&nmmouse, infoPtr, NM_RCLICK))
5710 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONUP, wParam, lParam);
5711
5712 return 0;
5713 }
5714
5715 static LRESULT
5716 TOOLBAR_RButtonDblClk( TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5717 {
5718 NMHDR nmhdr;
5719
5720 if (!TOOLBAR_SendNotify(&nmhdr, infoPtr, NM_RDBLCLK))
5721 return DefWindowProcW(infoPtr->hwndSelf, WM_RBUTTONDBLCLK, wParam, lParam);
5722
5723 return 0;
5724 }
5725
5726 static LRESULT
5727 TOOLBAR_CaptureChanged(TOOLBAR_INFO *infoPtr)
5728 {
5729 TBUTTON_INFO *btnPtr;
5730
5731 infoPtr->bCaptured = FALSE;
5732
5733 if (infoPtr->nButtonDown >= 0)
5734 {
5735 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5736 btnPtr->fsState &= ~TBSTATE_PRESSED;
5737
5738 infoPtr->nOldHit = -1;
5739
5740 if (btnPtr->fsState & TBSTATE_ENABLED)
5741 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5742 }
5743 return 0;
5744 }
5745
5746 static LRESULT
5747 TOOLBAR_MouseLeave (TOOLBAR_INFO *infoPtr)
5748 {
5749 /* don't remove hot effects when in anchor highlighting mode or when a
5750 * drop-down button is pressed */
5751 if (infoPtr->nHotItem >= 0 && !infoPtr->bAnchor)
5752 {
5753 TBUTTON_INFO *hotBtnPtr = &infoPtr->buttons[infoPtr->nHotItem];
5754 if (!hotBtnPtr->bDropDownPressed)
5755 TOOLBAR_SetHotItemEx(infoPtr, TOOLBAR_NOWHERE, HICF_MOUSE);
5756 }
5757
5758 if (infoPtr->nOldHit < 0)
5759 return TRUE;
5760
5761 /* If the last button we were over is depressed then make it not */
5762 /* depressed and redraw it */
5763 if(infoPtr->nOldHit == infoPtr->nButtonDown)
5764 {
5765 TBUTTON_INFO *btnPtr;
5766 RECT rc1;
5767
5768 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5769
5770 btnPtr->fsState &= ~TBSTATE_PRESSED;
5771
5772 rc1 = btnPtr->rect;
5773 InflateRect (&rc1, 1, 1);
5774 InvalidateRect (infoPtr->hwndSelf, &rc1, TRUE);
5775 }
5776
5777 if (infoPtr->bCaptured && !infoPtr->bDragOutSent)
5778 {
5779 NMTOOLBARW nmt;
5780 ZeroMemory(&nmt, sizeof(nmt));
5781 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5782 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5783 infoPtr->bDragOutSent = TRUE;
5784 }
5785
5786 infoPtr->nOldHit = -1; /* reset the old hit index as we've left the toolbar */
5787
5788 return TRUE;
5789 }
5790
5791 static LRESULT
5792 TOOLBAR_MouseMove (TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5793 {
5794 POINT pt;
5795 TRACKMOUSEEVENT trackinfo;
5796 INT nHit;
5797 TBUTTON_INFO *btnPtr;
5798 BOOL button;
5799
5800 if ((infoPtr->dwStyle & TBSTYLE_TOOLTIPS) && (infoPtr->hwndToolTip == NULL))
5801 TOOLBAR_TooltipCreateControl(infoPtr);
5802
5803 if ((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf)) {
5804 /* fill in the TRACKMOUSEEVENT struct */
5805 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
5806 trackinfo.dwFlags = TME_QUERY;
5807
5808 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5809 _TrackMouseEvent(&trackinfo);
5810
5811 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5812 if(trackinfo.hwndTrack != infoPtr->hwndSelf || !(trackinfo.dwFlags & TME_LEAVE)) {
5813 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
5814 trackinfo.hwndTrack = infoPtr->hwndSelf;
5815
5816 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5817 /* and can properly deactivate the hot toolbar button */
5818 _TrackMouseEvent(&trackinfo);
5819 }
5820 }
5821
5822 if (infoPtr->hwndToolTip)
5823 TOOLBAR_RelayEvent (infoPtr->hwndToolTip, infoPtr->hwndSelf,
5824 WM_MOUSEMOVE, wParam, lParam);
5825
5826 pt.x = (short)LOWORD(lParam);
5827 pt.y = (short)HIWORD(lParam);
5828
5829 nHit = TOOLBAR_InternalHitTest (infoPtr, &pt, &button);
5830
5831 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5832 && (!infoPtr->bAnchor || button))
5833 TOOLBAR_SetHotItemEx(infoPtr, button ? nHit : TOOLBAR_NOWHERE, HICF_MOUSE);
5834
5835 if (infoPtr->nOldHit != nHit)
5836 {
5837 if (infoPtr->bCaptured)
5838 {
5839 if (!infoPtr->bDragOutSent)
5840 {
5841 NMTOOLBARW nmt;
5842 ZeroMemory(&nmt, sizeof(nmt));
5843 nmt.iItem = infoPtr->buttons[infoPtr->nButtonDown].idCommand;
5844 TOOLBAR_SendNotify(&nmt.hdr, infoPtr, TBN_DRAGOUT);
5845 infoPtr->bDragOutSent = TRUE;
5846 }
5847
5848 btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
5849 if (infoPtr->nOldHit == infoPtr->nButtonDown) {
5850 btnPtr->fsState &= ~TBSTATE_PRESSED;
5851 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5852 }
5853 else if (nHit == infoPtr->nButtonDown) {
5854 btnPtr->fsState |= TBSTATE_PRESSED;
5855 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
5856 }
5857 infoPtr->nOldHit = nHit;
5858 }
5859 }
5860
5861 return 0;
5862 }
5863
5864
5865 static inline LRESULT
5866 TOOLBAR_NCActivate (HWND hwnd, WPARAM wParam, LPARAM lParam)
5867 {
5868 /* if (wndPtr->dwStyle & CCS_NODIVIDER) */
5869 return DefWindowProcW (hwnd, WM_NCACTIVATE, wParam, lParam);
5870 /* else */
5871 /* return TOOLBAR_NCPaint (wndPtr, wParam, lParam); */
5872 }
5873
5874
5875 static inline LRESULT
5876 TOOLBAR_NCCalcSize (HWND hwnd, WPARAM wParam, LPARAM lParam)
5877 {
5878 if (!(GetWindowLongW(hwnd, GWL_STYLE) & CCS_NODIVIDER))
5879 ((LPRECT)lParam)->top += GetSystemMetrics(SM_CYEDGE);
5880
5881 return DefWindowProcW (hwnd, WM_NCCALCSIZE, wParam, lParam);
5882 }
5883
5884
5885 static LRESULT
5886 TOOLBAR_NCCreate (HWND hwnd, WPARAM wParam, const CREATESTRUCTW *lpcs)
5887 {
5888 TOOLBAR_INFO *infoPtr;
5889 DWORD styleadd = 0;
5890
5891 /* allocate memory for info structure */
5892 infoPtr = Alloc (sizeof(TOOLBAR_INFO));
5893 SetWindowLongPtrW (hwnd, 0, (LONG_PTR)infoPtr);
5894
5895 /* paranoid!! */
5896 infoPtr->dwStructSize = sizeof(TBBUTTON);
5897 infoPtr->nRows = 1;
5898 infoPtr->nWidth = 0;
5899
5900 /* initialize info structure */
5901 infoPtr->nButtonWidth = 23;
5902 infoPtr->nButtonHeight = 22;
5903 infoPtr->nBitmapHeight = 16;
5904 infoPtr->nBitmapWidth = 16;
5905
5906 infoPtr->nMaxTextRows = 1;
5907 infoPtr->cxMin = -1;
5908 infoPtr->cxMax = -1;
5909 infoPtr->nNumBitmaps = 0;
5910 infoPtr->nNumStrings = 0;
5911
5912 infoPtr->bCaptured = FALSE;
5913 infoPtr->nButtonDown = -1;
5914 infoPtr->nButtonDrag = -1;
5915 infoPtr->nOldHit = -1;
5916 infoPtr->nHotItem = -1;
5917 infoPtr->hwndNotify = lpcs->hwndParent;
5918 infoPtr->dwDTFlags = (lpcs->style & TBSTYLE_LIST) ? DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS: DT_CENTER | DT_END_ELLIPSIS;
5919 infoPtr->bAnchor = FALSE; /* no anchor highlighting */
5920 infoPtr->bDragOutSent = FALSE;
5921 infoPtr->iVersion = 0;
5922 infoPtr->hwndSelf = hwnd;
5923 infoPtr->bDoRedraw = TRUE;
5924 infoPtr->clrBtnHighlight = CLR_DEFAULT;
5925 infoPtr->clrBtnShadow = CLR_DEFAULT;
5926 infoPtr->szPadding.cx = DEFPAD_CX;
5927 infoPtr->szPadding.cy = DEFPAD_CY;
5928 infoPtr->iListGap = DEFLISTGAP;
5929 infoPtr->iTopMargin = default_top_margin(infoPtr);
5930 infoPtr->dwStyle = lpcs->style;
5931 infoPtr->tbim.iButton = -1;
5932
5933 /* fix instance handle, if the toolbar was created by CreateToolbarEx() */
5934 if (!GetWindowLongPtrW (hwnd, GWLP_HINSTANCE)) {
5935 HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW (GetParent (hwnd), GWLP_HINSTANCE);
5936 SetWindowLongPtrW (hwnd, GWLP_HINSTANCE, (LONG_PTR)hInst);
5937 }
5938
5939 /* I think the code below is a bug, but it is the way that the native
5940 * controls seem to work. The effect is that if the user of TBSTYLE_FLAT
5941 * forgets to specify TBSTYLE_TRANSPARENT but does specify either
5942 * CCS_TOP or CCS_BOTTOM (_NOMOVEY and _TOP), then the control
5943 * does *not* set TBSTYLE_TRANSPARENT even though it should!!!!
5944 * Somehow, the only cases of this seem to be MFC programs.
5945 *
5946 * Note also that the addition of _TRANSPARENT occurs *only* here. It
5947 * does not occur in the WM_STYLECHANGING routine.
5948 * (Guy Albertelli 9/2001)
5949 *
5950 */
5951 if (((infoPtr->dwStyle & TBSTYLE_FLAT) || GetWindowTheme (infoPtr->hwndSelf))
5952 && !(lpcs->style & TBSTYLE_TRANSPARENT))
5953 styleadd |= TBSTYLE_TRANSPARENT;
5954 if (!(lpcs->style & (CCS_TOP | CCS_NOMOVEY))) {
5955 styleadd |= CCS_TOP; /* default to top */
5956 SetWindowLongW (hwnd, GWL_STYLE, lpcs->style | styleadd);
5957 }
5958
5959 return DefWindowProcW (hwnd, WM_NCCREATE, wParam, (LPARAM)lpcs);
5960 }
5961
5962
5963 static LRESULT
5964 TOOLBAR_NCPaint (HWND hwnd, WPARAM wParam, LPARAM lParam)
5965 {
5966 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
5967 RECT rcWindow;
5968 HDC hdc;
5969
5970 if (dwStyle & WS_MINIMIZE)
5971 return 0; /* Nothing to do */
5972
5973 DefWindowProcW (hwnd, WM_NCPAINT, wParam, lParam);
5974
5975 if (!(hdc = GetDCEx (hwnd, 0, DCX_USESTYLE | DCX_WINDOW)))
5976 return 0;
5977
5978 if (!(dwStyle & CCS_NODIVIDER))
5979 {
5980 GetWindowRect (hwnd, &rcWindow);
5981 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
5982 if( dwStyle & WS_BORDER )
5983 InflateRect (&rcWindow, -1, -1);
5984 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_TOP);
5985 }
5986
5987 ReleaseDC( hwnd, hdc );
5988
5989 return 0;
5990 }
5991
5992
5993 /* handles requests from the tooltip control on what text to display */
5994 static LRESULT TOOLBAR_TTGetDispInfo (TOOLBAR_INFO *infoPtr, NMTTDISPINFOW *lpnmtdi)
5995 {
5996 int index = TOOLBAR_GetButtonIndex(infoPtr, lpnmtdi->hdr.idFrom, FALSE);
5997
5998 TRACE("button index = %d\n", index);
5999
6000 Free (infoPtr->pszTooltipText);
6001 infoPtr->pszTooltipText = NULL;
6002
6003 if (index < 0)
6004 return 0;
6005
6006 if (infoPtr->bUnicode)
6007 {
6008 WCHAR wszBuffer[INFOTIPSIZE+1];
6009 NMTBGETINFOTIPW tbgit;
6010 unsigned int len; /* in chars */
6011
6012 wszBuffer[0] = '\0';
6013 wszBuffer[INFOTIPSIZE] = '\0';
6014
6015 tbgit.pszText = wszBuffer;
6016 tbgit.cchTextMax = INFOTIPSIZE;
6017 tbgit.iItem = lpnmtdi->hdr.idFrom;
6018 tbgit.lParam = infoPtr->buttons[index].dwData;
6019
6020 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPW);
6021
6022 TRACE("TBN_GETINFOTIPW - got string %s\n", debugstr_w(tbgit.pszText));
6023
6024 len = strlenW(tbgit.pszText);
6025 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6026 {
6027 /* need to allocate temporary buffer in infoPtr as there
6028 * isn't enough space in buffer passed to us by the
6029 * tooltip control */
6030 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6031 if (infoPtr->pszTooltipText)
6032 {
6033 memcpy(infoPtr->pszTooltipText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6034 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6035 return 0;
6036 }
6037 }
6038 else if (len > 0)
6039 {
6040 memcpy(lpnmtdi->lpszText, tbgit.pszText, (len+1)*sizeof(WCHAR));
6041 return 0;
6042 }
6043 }
6044 else
6045 {
6046 CHAR szBuffer[INFOTIPSIZE+1];
6047 NMTBGETINFOTIPA tbgit;
6048 unsigned int len; /* in chars */
6049
6050 szBuffer[0] = '\0';
6051 szBuffer[INFOTIPSIZE] = '\0';
6052
6053 tbgit.pszText = szBuffer;
6054 tbgit.cchTextMax = INFOTIPSIZE;
6055 tbgit.iItem = lpnmtdi->hdr.idFrom;
6056 tbgit.lParam = infoPtr->buttons[index].dwData;
6057
6058 TOOLBAR_SendNotify(&tbgit.hdr, infoPtr, TBN_GETINFOTIPA);
6059
6060 TRACE("TBN_GETINFOTIPA - got string %s\n", debugstr_a(tbgit.pszText));
6061
6062 len = MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, NULL, 0);
6063 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]))
6064 {
6065 /* need to allocate temporary buffer in infoPtr as there
6066 * isn't enough space in buffer passed to us by the
6067 * tooltip control */
6068 infoPtr->pszTooltipText = Alloc(len*sizeof(WCHAR));
6069 if (infoPtr->pszTooltipText)
6070 {
6071 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1, infoPtr->pszTooltipText, len);
6072 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6073 return 0;
6074 }
6075 }
6076 else if (tbgit.pszText && tbgit.pszText[0])
6077 {
6078 MultiByteToWideChar(CP_ACP, 0, tbgit.pszText, -1,
6079 lpnmtdi->lpszText, sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0]));
6080 return 0;
6081 }
6082 }
6083
6084 /* if button has text, but it is not shown then automatically
6085 * use that text as tooltip */
6086 if ((infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) &&
6087 !(infoPtr->buttons[index].fsStyle & BTNS_SHOWTEXT))
6088 {
6089 LPWSTR pszText = TOOLBAR_GetText(infoPtr, &infoPtr->buttons[index]);
6090 unsigned int len = pszText ? strlenW(pszText) : 0;
6091
6092 TRACE("using button hidden text %s\n", debugstr_w(pszText));
6093
6094 if (len > sizeof(lpnmtdi->szText)/sizeof(lpnmtdi->szText[0])-1)
6095 {
6096 /* need to allocate temporary buffer in infoPtr as there
6097 * isn't enough space in buffer passed to us by the
6098 * tooltip control */
6099 infoPtr->pszTooltipText = Alloc((len+1)*sizeof(WCHAR));
6100 if (infoPtr->pszTooltipText)
6101 {
6102 memcpy(infoPtr->pszTooltipText, pszText, (len+1)*sizeof(WCHAR));
6103 lpnmtdi->lpszText = infoPtr->pszTooltipText;
6104 return 0;
6105 }
6106 }
6107 else if (len > 0)
6108 {
6109 memcpy(lpnmtdi->lpszText, pszText, (len+1)*sizeof(WCHAR));
6110 return 0;
6111 }
6112 }
6113
6114 TRACE("Sending tooltip notification to %p\n", infoPtr->hwndNotify);
6115
6116 /* last resort: send notification on to app */
6117 /* FIXME: find out what is really used here */
6118 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, lpnmtdi->hdr.idFrom, (LPARAM)lpnmtdi);
6119 }
6120
6121
6122 static inline LRESULT
6123 TOOLBAR_Notify (TOOLBAR_INFO *infoPtr, LPNMHDR lpnmh)
6124 {
6125 switch (lpnmh->code)
6126 {
6127 case PGN_CALCSIZE:
6128 {
6129 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lpnmh;
6130
6131 if (lppgc->dwFlag == PGF_CALCWIDTH) {
6132 lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
6133 TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
6134 lppgc->iWidth);
6135 }
6136 else {
6137 lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
6138 TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
6139 lppgc->iHeight);
6140 }
6141 return 0;
6142 }
6143
6144 case PGN_SCROLL:
6145 {
6146 LPNMPGSCROLL lppgs = (LPNMPGSCROLL)lpnmh;
6147
6148 lppgs->iScroll = (lppgs->iDir & (PGF_SCROLLLEFT | PGF_SCROLLRIGHT)) ?
6149 infoPtr->nButtonWidth : infoPtr->nButtonHeight;
6150 TRACE("processed PGN_SCROLL, returning scroll=%d, dir=%d\n",
6151 lppgs->iScroll, lppgs->iDir);
6152 return 0;
6153 }
6154
6155 case TTN_GETDISPINFOW:
6156 return TOOLBAR_TTGetDispInfo(infoPtr, (LPNMTTDISPINFOW)lpnmh);
6157
6158 case TTN_GETDISPINFOA:
6159 FIXME("TTN_GETDISPINFOA - should not be received; please report\n");
6160 return 0;
6161
6162 default:
6163 return 0;
6164 }
6165 }
6166
6167
6168 static LRESULT
6169 TOOLBAR_NotifyFormat(const TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
6170 {
6171 LRESULT format;
6172
6173 TRACE("wParam = 0x%lx, lParam = 0x%08lx\n", wParam, lParam);
6174
6175 if (lParam == NF_QUERY)
6176 return NFR_UNICODE;
6177
6178 if (lParam == NF_REQUERY) {
6179 format = SendMessageW(infoPtr->hwndNotify,
6180 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
6181 if ((format != NFR_ANSI) && (format != NFR_UNICODE)) {
6182 ERR("wrong response to WM_NOTIFYFORMAT (%ld), assuming ANSI\n",
6183 format);
6184 format = NFR_ANSI;
6185 }
6186 return format;
6187 }
6188 return 0;
6189 }
6190
6191
6192 static LRESULT
6193 TOOLBAR_Paint (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6194 {
6195 HDC hdc;
6196 PAINTSTRUCT ps;
6197
6198 /* fill ps.rcPaint with a default rect */
6199 ps.rcPaint = infoPtr->rcBound;
6200
6201 hdc = wParam==0 ? BeginPaint(infoPtr->hwndSelf, &ps) : (HDC)wParam;
6202
6203 TRACE("psrect=(%s)\n", wine_dbgstr_rect(&ps.rcPaint));
6204
6205 TOOLBAR_Refresh (infoPtr, hdc, &ps);
6206 if (!wParam) EndPaint (infoPtr->hwndSelf, &ps);
6207
6208 return 0;
6209 }
6210
6211
6212 static LRESULT
6213 TOOLBAR_SetFocus (TOOLBAR_INFO *infoPtr)
6214 {
6215 TRACE("nHotItem = %d\n", infoPtr->nHotItem);
6216
6217 /* make first item hot */
6218 if (infoPtr->nNumButtons > 0)
6219 TOOLBAR_SetHotItemEx(infoPtr, 0, HICF_OTHER);
6220
6221 return 0;
6222 }
6223
6224 static LRESULT
6225 TOOLBAR_SetFont(TOOLBAR_INFO *infoPtr, HFONT hFont, WORD Redraw)
6226 {
6227 TRACE("font=%p redraw=%d\n", hFont, Redraw);
6228
6229 if (hFont == 0)
6230 infoPtr->hFont = infoPtr->hDefaultFont;
6231 else
6232 infoPtr->hFont = hFont;
6233
6234 TOOLBAR_CalcToolbar(infoPtr);
6235
6236 if (Redraw)
6237 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6238 return 1;
6239 }
6240
6241 static LRESULT
6242 TOOLBAR_SetRedraw (TOOLBAR_INFO *infoPtr, WPARAM wParam)
6243 /*****************************************************
6244 *
6245 * Function;
6246 * Handles the WM_SETREDRAW message.
6247 *
6248 * Documentation:
6249 * According to testing V4.71 of COMCTL32 returns the
6250 * *previous* status of the redraw flag (either 0 or 1)
6251 * instead of the MSDN documented value of 0 if handled.
6252 * (For laughs see the "consistency" with same function
6253 * in rebar.)
6254 *
6255 *****************************************************/
6256 {
6257 BOOL oldredraw = infoPtr->bDoRedraw;
6258
6259 TRACE("set to %s\n",
6260 (wParam) ? "TRUE" : "FALSE");
6261 infoPtr->bDoRedraw = (BOOL) wParam;
6262 if (wParam) {
6263 InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
6264 }
6265 return (oldredraw) ? 1 : 0;
6266 }
6267
6268
6269 static LRESULT
6270 TOOLBAR_Size (TOOLBAR_INFO *infoPtr)
6271 {
6272 TRACE("sizing toolbar!\n");
6273
6274 if (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS)
6275 {
6276 RECT delta_width, delta_height, client, dummy;
6277 DWORD min_x, max_x, min_y, max_y;
6278 TBUTTON_INFO *btnPtr;
6279 INT i;
6280
6281 GetClientRect(infoPtr->hwndSelf, &client);
6282 if(client.right > infoPtr->client_rect.right)
6283 {
6284 min_x = infoPtr->client_rect.right;
6285 max_x = client.right;
6286 }
6287 else
6288 {
6289 max_x = infoPtr->client_rect.right;
6290 min_x = client.right;
6291 }
6292 if(client.bottom > infoPtr->client_rect.bottom)
6293 {
6294 min_y = infoPtr->client_rect.bottom;
6295 max_y = client.bottom;
6296 }
6297 else
6298 {
6299 max_y = infoPtr->client_rect.bottom;
6300 min_y = client.bottom;
6301 }
6302
6303 SetRect(&delta_width, min_x, 0, max_x, min_y);
6304 SetRect(&delta_height, 0, min_y, max_x, max_y);
6305
6306 TRACE("delta_width %s delta_height %s\n", wine_dbgstr_rect(&delta_width), wine_dbgstr_rect(&delta_height));
6307 btnPtr = infoPtr->buttons;
6308 for (i = 0; i < infoPtr->nNumButtons; i++, btnPtr++)
6309 if(IntersectRect(&dummy, &delta_width, &btnPtr->rect) ||
6310 IntersectRect(&dummy, &delta_height, &btnPtr->rect))
6311 InvalidateRect(infoPtr->hwndSelf, &btnPtr->rect, TRUE);
6312 }
6313 GetClientRect(infoPtr->hwndSelf, &infoPtr->client_rect);
6314 TOOLBAR_AutoSize(infoPtr);
6315 return 0;
6316 }
6317
6318
6319 static LRESULT
6320 TOOLBAR_StyleChanged (TOOLBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
6321 {
6322 if (nType == GWL_STYLE)
6323 {
6324 DWORD dwOldStyle = infoPtr->dwStyle;
6325
6326 if (lpStyle->styleNew & TBSTYLE_LIST)
6327 infoPtr->dwDTFlags = DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS;
6328 else
6329 infoPtr->dwDTFlags = DT_CENTER | DT_END_ELLIPSIS;
6330
6331 TRACE("new style 0x%08x\n", lpStyle->styleNew);
6332
6333 infoPtr->dwStyle = lpStyle->styleNew;
6334 TOOLBAR_CheckStyle (infoPtr);
6335
6336 if ((dwOldStyle ^ lpStyle->styleNew) & (TBSTYLE_WRAPABLE | CCS_VERT))
6337 TOOLBAR_LayoutToolbar(infoPtr);
6338
6339 /* only resize if one of the CCS_* styles was changed */
6340 if ((dwOldStyle ^ lpStyle->styleNew) & COMMON_STYLES)
6341 {
6342 TOOLBAR_AutoSize (infoPtr);
6343
6344 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
6345 }
6346 }
6347
6348 return 0;
6349 }
6350
6351
6352 static LRESULT
6353 TOOLBAR_SysColorChange (void)
6354 {
6355 COMCTL32_RefreshSysColors();
6356
6357 return 0;
6358 }
6359
6360
6361 /* update theme after a WM_THEMECHANGED message */
6362 static LRESULT theme_changed (HWND hwnd)
6363 {
6364 HTHEME theme = GetWindowTheme (hwnd);
6365 CloseThemeData (theme);
6366 OpenThemeData (hwnd, themeClass);
6367 return 0;
6368 }
6369
6370
6371 static LRESULT WINAPI
6372 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
6373 {
6374 TOOLBAR_INFO *infoPtr = (TOOLBAR_INFO *)GetWindowLongPtrW(hwnd, 0);
6375
6376 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
6377 hwnd, uMsg, /* SPY_GetMsgName(uMsg), */ wParam, lParam);
6378
6379 if (!infoPtr && (uMsg != WM_NCCREATE))
6380 return DefWindowProcW( hwnd, uMsg, wParam, lParam );
6381
6382 switch (uMsg)
6383 {
6384 case TB_ADDBITMAP:
6385 return TOOLBAR_AddBitmap (infoPtr, (INT)wParam, (TBADDBITMAP*)lParam);
6386
6387 case TB_ADDBUTTONSA:
6388 case TB_ADDBUTTONSW:
6389 return TOOLBAR_AddButtonsT (infoPtr, wParam, (LPTBBUTTON)lParam,
6390 uMsg == TB_ADDBUTTONSW);
6391 case TB_ADDSTRINGA:
6392 return TOOLBAR_AddStringA (infoPtr, (HINSTANCE)wParam, lParam);
6393
6394 case TB_ADDSTRINGW:
6395 return TOOLBAR_AddStringW (infoPtr, (HINSTANCE)wParam, lParam);
6396
6397 case TB_AUTOSIZE:
6398 return TOOLBAR_AutoSize (infoPtr);
6399
6400 case TB_BUTTONCOUNT:
6401 return TOOLBAR_ButtonCount (infoPtr);
6402
6403 case TB_BUTTONSTRUCTSIZE:
6404 return TOOLBAR_ButtonStructSize (infoPtr, wParam);
6405
6406 case TB_CHANGEBITMAP:
6407 return TOOLBAR_ChangeBitmap (infoPtr, wParam, LOWORD(lParam));
6408
6409 case TB_CHECKBUTTON:
6410 return TOOLBAR_CheckButton (infoPtr, wParam, lParam);
6411
6412 case TB_COMMANDTOINDEX:
6413 return TOOLBAR_CommandToIndex (infoPtr, wParam);
6414
6415 case TB_CUSTOMIZE:
6416 return TOOLBAR_Customize (infoPtr);
6417
6418 case TB_DELETEBUTTON:
6419 return TOOLBAR_DeleteButton (infoPtr, wParam);
6420
6421 case TB_ENABLEBUTTON:
6422 return TOOLBAR_EnableButton (infoPtr, wParam, lParam);
6423
6424 case TB_GETANCHORHIGHLIGHT:
6425 return TOOLBAR_GetAnchorHighlight (infoPtr);
6426
6427 case TB_GETBITMAP:
6428 return TOOLBAR_GetBitmap (infoPtr, wParam);
6429
6430 case TB_GETBITMAPFLAGS:
6431 return TOOLBAR_GetBitmapFlags ();
6432
6433 case TB_GETBUTTON:
6434 return TOOLBAR_GetButton (infoPtr, wParam, (TBBUTTON*)lParam);
6435
6436 case TB_GETBUTTONINFOA:
6437 case TB_GETBUTTONINFOW:
6438 return TOOLBAR_GetButtonInfoT (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
6439 uMsg == TB_GETBUTTONINFOW);
6440 case TB_GETBUTTONSIZE:
6441 return TOOLBAR_GetButtonSize (infoPtr);
6442
6443 case TB_GETBUTTONTEXTA:
6444 case TB_GETBUTTONTEXTW:
6445 return TOOLBAR_GetButtonText (infoPtr, wParam, (LPWSTR)lParam,
6446 uMsg == TB_GETBUTTONTEXTW);
6447
6448 case TB_GETDISABLEDIMAGELIST:
6449 return TOOLBAR_GetDisabledImageList (infoPtr, wParam);
6450
6451 case TB_GETEXTENDEDSTYLE:
6452 return TOOLBAR_GetExtendedStyle (infoPtr);
6453
6454 case TB_GETHOTIMAGELIST:
6455 return TOOLBAR_GetHotImageList (infoPtr, wParam);
6456
6457 case TB_GETHOTITEM:
6458 return TOOLBAR_GetHotItem (infoPtr);
6459
6460 case TB_GETIMAGELIST:
6461 return TOOLBAR_GetDefImageList (infoPtr, wParam);
6462
6463 case TB_GETINSERTMARK:
6464 return TOOLBAR_GetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6465
6466 case TB_GETINSERTMARKCOLOR:
6467 return TOOLBAR_GetInsertMarkColor (infoPtr);
6468
6469 case TB_GETITEMRECT:
6470 return TOOLBAR_GetItemRect (infoPtr, wParam, (LPRECT)lParam);
6471
6472 case TB_GETMAXSIZE:
6473 return TOOLBAR_GetMaxSize (infoPtr, (LPSIZE)lParam);
6474
6475 /* case TB_GETOBJECT: */ /* 4.71 */
6476
6477 case TB_GETPADDING:
6478 return TOOLBAR_GetPadding (infoPtr);
6479
6480 case TB_GETRECT:
6481 return TOOLBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
6482
6483 case TB_GETROWS:
6484 return TOOLBAR_GetRows (infoPtr);
6485
6486 case TB_GETSTATE:
6487 return TOOLBAR_GetState (infoPtr, wParam);
6488
6489 case TB_GETSTRINGA:
6490 return TOOLBAR_GetStringA (infoPtr, wParam, (LPSTR)lParam);
6491
6492 case TB_GETSTRINGW:
6493 return TOOLBAR_GetStringW (infoPtr, wParam, (LPWSTR)lParam);
6494
6495 case TB_GETSTYLE:
6496 return TOOLBAR_GetStyle (infoPtr);
6497
6498 case TB_GETTEXTROWS:
6499 return TOOLBAR_GetTextRows (infoPtr);
6500
6501 case TB_GETTOOLTIPS:
6502 return TOOLBAR_GetToolTips (infoPtr);
6503
6504 case TB_GETUNICODEFORMAT:
6505 return TOOLBAR_GetUnicodeFormat (infoPtr);
6506
6507 case TB_HIDEBUTTON:
6508 return TOOLBAR_HideButton (infoPtr, wParam, LOWORD(lParam));
6509
6510 case TB_HITTEST:
6511 return TOOLBAR_HitTest (infoPtr, (LPPOINT)lParam);
6512
6513 case TB_INDETERMINATE:
6514 return TOOLBAR_Indeterminate (infoPtr, wParam, LOWORD(lParam));
6515
6516 case TB_INSERTBUTTONA:
6517 case TB_INSERTBUTTONW:
6518 return TOOLBAR_InsertButtonT(infoPtr, wParam, (TBBUTTON*)lParam,
6519 uMsg == TB_INSERTBUTTONW);
6520
6521 /* case TB_INSERTMARKHITTEST: */ /* 4.71 */
6522
6523 case TB_ISBUTTONCHECKED:
6524 return TOOLBAR_IsButtonChecked (infoPtr, wParam);
6525
6526 case TB_ISBUTTONENABLED:
6527 return TOOLBAR_IsButtonEnabled (infoPtr, wParam);
6528
6529 case TB_ISBUTTONHIDDEN:
6530 return TOOLBAR_IsButtonHidden (infoPtr, wParam);
6531
6532 case TB_ISBUTTONHIGHLIGHTED:
6533 return TOOLBAR_IsButtonHighlighted (infoPtr, wParam);
6534
6535 case TB_ISBUTTONINDETERMINATE:
6536 return TOOLBAR_IsButtonIndeterminate (infoPtr, wParam);
6537
6538 case TB_ISBUTTONPRESSED:
6539 return TOOLBAR_IsButtonPressed (infoPtr, wParam);
6540
6541 case TB_LOADIMAGES:
6542 return TOOLBAR_LoadImages (infoPtr, wParam, (HINSTANCE)lParam);
6543
6544 case TB_MAPACCELERATORA:
6545 case TB_MAPACCELERATORW:
6546 return TOOLBAR_MapAccelerator (infoPtr, wParam, (UINT*)lParam);
6547
6548 case TB_MARKBUTTON:
6549 return TOOLBAR_MarkButton (infoPtr, wParam, LOWORD(lParam));
6550
6551 case TB_MOVEBUTTON:
6552 return TOOLBAR_MoveButton (infoPtr, wParam, lParam);
6553
6554 case TB_PRESSBUTTON:
6555 return TOOLBAR_PressButton (infoPtr, wParam, LOWORD(lParam));
6556
6557 case TB_REPLACEBITMAP:
6558 return TOOLBAR_ReplaceBitmap (infoPtr, (LPTBREPLACEBITMAP)lParam);
6559
6560 case TB_SAVERESTOREA:
6561 return TOOLBAR_SaveRestoreA (infoPtr, wParam, (LPTBSAVEPARAMSA)lParam);
6562
6563 case TB_SAVERESTOREW:
6564 return TOOLBAR_SaveRestoreW (infoPtr, wParam, (LPTBSAVEPARAMSW)lParam);
6565
6566 case TB_SETANCHORHIGHLIGHT:
6567 return TOOLBAR_SetAnchorHighlight (infoPtr, (BOOL)wParam);
6568
6569 case TB_SETBITMAPSIZE:
6570 return TOOLBAR_SetBitmapSize (infoPtr, wParam, lParam);
6571
6572 case TB_SETBUTTONINFOA:
6573 case TB_SETBUTTONINFOW:
6574 return TOOLBAR_SetButtonInfo (infoPtr, wParam, (LPTBBUTTONINFOW)lParam,
6575 uMsg == TB_SETBUTTONINFOW);
6576 case TB_SETBUTTONSIZE:
6577 return TOOLBAR_SetButtonSize (infoPtr, lParam);
6578
6579 case TB_SETBUTTONWIDTH:
6580 return TOOLBAR_SetButtonWidth (infoPtr, lParam);
6581
6582 case TB_SETCMDID:
6583 return TOOLBAR_SetCmdId (infoPtr, wParam, lParam);
6584
6585 case TB_SETDISABLEDIMAGELIST:
6586 return TOOLBAR_SetDisabledImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6587
6588 case TB_SETDRAWTEXTFLAGS:
6589 return TOOLBAR_SetDrawTextFlags (infoPtr, wParam, lParam);
6590
6591 case TB_SETEXTENDEDSTYLE:
6592 return TOOLBAR_SetExtendedStyle (infoPtr, wParam, lParam);
6593
6594 case TB_SETHOTIMAGELIST:
6595 return TOOLBAR_SetHotImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6596
6597 case TB_SETHOTITEM:
6598 return TOOLBAR_SetHotItem (infoPtr, wParam);
6599
6600 case TB_SETIMAGELIST:
6601 return TOOLBAR_SetImageList (infoPtr, wParam, (HIMAGELIST)lParam);
6602
6603 case TB_SETINDENT:
6604 return TOOLBAR_SetIndent (infoPtr, wParam);
6605
6606 case TB_SETINSERTMARK:
6607 return TOOLBAR_SetInsertMark (infoPtr, (TBINSERTMARK*)lParam);
6608
6609 case TB_SETINSERTMARKCOLOR:
6610 return TOOLBAR_SetInsertMarkColor (infoPtr, lParam);
6611
6612 case TB_SETMAXTEXTROWS:
6613 return TOOLBAR_SetMaxTextRows (infoPtr, wParam);
6614
6615 case TB_SETPADDING:
6616 return TOOLBAR_SetPadding (infoPtr, lParam);
6617
6618 case TB_SETPARENT:
6619 return TOOLBAR_SetParent (infoPtr, (HWND)wParam);
6620
6621 case TB_SETROWS:
6622 return TOOLBAR_SetRows (infoPtr, wParam, (LPRECT)lParam);
6623
6624 case TB_SETSTATE:
6625 return TOOLBAR_SetState (infoPtr, wParam, lParam);
6626
6627 case TB_SETSTYLE:
6628 return TOOLBAR_SetStyle (infoPtr, lParam);
6629
6630 case TB_SETTOOLTIPS:
6631 return TOOLBAR_SetToolTips (infoPtr, (HWND)wParam);
6632
6633 case TB_SETUNICODEFORMAT:
6634 return TOOLBAR_SetUnicodeFormat (infoPtr, wParam);
6635
6636 case TB_UNKWN45D:
6637 return TOOLBAR_Unkwn45D(hwnd, wParam, lParam);
6638
6639 case TB_SETHOTITEM2:
6640 return TOOLBAR_SetHotItem2 (infoPtr, wParam, lParam);
6641
6642 case TB_SETLISTGAP:
6643 return TOOLBAR_SetListGap(infoPtr, wParam);
6644
6645 case TB_GETIMAGELISTCOUNT:
6646 return TOOLBAR_GetImageListCount(infoPtr);
6647
6648 case TB_GETIDEALSIZE:
6649 return TOOLBAR_GetIdealSize (infoPtr, wParam, lParam);
6650
6651 case TB_UNKWN464:
6652 return TOOLBAR_Unkwn464(hwnd, wParam, lParam);
6653
6654 /* Common Control Messages */
6655
6656 /* case TB_GETCOLORSCHEME: */ /* identical to CCM_ */
6657 case CCM_GETCOLORSCHEME:
6658 return TOOLBAR_GetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6659
6660 /* case TB_SETCOLORSCHEME: */ /* identical to CCM_ */
6661 case CCM_SETCOLORSCHEME:
6662 return TOOLBAR_SetColorScheme (infoPtr, (LPCOLORSCHEME)lParam);
6663
6664 case CCM_GETVERSION:
6665 return TOOLBAR_GetVersion (infoPtr);
6666
6667 case CCM_SETVERSION:
6668 return TOOLBAR_SetVersion (infoPtr, (INT)wParam);
6669
6670
6671 /* case WM_CHAR: */
6672
6673 case WM_CREATE:
6674 return TOOLBAR_Create (hwnd, (CREATESTRUCTW*)lParam);
6675
6676 case WM_DESTROY:
6677 return TOOLBAR_Destroy (infoPtr);
6678
6679 case WM_ERASEBKGND:
6680 return TOOLBAR_EraseBackground (infoPtr, wParam, lParam);
6681
6682 case WM_GETFONT:
6683 return TOOLBAR_GetFont (infoPtr);
6684
6685 case WM_KEYDOWN:
6686 return TOOLBAR_KeyDown (infoPtr, wParam, lParam);
6687
6688 /* case WM_KILLFOCUS: */
6689
6690 case WM_LBUTTONDBLCLK:
6691 return TOOLBAR_LButtonDblClk (infoPtr, wParam, lParam);
6692
6693 case WM_LBUTTONDOWN:
6694 return TOOLBAR_LButtonDown (infoPtr, wParam, lParam);
6695
6696 case WM_LBUTTONUP:
6697 return TOOLBAR_LButtonUp (infoPtr, wParam, lParam);
6698
6699 case WM_RBUTTONUP:
6700 return TOOLBAR_RButtonUp (infoPtr, wParam, lParam);
6701
6702 case WM_RBUTTONDBLCLK:
6703 return TOOLBAR_RButtonDblClk (infoPtr, wParam, lParam);
6704
6705 case WM_MOUSEMOVE:
6706 return TOOLBAR_MouseMove (infoPtr, wParam, lParam);
6707
6708 case WM_MOUSELEAVE:
6709 return TOOLBAR_MouseLeave (infoPtr);
6710
6711 case WM_CAPTURECHANGED:
6712 return TOOLBAR_CaptureChanged(infoPtr);
6713
6714 case WM_NCACTIVATE:
6715 return TOOLBAR_NCActivate (hwnd, wParam, lParam);
6716
6717 case WM_NCCALCSIZE:
6718 return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
6719
6720 case WM_NCCREATE:
6721 return TOOLBAR_NCCreate (hwnd, wParam, (CREATESTRUCTW*)lParam);
6722
6723 case WM_NCPAINT:
6724 return TOOLBAR_NCPaint (hwnd, wParam, lParam);
6725
6726 case WM_NOTIFY:
6727 return TOOLBAR_Notify (infoPtr, (LPNMHDR)lParam);
6728
6729 case WM_NOTIFYFORMAT:
6730 return TOOLBAR_NotifyFormat (infoPtr, wParam, lParam);
6731
6732 case WM_PRINTCLIENT:
6733 case WM_PAINT:
6734 return TOOLBAR_Paint (infoPtr, wParam);
6735
6736 case WM_SETFOCUS:
6737 return TOOLBAR_SetFocus (infoPtr);
6738
6739 case WM_SETFONT:
6740 return TOOLBAR_SetFont(infoPtr, (HFONT)wParam, (WORD)lParam);
6741
6742 case WM_SETREDRAW:
6743 return TOOLBAR_SetRedraw (infoPtr, wParam);
6744
6745 case WM_SIZE:
6746 return TOOLBAR_Size (infoPtr);
6747
6748 case WM_STYLECHANGED:
6749 return TOOLBAR_StyleChanged (infoPtr, (INT)wParam, (LPSTYLESTRUCT)lParam);
6750
6751 case WM_SYSCOLORCHANGE:
6752 return TOOLBAR_SysColorChange ();
6753
6754 case WM_THEMECHANGED:
6755 return theme_changed (hwnd);
6756
6757 /* case WM_WININICHANGE: */
6758
6759 case WM_CHARTOITEM:
6760 case WM_COMMAND:
6761 case WM_DRAWITEM:
6762 case WM_MEASUREITEM:
6763 case WM_VKEYTOITEM:
6764 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
6765
6766 /* We see this in Outlook Express 5.x and just does DefWindowProc */
6767 case PGM_FORWARDMOUSE:
6768 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6769
6770 default:
6771 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
6772 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
6773 uMsg, wParam, lParam);
6774 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
6775 }
6776 }
6777
6778
6779 VOID
6780 TOOLBAR_Register (void)
6781 {
6782 WNDCLASSW wndClass;
6783
6784 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
6785 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
6786 wndClass.lpfnWndProc = ToolbarWindowProc;
6787 wndClass.cbClsExtra = 0;
6788 wndClass.cbWndExtra = sizeof(TOOLBAR_INFO *);
6789 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
6790 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
6791 wndClass.lpszClassName = TOOLBARCLASSNAMEW;
6792
6793 RegisterClassW (&wndClass);
6794 }
6795
6796
6797 VOID
6798 TOOLBAR_Unregister (void)
6799 {
6800 UnregisterClassW (TOOLBARCLASSNAMEW, NULL);
6801 }
6802
6803 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id)
6804 {
6805 HIMAGELIST himlold;
6806 PIMLENTRY c = NULL;
6807
6808 /* Check if the entry already exists */
6809 c = TOOLBAR_GetImageListEntry(*pies, *cies, id);
6810
6811 /* If this is a new entry we must create it and insert into the array */
6812 if (!c)
6813 {
6814 PIMLENTRY *pnies;
6815
6816 c = Alloc(sizeof(IMLENTRY));
6817 c->id = id;
6818
6819 pnies = Alloc((*cies + 1) * sizeof(PIMLENTRY));
6820 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY)));
6821 pnies[*cies] = c;
6822 (*cies)++;
6823
6824 Free(*pies);
6825 *pies = pnies;
6826 }
6827
6828 himlold = c->himl;
6829 c->himl = himl;
6830
6831 return himlold;
6832 }
6833
6834
6835 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies)
6836 {
6837 int i;
6838
6839 for (i = 0; i < *cies; i++)
6840 Free((*pies)[i]);
6841
6842 Free(*pies);
6843
6844 *cies = 0;
6845 *pies = NULL;
6846 }
6847
6848
6849 static PIMLENTRY TOOLBAR_GetImageListEntry(const PIMLENTRY *pies, INT cies, INT id)
6850 {
6851 PIMLENTRY c = NULL;
6852
6853 if (pies != NULL)
6854 {
6855 int i;
6856
6857 for (i = 0; i < cies; i++)
6858 {
6859 if (pies[i]->id == id)
6860 {
6861 c = pies[i];
6862 break;
6863 }
6864 }
6865 }
6866
6867 return c;
6868 }
6869
6870
6871 static HIMAGELIST TOOLBAR_GetImageList(const PIMLENTRY *pies, INT cies, INT id)
6872 {
6873 HIMAGELIST himlDef = 0;
6874 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id);
6875
6876 if (pie)
6877 himlDef = pie->himl;
6878
6879 return himlDef;
6880 }
6881
6882
6883 static BOOL TOOLBAR_GetButtonInfo(const TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb)
6884 {
6885 if (infoPtr->bUnicode)
6886 return TOOLBAR_SendNotify(&nmtb->hdr, infoPtr, TBN_GETBUTTONINFOW);
6887 else
6888 {
6889 CHAR Buffer[256];
6890 NMTOOLBARA nmtba;
6891 BOOL bRet = FALSE;
6892
6893 nmtba.iItem = nmtb->iItem;
6894 nmtba.pszText = Buffer;
6895 nmtba.cchText = 256;
6896 ZeroMemory(nmtba.pszText, nmtba.cchText);
6897
6898 if (TOOLBAR_SendNotify(&nmtba.hdr, infoPtr, TBN_GETBUTTONINFOA))
6899 {
6900 int ccht = strlen(nmtba.pszText);
6901 if (ccht)
6902 MultiByteToWideChar(CP_ACP, 0, nmtba.pszText, -1,
6903 nmtb->pszText, nmtb->cchText);
6904
6905 nmtb->tbButton = nmtba.tbButton;
6906 bRet = TRUE;
6907 }
6908
6909 return bRet;
6910 }
6911 }
6912
6913
6914 static BOOL TOOLBAR_IsButtonRemovable(const TOOLBAR_INFO *infoPtr, int iItem, const CUSTOMBUTTON *btnInfo)
6915 {
6916 NMTOOLBARW nmtb;
6917
6918 /* MSDN states that iItem is the index of the button, rather than the
6919 * command ID as used by every other NMTOOLBAR notification */
6920 nmtb.iItem = iItem;
6921 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON));
6922
6923 return TOOLBAR_SendNotify(&nmtb.hdr, infoPtr, TBN_QUERYDELETE);
6924 }