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