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