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