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