1 /*
2 * Rebar control
3 *
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2007, 2008 Mikolaj Zalewski
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * NOTES
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Oct. 19, 2004, by Robert Shearman.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features or bugs please note them below.
29 *
30 * TODO
31 * Styles:
32 * - RBS_DBLCLKTOGGLE
33 * - RBS_FIXEDORDER
34 * - RBS_REGISTERDROP
35 * - RBS_TOOLTIPS
36 * Messages:
37 * - RB_BEGINDRAG
38 * - RB_DRAGMOVE
39 * - RB_ENDDRAG
40 * - RB_GETBANDMARGINS
41 * - RB_GETCOLORSCHEME
42 * - RB_GETDROPTARGET
43 * - RB_GETPALETTE
44 * - RB_SETCOLORSCHEME
45 * - RB_SETPALETTE
46 * - RB_SETTOOLTIPS
47 * - WM_CHARTOITEM
48 * - WM_LBUTTONDBLCLK
49 * - WM_MEASUREITEM
50 * - WM_PALETTECHANGED
51 * - WM_QUERYNEWPALETTE
52 * - WM_RBUTTONDOWN
53 * - WM_RBUTTONUP
54 * - WM_SYSCOLORCHANGE
55 * - WM_VKEYTOITEM
56 * - WM_WININICHANGE
57 * Notifications:
58 * - NM_HCHITTEST
59 * - NM_RELEASEDCAPTURE
60 * - RBN_AUTOBREAK
61 * - RBN_GETOBJECT
62 * - RBN_MINMAX
63 * Band styles:
64 * - RBBS_FIXEDBMP
65 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
66 * to set the size of the separator width (the value SEP_WIDTH_SIZE
67 * in here). Should be fixed!!
68 */
69
70 /*
71 * Testing: set to 1 to make background brush *always* green
72 */
73 #define GLATESTING 0
74
75 /*
76 * 3. REBAR_MoveChildWindows should have a loop because more than
77 * one pass (together with the RBN_CHILDSIZEs) is made on
78 * at least RB_INSERTBAND
79 */
80
81 #include <stdarg.h>
82 #include <stdlib.h>
83 #include <string.h>
84
85 #include "windef.h"
86 #include "winbase.h"
87 #include "wingdi.h"
88 #include "wine/unicode.h"
89 #include "winuser.h"
90 #include "winnls.h"
91 #include "commctrl.h"
92 #include "comctl32.h"
93 #include "uxtheme.h"
94 #include "tmschema.h"
95 #include "wine/debug.h"
96
97 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
98
99 typedef struct
100 {
101 UINT fStyle;
102 UINT fMask;
103 COLORREF clrFore;
104 COLORREF clrBack;
105 INT iImage;
106 HWND hwndChild;
107 UINT cxMinChild; /* valid if _CHILDSIZE */
108 UINT cyMinChild; /* valid if _CHILDSIZE */
109 UINT cx; /* valid if _SIZE */
110 HBITMAP hbmBack;
111 UINT wID;
112 UINT cyChild; /* valid if _CHILDSIZE */
113 UINT cyMaxChild; /* valid if _CHILDSIZE */
114 UINT cyIntegral; /* valid if _CHILDSIZE */
115 UINT cxIdeal;
116 LPARAM lParam;
117 UINT cxHeader;
118
119 INT cxEffective; /* current cx for band */
120 UINT cyHeader; /* the height of the header */
121 UINT cxMinBand; /* minimum cx for band */
122 UINT cyMinBand; /* minimum cy for band */
123
124 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
125 INT iRow; /* zero-based index of the row this band assigned to */
126 UINT fStatus; /* status flags, reset only by _Validate */
127 UINT fDraw; /* drawing flags, reset only by _Layout */
128 UINT uCDret; /* last return from NM_CUSTOMDRAW */
129 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
130 RECT rcGripper; /* calculated gripper rectangle */
131 RECT rcCapImage; /* calculated caption image rectangle */
132 RECT rcCapText; /* calculated caption text rectangle */
133 RECT rcChild; /* calculated child rectangle */
134 RECT rcChevron; /* calculated chevron rectangle */
135
136 LPWSTR lpText;
137 HWND hwndPrevParent;
138 } REBAR_BAND;
139
140 /* fStatus flags */
141 #define HAS_GRIPPER 0x00000001
142 #define HAS_IMAGE 0x00000002
143 #define HAS_TEXT 0x00000004
144
145 /* fDraw flags */
146 #define DRAW_GRIPPER 0x00000001
147 #define DRAW_IMAGE 0x00000002
148 #define DRAW_TEXT 0x00000004
149 #define DRAW_CHEVRONHOT 0x00000040
150 #define DRAW_CHEVRONPUSHED 0x00000080
151 #define NTF_INVALIDATE 0x01000000
152
153 typedef struct
154 {
155 COLORREF clrBk; /* background color */
156 COLORREF clrText; /* text color */
157 COLORREF clrBtnText; /* system color for BTNTEXT */
158 COLORREF clrBtnFace; /* system color for BTNFACE */
159 HIMAGELIST himl; /* handle to imagelist */
160 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
161 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
162 HWND hwndSelf; /* handle of REBAR window itself */
163 HWND hwndToolTip; /* handle to the tool tip control */
164 HWND hwndNotify; /* notification window (parent) */
165 HFONT hDefaultFont;
166 HFONT hFont; /* handle to the rebar's font */
167 SIZE imageSize; /* image size (image list) */
168 DWORD dwStyle; /* window style */
169 DWORD orgStyle; /* original style (dwStyle may change) */
170 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
171 BOOL bUnicode; /* TRUE if parent wants notify in W format */
172 BOOL DoRedraw; /* TRUE to actually draw bands */
173 UINT fStatus; /* Status flags (see below) */
174 HCURSOR hcurArrow; /* handle to the arrow cursor */
175 HCURSOR hcurHorz; /* handle to the EW cursor */
176 HCURSOR hcurVert; /* handle to the NS cursor */
177 HCURSOR hcurDrag; /* handle to the drag cursor */
178 INT iVersion; /* version number */
179 POINT dragStart; /* x,y of button down */
180 POINT dragNow; /* x,y of this MouseMove */
181 INT iOldBand; /* last band that had the mouse cursor over it */
182 INT ihitoffset; /* offset of hotspot from gripper.left */
183 INT ichevronhotBand; /* last band that had a hot chevron */
184 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
185
186 REBAR_BAND *bands; /* pointer to the array of rebar bands */
187 } REBAR_INFO;
188
189 /* fStatus flags */
190 #define BEGIN_DRAG_ISSUED 0x00000001
191 #define SELF_RESIZE 0x00000002
192 #define BAND_NEEDS_REDRAW 0x00000020
193
194 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
195 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
196
197 /* ---- REBAR layout constants. Mostly determined by ---- */
198 /* ---- experiment on WIN 98. ---- */
199
200 /* Width (or height) of separators between bands (either horz. or */
201 /* vert.). True only if RBS_BANDBORDERS is set */
202 #define SEP_WIDTH_SIZE 2
203 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
204
205 /* Blank (background color) space between Gripper (if present) */
206 /* and next item (image, text, or window). Always present */
207 #define REBAR_ALWAYS_SPACE 4
208
209 /* Blank (background color) space after Image (if present). */
210 #define REBAR_POST_IMAGE 2
211
212 /* Blank (background color) space after Text (if present). */
213 #define REBAR_POST_TEXT 4
214
215 /* Height of vertical gripper in a CCS_VERT rebar. */
216 #define GRIPPER_HEIGHT 16
217
218 /* Blank (background color) space before Gripper (if present). */
219 #define REBAR_PRE_GRIPPER 2
220
221 /* Width (of normal vertical gripper) or height (of horz. gripper) */
222 /* if present. */
223 #define GRIPPER_WIDTH 3
224
225 /* Width of the chevron button if present */
226 #define CHEVRON_WIDTH 10
227
228 /* the gap between the child and the next band */
229 #define REBAR_POST_CHILD 4
230
231 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
232 /* either top or bottom */
233 #define REBAR_DIVIDER 2
234
235 /* height of a rebar without a child */
236 #define REBAR_NO_CHILD_HEIGHT 4
237
238 /* minimum vertical height of a normal bar */
239 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
240 #define REBAR_MINSIZE 23
241
242 /* This is the increment that is used over the band height */
243 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
244
245 /* ---- End of REBAR layout constants. ---- */
246
247 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
248
249 /* The following define determines if a given band is hidden */
250 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
251 ((infoPtr->dwStyle & CCS_VERT) && \
252 ((a)->fStyle & RBBS_NOVERT)))
253
254 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
255
256 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
257 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
258
259 /* "constant values" retrieved when DLL was initialized */
260 /* FIXME we do this when the classes are registered. */
261 static UINT mindragx = 0;
262 static UINT mindragy = 0;
263
264 static const char * const band_stylename[] = {
265 "RBBS_BREAK", /* 0001 */
266 "RBBS_FIXEDSIZE", /* 0002 */
267 "RBBS_CHILDEDGE", /* 0004 */
268 "RBBS_HIDDEN", /* 0008 */
269 "RBBS_NOVERT", /* 0010 */
270 "RBBS_FIXEDBMP", /* 0020 */
271 "RBBS_VARIABLEHEIGHT", /* 0040 */
272 "RBBS_GRIPPERALWAYS", /* 0080 */
273 "RBBS_NOGRIPPER", /* 0100 */
274 NULL };
275
276 static const char * const band_maskname[] = {
277 "RBBIM_STYLE", /* 0x00000001 */
278 "RBBIM_COLORS", /* 0x00000002 */
279 "RBBIM_TEXT", /* 0x00000004 */
280 "RBBIM_IMAGE", /* 0x00000008 */
281 "RBBIM_CHILD", /* 0x00000010 */
282 "RBBIM_CHILDSIZE", /* 0x00000020 */
283 "RBBIM_SIZE", /* 0x00000040 */
284 "RBBIM_BACKGROUND", /* 0x00000080 */
285 "RBBIM_ID", /* 0x00000100 */
286 "RBBIM_IDEALSIZE", /* 0x00000200 */
287 "RBBIM_LPARAM", /* 0x00000400 */
288 "RBBIM_HEADERSIZE", /* 0x00000800 */
289 NULL };
290
291
292 static CHAR line[200];
293
294 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
295
296 static CHAR *
297 REBAR_FmtStyle( UINT style)
298 {
299 INT i = 0;
300
301 *line = 0;
302 while (band_stylename[i]) {
303 if (style & (1<<i)) {
304 if (*line != 0) strcat(line, " | ");
305 strcat(line, band_stylename[i]);
306 }
307 i++;
308 }
309 return line;
310 }
311
312
313 static CHAR *
314 REBAR_FmtMask( UINT mask)
315 {
316 INT i = 0;
317
318 *line = 0;
319 while (band_maskname[i]) {
320 if (mask & (1<<i)) {
321 if (*line != 0) strcat(line, " | ");
322 strcat(line, band_maskname[i]);
323 }
324 i++;
325 }
326 return line;
327 }
328
329
330 static VOID
331 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
332 {
333 if( !TRACE_ON(rebar) ) return;
334 TRACE("band info: ");
335 if (pB->fMask & RBBIM_ID)
336 TRACE("ID=%u, ", pB->wID);
337 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
338 if (pB->fMask & RBBIM_COLORS)
339 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
340 TRACE("\n");
341
342 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
343 if (pB->fMask & RBBIM_STYLE)
344 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
345 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
346 TRACE("band info:");
347 if (pB->fMask & RBBIM_SIZE)
348 TRACE(" cx=%u", pB->cx);
349 if (pB->fMask & RBBIM_IDEALSIZE)
350 TRACE(" xIdeal=%u", pB->cxIdeal);
351 if (pB->fMask & RBBIM_HEADERSIZE)
352 TRACE(" xHeader=%u", pB->cxHeader);
353 if (pB->fMask & RBBIM_LPARAM)
354 TRACE(" lParam=0x%08lx", pB->lParam);
355 TRACE("\n");
356 }
357 if (pB->fMask & RBBIM_CHILDSIZE)
358 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
359 pB->cxMinChild,
360 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
361 }
362
363 static VOID
364 REBAR_DumpBand (const REBAR_INFO *iP)
365 {
366 REBAR_BAND *pB;
367 UINT i;
368
369 if(! TRACE_ON(rebar) ) return;
370
371 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
372 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
373 iP->calcSize.cx, iP->calcSize.cy);
374 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
375 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
376 iP->dragNow.x, iP->dragNow.y,
377 iP->iGrabbedBand);
378 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
379 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
380 (iP->DoRedraw)?"TRUE":"FALSE");
381 for (i = 0; i < iP->uNumBands; i++) {
382 pB = &iP->bands[i];
383 TRACE("band # %u:", i);
384 if (pB->fMask & RBBIM_ID)
385 TRACE(" ID=%u", pB->wID);
386 if (pB->fMask & RBBIM_CHILD)
387 TRACE(" child=%p", pB->hwndChild);
388 if (pB->fMask & RBBIM_COLORS)
389 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
390 TRACE("\n");
391 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
392 if (pB->fMask & RBBIM_STYLE)
393 TRACE("band # %u: style=0x%08x (%s)\n",
394 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
395 TRACE("band # %u: xHeader=%u",
396 i, pB->cxHeader);
397 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
398 if (pB->fMask & RBBIM_SIZE)
399 TRACE(" cx=%u", pB->cx);
400 if (pB->fMask & RBBIM_IDEALSIZE)
401 TRACE(" xIdeal=%u", pB->cxIdeal);
402 if (pB->fMask & RBBIM_LPARAM)
403 TRACE(" lParam=0x%08lx", pB->lParam);
404 }
405 TRACE("\n");
406 if (RBBIM_CHILDSIZE)
407 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
408 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
409 if (pB->fMask & RBBIM_TEXT)
410 TRACE("band # %u: text=%s\n",
411 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
412 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
413 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
414 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
415 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
416 wine_dbgstr_rect(&pB->rcGripper));
417 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
418 i, wine_dbgstr_rect(&pB->rcCapImage),
419 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
420 }
421
422 }
423
424 /* dest can be equal to src */
425 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
426 {
427 if (infoPtr->dwStyle & CCS_VERT) {
428 int tmp;
429 tmp = src->left;
430 dest->left = src->top;
431 dest->top = tmp;
432
433 tmp = src->right;
434 dest->right = src->bottom;
435 dest->bottom = tmp;
436 } else {
437 *dest = *src;
438 }
439 }
440
441 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
442 {
443 if (infoPtr->dwStyle & CCS_VERT)
444 return lpRect->bottom - lpRect->top;
445 return lpRect->right - lpRect->left;
446 }
447
448 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
449 {
450 if (infoPtr->dwStyle & CCS_VERT)
451 return lpRect->right - lpRect->left;
452 return lpRect->bottom - lpRect->top;
453 }
454
455 static int round_child_height(REBAR_BAND *lpBand, int cyHeight)
456 {
457 int cy = 0;
458 if (lpBand->cyIntegral == 0)
459 return cyHeight;
460 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
461 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
462 cy = min(cy, lpBand->cyMaxChild);
463 return cy;
464 }
465
466 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
467 {
468 lpBand->cyMinBand = max(lpBand->cyHeader,
469 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
470 }
471
472 static void
473 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
474 {
475 INT x, y;
476 HPEN hPen, hOldPen;
477
478 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
479 hOldPen = SelectObject ( hdc, hPen );
480 x = left + 2;
481 y = top;
482 MoveToEx (hdc, x, y, NULL);
483 LineTo (hdc, x+5, y++); x++;
484 MoveToEx (hdc, x, y, NULL);
485 LineTo (hdc, x+3, y++); x++;
486 MoveToEx (hdc, x, y, NULL);
487 LineTo (hdc, x+1, y++);
488 SelectObject( hdc, hOldPen );
489 DeleteObject( hPen );
490 }
491
492 static HWND
493 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
494 {
495 HWND parent, owner;
496
497 parent = infoPtr->hwndNotify;
498 if (!parent) {
499 parent = GetParent (infoPtr->hwndSelf);
500 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
501 if (owner) parent = owner;
502 }
503 return parent;
504 }
505
506
507 static INT
508 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
509 {
510 HWND parent;
511
512 parent = REBAR_GetNotifyParent (infoPtr);
513 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
514 nmhdr->hwndFrom = infoPtr->hwndSelf;
515 nmhdr->code = code;
516
517 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
518
519 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
520 }
521
522 static INT
523 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
524 {
525 NMREBAR notify_rebar;
526 REBAR_BAND *lpBand;
527
528 notify_rebar.dwMask = 0;
529 if (uBand!=-1) {
530 lpBand = &infoPtr->bands[uBand];
531 if (lpBand->fMask & RBBIM_ID) {
532 notify_rebar.dwMask |= RBNM_ID;
533 notify_rebar.wID = lpBand->wID;
534 }
535 if (lpBand->fMask & RBBIM_LPARAM) {
536 notify_rebar.dwMask |= RBNM_LPARAM;
537 notify_rebar.lParam = lpBand->lParam;
538 }
539 if (lpBand->fMask & RBBIM_STYLE) {
540 notify_rebar.dwMask |= RBNM_STYLE;
541 notify_rebar.fStyle = lpBand->fStyle;
542 }
543 }
544 notify_rebar.uBand = uBand;
545 return REBAR_Notify ((NMHDR *)¬ify_rebar, infoPtr, code);
546 }
547
548 static VOID
549 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
550 {
551 HFONT hOldFont = 0;
552 INT oldBkMode = 0;
553 NMCUSTOMDRAW nmcd;
554 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
555 RECT rcBand;
556
557 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
558
559 if (lpBand->fDraw & DRAW_TEXT) {
560 hOldFont = SelectObject (hdc, infoPtr->hFont);
561 oldBkMode = SetBkMode (hdc, TRANSPARENT);
562 }
563
564 /* should test for CDRF_NOTIFYITEMDRAW here */
565 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
566 nmcd.hdc = hdc;
567 nmcd.rc = rcBand;
568 nmcd.rc.right = lpBand->rcCapText.right;
569 nmcd.rc.bottom = lpBand->rcCapText.bottom;
570 nmcd.dwItemSpec = lpBand->wID;
571 nmcd.uItemState = 0;
572 nmcd.lItemlParam = lpBand->lParam;
573 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
574 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
575 if (oldBkMode != TRANSPARENT)
576 SetBkMode (hdc, oldBkMode);
577 SelectObject (hdc, hOldFont);
578 return;
579 }
580
581 /* draw gripper */
582 if (lpBand->fDraw & DRAW_GRIPPER)
583 {
584 if (theme)
585 {
586 RECT rcGripper = lpBand->rcGripper;
587 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
588 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
589 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
590 lpBand->rcGripper.top - rcGripper.top);
591 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
592 }
593 else
594 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
595 }
596
597 /* draw caption image */
598 if (lpBand->fDraw & DRAW_IMAGE) {
599 POINT pt;
600
601 /* center image */
602 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
603 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
604
605 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
606 pt.x, pt.y,
607 ILD_TRANSPARENT);
608 }
609
610 /* draw caption text */
611 if (lpBand->fDraw & DRAW_TEXT) {
612 /* need to handle CDRF_NEWFONT here */
613 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
614 COLORREF oldcolor = CLR_NONE;
615 COLORREF new;
616 if (lpBand->clrFore != CLR_NONE) {
617 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
618 lpBand->clrFore;
619 oldcolor = SetTextColor (hdc, new);
620 }
621 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
622 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
623 if (oldBkMode != TRANSPARENT)
624 SetBkMode (hdc, oldBkMode);
625 if (lpBand->clrFore != CLR_NONE)
626 SetTextColor (hdc, oldcolor);
627 SelectObject (hdc, hOldFont);
628 }
629
630 if (!IsRectEmpty(&lpBand->rcChevron))
631 {
632 if (theme)
633 {
634 int stateId;
635 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
636 stateId = CHEVS_PRESSED;
637 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
638 stateId = CHEVS_HOT;
639 else
640 stateId = CHEVS_NORMAL;
641 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
642 }
643 else
644 {
645 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
646 {
647 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
648 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
649 }
650 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
651 {
652 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
653 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
654 }
655 else
656 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
657 }
658 }
659
660 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
661 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
662 nmcd.hdc = hdc;
663 nmcd.rc = rcBand;
664 nmcd.rc.right = lpBand->rcCapText.right;
665 nmcd.rc.bottom = lpBand->rcCapText.bottom;
666 nmcd.dwItemSpec = lpBand->wID;
667 nmcd.uItemState = 0;
668 nmcd.lItemlParam = lpBand->lParam;
669 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
670 }
671 }
672
673
674 static VOID
675 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
676 {
677 REBAR_BAND *lpBand;
678 UINT i;
679
680 if (!infoPtr->DoRedraw) return;
681
682 for (i = 0; i < infoPtr->uNumBands; i++) {
683 lpBand = &infoPtr->bands[i];
684
685 if (HIDDENBAND(lpBand)) continue;
686
687 /* now draw the band */
688 TRACE("[%p] drawing band %i, flags=%08x\n",
689 infoPtr->hwndSelf, i, lpBand->fDraw);
690 REBAR_DrawBand (hdc, infoPtr, lpBand);
691
692 }
693 }
694
695
696 static void
697 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
698 /* Function: this routine initializes all the rectangles in */
699 /* each band in a row to fit in the adjusted rcBand rect. */
700 /* *** Supports only Horizontal bars. *** */
701 {
702 REBAR_BAND *lpBand;
703 UINT i, xoff, yoff;
704 RECT work;
705
706 for(i=rstart; i<rend; i++){
707 lpBand = &infoPtr->bands[i];
708 if (HIDDENBAND(lpBand)) {
709 SetRect (&lpBand->rcChild,
710 lpBand->rcBand.right, lpBand->rcBand.top,
711 lpBand->rcBand.right, lpBand->rcBand.bottom);
712 continue;
713 }
714
715 /* set initial gripper rectangle */
716 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
717 lpBand->rcBand.left, lpBand->rcBand.bottom);
718
719 /* calculate gripper rectangle */
720 if ( lpBand->fStatus & HAS_GRIPPER) {
721 lpBand->fDraw |= DRAW_GRIPPER;
722 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
723 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
724 lpBand->rcGripper.top += 2;
725 lpBand->rcGripper.bottom -= 2;
726
727 SetRect (&lpBand->rcCapImage,
728 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
729 lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
730 }
731 else { /* no gripper will be drawn */
732 xoff = 0;
733 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
734 /* if no gripper but either image or text, then leave space */
735 xoff = REBAR_ALWAYS_SPACE;
736 SetRect (&lpBand->rcCapImage,
737 lpBand->rcBand.left+xoff, lpBand->rcBand.top,
738 lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
739 }
740
741 /* image is visible */
742 if (lpBand->fStatus & HAS_IMAGE) {
743 lpBand->fDraw |= DRAW_IMAGE;
744 lpBand->rcCapImage.right += infoPtr->imageSize.cx;
745 lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
746
747 /* set initial caption text rectangle */
748 SetRect (&lpBand->rcCapText,
749 lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
750 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
751 }
752 else {
753 /* set initial caption text rectangle */
754 SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
755 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
756 }
757
758 /* text is visible */
759 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
760 lpBand->fDraw |= DRAW_TEXT;
761 lpBand->rcCapText.right = max(lpBand->rcCapText.left,
762 lpBand->rcCapText.right-REBAR_POST_TEXT);
763 }
764
765 /* set initial child window rectangle if there is a child */
766 if (lpBand->hwndChild != NULL) {
767 int cyBand = lpBand->rcBand.bottom - lpBand->rcBand.top;
768 yoff = (cyBand - lpBand->cyChild) / 2;
769 SetRect (&lpBand->rcChild,
770 lpBand->rcBand.left + lpBand->cxHeader, lpBand->rcBand.top + yoff,
771 lpBand->rcBand.right - REBAR_POST_CHILD, lpBand->rcBand.top + yoff + lpBand->cyChild);
772 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
773 {
774 lpBand->rcChild.right -= CHEVRON_WIDTH;
775 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
776 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
777 lpBand->rcChild.bottom);
778 }
779 }
780 else {
781 SetRect (&lpBand->rcChild,
782 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
783 lpBand->rcBand.right, lpBand->rcBand.bottom);
784 }
785
786 /* flag if notify required and invalidate rectangle */
787 if (lpBand->fDraw & NTF_INVALIDATE) {
788 TRACE("invalidating (%d,%d)-(%d,%d)\n",
789 lpBand->rcBand.left,
790 lpBand->rcBand.top,
791 lpBand->rcBand.right + SEP_WIDTH,
792 lpBand->rcBand.bottom + SEP_WIDTH);
793 lpBand->fDraw &= ~NTF_INVALIDATE;
794 work = lpBand->rcBand;
795 work.right += SEP_WIDTH;
796 work.bottom += SEP_WIDTH;
797 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
798 InvalidateRect(lpBand->hwndChild, NULL, TRUE);
799 }
800
801 }
802
803 }
804
805
806 static VOID
807 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
808 /* Function: this routine initializes all the rectangles in */
809 /* each band in a row to fit in the adjusted rcBand rect. */
810 /* *** Supports only Vertical bars. *** */
811 {
812 REBAR_BAND *lpBand;
813 UINT i, xoff;
814 RECT work;
815
816 for(i=rstart; i<rend; i++){
817 RECT rcBand;
818 lpBand = &infoPtr->bands[i];
819 if (HIDDENBAND(lpBand)) continue;
820
821 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
822
823 /* set initial gripper rectangle */
824 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
825
826 /* calculate gripper rectangle */
827 if (lpBand->fStatus & HAS_GRIPPER) {
828 lpBand->fDraw |= DRAW_GRIPPER;
829
830 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
831 /* vertical gripper */
832 lpBand->rcGripper.left += 3;
833 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
834 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
835 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
836
837 /* initialize Caption image rectangle */
838 SetRect (&lpBand->rcCapImage, rcBand.left,
839 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
840 rcBand.right,
841 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
842 }
843 else {
844 /* horizontal gripper */
845 lpBand->rcGripper.left += 2;
846 lpBand->rcGripper.right -= 2;
847 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
848 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
849
850 /* initialize Caption image rectangle */
851 SetRect (&lpBand->rcCapImage, rcBand.left,
852 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
853 rcBand.right,
854 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
855 }
856 }
857 else { /* no gripper will be drawn */
858 xoff = 0;
859 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
860 /* if no gripper but either image or text, then leave space */
861 xoff = REBAR_ALWAYS_SPACE;
862 /* initialize Caption image rectangle */
863 SetRect (&lpBand->rcCapImage,
864 rcBand.left, rcBand.top+xoff,
865 rcBand.right, rcBand.top+xoff);
866 }
867
868 /* image is visible */
869 if (lpBand->fStatus & HAS_IMAGE) {
870 lpBand->fDraw |= DRAW_IMAGE;
871
872 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
873 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
874
875 /* set initial caption text rectangle */
876 SetRect (&lpBand->rcCapText,
877 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
878 rcBand.right, rcBand.top+lpBand->cxHeader);
879 }
880 else {
881 /* set initial caption text rectangle */
882 SetRect (&lpBand->rcCapText,
883 rcBand.left, lpBand->rcCapImage.bottom,
884 rcBand.right, rcBand.top+lpBand->cxHeader);
885 }
886
887 /* text is visible */
888 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
889 lpBand->fDraw |= DRAW_TEXT;
890 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
891 lpBand->rcCapText.bottom);
892 }
893
894 /* set initial child window rectangle if there is a child */
895 if (lpBand->hwndChild != NULL) {
896 int cxBand = rcBand.right - rcBand.left;
897 xoff = (cxBand - lpBand->cyChild) / 2;
898 SetRect (&lpBand->rcChild,
899 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
900 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
901 }
902 else {
903 SetRect (&lpBand->rcChild,
904 rcBand.left, rcBand.top+lpBand->cxHeader,
905 rcBand.right, rcBand.bottom);
906 }
907
908 if (lpBand->fDraw & NTF_INVALIDATE) {
909 TRACE("invalidating (%d,%d)-(%d,%d)\n",
910 rcBand.left,
911 rcBand.top,
912 rcBand.right + SEP_WIDTH,
913 rcBand.bottom + SEP_WIDTH);
914 lpBand->fDraw &= ~NTF_INVALIDATE;
915 work = rcBand;
916 work.bottom += SEP_WIDTH;
917 work.right += SEP_WIDTH;
918 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
919 InvalidateRect(lpBand->hwndChild, NULL, TRUE);
920 }
921
922 }
923 }
924
925
926 static VOID
927 REBAR_ForceResize (REBAR_INFO *infoPtr)
928 /* Function: This changes the size of the REBAR window to that */
929 /* calculated by REBAR_Layout. */
930 {
931 INT x, y, width, height;
932 INT xedge = 0, yedge = 0;
933 RECT rcSelf;
934
935 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
936
937 if (infoPtr->dwStyle & CCS_NORESIZE)
938 return;
939
940 if (infoPtr->dwStyle & WS_BORDER)
941 {
942 xedge = GetSystemMetrics(SM_CXEDGE);
943 yedge = GetSystemMetrics(SM_CYEDGE);
944 /* swap for CCS_VERT? */
945 }
946
947 /* compute rebar window rect in parent client coordinates */
948 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
949 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
950 translate_rect(infoPtr, &rcSelf, &rcSelf);
951
952 height = infoPtr->calcSize.cy + 2*yedge;
953 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {