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