[COMCTL32] rebar: Use DrawThemeText when drawing text with themes. CORE-13855
[reactos.git] / dll / win32 / comctl32 / rebar.c
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_PALETTECHANGED
50 * - WM_QUERYNEWPALETTE
51 * - WM_RBUTTONDOWN
52 * - WM_RBUTTONUP
53 * - WM_VKEYTOITEM
54 * - WM_WININICHANGE
55 * Notifications:
56 * - NM_HCHITTEST
57 * - NM_RELEASEDCAPTURE
58 * - RBN_AUTOBREAK
59 * - RBN_GETOBJECT
60 * - RBN_MINMAX
61 * Band styles:
62 * - RBBS_FIXEDBMP
63 * Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
64 * to set the size of the separator width (the value SEP_WIDTH_SIZE
65 * in here). Should be fixed!!
66 */
67
68 /*
69 * Testing: set to 1 to make background brush *always* green
70 */
71 #define GLATESTING 0
72
73 /*
74 * 3. REBAR_MoveChildWindows should have a loop because more than
75 * one pass (together with the RBN_CHILDSIZEs) is made on
76 * at least RB_INSERTBAND
77 */
78
79 #include "comctl32.h"
80
81 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
82
83 typedef struct
84 {
85 UINT fStyle;
86 UINT fMask;
87 COLORREF clrFore;
88 COLORREF clrBack;
89 INT iImage;
90 HWND hwndChild;
91 UINT cxMinChild; /* valid if _CHILDSIZE */
92 UINT cyMinChild; /* valid if _CHILDSIZE */
93 UINT cx; /* valid if _SIZE */
94 HBITMAP hbmBack;
95 UINT wID;
96 UINT cyChild; /* valid if _CHILDSIZE */
97 UINT cyMaxChild; /* valid if _CHILDSIZE */
98 UINT cyIntegral; /* valid if _CHILDSIZE */
99 UINT cxIdeal;
100 LPARAM lParam;
101 UINT cxHeader;
102
103 INT cxEffective; /* current cx for band */
104 UINT cyHeader; /* the height of the header */
105 UINT cxMinBand; /* minimum cx for band */
106 UINT cyMinBand; /* minimum cy for band */
107
108 UINT cyRowSoFar; /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
109 INT iRow; /* zero-based index of the row this band assigned to */
110 UINT fStatus; /* status flags, reset only by _Validate */
111 UINT fDraw; /* drawing flags, reset only by _Layout */
112 UINT uCDret; /* last return from NM_CUSTOMDRAW */
113 RECT rcBand; /* calculated band rectangle - coordinates swapped for CCS_VERT */
114 RECT rcGripper; /* calculated gripper rectangle */
115 RECT rcCapImage; /* calculated caption image rectangle */
116 RECT rcCapText; /* calculated caption text rectangle */
117 RECT rcChild; /* calculated child rectangle */
118 RECT rcChevron; /* calculated chevron rectangle */
119
120 LPWSTR lpText;
121 HWND hwndPrevParent;
122 } REBAR_BAND;
123
124 /* has a value of: 0, CCS_TOP, CCS_NOMOVEY, CCS_BOTTOM */
125 #define CCS_LAYOUT_MASK 0x3
126
127 /* fStatus flags */
128 #define HAS_GRIPPER 0x00000001
129 #define HAS_IMAGE 0x00000002
130 #define HAS_TEXT 0x00000004
131
132 /* fDraw flags */
133 #define DRAW_GRIPPER 0x00000001
134 #define DRAW_IMAGE 0x00000002
135 #define DRAW_TEXT 0x00000004
136 #define DRAW_CHEVRONHOT 0x00000040
137 #define DRAW_CHEVRONPUSHED 0x00000080
138 #define NTF_INVALIDATE 0x01000000
139
140 typedef struct
141 {
142 COLORREF clrBk; /* background color */
143 COLORREF clrText; /* text color */
144 COLORREF clrBtnText; /* system color for BTNTEXT */
145 COLORREF clrBtnFace; /* system color for BTNFACE */
146 HIMAGELIST himl; /* handle to imagelist */
147 UINT uNumBands; /* # of bands in rebar (first=0, last=uNumBands-1 */
148 UINT uNumRows; /* # of rows of bands (first=1, last=uNumRows */
149 HWND hwndSelf; /* handle of REBAR window itself */
150 HWND hwndToolTip; /* handle to the tool tip control */
151 HWND hwndNotify; /* notification window (parent) */
152 HFONT hDefaultFont;
153 HFONT hFont; /* handle to the rebar's font */
154 SIZE imageSize; /* image size (image list) */
155 DWORD dwStyle; /* window style */
156 DWORD orgStyle; /* original style (dwStyle may change) */
157 SIZE calcSize; /* calculated rebar size - coordinates swapped for CCS_VERT */
158 BOOL bUnicode; /* TRUE if parent wants notify in W format */
159 BOOL DoRedraw; /* TRUE to actually draw bands */
160 UINT fStatus; /* Status flags (see below) */
161 HCURSOR hcurArrow; /* handle to the arrow cursor */
162 HCURSOR hcurHorz; /* handle to the EW cursor */
163 HCURSOR hcurVert; /* handle to the NS cursor */
164 HCURSOR hcurDrag; /* handle to the drag cursor */
165 INT iVersion; /* version number */
166 POINT dragStart; /* x,y of button down */
167 POINT dragNow; /* x,y of this MouseMove */
168 INT iOldBand; /* last band that had the mouse cursor over it */
169 INT ihitoffset; /* offset of hotspot from gripper.left */
170 INT ichevronhotBand; /* last band that had a hot chevron */
171 INT iGrabbedBand;/* band number of band whose gripper was grabbed */
172
173 HDPA bands; /* pointer to the array of rebar bands */
174 } REBAR_INFO;
175
176 /* fStatus flags */
177 #define BEGIN_DRAG_ISSUED 0x00000001
178 #define SELF_RESIZE 0x00000002
179 #define BAND_NEEDS_REDRAW 0x00000020
180
181 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
182 #define RBBS_UNDOC_FIXEDHEADER 0x40000000
183
184 /* ---- REBAR layout constants. Mostly determined by ---- */
185 /* ---- experiment on WIN 98. ---- */
186
187 /* Width (or height) of separators between bands (either horz. or */
188 /* vert.). True only if RBS_BANDBORDERS is set */
189 #define SEP_WIDTH_SIZE 2
190 #define SEP_WIDTH ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
191
192 /* Blank (background color) space between Gripper (if present) */
193 /* and next item (image, text, or window). Always present */
194 #define REBAR_ALWAYS_SPACE 4
195
196 /* Blank (background color) space after Image (if present). */
197 #define REBAR_POST_IMAGE 2
198
199 /* Blank (background color) space after Text (if present). */
200 #define REBAR_POST_TEXT 4
201
202 /* Height of vertical gripper in a CCS_VERT rebar. */
203 #define GRIPPER_HEIGHT 16
204
205 /* Blank (background color) space before Gripper (if present). */
206 #define REBAR_PRE_GRIPPER 2
207
208 /* Width (of normal vertical gripper) or height (of horz. gripper) */
209 /* if present. */
210 #define GRIPPER_WIDTH 3
211
212 /* Width of the chevron button if present */
213 #define CHEVRON_WIDTH 10
214
215 /* the gap between the child and the next band */
216 #define REBAR_POST_CHILD 4
217
218 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER) */
219 /* either top or bottom */
220 #define REBAR_DIVIDER 2
221
222 /* height of a rebar without a child */
223 #define REBAR_NO_CHILD_HEIGHT 4
224
225 /* minimum vertical height of a normal bar */
226 /* or minimum width of a CCS_VERT bar - from experiment on Win2k */
227 #define REBAR_MINSIZE 23
228
229 /* This is the increment that is used over the band height */
230 #define REBARSPACE(a) ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
231
232 /* ---- End of REBAR layout constants. ---- */
233
234 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
235
236 /* The following define determines if a given band is hidden */
237 #define HIDDENBAND(a) (((a)->fStyle & RBBS_HIDDEN) || \
238 ((infoPtr->dwStyle & CCS_VERT) && \
239 ((a)->fStyle & RBBS_NOVERT)))
240
241 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
242
243 static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
244 static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
245
246 /* no index check here */
247 static inline REBAR_BAND* REBAR_GetBand(const REBAR_INFO *infoPtr, INT i)
248 {
249 assert(i >= 0 && i < infoPtr->uNumBands);
250 return DPA_GetPtr(infoPtr->bands, i);
251 }
252
253 /* "constant values" retrieved when DLL was initialized */
254 /* FIXME we do this when the classes are registered. */
255 static UINT mindragx = 0;
256 static UINT mindragy = 0;
257
258 static const char * const band_stylename[] = {
259 "RBBS_BREAK", /* 0001 */
260 "RBBS_FIXEDSIZE", /* 0002 */
261 "RBBS_CHILDEDGE", /* 0004 */
262 "RBBS_HIDDEN", /* 0008 */
263 "RBBS_NOVERT", /* 0010 */
264 "RBBS_FIXEDBMP", /* 0020 */
265 "RBBS_VARIABLEHEIGHT", /* 0040 */
266 "RBBS_GRIPPERALWAYS", /* 0080 */
267 "RBBS_NOGRIPPER", /* 0100 */
268 NULL };
269
270 static const char * const band_maskname[] = {
271 "RBBIM_STYLE", /* 0x00000001 */
272 "RBBIM_COLORS", /* 0x00000002 */
273 "RBBIM_TEXT", /* 0x00000004 */
274 "RBBIM_IMAGE", /* 0x00000008 */
275 "RBBIM_CHILD", /* 0x00000010 */
276 "RBBIM_CHILDSIZE", /* 0x00000020 */
277 "RBBIM_SIZE", /* 0x00000040 */
278 "RBBIM_BACKGROUND", /* 0x00000080 */
279 "RBBIM_ID", /* 0x00000100 */
280 "RBBIM_IDEALSIZE", /* 0x00000200 */
281 "RBBIM_LPARAM", /* 0x00000400 */
282 "RBBIM_HEADERSIZE", /* 0x00000800 */
283 NULL };
284
285
286 static CHAR line[200];
287
288 static const WCHAR themeClass[] = { 'R','e','b','a','r',0 };
289
290 static CHAR *
291 REBAR_FmtStyle( UINT style)
292 {
293 INT i = 0;
294
295 *line = 0;
296 while (band_stylename[i]) {
297 if (style & (1<<i)) {
298 if (*line != 0) strcat(line, " | ");
299 strcat(line, band_stylename[i]);
300 }
301 i++;
302 }
303 return line;
304 }
305
306
307 static CHAR *
308 REBAR_FmtMask( UINT mask)
309 {
310 INT i = 0;
311
312 *line = 0;
313 while (band_maskname[i]) {
314 if (mask & (1<<i)) {
315 if (*line != 0) strcat(line, " | ");
316 strcat(line, band_maskname[i]);
317 }
318 i++;
319 }
320 return line;
321 }
322
323
324 static VOID
325 REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
326 {
327 if( !TRACE_ON(rebar) ) return;
328 TRACE("band info: ");
329 if (pB->fMask & RBBIM_ID)
330 TRACE("ID=%u, ", pB->wID);
331 TRACE("size=%u, child=%p", pB->cbSize, pB->hwndChild);
332 if (pB->fMask & RBBIM_COLORS)
333 TRACE(", clrF=0x%06x, clrB=0x%06x", pB->clrFore, pB->clrBack);
334 TRACE("\n");
335
336 TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
337 if (pB->fMask & RBBIM_STYLE)
338 TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
339 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
340 TRACE("band info:");
341 if (pB->fMask & RBBIM_SIZE)
342 TRACE(" cx=%u", pB->cx);
343 if (pB->fMask & RBBIM_IDEALSIZE)
344 TRACE(" xIdeal=%u", pB->cxIdeal);
345 if (pB->fMask & RBBIM_HEADERSIZE)
346 TRACE(" xHeader=%u", pB->cxHeader);
347 if (pB->fMask & RBBIM_LPARAM)
348 TRACE(" lParam=0x%08lx", pB->lParam);
349 TRACE("\n");
350 }
351 if (pB->fMask & RBBIM_CHILDSIZE)
352 TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
353 pB->cxMinChild,
354 pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
355 }
356
357 static VOID
358 REBAR_DumpBand (const REBAR_INFO *iP)
359 {
360 REBAR_BAND *pB;
361 UINT i;
362
363 if(! TRACE_ON(rebar) ) return;
364
365 TRACE("hwnd=%p: color=%08x/%08x, bands=%u, rows=%u, cSize=%d,%d\n",
366 iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
367 iP->calcSize.cx, iP->calcSize.cy);
368 TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
369 iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
370 iP->dragNow.x, iP->dragNow.y,
371 iP->iGrabbedBand);
372 TRACE("hwnd=%p: style=%08x, notify in Unicode=%s, redraw=%s\n",
373 iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
374 (iP->DoRedraw)?"TRUE":"FALSE");
375 for (i = 0; i < iP->uNumBands; i++) {
376 pB = REBAR_GetBand(iP, i);
377 TRACE("band # %u:", i);
378 if (pB->fMask & RBBIM_ID)
379 TRACE(" ID=%u", pB->wID);
380 if (pB->fMask & RBBIM_CHILD)
381 TRACE(" child=%p", pB->hwndChild);
382 if (pB->fMask & RBBIM_COLORS)
383 TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
384 TRACE("\n");
385 TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
386 if (pB->fMask & RBBIM_STYLE)
387 TRACE("band # %u: style=0x%08x (%s)\n",
388 i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
389 TRACE("band # %u: xHeader=%u",
390 i, pB->cxHeader);
391 if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
392 if (pB->fMask & RBBIM_SIZE)
393 TRACE(" cx=%u", pB->cx);
394 if (pB->fMask & RBBIM_IDEALSIZE)
395 TRACE(" xIdeal=%u", pB->cxIdeal);
396 if (pB->fMask & RBBIM_LPARAM)
397 TRACE(" lParam=0x%08lx", pB->lParam);
398 }
399 TRACE("\n");
400 if (RBBIM_CHILDSIZE)
401 TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
402 i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
403 if (pB->fMask & RBBIM_TEXT)
404 TRACE("band # %u: text=%s\n",
405 i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
406 TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
407 i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
408 TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
409 i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
410 wine_dbgstr_rect(&pB->rcGripper));
411 TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
412 i, wine_dbgstr_rect(&pB->rcCapImage),
413 wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
414 }
415
416 }
417
418 /* dest can be equal to src */
419 static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
420 {
421 if (infoPtr->dwStyle & CCS_VERT) {
422 int tmp;
423 tmp = src->left;
424 dest->left = src->top;
425 dest->top = tmp;
426
427 tmp = src->right;
428 dest->right = src->bottom;
429 dest->bottom = tmp;
430 } else {
431 *dest = *src;
432 }
433 }
434
435 static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
436 {
437 if (infoPtr->dwStyle & CCS_VERT)
438 return lpRect->bottom - lpRect->top;
439 return lpRect->right - lpRect->left;
440 }
441
442 static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
443 {
444 if (infoPtr->dwStyle & CCS_VERT)
445 return lpRect->right - lpRect->left;
446 return lpRect->bottom - lpRect->top;
447 }
448
449 static int round_child_height(const REBAR_BAND *lpBand, int cyHeight)
450 {
451 int cy = 0;
452 if (lpBand->cyIntegral == 0)
453 return cyHeight;
454 cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
455 cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
456 cy = min(cy, lpBand->cyMaxChild);
457 return cy;
458 }
459
460 static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
461 {
462 lpBand->cyMinBand = max(lpBand->cyHeader,
463 (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
464 }
465
466 static void
467 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
468 {
469 INT x, y;
470 HPEN hPen, hOldPen;
471
472 if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
473 hOldPen = SelectObject ( hdc, hPen );
474 x = left + 2;
475 y = top;
476 MoveToEx (hdc, x, y, NULL);
477 LineTo (hdc, x+5, y++); x++;
478 MoveToEx (hdc, x, y, NULL);
479 LineTo (hdc, x+3, y++); x++;
480 MoveToEx (hdc, x, y, NULL);
481 LineTo (hdc, x+1, y);
482 SelectObject( hdc, hOldPen );
483 DeleteObject( hPen );
484 }
485
486 static HWND
487 REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
488 {
489 HWND parent, owner;
490
491 parent = infoPtr->hwndNotify;
492 if (!parent) {
493 parent = GetParent (infoPtr->hwndSelf);
494 owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
495 if (owner) parent = owner;
496 }
497 return parent;
498 }
499
500
501 static INT
502 REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
503 {
504 HWND parent;
505
506 parent = REBAR_GetNotifyParent (infoPtr);
507 nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
508 nmhdr->hwndFrom = infoPtr->hwndSelf;
509 nmhdr->code = code;
510
511 TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
512
513 return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
514 }
515
516 static INT
517 REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
518 {
519 NMREBAR notify_rebar;
520
521 notify_rebar.dwMask = 0;
522 if (uBand != -1) {
523 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
524
525 if (lpBand->fMask & RBBIM_ID) {
526 notify_rebar.dwMask |= RBNM_ID;
527 notify_rebar.wID = lpBand->wID;
528 }
529 if (lpBand->fMask & RBBIM_LPARAM) {
530 notify_rebar.dwMask |= RBNM_LPARAM;
531 notify_rebar.lParam = lpBand->lParam;
532 }
533 if (lpBand->fMask & RBBIM_STYLE) {
534 notify_rebar.dwMask |= RBNM_STYLE;
535 notify_rebar.fStyle = lpBand->fStyle;
536 }
537 }
538 notify_rebar.uBand = uBand;
539 return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
540 }
541
542 static VOID
543 REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
544 {
545 HFONT hOldFont = 0;
546 INT oldBkMode = 0;
547 NMCUSTOMDRAW nmcd;
548 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
549 RECT rcBand;
550
551 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
552
553 if (lpBand->fDraw & DRAW_TEXT) {
554 hOldFont = SelectObject (hdc, infoPtr->hFont);
555 oldBkMode = SetBkMode (hdc, TRANSPARENT);
556 }
557
558 /* should test for CDRF_NOTIFYITEMDRAW here */
559 nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
560 nmcd.hdc = hdc;
561 nmcd.rc = rcBand;
562 nmcd.rc.right = lpBand->rcCapText.right;
563 nmcd.rc.bottom = lpBand->rcCapText.bottom;
564 nmcd.dwItemSpec = lpBand->wID;
565 nmcd.uItemState = 0;
566 nmcd.lItemlParam = lpBand->lParam;
567 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
568 if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
569 if (oldBkMode != TRANSPARENT)
570 SetBkMode (hdc, oldBkMode);
571 SelectObject (hdc, hOldFont);
572 return;
573 }
574
575 /* draw gripper */
576 if (lpBand->fDraw & DRAW_GRIPPER)
577 {
578 if (theme)
579 {
580 RECT rcGripper = lpBand->rcGripper;
581 int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
582 GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
583 OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
584 lpBand->rcGripper.top - rcGripper.top);
585 DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
586 }
587 else
588 DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
589 }
590
591 /* draw caption image */
592 if (lpBand->fDraw & DRAW_IMAGE) {
593 POINT pt;
594
595 /* center image */
596 pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
597 pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
598
599 ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
600 pt.x, pt.y,
601 ILD_TRANSPARENT);
602 }
603
604 /* draw caption text */
605 if (lpBand->fDraw & DRAW_TEXT) {
606 /* need to handle CDRF_NEWFONT here */
607 INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
608 COLORREF oldcolor = CLR_NONE;
609 COLORREF new;
610 if (lpBand->clrFore != CLR_NONE) {
611 new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
612 lpBand->clrFore;
613 oldcolor = SetTextColor (hdc, new);
614 }
615
616 if (!theme)
617 {
618 DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
619 }
620 else
621 {
622 DrawThemeText(theme, hdc, 0, 0, lpBand->lpText, -1, DT_CENTER | DT_VCENTER | DT_SINGLELINE, 0, &lpBand->rcCapText);
623 }
624
625 if (oldBkMode != TRANSPARENT)
626 SetBkMode (hdc, oldBkMode);
627 if (lpBand->clrFore != CLR_NONE)
628 SetTextColor (hdc, oldcolor);
629 SelectObject (hdc, hOldFont);
630 }
631
632 if (!IsRectEmpty(&lpBand->rcChevron))
633 {
634 if (theme)
635 {
636 int stateId;
637 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
638 stateId = CHEVS_PRESSED;
639 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
640 stateId = CHEVS_HOT;
641 else
642 stateId = CHEVS_NORMAL;
643 DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
644 }
645 else
646 {
647 if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
648 {
649 DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
650 REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
651 }
652 else if (lpBand->fDraw & DRAW_CHEVRONHOT)
653 {
654 DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
655 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
656 }
657 else
658 REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
659 }
660 }
661
662 if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
663 nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
664 nmcd.hdc = hdc;
665 nmcd.rc = rcBand;
666 nmcd.rc.right = lpBand->rcCapText.right;
667 nmcd.rc.bottom = lpBand->rcCapText.bottom;
668 nmcd.dwItemSpec = lpBand->wID;
669 nmcd.uItemState = 0;
670 nmcd.lItemlParam = lpBand->lParam;
671 lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
672 }
673 }
674
675
676 static VOID
677 REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
678 {
679 REBAR_BAND *lpBand;
680 UINT i;
681
682 if (!infoPtr->DoRedraw) return;
683
684 for (i = 0; i < infoPtr->uNumBands; i++) {
685 lpBand = REBAR_GetBand(infoPtr, i);
686
687 if (HIDDENBAND(lpBand)) continue;
688
689 /* now draw the band */
690 TRACE("[%p] drawing band %i, flags=%08x\n",
691 infoPtr->hwndSelf, i, lpBand->fDraw);
692 REBAR_DrawBand (hdc, infoPtr, lpBand);
693 }
694 }
695
696
697 static void
698 REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
699 /* Function: this routine initializes all the rectangles in */
700 /* each band in a row to fit in the adjusted rcBand rect. */
701 /* *** Supports only Horizontal bars. *** */
702 {
703 REBAR_BAND *lpBand;
704 UINT i, xoff;
705 RECT work;
706
707 for(i=rstart; i<rend; i++){
708 lpBand = REBAR_GetBand(infoPtr, i);
709 if (HIDDENBAND(lpBand)) {
710 SetRect (&lpBand->rcChild,
711 lpBand->rcBand.right, lpBand->rcBand.top,
712 lpBand->rcBand.right, lpBand->rcBand.bottom);
713 continue;
714 }
715
716 /* set initial gripper rectangle */
717 SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
718 lpBand->rcBand.left, lpBand->rcBand.bottom);
719
720 /* calculate gripper rectangle */
721 if ( lpBand->fStatus & HAS_GRIPPER) {
722 lpBand->fDraw |= DRAW_GRIPPER;
723 lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
724 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
725 InflateRect(&lpBand->rcGripper, 0, -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) {
767
768 lpBand->rcChild.left = lpBand->rcBand.left + lpBand->cxHeader;
769 lpBand->rcChild.right = lpBand->rcBand.right - REBAR_POST_CHILD;
770
771 if (lpBand->cyChild > 0) {
772
773 UINT yoff = (lpBand->rcBand.bottom - lpBand->rcBand.top - lpBand->cyChild) / 2;
774
775 /* center child if height is known */
776 lpBand->rcChild.top = lpBand->rcBand.top + yoff;
777 lpBand->rcChild.bottom = lpBand->rcBand.top + yoff + lpBand->cyChild;
778 }
779 else {
780 lpBand->rcChild.top = lpBand->rcBand.top;
781 lpBand->rcChild.bottom = lpBand->rcBand.bottom;
782 }
783
784 if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
785 {
786 lpBand->rcChild.right -= CHEVRON_WIDTH;
787 SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
788 lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
789 lpBand->rcChild.bottom);
790 }
791 }
792 else {
793 SetRect (&lpBand->rcChild,
794 lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
795 lpBand->rcBand.right, lpBand->rcBand.bottom);
796 }
797
798 /* flag if notify required and invalidate rectangle */
799 if (lpBand->fDraw & NTF_INVALIDATE) {
800 lpBand->fDraw &= ~NTF_INVALIDATE;
801 work = lpBand->rcBand;
802 work.right += SEP_WIDTH;
803 work.bottom += SEP_WIDTH;
804 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
805 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
806 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
807 }
808
809 }
810
811 }
812
813
814 static VOID
815 REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
816 /* Function: this routine initializes all the rectangles in */
817 /* each band in a row to fit in the adjusted rcBand rect. */
818 /* *** Supports only Vertical bars. *** */
819 {
820 REBAR_BAND *lpBand;
821 UINT i, xoff;
822 RECT work;
823
824 for(i=rstart; i<rend; i++){
825 RECT rcBand;
826 lpBand = REBAR_GetBand(infoPtr, i);
827 if (HIDDENBAND(lpBand)) continue;
828
829 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
830
831 /* set initial gripper rectangle */
832 SetRect (&lpBand->rcGripper, rcBand.left, rcBand.top, rcBand.right, rcBand.top);
833
834 /* calculate gripper rectangle */
835 if (lpBand->fStatus & HAS_GRIPPER) {
836 lpBand->fDraw |= DRAW_GRIPPER;
837
838 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
839 /* vertical gripper */
840 lpBand->rcGripper.left += 3;
841 lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
842 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
843 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
844
845 /* initialize Caption image rectangle */
846 SetRect (&lpBand->rcCapImage, rcBand.left,
847 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
848 rcBand.right,
849 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
850 }
851 else {
852 /* horizontal gripper */
853 InflateRect(&lpBand->rcGripper, -2, 0);
854 lpBand->rcGripper.top += REBAR_PRE_GRIPPER;
855 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_WIDTH;
856
857 /* initialize Caption image rectangle */
858 SetRect (&lpBand->rcCapImage, rcBand.left,
859 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
860 rcBand.right,
861 lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
862 }
863 }
864 else { /* no gripper will be drawn */
865 xoff = 0;
866 if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
867 /* if no gripper but either image or text, then leave space */
868 xoff = REBAR_ALWAYS_SPACE;
869 /* initialize Caption image rectangle */
870 SetRect (&lpBand->rcCapImage,
871 rcBand.left, rcBand.top+xoff,
872 rcBand.right, rcBand.top+xoff);
873 }
874
875 /* image is visible */
876 if (lpBand->fStatus & HAS_IMAGE) {
877 lpBand->fDraw |= DRAW_IMAGE;
878
879 lpBand->rcCapImage.right = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
880 lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
881
882 /* set initial caption text rectangle */
883 SetRect (&lpBand->rcCapText,
884 rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
885 rcBand.right, rcBand.top+lpBand->cxHeader);
886 }
887 else {
888 /* set initial caption text rectangle */
889 SetRect (&lpBand->rcCapText,
890 rcBand.left, lpBand->rcCapImage.bottom,
891 rcBand.right, rcBand.top+lpBand->cxHeader);
892 }
893
894 /* text is visible */
895 if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
896 lpBand->fDraw |= DRAW_TEXT;
897 lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
898 lpBand->rcCapText.bottom);
899 }
900
901 /* set initial child window rectangle if there is a child */
902 if (lpBand->hwndChild) {
903 int cxBand = rcBand.right - rcBand.left;
904 xoff = (cxBand - lpBand->cyChild) / 2;
905 SetRect (&lpBand->rcChild,
906 rcBand.left + xoff, rcBand.top + lpBand->cxHeader,
907 rcBand.left + xoff + lpBand->cyChild, rcBand.bottom - REBAR_POST_CHILD);
908 }
909 else {
910 SetRect (&lpBand->rcChild,
911 rcBand.left, rcBand.top+lpBand->cxHeader,
912 rcBand.right, rcBand.bottom);
913 }
914
915 if (lpBand->fDraw & NTF_INVALIDATE) {
916 lpBand->fDraw &= ~NTF_INVALIDATE;
917 work = rcBand;
918 work.bottom += SEP_WIDTH;
919 work.right += SEP_WIDTH;
920 TRACE("invalidating %s\n", wine_dbgstr_rect(&work));
921 InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
922 if (lpBand->hwndChild) InvalidateRect(lpBand->hwndChild, NULL, TRUE);
923 }
924
925 }
926 }
927
928
929 static VOID
930 REBAR_ForceResize (REBAR_INFO *infoPtr)
931 /* Function: This changes the size of the REBAR window to that */
932 /* calculated by REBAR_Layout. */
933 {
934 INT x, y, width, height;
935 INT xedge = 0, yedge = 0;
936 RECT rcSelf;
937
938 TRACE("new size [%d x %d]\n", infoPtr->calcSize.cx, infoPtr->calcSize.cy);
939
940 if (infoPtr->dwStyle & CCS_NORESIZE)
941 return;
942
943 if (infoPtr->dwStyle & WS_BORDER)
944 {
945 xedge = GetSystemMetrics(SM_CXEDGE);
946 yedge = GetSystemMetrics(SM_CYEDGE);
947 /* swap for CCS_VERT? */
948 }
949
950 /* compute rebar window rect in parent client coordinates */
951 GetWindowRect(infoPtr->hwndSelf, &rcSelf);
952 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->hwndSelf), (LPPOINT)&rcSelf, 2);
953 translate_rect(infoPtr, &rcSelf, &rcSelf);
954
955 height = infoPtr->calcSize.cy + 2*yedge;
956 if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
957 RECT rcParent;
958
959 x = -xedge;
960 width = infoPtr->calcSize.cx + 2*xedge;
961 y = 0; /* quiet compiler warning */
962 switch ( infoPtr->dwStyle & CCS_LAYOUT_MASK) {
963 case 0: /* shouldn't happen - see NCCreate */
964 case CCS_TOP:
965 y = ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER) - yedge;
966 break;
967 case CCS_NOMOVEY:
968 y = rcSelf.top;
969 break;
970 case CCS_BOTTOM:
971 GetClientRect(GetParent(infoPtr->hwndSelf), &rcParent);
972 translate_rect(infoPtr, &rcParent, &rcParent);
973 y = rcParent.bottom - infoPtr->calcSize.cy - yedge;
974 break;
975 }
976 }
977 else {
978 x = rcSelf.left;
979 /* As on Windows if the CCS_NODIVIDER is not present the control will move
980 * 2 pixel down after every layout */
981 y = rcSelf.top + ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
982 width = rcSelf.right - rcSelf.left;
983 }
984
985 TRACE("hwnd %p, style=%08x, setting at (%d,%d) for (%d,%d)\n",
986 infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
987
988 /* Set flag to ignore next WM_SIZE message and resize the window */
989 infoPtr->fStatus |= SELF_RESIZE;
990 if ((infoPtr->dwStyle & CCS_VERT) == 0)
991 SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
992 else
993 SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
994 infoPtr->fStatus &= ~SELF_RESIZE;
995 }
996
997
998 static VOID
999 REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
1000 {
1001 static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
1002 REBAR_BAND *lpBand;
1003 WCHAR szClassName[40];
1004 UINT i;
1005 NMREBARCHILDSIZE rbcz;
1006 HDWP deferpos;
1007
1008 if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1009 ERR("BeginDeferWindowPos returned NULL\n");
1010
1011 for (i = start; i < endplus; i++) {
1012 lpBand = REBAR_GetBand(infoPtr, i);
1013
1014 if (HIDDENBAND(lpBand)) continue;
1015 if (lpBand->hwndChild) {
1016 TRACE("hwndChild = %p\n", lpBand->hwndChild);
1017
1018 /* Always generate the RBN_CHILDSIZE even if child
1019 did not change */
1020 rbcz.uBand = i;
1021 rbcz.wID = lpBand->wID;
1022 rbcz.rcChild = lpBand->rcChild;
1023 translate_rect(infoPtr, &rbcz.rcBand, &lpBand->rcBand);
1024 if (infoPtr->dwStyle & CCS_VERT)
1025 rbcz.rcBand.top += lpBand->cxHeader;
1026 else
1027 rbcz.rcBand.left += lpBand->cxHeader;
1028 REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1029 if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1030 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1031 TRACE(" from (%s) to (%s)\n",
1032 wine_dbgstr_rect(&lpBand->rcChild),
1033 wine_dbgstr_rect(&rbcz.rcChild));
1034 lpBand->rcChild = rbcz.rcChild; /* *** ??? */
1035 }
1036
1037 GetClassNameW (lpBand->hwndChild, szClassName, sizeof(szClassName)/sizeof(szClassName[0]));
1038 if (!lstrcmpW (szClassName, strComboBox) ||
1039 !lstrcmpW (szClassName, WC_COMBOBOXEXW)) {
1040 INT nEditHeight, yPos;
1041 RECT rc;
1042
1043 /* special placement code for combo or comboex box */
1044
1045
1046 /* get size of edit line */
1047 GetWindowRect (lpBand->hwndChild, &rc);
1048 nEditHeight = rc.bottom - rc.top;
1049 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1050
1051 /* center combo box inside child area */
1052 TRACE("moving child (Combo(Ex)) %p to (%d,%d) for (%d,%d)\n",
1053 lpBand->hwndChild,
1054 lpBand->rcChild.left, yPos,
1055 lpBand->rcChild.right - lpBand->rcChild.left,
1056 nEditHeight);
1057 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1058 lpBand->rcChild.left,
1059 /*lpBand->rcChild.top*/ yPos,
1060 lpBand->rcChild.right - lpBand->rcChild.left,
1061 nEditHeight,
1062 SWP_NOZORDER);
1063 if (!deferpos)
1064 ERR("DeferWindowPos returned NULL\n");
1065 }
1066 else {
1067 TRACE("moving child (Other) %p to (%d,%d) for (%d,%d)\n",
1068 lpBand->hwndChild,
1069 lpBand->rcChild.left, lpBand->rcChild.top,
1070 lpBand->rcChild.right - lpBand->rcChild.left,
1071 lpBand->rcChild.bottom - lpBand->rcChild.top);
1072 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1073 lpBand->rcChild.left,
1074 lpBand->rcChild.top,
1075 lpBand->rcChild.right - lpBand->rcChild.left,
1076 lpBand->rcChild.bottom - lpBand->rcChild.top,
1077 SWP_NOZORDER);
1078 if (!deferpos)
1079 ERR("DeferWindowPos returned NULL\n");
1080 }
1081 }
1082 }
1083 if (!EndDeferWindowPos(deferpos))
1084 ERR("EndDeferWindowPos returned NULL\n");
1085
1086 if (infoPtr->DoRedraw)
1087 UpdateWindow (infoPtr->hwndSelf);
1088 }
1089
1090 /* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
1091 * or infoPtr->uNumBands if none */
1092 static int next_visible(const REBAR_INFO *infoPtr, int i)
1093 {
1094 unsigned int n;
1095 for (n = i + 1; n < infoPtr->uNumBands; n++)
1096 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1097 break;
1098 return n;
1099 }
1100
1101 /* Returns the previous visible band (the last visible band in [0; i) )
1102 * or -1 if none */
1103 static int prev_visible(const REBAR_INFO *infoPtr, int i)
1104 {
1105 int n;
1106 for (n = i - 1; n >= 0; n--)
1107 if (!HIDDENBAND(REBAR_GetBand(infoPtr, n)))
1108 break;
1109 return n;
1110 }
1111
1112 /* Returns the first visible band or infoPtr->uNumBands if none */
1113 static int first_visible(const REBAR_INFO *infoPtr)
1114 {
1115 return next_visible(infoPtr, -1); /* this works*/
1116 }
1117
1118 /* Returns the first visible band for the given row (or iBand if none) */
1119 static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
1120 {
1121 int iLastBand = iBand;
1122 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1123 while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
1124 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1125 break;
1126 else
1127 iLastBand = iBand;
1128 }
1129 return iLastBand;
1130 }
1131
1132 /* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
1133 static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
1134 {
1135 int iRow = REBAR_GetBand(infoPtr, iBand)->iRow;
1136 while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
1137 if (REBAR_GetBand(infoPtr, iBand)->iRow != iRow)
1138 break;
1139 return iBand;
1140 }
1141
1142 /* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
1143 * iBeginBand must be visible */
1144 static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1145 {
1146 int xPos = 0, i;
1147 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1148 {
1149 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1150 if (lpBand->rcBand.left != xPos || lpBand->rcBand.right != xPos + lpBand->cxEffective) {
1151 lpBand->fDraw |= NTF_INVALIDATE;
1152 TRACE("Setting rect %d to %d,%d\n", i, xPos, xPos + lpBand->cxEffective);
1153 lpBand->rcBand.left = xPos;
1154 lpBand->rcBand.right = xPos + lpBand->cxEffective;
1155 }
1156 xPos += lpBand->cxEffective + SEP_WIDTH;
1157 }
1158 }
1159
1160 /* The rationale of this function is probably as follows: if we have some space
1161 * to distribute we want to add it to a band on the right. However we don't want
1162 * to unminimize a minimized band so we search for a band that is big enough.
1163 * For some reason "big enough" is defined as bigger than the minimum size of the
1164 * first band in the row
1165 */
1166 static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
1167 {
1168 INT cxMinFirstBand = 0, i;
1169
1170 cxMinFirstBand = REBAR_GetBand(infoPtr, iBeginBand)->cxMinBand;
1171
1172 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1173 if (REBAR_GetBand(infoPtr, i)->cxEffective > cxMinFirstBand &&
1174 !(REBAR_GetBand(infoPtr, i)->fStyle & RBBS_FIXEDSIZE))
1175 break;
1176
1177 if (i < iBeginBand)
1178 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1179 if (REBAR_GetBand(infoPtr, i)->cxMinBand == cxMinFirstBand)
1180 break;
1181
1182 TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
1183 return REBAR_GetBand(infoPtr, i);
1184 }
1185
1186 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
1187 static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1188 {
1189 REBAR_BAND *lpBand;
1190 INT width, i;
1191
1192 TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
1193 for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
1194 {
1195 lpBand = REBAR_GetBand(infoPtr, i);
1196
1197 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1198 cxShrink -= lpBand->cxEffective - width;
1199 lpBand->cxEffective = width;
1200 if (bEnforce && lpBand->cx > lpBand->cxEffective)
1201 lpBand->cx = lpBand->cxEffective;
1202 if (cxShrink == 0)
1203 break;
1204 }
1205 return cxShrink;
1206 }
1207
1208
1209 /* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
1210 * iBeginBand must be visible */
1211 static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
1212 {
1213 REBAR_BAND *lpBand;
1214 INT width, i;
1215
1216 TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
1217 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1218 {
1219 lpBand = REBAR_GetBand(infoPtr, i);
1220
1221 width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
1222 cxShrink -= lpBand->cxEffective - width;
1223 lpBand->cxEffective = width;
1224 if (bEnforce)
1225 lpBand->cx = lpBand->cxEffective;
1226 if (cxShrink == 0)
1227 break;
1228 }
1229 return cxShrink;
1230 }
1231
1232 /* Tries to move a band to a given offset within a row. */
1233 static int REBAR_MoveBandToRowOffset(REBAR_INFO *infoPtr, INT iBand, INT iFirstBand,
1234 INT iLastBand, INT xOff, BOOL reorder)
1235 {
1236 REBAR_BAND *insertBand = REBAR_GetBand(infoPtr, iBand);
1237 int xPos = 0, i;
1238 const BOOL setBreak = REBAR_GetBand(infoPtr, iFirstBand)->fStyle & RBBS_BREAK;
1239
1240 /* Find the band's new position */
1241 if(reorder)
1242 {
1243 /* Used during an LR band reorder drag */
1244 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1245 {
1246 if(xPos > xOff)
1247 break;
1248 xPos += REBAR_GetBand(infoPtr, i)->cxEffective + SEP_WIDTH;
1249 }
1250 }
1251 else
1252 {
1253 /* Used during a UD band insertion drag */
1254 for (i = iFirstBand; i < iLastBand; i = next_visible(infoPtr, i))
1255 {
1256 const REBAR_BAND *band = REBAR_GetBand(infoPtr, i);
1257 if(xPos + band->cxMinBand / 2 > xOff)
1258 break;
1259 xPos += band->cxEffective + SEP_WIDTH;
1260 }
1261 }
1262
1263 /* Move the band to its new position */
1264 DPA_DeletePtr(infoPtr->bands, iBand);
1265 if(i > iBand)
1266 i--;
1267 DPA_InsertPtr(infoPtr->bands, i, insertBand);
1268
1269 /* Ensure only the last band has the RBBS_BREAK flag set */
1270 insertBand->fStyle &= ~RBBS_BREAK;
1271 if(setBreak)
1272 REBAR_GetBand(infoPtr, iFirstBand)->fStyle |= RBBS_BREAK;
1273
1274 /* Return the currently grabbed band */
1275 if(infoPtr->iGrabbedBand == iBand)
1276 {
1277 infoPtr->iGrabbedBand = i;
1278 return i;
1279 }
1280 else return -1;
1281 }
1282
1283 /* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
1284 static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
1285 {
1286 REBAR_BAND *lpBand;
1287 int yMaxHeight = 0;
1288 int yPos = yStart;
1289 int row = REBAR_GetBand(infoPtr, iBeginBand)->iRow;
1290 int i;
1291 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1292 {
1293 lpBand = REBAR_GetBand(infoPtr, i);
1294 lpBand->cyRowSoFar = yMaxHeight;
1295 yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
1296 }
1297 TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
1298
1299 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1300 {
1301 lpBand = REBAR_GetBand(infoPtr, i);
1302 /* we may be called for multiple rows if RBS_VARHEIGHT not set */
1303 if (lpBand->iRow != row) {
1304 yPos += yMaxHeight + SEP_WIDTH;
1305 row = lpBand->iRow;
1306 }
1307
1308 if (lpBand->rcBand.top != yPos || lpBand->rcBand.bottom != yPos + yMaxHeight) {
1309 lpBand->fDraw |= NTF_INVALIDATE;
1310 lpBand->rcBand.top = yPos;
1311 lpBand->rcBand.bottom = yPos + yMaxHeight;
1312 TRACE("Band %d: %s\n", i, wine_dbgstr_rect(&lpBand->rcBand));
1313 }
1314 }
1315 return yPos + yMaxHeight;
1316 }
1317
1318 /* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
1319 static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
1320 {
1321 REBAR_BAND *lpBand;
1322 int i, extra;
1323 int width = 0;
1324
1325 TRACE("Adjusting row [%d;%d). Width: %d\n", iBeginBand, iEndBand, cx);
1326 for (i = iBeginBand; i < iEndBand; i++)
1327 REBAR_GetBand(infoPtr, i)->iRow = *piRow;
1328
1329 /* compute the extra space */
1330 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1331 {
1332 lpBand = REBAR_GetBand(infoPtr, i);
1333 if (i > iBeginBand)
1334 width += SEP_WIDTH;
1335 lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
1336 width += lpBand->cxEffective;
1337 }
1338
1339 extra = cx - width;
1340 TRACE("Extra space: %d\n", extra);
1341 if (extra < 0) {
1342 int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
1343 if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand) /* one band may be longer than expected... */
1344 ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
1345 } else
1346 if (extra > 0) {
1347 lpBand = REBAR_FindBandToGrow(infoPtr, iBeginBand, iEndBand);
1348 lpBand->cxEffective += extra;
1349 }
1350
1351 REBAR_SetRowRectsX(infoPtr, iBeginBand, iEndBand);
1352 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1353 {
1354 if (*piRow > 0)
1355 *pyPos += SEP_WIDTH;
1356 *pyPos = REBAR_SetBandsHeight(infoPtr, iBeginBand, iEndBand, *pyPos);
1357 }
1358 (*piRow)++;
1359 }
1360
1361 static VOID
1362 REBAR_Layout(REBAR_INFO *infoPtr)
1363 {
1364 REBAR_BAND *lpBand;
1365 RECT rcAdj;
1366 SIZE oldSize;
1367 INT adjcx, i;
1368 INT rowstart;
1369 INT row = 0;
1370 INT xMin, yPos;
1371
1372 if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
1373 GetClientRect(infoPtr->hwndSelf, &rcAdj);
1374 else
1375 GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
1376 TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
1377
1378 adjcx = get_rect_cx(infoPtr, &rcAdj);
1379
1380 if (infoPtr->uNumBands == 0) {
1381 TRACE("No bands - setting size to (0,%d), style: %x\n", adjcx, infoPtr->dwStyle);
1382 infoPtr->calcSize.cx = adjcx;
1383 /* the calcSize.cy won't change for a 0 band rebar */
1384 infoPtr->uNumRows = 0;
1385 REBAR_ForceResize(infoPtr);
1386 return;
1387 }
1388
1389 yPos = 0;
1390 xMin = 0;
1391 rowstart = first_visible(infoPtr);
1392 /* divide rows */
1393 for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
1394 {
1395 lpBand = REBAR_GetBand(infoPtr, i);
1396
1397 if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
1398 TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
1399 REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
1400 rowstart = i;
1401 xMin = 0;
1402 }
1403 else
1404 xMin += SEP_WIDTH;
1405
1406 xMin += lpBand->cxMinBand;
1407 }
1408 if (rowstart < infoPtr->uNumBands)
1409 REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
1410
1411 if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
1412 yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
1413
1414 infoPtr->uNumRows = row;
1415
1416 if (infoPtr->dwStyle & CCS_VERT)
1417 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
1418 else
1419 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
1420 /* now compute size of Rebar itself */
1421 oldSize = infoPtr->calcSize;
1422
1423 infoPtr->calcSize.cx = adjcx;
1424 infoPtr->calcSize.cy = yPos;
1425 TRACE("calcsize size=(%d, %d), origheight=(%d,%d)\n",
1426 infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1427 oldSize.cx, oldSize.cy);
1428
1429 REBAR_DumpBand (infoPtr);
1430 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1431 REBAR_ForceResize (infoPtr);
1432
1433 /* note: after a RBN_HEIGHTCHANGE native sends once again all the RBN_CHILDSIZE
1434 * and does another ForceResize */
1435 if (oldSize.cy != infoPtr->calcSize.cy)
1436 {
1437 NMHDR heightchange;
1438 REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1439 REBAR_AutoSize(infoPtr, FALSE);
1440 }
1441 }
1442
1443 /* iBeginBand must be visible */
1444 static int
1445 REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
1446 {
1447 int cyBandsOld;
1448 int cyBandsNew = 0;
1449 int i;
1450
1451 TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
1452
1453 cyBandsOld = REBAR_GetBand(infoPtr, iBeginBand)->rcBand.bottom -
1454 REBAR_GetBand(infoPtr, iBeginBand)->rcBand.top;
1455 for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
1456 {
1457 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1458 int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
1459 int cyChild = round_child_height(lpBand, cyMaxChild);
1460
1461 if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
1462 {
1463 TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
1464 *fChanged = TRUE;
1465 lpBand->cyChild = cyChild;
1466 lpBand->fDraw |= NTF_INVALIDATE;
1467 update_min_band_height(infoPtr, lpBand);
1468 }
1469 cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
1470 }
1471 return cyBandsNew - cyBandsOld;
1472 }
1473
1474 /* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
1475 static VOID
1476 REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
1477 {
1478 int extra = height - infoPtr->calcSize.cy; /* may be negative */
1479 BOOL fChanged = FALSE;
1480 UINT uNumRows = infoPtr->uNumRows;
1481 int i;
1482
1483 if (uNumRows == 0) /* avoid division by 0 */
1484 return;
1485
1486 /* That's not exactly what Windows does but should be similar */
1487
1488 /* Pass one: break-up/glue rows */
1489 if (extra > 0)
1490 {
1491 for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
1492 {
1493 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1494 int cyBreakExtra; /* additional cy for the rebar after a RBBS_BREAK on this band */
1495
1496 height = lpBand->rcBand.bottom - lpBand->rcBand.top;
1497
1498 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1499 cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
1500 else
1501 cyBreakExtra = height; /* 'height' => 'height' + 'height'*/
1502 cyBreakExtra += SEP_WIDTH;
1503
1504 if (extra <= cyBreakExtra / 2)
1505 break;
1506
1507 if (!(lpBand->fStyle & RBBS_BREAK))
1508 {
1509 TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
1510 lpBand->fStyle |= RBBS_BREAK;
1511 lpBand->fDraw |= NTF_INVALIDATE;
1512 fChanged = TRUE;
1513 extra -= cyBreakExtra;
1514 uNumRows++;
1515 /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
1516 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1517 lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
1518 }
1519 }
1520 }
1521 /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
1522
1523 /* Pass two: increase/decrease control height */
1524 if (infoPtr->dwStyle & RBS_VARHEIGHT)
1525 {
1526 int i = first_visible(infoPtr);
1527 int iRow = 0;
1528 while (i < infoPtr->uNumBands)
1529 {
1530 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, i);
1531 int extraForRow = extra / (int)(uNumRows - iRow);
1532 int rowEnd;
1533
1534 /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
1535 for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
1536 if (REBAR_GetBand(infoPtr, rowEnd)->iRow != lpBand->iRow ||
1537 REBAR_GetBand(infoPtr, rowEnd)->fStyle & RBBS_BREAK)
1538 break;
1539
1540 extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
1541 TRACE("extra = %d\n", extra);
1542 i = rowEnd;
1543 iRow++;
1544 }
1545 }
1546 else
1547 REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
1548
1549 if (fChanged)
1550 REBAR_Layout(infoPtr);
1551 }
1552
1553 static VOID
1554 REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
1555 {
1556 RECT rc, rcNew;
1557 NMRBAUTOSIZE autosize;
1558
1559 if (needsLayout)
1560 REBAR_Layout(infoPtr);
1561 GetClientRect(infoPtr->hwndSelf, &rc);
1562 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
1563 GetClientRect(infoPtr->hwndSelf, &rcNew);
1564
1565 GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
1566 autosize.fChanged = EqualRect(&rc, &rcNew);
1567 autosize.rcTarget = rc;
1568 autosize.rcActual = rcNew;
1569 REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
1570 }
1571
1572 static VOID
1573 REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1574 /* Function: This routine evaluates the band specs supplied */
1575 /* by the user and updates the following 5 fields in */
1576 /* the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
1577 {
1578 UINT header=0;
1579 UINT textheight=0, imageheight = 0;
1580 UINT i, nonfixed;
1581 REBAR_BAND *tBand;
1582
1583 lpBand->fStatus = 0;
1584 lpBand->cxMinBand = 0;
1585 lpBand->cyMinBand = 0;
1586
1587 /* Data coming in from users into the cx... and cy... fields */
1588 /* may be bad, just garbage, because the user never clears */
1589 /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data */
1590 /* along if the fields exist in the input area. Here we must */
1591 /* determine if the data is valid. I have no idea how MS does */
1592 /* the validation, but it does because the RB_GETBANDINFO */
1593 /* returns a 0 when I know the sample program passed in an */
1594 /* address. Here I will use the algorithm that if the value */
1595 /* is greater than 65535 then it is bad and replace it with */
1596 /* a zero. Feel free to improve the algorithm. - GA 12/2000 */
1597 if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1598 if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1599 if (lpBand->cx > 65535) lpBand->cx = 0;
1600 if (lpBand->cyChild > 65535) lpBand->cyChild = 0;
1601 if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1602 if (lpBand->cxIdeal > 65535) lpBand->cxIdeal = 0;
1603 if (lpBand->cxHeader > 65535) lpBand->cxHeader = 0;
1604
1605 /* TODO : we could try return to the caller if a value changed so that */
1606 /* a REBAR_Layout is needed. Till now the caller should call it */
1607 /* it always (we should also check what native does) */
1608
1609 /* Header is where the image, text and gripper exist */
1610 /* in the band and precede the child window. */
1611
1612 /* count number of non-FIXEDSIZE and non-Hidden bands */
1613 nonfixed = 0;
1614 for (i=0; i<infoPtr->uNumBands; i++){
1615 tBand = REBAR_GetBand(infoPtr, i);
1616 if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
1617 nonfixed++;
1618 }
1619
1620 /* calculate gripper rectangle */
1621 if ( (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
1622 ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
1623 ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
1624 ) {
1625 lpBand->fStatus |= HAS_GRIPPER;
1626 if (infoPtr->dwStyle & CCS_VERT)
1627 if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
1628 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
1629 else
1630 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
1631 else
1632 header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
1633 /* Always have 4 pixels before anything else */
1634 header += REBAR_ALWAYS_SPACE;
1635 }
1636
1637 /* image is visible */
1638 if (lpBand->iImage != -1 && (infoPtr->himl)) {
1639 lpBand->fStatus |= HAS_IMAGE;
1640 if (infoPtr->dwStyle & CCS_VERT) {
1641 header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
1642 imageheight = infoPtr->imageSize.cx + 4;
1643 }
1644 else {
1645 header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
1646 imageheight = infoPtr->imageSize.cy + 4;
1647 }
1648 }
1649
1650 /* text is visible */
1651 if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
1652 !(lpBand->fStyle & RBBS_HIDETITLE)) {
1653 HDC hdc = GetDC (0);
1654 HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
1655 SIZE size;
1656
1657 lpBand->fStatus |= HAS_TEXT;
1658 GetTextExtentPoint32W (hdc, lpBand->lpText,
1659 lstrlenW (lpBand->lpText), &size);
1660 header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
1661 textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
1662
1663 SelectObject (hdc, hOldFont);
1664 ReleaseDC (0, hdc);
1665 }
1666
1667 /* if no gripper but either image or text, then leave space */
1668 if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
1669 !(lpBand->fStatus & HAS_GRIPPER)) {
1670 header += REBAR_ALWAYS_SPACE;
1671 }
1672
1673 /* check if user overrode the header value */
1674 if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
1675 lpBand->cxHeader = header;
1676 lpBand->cyHeader = max(textheight, imageheight);
1677
1678 /* Now compute minimum size of child window */
1679 update_min_band_height(infoPtr, lpBand); /* update lpBand->cyMinBand from cyHeader and cyChild*/
1680
1681 lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
1682 if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
1683 lpBand->cxMinBand += CHEVRON_WIDTH;
1684 }
1685
1686 static UINT
1687 REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
1688 /* Function: This routine copies the supplied values from */
1689 /* user input (lprbbi) to the internal band structure. */
1690 /* It returns the mask of what changed. */
1691 {
1692 UINT uChanged = 0x0;
1693
1694 lpBand->fMask |= lprbbi->fMask;
1695
1696 if( (lprbbi->fMask & RBBIM_STYLE) &&
1697 (lpBand->fStyle != lprbbi->fStyle ) )
1698 {
1699 lpBand->fStyle = lprbbi->fStyle;
1700 uChanged |= RBBIM_STYLE;
1701 }
1702
1703 if( (lprbbi->fMask & RBBIM_COLORS) &&
1704 ( ( lpBand->clrFore != lprbbi->clrFore ) ||
1705 ( lpBand->clrBack != lprbbi->clrBack ) ) )
1706 {
1707 lpBand->clrFore = lprbbi->clrFore;
1708 lpBand->clrBack = lprbbi->clrBack;
1709 uChanged |= RBBIM_COLORS;
1710 }
1711
1712 if( (lprbbi->fMask & RBBIM_IMAGE) &&
1713 ( lpBand->iImage != lprbbi->iImage ) )
1714 {
1715 lpBand->iImage = lprbbi->iImage;
1716 uChanged |= RBBIM_IMAGE;
1717 }
1718
1719 if( (lprbbi->fMask & RBBIM_CHILD) &&
1720 (lprbbi->hwndChild != lpBand->hwndChild ) )
1721 {
1722 if (lprbbi->hwndChild) {
1723 lpBand->hwndChild = lprbbi->hwndChild;
1724 lpBand->hwndPrevParent =
1725 SetParent (lpBand->hwndChild, hwnd);
1726 /* below in trace from WinRAR */
1727 ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
1728 /* above in trace from WinRAR */
1729 }
1730 else {
1731 TRACE("child: %p prev parent: %p\n",
1732 lpBand->hwndChild, lpBand->hwndPrevParent);
1733 lpBand->hwndChild = 0;
1734 lpBand->hwndPrevParent = 0;
1735 }
1736 uChanged |= RBBIM_CHILD;
1737 }
1738
1739 if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
1740 ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
1741 (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
1742 ( (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
1743 ( (lpBand->cyChild != lprbbi->cyChild ) ||
1744 (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
1745 (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
1746 ( (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE) &&
1747 ( (lpBand->cyChild ||
1748 lpBand->cyMaxChild ||
1749 lpBand->cyIntegral ) ) ) ) )
1750 {
1751 lpBand->cxMinChild = lprbbi->cxMinChild;
1752 lpBand->cyMinChild = lprbbi->cyMinChild;
1753 /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
1754 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
1755 lpBand->cyMaxChild = lprbbi->cyMaxChild;
1756 lpBand->cyIntegral = lprbbi->cyIntegral;
1757
1758 lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild); /* make (cyChild - cyMinChild) a multiple of cyIntergral */
1759 }
1760 else {
1761 lpBand->cyChild = lpBand->cyMinChild;
1762 lpBand->cyMaxChild = 0x7fffffff;
1763 lpBand->cyIntegral = 0;
1764 }
1765 uChanged |= RBBIM_CHILDSIZE;
1766 }
1767
1768 if( (lprbbi->fMask & RBBIM_SIZE) &&
1769 (lpBand->cx != lprbbi->cx ) )
1770 {
1771 lpBand->cx = lprbbi->cx;
1772 uChanged |= RBBIM_SIZE;
1773 }
1774
1775 if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
1776 ( lpBand->hbmBack != lprbbi->hbmBack ) )
1777 {
1778 lpBand->hbmBack = lprbbi->hbmBack;
1779 uChanged |= RBBIM_BACKGROUND;
1780 }
1781
1782 if( (lprbbi->fMask & RBBIM_ID) &&
1783 (lpBand->wID != lprbbi->wID ) )
1784 {
1785 lpBand->wID = lprbbi->wID;
1786 uChanged |= RBBIM_ID;
1787 }
1788
1789 /* check for additional data */
1790 if (lprbbi->cbSize >= REBARBANDINFOA_V6_SIZE) {
1791 if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
1792 ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
1793 {
1794 lpBand->cxIdeal = lprbbi->cxIdeal;
1795 uChanged |= RBBIM_IDEALSIZE;
1796 }
1797
1798 if( (lprbbi->fMask & RBBIM_LPARAM) &&
1799 (lpBand->lParam != lprbbi->lParam ) )
1800 {
1801 lpBand->lParam = lprbbi->lParam;
1802 uChanged |= RBBIM_LPARAM;
1803 }
1804
1805 if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
1806 (lpBand->cxHeader != lprbbi->cxHeader ) )
1807 {
1808 lpBand->cxHeader = lprbbi->cxHeader;
1809 lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
1810 uChanged |= RBBIM_HEADERSIZE;
1811 }
1812 }
1813
1814 return uChanged;
1815 }
1816
1817 static LRESULT REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, HDC hdc)
1818 /* Function: This erases the background rectangle by drawing */
1819 /* each band with its background color (or the default) and */
1820 /* draws each bands right separator if necessary. The row */
1821 /* separators are drawn on the first band of the next row. */
1822 {
1823 REBAR_BAND *lpBand;
1824 UINT i;
1825 INT oldrow;
1826 RECT cr;
1827 COLORREF old = CLR_NONE, new;
1828 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
1829 #ifdef __REACTOS__
1830 HRGN hrgn;
1831 #endif
1832
1833 GetClientRect (infoPtr->hwndSelf, &cr);
1834
1835 #ifdef __REACTOS__
1836
1837 if (theme)
1838 {
1839 if (IsThemeBackgroundPartiallyTransparent(theme, RP_BACKGROUND, 0))
1840 {
1841 DrawThemeParentBackground (infoPtr->hwndSelf, hdc, &cr);
1842 }
1843 DrawThemeBackground (theme, hdc, 0, 0, &cr, NULL);
1844 }
1845
1846 hrgn = CreateRectRgn(cr.left, cr.top, cr.right, cr.bottom);
1847
1848 #endif
1849
1850 oldrow = -1;
1851 for(i=0; i<infoPtr->uNumBands; i++) {
1852 RECT rcBand;
1853 #ifdef __REACTOS__
1854 RECT rcBandReal;
1855 HRGN hrgnBand;
1856 #endif
1857
1858 lpBand = REBAR_GetBand(infoPtr, i);
1859 if (HIDDENBAND(lpBand)) continue;
1860 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
1861
1862 #ifdef __REACTOS__
1863 rcBandReal = rcBand;
1864 #endif
1865
1866 /* draw band separator between rows */
1867 if (lpBand->iRow != oldrow) {
1868 oldrow = lpBand->iRow;
1869 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1870 RECT rcRowSep;
1871 rcRowSep = rcBand;
1872 if (infoPtr->dwStyle & CCS_VERT) {
1873 rcRowSep.right += SEP_WIDTH_SIZE;
1874 rcRowSep.bottom = infoPtr->calcSize.cx;
1875 if (theme)
1876 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_RIGHT, NULL);
1877 else
1878 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
1879 }
1880 else {
1881 rcRowSep.bottom += SEP_WIDTH_SIZE;
1882 rcRowSep.right = infoPtr->calcSize.cx;
1883 if (theme)
1884 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcRowSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1885 else
1886 DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
1887 }
1888 TRACE ("drawing band separator bottom (%s)\n",
1889 wine_dbgstr_rect(&rcRowSep));
1890 #ifdef __REACTOS__
1891 rcBandReal = rcRowSep;
1892 #endif
1893 }
1894 }
1895
1896 /* draw band separator between bands in a row */
1897 if (infoPtr->dwStyle & RBS_BANDBORDERS && lpBand->rcBand.left > 0) {
1898 RECT rcSep;
1899 rcSep = rcBand;
1900 if (infoPtr->dwStyle & CCS_VERT) {
1901 rcSep.bottom = rcSep.top;
1902 rcSep.top -= SEP_WIDTH_SIZE;
1903 #ifdef __REACTOS__
1904 rcBandReal.top -= SEP_WIDTH_SIZE;
1905 #endif
1906 if (theme)
1907 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_BOTTOM, NULL);
1908 else
1909 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
1910 }
1911 else {
1912 rcSep.right = rcSep.left;
1913 rcSep.left -= SEP_WIDTH_SIZE;
1914 #ifdef __REACTOS__
1915 rcBandReal.left -= SEP_WIDTH_SIZE;
1916 #endif
1917 if (theme)
1918 DrawThemeEdge (theme, hdc, RP_BAND, 0, &rcSep, EDGE_ETCHED, BF_RIGHT, NULL);
1919 else
1920 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
1921 }
1922 TRACE("drawing band separator right (%s)\n",
1923 wine_dbgstr_rect(&rcSep));
1924 }
1925
1926 /* draw the actual background */
1927 if (lpBand->clrBack != CLR_NONE) {
1928 new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
1929 lpBand->clrBack;
1930 #if GLATESTING
1931 /* testing only - make background green to see it */
1932 new = RGB(0,128,0);
1933 #endif
1934 }
1935 else {
1936 /* In the absence of documentation for Rebar vs. CLR_NONE,
1937 * we will use the default BtnFace color. Note documentation
1938 * exists for Listview and Imagelist.
1939 */
1940 new = infoPtr->clrBtnFace;
1941 #if GLATESTING
1942 /* testing only - make background green to see it */
1943 new = RGB(0,128,0);
1944 #endif
1945 }
1946
1947 #ifdef __REACTOS__
1948 if (!theme)
1949 #else
1950 if (theme)
1951 {
1952 /* When themed, the background color is ignored (but not a
1953 * background bitmap */
1954 DrawThemeBackground (theme, hdc, 0, 0, &cr, &rcBand);
1955 }
1956 else
1957 #endif
1958 {
1959 old = SetBkColor (hdc, new);
1960 TRACE("%s background color=0x%06x, band %s\n",
1961 (lpBand->clrBack == CLR_NONE) ? "none" :
1962 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
1963 GetBkColor(hdc), wine_dbgstr_rect(&rcBand));
1964 ExtTextOutW (hdc, 0, 0, ETO_OPAQUE, &rcBand, NULL, 0, 0);
1965 if (lpBand->clrBack != CLR_NONE)
1966 SetBkColor (hdc, old);
1967 }
1968
1969 #ifdef __REACTOS__
1970 hrgnBand = CreateRectRgn(rcBandReal.left, rcBandReal.top, rcBandReal.right, rcBandReal.bottom);
1971 CombineRgn(hrgn, hrgn, hrgnBand, RGN_DIFF);
1972 DeleteObject(hrgnBand);
1973 #endif
1974 }
1975
1976 #if 1
1977 #ifdef __REACTOS__
1978 if (!theme)
1979 #endif
1980 {
1981 //FIXME: Apparently painting the remaining area is a v6 feature
1982 HBRUSH hbrush = CreateSolidBrush(new);
1983 FillRgn(hdc, hrgn, hbrush);
1984 DeleteObject(hbrush);
1985 }
1986 DeleteObject(hrgn);
1987 #endif
1988 return TRUE;
1989 }
1990
1991 static void
1992 REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
1993 {
1994 REBAR_BAND *lpBand;
1995 RECT rect;
1996 UINT iCount;
1997
1998 GetClientRect (infoPtr->hwndSelf, &rect);
1999
2000 *pFlags = RBHT_NOWHERE;
2001 if (PtInRect (&rect, *lpPt))
2002 {
2003 if (infoPtr->uNumBands == 0) {
2004 *pFlags = RBHT_NOWHERE;
2005 if (pBand)
2006 *pBand = -1;
2007 TRACE("NOWHERE\n");
2008 return;
2009 }
2010 else {
2011 /* somewhere inside */
2012 for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2013 RECT rcBand;
2014 lpBand = REBAR_GetBand(infoPtr, iCount);
2015 translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
2016 if (HIDDENBAND(lpBand)) continue;
2017 if (PtInRect (&rcBand, *lpPt)) {
2018 if (pBand)
2019 *pBand = iCount;
2020 if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2021 *pFlags = RBHT_GRABBER;
2022 TRACE("ON GRABBER %d\n", iCount);
2023 return;
2024 }
2025 else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2026 *pFlags = RBHT_CAPTION;
2027 TRACE("ON CAPTION %d\n", iCount);
2028 return;
2029 }
2030 else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2031 *pFlags = RBHT_CAPTION;
2032 TRACE("ON CAPTION %d\n", iCount);
2033 return;
2034 }
2035 else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2036 *pFlags = RBHT_CLIENT;
2037 TRACE("ON CLIENT %d\n", iCount);
2038 return;
2039 }
2040 else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2041 *pFlags = RBHT_CHEVRON;
2042 TRACE("ON CHEVRON %d\n", iCount);
2043 return;
2044 }
2045 else {
2046 *pFlags = RBHT_NOWHERE;
2047 TRACE("NOWHERE %d\n", iCount);
2048 return;
2049 }
2050 }
2051 }
2052
2053 *pFlags = RBHT_NOWHERE;
2054 if (pBand)
2055 *pBand = -1;
2056
2057 TRACE("NOWHERE\n");
2058 return;
2059 }
2060 }
2061 else {
2062 *pFlags = RBHT_NOWHERE;
2063 if (pBand)
2064 *pBand = -1;
2065 TRACE("NOWHERE\n");
2066 return;
2067 }
2068 }
2069
2070 static void
2071 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2072 /* Function: This will implement the functionality of a */
2073 /* Gripper drag within a row. It will not implement "out- */
2074 /* of-row" drags. (They are detected and handled in */
2075 /* REBAR_MouseMove.) */
2076 {
2077 REBAR_BAND *hitBand;
2078 INT iHitBand, iRowBegin, iRowEnd;
2079 INT movement, xBand, cxLeft = 0;
2080 BOOL shrunkBands = FALSE;
2081
2082 iHitBand = infoPtr->iGrabbedBand;
2083 iRowBegin = get_row_begin_for_band(infoPtr, iHitBand);
2084 iRowEnd = get_row_end_for_band(infoPtr, iHitBand);
2085 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2086
2087 xBand = hitBand->rcBand.left;
2088 movement = (infoPtr->dwStyle&CCS_VERT ? ptsmove->y : ptsmove->x)
2089 - (xBand + REBAR_PRE_GRIPPER - infoPtr->ihitoffset);
2090
2091 /* Dragging the first band in a row cannot cause shrinking */
2092 if(iHitBand != iRowBegin)
2093 {
2094 if (movement < 0) {
2095 cxLeft = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iHitBand, -movement, TRUE);
2096
2097 if(cxLeft < -movement)
2098 {
2099 hitBand->cxEffective += -movement - cxLeft;
2100 hitBand->cx = hitBand->cxEffective;
2101 shrunkBands = TRUE;
2102 }
2103
2104 } else if (movement > 0) {
2105
2106 cxLeft = movement;
2107 if (prev_visible(infoPtr, iHitBand) >= 0)
2108 cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
2109
2110 if(cxLeft < movement)
2111 {
2112 REBAR_BAND *lpPrev = REBAR_GetBand(infoPtr, prev_visible(infoPtr, iHitBand));
2113 lpPrev->cxEffective += movement - cxLeft;
2114 lpPrev->cx = hitBand->cxEffective;
2115 shrunkBands = TRUE;
2116 }
2117
2118 }
2119 }
2120
2121 if(!shrunkBands)
2122 {
2123 /* It was not possible to move the band by shrinking bands.
2124 * Try relocating the band instead. */
2125 REBAR_MoveBandToRowOffset(infoPtr, iHitBand, iRowBegin,
2126 iRowEnd, xBand + movement, TRUE);
2127 }
2128
2129 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2130 if (infoPtr->dwStyle & CCS_VERT)
2131 REBAR_CalcVertBand(infoPtr, 0, infoPtr->uNumBands);
2132 else
2133 REBAR_CalcHorzBand(infoPtr, 0, infoPtr->uNumBands);
2134 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2135 }
2136
2137 static void
2138 REBAR_HandleUDDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
2139 {
2140 INT yOff = (infoPtr->dwStyle & CCS_VERT) ? ptsmove->x : ptsmove->y;
2141 INT iHitBand, iRowBegin, iNextRowBegin;
2142 REBAR_BAND *hitBand, *rowBeginBand;
2143
2144 if(infoPtr->uNumBands <= 0)
2145 ERR("There are no bands in this rebar\n");
2146
2147 /* Up/down dragging can only occur when there is more than one
2148 * band in the rebar */
2149 if(infoPtr->uNumBands <= 1)
2150 return;
2151
2152 iHitBand = infoPtr->iGrabbedBand;
2153 hitBand = REBAR_GetBand(infoPtr, iHitBand);
2154
2155 /* If we're taking a band that has the RBBS_BREAK style set, this
2156 * style needs to be reapplied to the band that is going to become
2157 * the new start of the row. */
2158 if((hitBand->fStyle & RBBS_BREAK) &&
2159 (iHitBand < infoPtr->uNumBands - 1))
2160 REBAR_GetBand(infoPtr, iHitBand + 1)->fStyle |= RBBS_BREAK;
2161
2162 if(yOff < 0)
2163 {
2164 /* Place the band above the current top row */
2165 if(iHitBand==0 && (infoPtr->uNumBands==1 || REBAR_GetBand(infoPtr, 1)->fStyle&RBBS_BREAK))
2166 return;
2167 DPA_DeletePtr(infoPtr->bands, iHitBand);
2168 hitBand->fStyle &= ~RBBS_BREAK;
2169 REBAR_GetBand(infoPtr, 0)->fStyle |= RBBS_BREAK;
2170 infoPtr->iGrabbedBand = DPA_InsertPtr(
2171 infoPtr->bands, 0, hitBand);
2172 }
2173 else if(yOff > REBAR_GetBand(infoPtr, infoPtr->uNumBands - 1)->rcBand.bottom)
2174 {
2175 /* Place the band below the current bottom row */
2176 if(iHitBand == infoPtr->uNumBands-1 && hitBand->fStyle&RBBS_BREAK)
2177 return;
2178 DPA_DeletePtr(infoPtr->bands, iHitBand);
2179 hitBand->fStyle |= RBBS_BREAK;
2180 infoPtr->iGrabbedBand = DPA_InsertPtr(
2181 infoPtr->bands, infoPtr->uNumBands - 1, hitBand);
2182 }
2183 else
2184 {
2185 /* Place the band in the prexisting row the mouse is hovering over */
2186 iRowBegin = first_visible(infoPtr);
2187 while(iRowBegin < infoPtr->uNumBands)
2188 {
2189 iNextRowBegin = get_row_end_for_band(infoPtr, iRowBegin);
2190 rowBeginBand = REBAR_GetBand(infoPtr, iRowBegin);
2191 if(rowBeginBand->rcBand.bottom > yOff)
2192 {
2193 REBAR_MoveBandToRowOffset(
2194 infoPtr, iHitBand, iRowBegin, iNextRowBegin,
2195 ((infoPtr->dwStyle & CCS_VERT) ? ptsmove->y : ptsmove->x)
2196 - REBAR_PRE_GRIPPER - infoPtr->ihitoffset, FALSE);
2197 break;
2198 }
2199
2200 iRowBegin = iNextRowBegin;
2201 }
2202 }
2203
2204 REBAR_Layout(infoPtr);
2205 }
2206
2207
2208 /* << REBAR_BeginDrag >> */
2209
2210
2211 static LRESULT
2212 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
2213 {
2214 UINT uBand = (UINT)wParam;
2215 REBAR_BAND *lpBand;
2216
2217 if (uBand >= infoPtr->uNumBands)
2218 return FALSE;
2219
2220 TRACE("deleting band %u!\n", uBand);
2221 lpBand = REBAR_GetBand(infoPtr, uBand);
2222 REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2223 /* TODO: a return of 1 should probably cancel the deletion */
2224
2225 if (lpBand->hwndChild)
2226 ShowWindow(lpBand->hwndChild, SW_HIDE);
2227 Free(lpBand->lpText);
2228 Free(lpBand);
2229
2230 infoPtr->uNumBands--;
2231 DPA_DeletePtr(infoPtr->bands, uBand);
2232
2233 REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2234
2235 /* if only 1 band left the re-validate to possible eliminate gripper */
2236 if (infoPtr->uNumBands == 1)
2237 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2238
2239 REBAR_Layout(infoPtr);
2240
2241 return TRUE;
2242 }
2243
2244
2245 /* << REBAR_DragMove >> */
2246 /* << REBAR_EndDrag >> */
2247
2248
2249 static LRESULT
2250 REBAR_GetBandBorders (const REBAR_INFO *infoPtr, UINT uBand, RECT *lpRect)
2251 {
2252 REBAR_BAND *lpBand;
2253
2254 if (!lpRect)
2255 return 0;
2256 if (uBand >= infoPtr->uNumBands)
2257 return 0;
2258
2259 lpBand = REBAR_GetBand(infoPtr, uBand);
2260
2261 /* FIXME - the following values were determined by experimentation */
2262 /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2263 /* 1 are, but I am not sure. There doesn't seem to be any actual */
2264 /* difference in size of the control area with and without the */
2265 /* style. - GA */
2266 if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2267 if (infoPtr->dwStyle & CCS_VERT) {
2268 lpRect->left = 1;
2269 lpRect->top = lpBand->cxHeader + 4;
2270 lpRect->right = 1;
2271 lpRect->bottom = 0;
2272 }
2273 else {
2274 lpRect->left = lpBand->cxHeader + 4;
2275 lpRect->top = 1;
2276 lpRect->right = 0;
2277 lpRect->bottom = 1;
2278 }
2279 }
2280 else {
2281 lpRect->left = lpBand->cxHeader;
2282 }
2283 return 0;
2284 }
2285
2286
2287 static inline LRESULT
2288 REBAR_GetBandCount (const REBAR_INFO *infoPtr)
2289 {
2290 TRACE("band count %u!\n", infoPtr->uNumBands);
2291
2292 return infoPtr->uNumBands;
2293 }
2294
2295
2296 static LRESULT
2297 REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, UINT uIndex, LPREBARBANDINFOW lprbbi, BOOL bUnicode)
2298 {
2299 REBAR_BAND *lpBand;
2300
2301 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2302 return FALSE;
2303
2304 if (uIndex >= infoPtr->uNumBands)
2305 return FALSE;
2306
2307 TRACE("index %u (bUnicode=%d)\n", uIndex, bUnicode);
2308
2309 /* copy band information */
2310 lpBand = REBAR_GetBand(infoPtr, uIndex);
2311
2312 if (lprbbi->fMask & RBBIM_STYLE)
2313 lprbbi->fStyle = lpBand->fStyle;
2314
2315 if (lprbbi->fMask & RBBIM_COLORS) {
2316 lprbbi->clrFore = lpBand->clrFore;
2317 lprbbi->clrBack = lpBand->clrBack;
2318 if (lprbbi->clrBack == CLR_DEFAULT)
2319 lprbbi->clrBack = infoPtr->clrBtnFace;
2320 }
2321
2322 if (lprbbi->fMask & RBBIM_TEXT) {
2323 if (bUnicode)
2324 Str_GetPtrW(lpBand->lpText, lprbbi->lpText, lprbbi->cch);
2325 else
2326 Str_GetPtrWtoA(lpBand->lpText, (LPSTR)lprbbi->lpText, lprbbi->cch);
2327 }
2328
2329 if (lprbbi->fMask & RBBIM_IMAGE)
2330 lprbbi->iImage = lpBand->iImage;
2331
2332 if (lprbbi->fMask & RBBIM_CHILD)
2333 lprbbi->hwndChild = lpBand->hwndChild;
2334
2335 if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2336 lprbbi->cxMinChild = lpBand->cxMinChild;
2337 lprbbi->cyMinChild = lpBand->cyMinChild;
2338 /* to make tests pass we follow Windows' behaviour and allow reading these fields only
2339 * for RBBS_VARIABLEHEIGHTS bands */
2340 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2341 lprbbi->cyChild = lpBand->cyChild;
2342 lprbbi->cyMaxChild = lpBand->cyMaxChild;
2343 lprbbi->cyIntegral = lpBand->cyIntegral;
2344 }
2345 }
2346
2347 if (lprbbi->fMask & RBBIM_SIZE)
2348 lprbbi->cx = lpBand->cx;
2349
2350 if (lprbbi->fMask & RBBIM_BACKGROUND)
2351 lprbbi->hbmBack = lpBand->hbmBack;
2352
2353 if (lprbbi->fMask & RBBIM_ID)
2354 lprbbi->wID = lpBand->wID;
2355
2356 /* check for additional data */
2357 if (lprbbi->cbSize >= REBARBANDINFOW_V6_SIZE) {
2358 if (lprbbi->fMask & RBBIM_IDEALSIZE)
2359 lprbbi->cxIdeal = lpBand->cxIdeal;
2360
2361 if (lprbbi->fMask & RBBIM_LPARAM)
2362 lprbbi->lParam = lpBand->lParam;
2363
2364 if (lprbbi->fMask & RBBIM_HEADERSIZE)
2365 lprbbi->cxHeader = lpBand->cxHeader;
2366 }
2367
2368 REBAR_DumpBandInfo(lprbbi);
2369
2370 return TRUE;
2371 }
2372
2373
2374 static LRESULT
2375 REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
2376 {
2377 INT nHeight;
2378
2379 nHeight = infoPtr->calcSize.cy;
2380
2381 TRACE("height = %d\n", nHeight);
2382
2383 return nHeight;
2384 }
2385
2386
2387 static LRESULT
2388 REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPREBARINFO lpInfo)
2389 {
2390 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2391 return FALSE;
2392
2393 TRACE("getting bar info!\n");
2394
2395 if (infoPtr->himl) {
2396 lpInfo->himl = infoPtr->himl;
2397 lpInfo->fMask |= RBIM_IMAGELIST;
2398 }
2399
2400 return TRUE;
2401 }
2402
2403
2404 static inline LRESULT
2405 REBAR_GetBkColor (const REBAR_INFO *infoPtr)
2406 {
2407 COLORREF clr = infoPtr->clrBk;
2408
2409 if (clr == CLR_DEFAULT)
2410 clr = infoPtr->clrBtnFace;
2411
2412 TRACE("background color 0x%06x!\n", clr);
2413
2414 return clr;
2415 }
2416
2417
2418 /* << REBAR_GetColorScheme >> */
2419 /* << REBAR_GetDropTarget >> */
2420
2421
2422 static LRESULT
2423 REBAR_GetPalette (const REBAR_INFO *infoPtr)
2424 {
2425 FIXME("empty stub!\n");
2426
2427 return 0;
2428 }
2429
2430
2431 static LRESULT
2432 REBAR_GetRect (const REBAR_INFO *infoPtr, INT iBand, RECT *lprc)
2433 {
2434 REBAR_BAND *lpBand;
2435
2436 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2437 return FALSE;
2438 if (!lprc)
2439 return FALSE;
2440
2441 lpBand = REBAR_GetBand(infoPtr, iBand);
2442 /* For CCS_VERT the coordinates will be swapped - like on Windows */
2443 *lprc = lpBand->rcBand;
2444
2445 TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
2446
2447 return TRUE;
2448 }
2449
2450
2451 static inline LRESULT
2452 REBAR_GetRowCount (const REBAR_INFO *infoPtr)
2453 {
2454 TRACE("%u\n", infoPtr->uNumRows);
2455
2456 return infoPtr->uNumRows;
2457 }
2458
2459
2460 static LRESULT
2461 REBAR_GetRowHeight (const REBAR_INFO *infoPtr, INT iRow)
2462 {
2463 int j = 0, ret = 0;
2464 UINT i;
2465 REBAR_BAND *lpBand;
2466
2467 for (i=0; i<infoPtr->uNumBands; i++) {
2468 lpBand = REBAR_GetBand(infoPtr, i);
2469 if (HIDDENBAND(lpBand)) continue;
2470 if (lpBand->iRow != iRow) continue;
2471 j = lpBand->rcBand.bottom - lpBand->rcBand.top;
2472 if (j > ret) ret = j;
2473 }
2474
2475 TRACE("row %d, height %d\n", iRow, ret);
2476
2477 return ret;
2478 }
2479
2480
2481 static inline LRESULT
2482 REBAR_GetTextColor (const REBAR_INFO *infoPtr)
2483 {
2484 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2485
2486 return infoPtr->clrText;
2487 }
2488
2489
2490 static inline LRESULT
2491 REBAR_GetToolTips (const REBAR_INFO *infoPtr)
2492 {
2493 return (LRESULT)infoPtr->hwndToolTip;
2494 }
2495
2496
2497 static inline LRESULT
2498 REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
2499 {
2500 TRACE("%s hwnd=%p\n",
2501 infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
2502
2503 return infoPtr->bUnicode;
2504 }
2505
2506
2507 static inline LRESULT
2508 REBAR_GetVersion (const REBAR_INFO *infoPtr)
2509 {
2510 TRACE("version %d\n", infoPtr->iVersion);
2511 return infoPtr->iVersion;
2512 }
2513
2514
2515 static LRESULT
2516 REBAR_HitTest (const REBAR_INFO *infoPtr, LPRBHITTESTINFO lprbht)
2517 {
2518 if (!lprbht)
2519 return -1;
2520
2521 REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
2522
2523 return lprbht->iBand;
2524 }
2525
2526
2527 static LRESULT
2528 REBAR_IdToIndex (const REBAR_INFO *infoPtr, UINT uId)
2529 {
2530 UINT i;
2531
2532 if (infoPtr->uNumBands < 1)
2533 return -1;
2534
2535 for (i = 0; i < infoPtr->uNumBands; i++) {
2536 if (REBAR_GetBand(infoPtr, i)->wID == uId) {
2537 TRACE("id %u is band %u found!\n", uId, i);
2538 return i;
2539 }
2540 }
2541
2542 TRACE("id %u is not found\n", uId);
2543 return -1;
2544 }
2545
2546
2547 static LRESULT
2548 REBAR_InsertBandT(REBAR_INFO *infoPtr, INT iIndex, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2549 {
2550 REBAR_BAND *lpBand;
2551
2552 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2553 return FALSE;
2554
2555 /* trace the index as signed to see the -1 */
2556 TRACE("insert band at %d (bUnicode=%d)!\n", iIndex, bUnicode);
2557 REBAR_DumpBandInfo(lprbbi);
2558
2559 if (!(lpBand = Alloc(sizeof(REBAR_BAND)))) return FALSE;
2560 if ((iIndex == -1) || (iIndex > infoPtr->uNumBands))
2561 iIndex = infoPtr->uNumBands;
2562 if (DPA_InsertPtr(infoPtr->bands, iIndex, lpBand) == -1)
2563 {
2564 Free(lpBand);
2565 return FALSE;
2566 }
2567 infoPtr->uNumBands++;
2568
2569 TRACE("index %d!\n", iIndex);
2570
2571 /* initialize band */
2572 memset(lpBand, 0, sizeof(*lpBand));
2573 lpBand->clrFore = infoPtr->clrText == CLR_NONE ? infoPtr->clrBtnText :
2574 infoPtr->clrText;
2575 lpBand->clrBack = infoPtr->clrBk == CLR_NONE ? infoPtr->clrBtnFace :
2576 infoPtr->clrBk;
2577 lpBand->iImage = -1;
2578
2579 REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
2580
2581 /* Make sure the defaults for these are correct */
2582 if (lprbbi->cbSize < REBARBANDINFOA_V6_SIZE || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
2583 lpBand->cyChild = lpBand->cyMinChild;
2584 lpBand->cyMaxChild = 0x7fffffff;
2585 lpBand->cyIntegral = 0;
2586 }
2587
2588 if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2589 if (bUnicode)
2590 Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
2591 else
2592 Str_SetPtrAtoW(&lpBand->lpText, (LPSTR)lprbbi->lpText);
2593 }
2594
2595 REBAR_ValidateBand (infoPtr, lpBand);
2596 /* On insert of second band, revalidate band 1 to possible add gripper */
2597 if (infoPtr->uNumBands == 2)
2598 REBAR_ValidateBand (infoPtr, REBAR_GetBand(infoPtr, 0));
2599
2600 REBAR_DumpBand (infoPtr);
2601
2602 REBAR_Layout(infoPtr);
2603 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2604
2605 return TRUE;
2606 }
2607
2608
2609 static LRESULT
2610 REBAR_MaximizeBand (const REBAR_INFO *infoPtr, INT iBand, LPARAM lParam)
2611 {
2612 REBAR_BAND *lpBand;
2613 int iRowBegin, iRowEnd;
2614 int cxDesired, extra, extraOrig;
2615 int cxIdealBand;
2616
2617 /* Validate */
2618 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2619 /* error !!! */
2620 ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
2621 iBand, infoPtr->uNumBands);
2622 return FALSE;
2623 }
2624
2625 lpBand = REBAR_GetBand(infoPtr, iBand);
2626
2627 if (lpBand->fStyle & RBBS_HIDDEN)
2628 {
2629 /* Windows is buggy and creates a hole */
2630 WARN("Ignoring maximize request on a hidden band (%d)\n", iBand);
2631 return FALSE;
2632 }
2633
2634 cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
2635 if (lParam && (lpBand->cxEffective < cxIdealBand))
2636 cxDesired = cxIdealBand;
2637 else
2638 cxDesired = infoPtr->calcSize.cx;
2639
2640 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2641 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2642 extraOrig = extra = cxDesired - lpBand->cxEffective;
2643 if (extra > 0)
2644 extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, iBand, extra, TRUE);
2645 if (extra > 0)
2646 extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, iBand), iRowEnd, extra, TRUE);
2647 lpBand->cxEffective += extraOrig - extra;
2648 lpBand->cx = lpBand->cxEffective;
2649 TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", iBand, lParam, cxDesired, lpBand->cx, extraOrig, extra);
2650 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2651
2652 if (infoPtr->dwStyle & CCS_VERT)
2653 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2654 else
2655 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2656 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2657 return TRUE;
2658
2659 }
2660
2661
2662 static LRESULT
2663 REBAR_MinimizeBand (const REBAR_INFO *infoPtr, INT iBand)
2664 {
2665 REBAR_BAND *lpBand;
2666 int iPrev, iRowBegin, iRowEnd;
2667
2668 /* A "minimize" band is equivalent to "dragging" the gripper
2669 * of than band to the right till the band is only the size
2670 * of the cxHeader.
2671 */
2672
2673 /* Validate */
2674 if (infoPtr->uNumBands == 0 || iBand < 0 || iBand >= infoPtr->uNumBands) {
2675 /* error !!! */
2676 ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
2677 iBand, infoPtr->uNumBands);
2678 return FALSE;
2679 }
2680
2681 /* compute amount of movement and validate */
2682 lpBand = REBAR_GetBand(infoPtr, iBand);
2683
2684 if (lpBand->fStyle & RBBS_HIDDEN)
2685 {
2686 /* Windows is buggy and creates a hole/overlap */
2687 WARN("Ignoring minimize request on a hidden band (%d)\n", iBand);
2688 return FALSE;
2689 }
2690
2691 iPrev = prev_visible(infoPtr, iBand);
2692 /* if first band in row */
2693 if (iPrev < 0 || REBAR_GetBand(infoPtr, iPrev)->iRow != lpBand->iRow) {
2694 int iNext = next_visible(infoPtr, iBand);
2695 if (iNext < infoPtr->uNumBands && REBAR_GetBand(infoPtr, iNext)->iRow == lpBand->iRow) {
2696 TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", iBand);
2697 REBAR_MaximizeBand(infoPtr, iNext, FALSE);
2698 }
2699 else
2700 TRACE("(%d): Only one band in row - nothing to do\n", iBand);
2701 return TRUE;
2702 }
2703
2704 REBAR_GetBand(infoPtr, iPrev)->cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
2705 REBAR_GetBand(infoPtr, iPrev)->cx = REBAR_GetBand(infoPtr, iPrev)->cxEffective;
2706 lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
2707
2708 iRowBegin = get_row_begin_for_band(infoPtr, iBand);
2709 iRowEnd = get_row_end_for_band(infoPtr, iBand);
2710 REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
2711
2712 if (infoPtr->dwStyle & CCS_VERT)
2713 REBAR_CalcVertBand(infoPtr, iRowBegin, iRowEnd);
2714 else
2715 REBAR_CalcHorzBand(infoPtr, iRowBegin, iRowEnd);
2716 REBAR_MoveChildWindows(infoPtr, iRowBegin, iRowEnd);
2717 return FALSE;
2718 }
2719
2720
2721 static LRESULT
2722 REBAR_MoveBand (REBAR_INFO *infoPtr, INT iFrom, INT iTo)
2723 {
2724 REBAR_BAND *lpBand;
2725
2726 /* Validate */
2727 if ((infoPtr->uNumBands == 0) ||
2728 (iFrom < 0) || iFrom >= infoPtr->uNumBands ||
2729 (iTo < 0) || iTo >= infoPtr->uNumBands) {
2730 /* error !!! */
2731 ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
2732 iFrom, iTo, infoPtr->uNumBands);
2733 return FALSE;
2734 }
2735
2736 lpBand = REBAR_GetBand(infoPtr, iFrom);
2737 DPA_DeletePtr(infoPtr->bands, iFrom);
2738 DPA_InsertPtr(infoPtr->bands, iTo, lpBand);
2739
2740 TRACE("moved band %d to index %d\n", iFrom, iTo);
2741 REBAR_DumpBand (infoPtr);
2742
2743 /* **************************************************** */
2744 /* */
2745 /* We do not do a REBAR_Layout here because the native */
2746 /* control does not do that. The actual layout and */
2747 /* repaint is done by the *next* real action, ex.: */
2748 /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc. */
2749 /* */
2750 /* **************************************************** */
2751
2752 return TRUE;
2753 }
2754
2755
2756 /* return TRUE if two strings are different */
2757 static BOOL
2758 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
2759 {
2760 return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
2761 }
2762
2763 static LRESULT
2764 REBAR_SetBandInfoT(REBAR_INFO *infoPtr, INT iBand, const REBARBANDINFOW *lprbbi, BOOL bUnicode)
2765 {
2766 REBAR_BAND *lpBand;
2767 UINT uChanged;
2768
2769 if (!lprbbi || lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2770 return FALSE;
2771
2772 if (iBand >= infoPtr->uNumBands)
2773 return FALSE;
2774
2775 TRACE("index %d\n", iBand);
2776 REBAR_DumpBandInfo (lprbbi);
2777
2778 /* set band information */
2779 lpBand = REBAR_GetBand(infoPtr, iBand);
2780
2781 uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
2782 if (lprbbi->fMask & RBBIM_TEXT) {
2783 LPWSTR wstr = NULL;
2784 if (bUnicode)
2785 Str_SetPtrW(&wstr, lprbbi->lpText);
2786 else
2787 Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
2788
2789 if (REBAR_strdifW(wstr, lpBand->lpText)) {
2790 Free(lpBand->lpText);
2791 lpBand->lpText = wstr;
2792 uChanged |= RBBIM_TEXT;
2793 }
2794 else
2795 Free(wstr);
2796 }
2797
2798 REBAR_ValidateBand (infoPtr, lpBand);
2799
2800 REBAR_DumpBand (infoPtr);
2801
2802 if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
2803 REBAR_Layout(infoPtr);
2804 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2805 }
2806
2807 return TRUE;
2808 }
2809
2810
2811 static LRESULT
2812 REBAR_SetBarInfo (REBAR_INFO *infoPtr, const REBARINFO *lpInfo)
2813 {
2814 REBAR_BAND *lpBand;
2815 UINT i;
2816
2817 if (!lpInfo || lpInfo->cbSize < sizeof (REBARINFO))
2818 return FALSE;
2819
2820 TRACE("setting bar info!\n");
2821
2822 if (lpInfo->fMask & RBIM_IMAGELIST) {
2823 infoPtr->himl = lpInfo->himl;
2824 if (infoPtr->himl) {
2825 INT cx, cy;
2826 ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
2827 infoPtr->imageSize.cx = cx;
2828 infoPtr->imageSize.cy = cy;
2829 }
2830 else {
2831 infoPtr->imageSize.cx = 0;
2832 infoPtr->imageSize.cy = 0;
2833 }
2834 TRACE("new image cx=%d, cy=%d\n", infoPtr->imageSize.cx,
2835 infoPtr->imageSize.cy);
2836 }
2837
2838 /* revalidate all bands to reset flags for images in headers of bands */
2839 for (i=0; i<infoPtr->uNumBands; i++) {
2840 lpBand = REBAR_GetBand(infoPtr, i);
2841 REBAR_ValidateBand (infoPtr, lpBand);
2842 }
2843
2844 return TRUE;
2845 }
2846
2847
2848 static LRESULT
2849 REBAR_SetBkColor (REBAR_INFO *infoPtr, COLORREF clr)
2850 {
2851 COLORREF clrTemp;
2852
2853 clrTemp = infoPtr->clrBk;
2854 infoPtr->clrBk = clr;
2855
2856 TRACE("background color 0x%06x!\n", infoPtr->clrBk);
2857
2858 return clrTemp;
2859 }
2860
2861
2862 /* << REBAR_SetColorScheme >> */
2863 /* << REBAR_SetPalette >> */
2864
2865
2866 static LRESULT
2867 REBAR_SetParent (REBAR_INFO *infoPtr, HWND parent)
2868 {
2869 HWND hwndTemp = infoPtr->hwndNotify;
2870
2871 infoPtr->hwndNotify = parent;
2872
2873 return (LRESULT)hwndTemp;
2874 }
2875
2876
2877 static LRESULT
2878 REBAR_SetTextColor (REBAR_INFO *infoPtr, COLORREF clr)
2879 {
2880 COLORREF clrTemp;
2881
2882 clrTemp = infoPtr->clrText;
2883 infoPtr->clrText = clr;
2884
2885 TRACE("text color 0x%06x!\n", infoPtr->clrText);
2886
2887 return clrTemp;
2888 }
2889
2890
2891 /* << REBAR_SetTooltips >> */
2892
2893
2894 static inline LRESULT
2895 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, BOOL unicode)
2896 {
2897 BOOL bTemp = infoPtr->bUnicode;
2898
2899 TRACE("to %s hwnd=%p, was %s\n",
2900 unicode ? "TRUE" : "FALSE", infoPtr->hwndSelf,
2901 (bTemp) ? "TRUE" : "FALSE");
2902
2903 infoPtr->bUnicode = unicode;
2904
2905 return bTemp;
2906 }
2907
2908
2909 static LRESULT
2910 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
2911 {
2912 INT iOldVersion = infoPtr->iVersion;
2913
2914 if (iVersion > COMCTL32_VERSION)
2915 return -1;
2916
2917 infoPtr->iVersion = iVersion;
2918
2919 TRACE("new version %d\n", iVersion);
2920
2921 return iOldVersion;
2922 }
2923
2924
2925 static LRESULT
2926 REBAR_ShowBand (REBAR_INFO *infoPtr, INT iBand, BOOL show)
2927 {
2928 REBAR_BAND *lpBand;
2929
2930 if (iBand < 0 || iBand >= infoPtr->uNumBands)
2931 return FALSE;
2932
2933 lpBand = REBAR_GetBand(infoPtr, iBand);
2934
2935 if (show) {
2936 TRACE("show band %d\n", iBand);
2937 lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
2938 if (IsWindow (lpBand->hwndChild))
2939 ShowWindow (lpBand->hwndChild, SW_SHOW);
2940 }
2941 else {
2942 TRACE("hide band %d\n", iBand);
2943 lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
2944 if (IsWindow (lpBand->hwndChild))
2945 ShowWindow (lpBand->hwndChild, SW_HIDE);
2946 }
2947
2948 REBAR_Layout(infoPtr);
2949 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2950
2951 return TRUE;
2952 }
2953
2954
2955 static LRESULT
2956 #ifdef __REACTOS__
2957 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM flags, RECT *lpRect)
2958 #else
2959 REBAR_SizeToRect (REBAR_INFO *infoPtr, const RECT *lpRect)
2960 #endif
2961 {
2962 if (!lpRect) return FALSE;
2963
2964 TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
2965 REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
2966
2967 #ifdef __REACTOS__
2968 /* Note that this undocumented flag is available on comctl32 v6 or later */
2969 if ((flags & RBSTR_CHANGERECT) != 0)
2970 {
2971 RECT rcRebar;
2972 GetClientRect(infoPtr->hwndSelf, &rcRebar);
2973 lpRect->bottom = lpRect->top + (rcRebar.bottom - rcRebar.top);
2974 }
2975 #endif
2976 return TRUE;
2977 }
2978
2979
2980
2981 static LRESULT
2982 REBAR_Create (REBAR_INFO *infoPtr, LPCREATESTRUCTW cs)
2983 {
2984 RECT wnrc1, clrc1;
2985
2986 if (TRACE_ON(rebar)) {
2987 GetWindowRect(infoPtr->hwndSelf, &wnrc1);
2988 GetClientRect(infoPtr->hwndSelf, &clrc1);
2989 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
2990 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
2991 cs->x, cs->y, cs->cx, cs->cy);
2992 }
2993
2994 TRACE("created!\n");
2995
2996 if (OpenThemeData (infoPtr->hwndSelf, themeClass))
2997 {
2998 /* native seems to clear WS_BORDER when themed */
2999 infoPtr->dwStyle &= ~WS_BORDER;
3000 }
3001
3002 return 0;
3003 }
3004
3005
3006 static LRESULT
3007 REBAR_Destroy (REBAR_INFO *infoPtr)
3008 {
3009 REBAR_BAND *lpBand;
3010 UINT i;
3011
3012 /* clean up each band */
3013 for (i = 0; i < infoPtr->uNumBands; i++) {
3014 lpBand = REBAR_GetBand(infoPtr, i);
3015
3016 /* delete text strings */
3017 Free (lpBand->lpText);
3018 lpBand->lpText = NULL;
3019 /* destroy child window */
3020 DestroyWindow (lpBand->hwndChild);
3021 Free (lpBand);
3022 }
3023
3024 /* free band array */
3025 DPA_Destroy (infoPtr->bands);
3026 infoPtr->bands = NULL;
3027
3028 DestroyCursor (infoPtr->hcurArrow);
3029 DestroyCursor (infoPtr->hcurHorz);
3030 DestroyCursor (infoPtr->hcurVert);
3031 DestroyCursor (infoPtr->hcurDrag);
3032 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3033 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
3034
3035 CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
3036
3037 /* free rebar info data */
3038 Free (infoPtr);
3039 TRACE("destroyed!\n");
3040 return 0;
3041 }
3042
3043 static LRESULT
3044 REBAR_GetFont (const REBAR_INFO *infoPtr)
3045 {
3046 return (LRESULT)infoPtr->hFont;
3047 }
3048
3049 static LRESULT
3050 REBAR_PushChevron(const REBAR_INFO *infoPtr, UINT uBand, LPARAM lParam)
3051 {
3052 if (uBand < infoPtr->uNumBands)
3053 {
3054 NMREBARCHEVRON nmrbc;
3055 REBAR_BAND *lpBand = REBAR_GetBand(infoPtr, uBand);
3056
3057 TRACE("Pressed chevron on band %u\n", uBand);
3058
3059 /* redraw chevron in pushed state */
3060 lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3061 RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3062 RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3063
3064 /* notify app so it can display a popup menu or whatever */
3065 nmrbc.uBand = uBand;
3066 nmrbc.wID = lpBand->wID;
3067 nmrbc.lParam = lpBand->lParam;
3068 nmrbc.rc = lpBand->rcChevron;
3069 nmrbc.lParamNM = lParam;
3070 REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3071
3072 /* redraw chevron in previous state */
3073 lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3074 InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3075
3076 return TRUE;
3077 }
3078 return FALSE;
3079 }
3080
3081 static LRESULT
3082 REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
3083 {
3084 UINT htFlags;
3085 INT iHitBand;
3086 POINT ptMouseDown;
3087 ptMouseDown.x = (short)LOWORD(lParam);
3088 ptMouseDown.y = (short)HIWORD(lParam);
3089
3090 REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3091
3092 if (htFlags == RBHT_CHEVRON)
3093 {
3094 REBAR_PushChevron(infoPtr, iHitBand, 0);
3095 }
3096 else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3097 {
3098 REBAR_BAND *lpBand;
3099
3100 TRACE("Starting drag\n");
3101
3102 lpBand = REBAR_GetBand(infoPtr, iHitBand);
3103
3104 SetCapture (infoPtr->hwndSelf);
3105 infoPtr->iGrabbedBand = iHitBand;
3106
3107 /* save off the LOWORD and HIWORD of lParam as initial x,y */
3108 infoPtr->dragStart.x = (short)LOWORD(lParam);
3109 infoPtr->dragStart.y = (short)HIWORD(lParam);
3110 infoPtr->dragNow = infoPtr->dragStart;
3111 if (infoPtr->dwStyle & CCS_VERT)
3112 infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3113 else
3114 infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left + REBAR_PRE_GRIPPER);
3115 }
3116 return 0;
3117 }
3118
3119 static LRESULT
3120 REBAR_LButtonUp (REBAR_INFO *infoPtr)
3121 {
3122 if (infoPtr->iGrabbedBand >= 0)
3123 {
3124 NMHDR layout;
3125 RECT rect;
3126
3127 infoPtr->dragStart.x = 0;
3128 infoPtr->dragStart.y = 0;
3129 infoPtr->dragNow = infoPtr->dragStart;
3130
3131 ReleaseCapture ();
3132
3133 if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3134 REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3135 REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3136 infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3137 }
3138
3139 infoPtr->iGrabbedBand = -1;
3140
3141 GetClientRect(infoPtr->hwndSelf, &rect);
3142 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3143 }
3144
3145 return 0;
3146 }
3147
3148 static LRESULT
3149 REBAR_MouseLeave (REBAR_INFO *infoPtr)
3150 {
3151 if (infoPtr->ichevronhotBand >= 0)
3152 {
3153 REBAR_BAND *lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3154 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3155 {
3156 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3157 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3158 }
3159 }
3160 infoPtr->iOldBand = -1;
3161 infoPtr->ichevronhotBand = -2;
3162
3163 return TRUE;
3164 }
3165
3166 static LRESULT
3167 REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
3168 {
3169 REBAR_BAND *lpChevronBand;
3170 POINT ptMove;
3171
3172 ptMove.x = (short)LOWORD(lParam);
3173 ptMove.y = (short)HIWORD(lParam);
3174
3175 /* if we are currently dragging a band */
3176 if (infoPtr->iGrabbedBand >= 0)
3177 {
3178 REBAR_BAND *band;
3179 int yPtMove = (infoPtr->dwStyle & CCS_VERT ? ptMove.x : ptMove.y);
3180
3181 if (GetCapture() != infoPtr->hwndSelf)
3182 ERR("We are dragging but haven't got capture?!?\n");
3183
3184 band = REBAR_GetBand(infoPtr, infoPtr->iGrabbedBand);
3185
3186 /* if mouse did not move much, exit */
3187 if ((abs(ptMove.x - infoPtr->dragNow.x) <= mindragx) &&
3188 (abs(ptMove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
3189
3190 /* on first significant mouse movement, issue notify */
3191 if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
3192 if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
3193 /* Notify returned TRUE - abort drag */
3194 infoPtr->dragStart.x = 0;
3195 infoPtr->dragStart.y = 0;
3196 infoPtr->dragNow = infoPtr->dragStart;
3197 infoPtr->iGrabbedBand = -1;
3198 ReleaseCapture ();
3199 return 0;
3200 }
3201 infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
3202 }
3203
3204 /* Test for valid drag case - must not be first band in row */
3205 if ((yPtMove < band->rcBand.top) ||
3206 (yPtMove > band->rcBand.bottom)) {
3207 REBAR_HandleUDDrag (infoPtr, &ptMove);
3208 }
3209 else {
3210 REBAR_HandleLRDrag (infoPtr, &ptMove);
3211 }
3212 }
3213 else
3214 {
3215 INT iHitBand;
3216 UINT htFlags;
3217 TRACKMOUSEEVENT trackinfo;
3218
3219 REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
3220
3221 if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
3222 {
3223 lpChevronBand = REBAR_GetBand(infoPtr, infoPtr->ichevronhotBand);
3224 if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3225 {
3226 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3227 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3228 }
3229 infoPtr->ichevronhotBand = -2;
3230 }
3231
3232 if (htFlags == RBHT_CHEVRON)
3233 {
3234 /* fill in the TRACKMOUSEEVENT struct */
3235 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3236 trackinfo.dwFlags = TME_QUERY;
3237 trackinfo.hwndTrack = infoPtr->hwndSelf;
3238 trackinfo.dwHoverTime = 0;
3239
3240 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
3241 _TrackMouseEvent(&trackinfo);
3242
3243 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
3244 if(!(trackinfo.dwFlags & TME_LEAVE))
3245 {
3246 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
3247
3248 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
3249 /* and can properly deactivate the hot chevron */
3250 _TrackMouseEvent(&trackinfo);
3251 }
3252
3253 lpChevronBand = REBAR_GetBand(infoPtr, iHitBand);
3254 if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
3255 {
3256 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
3257 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3258 infoPtr->ichevronhotBand = iHitBand;
3259 }
3260 }
3261 infoPtr->iOldBand = iHitBand;
3262 }
3263
3264 return 0;
3265 }
3266
3267
3268 static inline LRESULT
3269 REBAR_NCCalcSize (const REBAR_INFO *infoPtr, RECT *rect)
3270 {
3271 HTHEME theme;
3272
3273 if (infoPtr->dwStyle & WS_BORDER) {
3274 rect->left = min(rect->left + GetSystemMetrics(SM_CXEDGE), rect->right);
3275 rect->right = max(rect->right - GetSystemMetrics(SM_CXEDGE), rect->left);
3276 rect->top = min(rect->top + GetSystemMetrics(SM_CYEDGE), rect->bottom);
3277 rect->bottom = max(rect->bottom - GetSystemMetrics(SM_CYEDGE), rect->top);
3278 }
3279 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3280 {
3281 /* FIXME: should use GetThemeInt */
3282 #ifdef __REACTOS__
3283 rect->top = (rect->top + 1 < rect->bottom) ? rect->top : rect->bottom;
3284 #else
3285 rect->top = min(rect->top + 1, rect->bottom);
3286 #endif
3287 }
3288 TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
3289 return 0;
3290 }
3291
3292
3293 static LRESULT
3294 REBAR_NCCreate (HWND hwnd, const CREATESTRUCTW *cs)
3295 {
3296 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3297 RECT wnrc1, clrc1;
3298 NONCLIENTMETRICSW ncm;
3299 HFONT tfont;
3300
3301 if (infoPtr) {
3302 ERR("Strange info structure pointer *not* NULL\n");
3303 return FALSE;
3304 }
3305
3306 if (TRACE_ON(rebar)) {
3307 GetWindowRect(hwnd, &wnrc1);
3308 GetClientRect(hwnd, &clrc1);
3309 TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
3310 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
3311 cs->x, cs->y, cs->cx, cs->cy);
3312 }
3313
3314 /* allocate memory for info structure */
3315 infoPtr = Alloc (sizeof(REBAR_INFO));
3316 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
3317
3318 /* initialize info structure - initial values are 0 */
3319 infoPtr->clrBk = CLR_NONE;
3320 infoPtr->clrText = CLR_NONE;
3321 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3322 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3323 infoPtr->iOldBand = -1;
3324 infoPtr->ichevronhotBand = -2;
3325 infoPtr->iGrabbedBand = -1;
3326 infoPtr->hwndSelf = hwnd;
3327 infoPtr->DoRedraw = TRUE;
3328 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
3329 infoPtr->hcurHorz = LoadCursorW (0, (LPWSTR)IDC_SIZEWE);
3330 infoPtr->hcurVert = LoadCursorW (0, (LPWSTR)IDC_SIZENS);
3331 infoPtr->hcurDrag = LoadCursorW (0, (LPWSTR)IDC_SIZE);
3332 infoPtr->fStatus = 0;
3333 infoPtr->hFont = GetStockObject (SYSTEM_FONT);
3334 infoPtr->bands = DPA_Create(8);
3335
3336 /* issue WM_NOTIFYFORMAT to get unicode status of parent */
3337 REBAR_NotifyFormat(infoPtr, NF_REQUERY);
3338
3339 /* Stow away the original style */
3340 infoPtr->orgStyle = cs->style;
3341 /* add necessary styles to the requested styles */
3342 infoPtr->dwStyle = cs->style | WS_VISIBLE;
3343 if ((infoPtr->dwStyle & CCS_LAYOUT_MASK) == 0)
3344 infoPtr->dwStyle |= CCS_TOP;
3345 SetWindowLongW (hwnd, GWL_STYLE, infoPtr->dwStyle);
3346
3347 /* get font handle for Caption Font */
3348 ncm.cbSize = sizeof(ncm);
3349 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0);
3350 /* if the font is bold, set to normal */
3351 if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
3352 ncm.lfCaptionFont.lfWeight = FW_NORMAL;
3353 }
3354 tfont = CreateFontIndirectW (&ncm.lfCaptionFont);
3355 if (tfont) {
3356 infoPtr->hFont = infoPtr->hDefaultFont = tfont;
3357 }
3358
3359 return TRUE;
3360 }
3361
3362
3363 static LRESULT
3364 REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
3365 {
3366 NMMOUSE nmmouse;
3367 POINT clpt;
3368 INT i;
3369 UINT scrap;
3370 LRESULT ret = HTCLIENT;
3371
3372 /*
3373 * Differences from doc at MSDN (as observed with version 4.71 of
3374 * comctl32.dll
3375 * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
3376 * 2. if band is not identified .dwItemSpec is 0xffffffff.
3377 * 3. native always seems to return HTCLIENT if notify return is 0.
3378 */
3379
3380 clpt.x = (short)LOWORD(lParam);
3381 clpt.y = (short)HIWORD(lParam);
3382 ScreenToClient (infoPtr->hwndSelf, &clpt);
3383 REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
3384 (INT *)&nmmouse.dwItemSpec);
3385 nmmouse.dwItemData = 0;
3386 nmmouse.pt = clpt;
3387 #ifdef __REACTOS__
3388 nmmouse.dwHitInfo = scrap;
3389 #else
3390 nmmouse.dwHitInfo = 0;
3391 #endif
3392 if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
3393 TRACE("notify changed return value from %ld to %d\n",
3394 ret, i);
3395 ret = (LRESULT) i;
3396 }
3397 TRACE("returning %ld, client point %s\n", ret, wine_dbgstr_point(&clpt));
3398 return ret;
3399 }
3400
3401
3402 static LRESULT
3403 REBAR_NCPaint (const REBAR_INFO *infoPtr)
3404 {
3405 RECT rcWindow;
3406 HDC hdc;
3407 HTHEME theme;
3408
3409 if (infoPtr->dwStyle & WS_MINIMIZE)
3410 return 0; /* Nothing to do */
3411
3412 if (infoPtr->dwStyle & WS_BORDER) {
3413
3414 /* adjust rectangle and draw the necessary edge */
3415 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3416 return 0;
3417 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3418 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3419 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3420 DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
3421 ReleaseDC( infoPtr->hwndSelf, hdc );
3422 }
3423 else if ((theme = GetWindowTheme (infoPtr->hwndSelf)))
3424 {
3425 /* adjust rectangle and draw the necessary edge */
3426 if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
3427 return 0;
3428 GetWindowRect (infoPtr->hwndSelf, &rcWindow);
3429 OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
3430 TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
3431 DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
3432 ReleaseDC( infoPtr->hwndSelf, hdc );
3433 }
3434
3435 return 0;
3436 }
3437
3438
3439 static LRESULT
3440 REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM cmd)
3441 {
3442 INT i;
3443
3444 if (cmd == NF_REQUERY) {
3445 i = SendMessageW(REBAR_GetNotifyParent (infoPtr),
3446 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
3447 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
3448 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
3449 i = NFR_ANSI;
3450 }
3451 infoPtr->bUnicode = (i == NFR_UNICODE);
3452 return (LRESULT)i;
3453 }
3454 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
3455 }
3456
3457
3458 static LRESULT
3459 REBAR_Paint (const REBAR_INFO *infoPtr, HDC hdc)
3460 {
3461 if (hdc) {
3462 TRACE("painting\n");
3463 #ifdef __REACTOS__
3464 REBAR_EraseBkGnd (infoPtr, hdc);
3465 #endif
3466 REBAR_Refresh (infoPtr, hdc);
3467 } else {
3468 PAINTSTRUCT ps;
3469 hdc = BeginPaint (infoPtr->hwndSelf, &ps);
3470 TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
3471 if (ps.fErase) {
3472 /* Erase area of paint if requested */
3473 REBAR_EraseBkGnd (infoPtr, hdc);
3474 }
3475 REBAR_Refresh (infoPtr, hdc);
3476 EndPaint (infoPtr->hwndSelf, &ps);
3477 }
3478
3479 return 0;
3480 }
3481
3482
3483 static LRESULT
3484 REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
3485 {
3486 POINT pt;
3487 UINT flags;
3488
3489 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
3490
3491 GetCursorPos (&pt);
3492 ScreenToClient (infoPtr->hwndSelf, &pt);
3493
3494 REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
3495
3496 if (flags == RBHT_GRABBER) {
3497 if ((infoPtr->dwStyle & CCS_VERT) &&
3498 !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
3499 SetCursor (infoPtr->hcurVert);
3500 else
3501 SetCursor (infoPtr->hcurHorz);
3502 }
3503 else if (flags != RBHT_CLIENT)
3504 SetCursor (infoPtr->hcurArrow);
3505
3506 return 0;
3507 }
3508
3509
3510 static LRESULT
3511 REBAR_SetFont (REBAR_INFO *infoPtr, HFONT font)
3512 {
3513 REBAR_BAND *lpBand;
3514 UINT i;
3515
3516 infoPtr->hFont = font;
3517
3518 /* revalidate all bands to change sizes of text in headers of bands */
3519 for (i=0; i<infoPtr->uNumBands; i++) {
3520 lpBand = REBAR_GetBand(infoPtr, i);
3521 REBAR_ValidateBand (infoPtr, lpBand);
3522 }
3523
3524 REBAR_Layout(infoPtr);
3525 return 0;
3526 }
3527
3528
3529 /*****************************************************
3530 *
3531 * Handles the WM_SETREDRAW message.
3532 *
3533 * Documentation:
3534 * According to testing V4.71 of COMCTL32 returns the
3535 * *previous* status of the redraw flag (either 0 or -1)
3536 * instead of the MSDN documented value of 0 if handled
3537 *
3538 *****************************************************/
3539 static inline LRESULT
3540 REBAR_SetRedraw (REBAR_INFO *infoPtr, BOOL redraw)
3541 {
3542 BOOL oldredraw = infoPtr->DoRedraw;
3543
3544 TRACE("set to %s, fStatus=%08x\n",
3545 (redraw) ? "TRUE" : "FALSE", infoPtr->fStatus);
3546 infoPtr->DoRedraw = redraw;
3547 if (redraw) {
3548 if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
3549 REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
3550 REBAR_ForceResize (infoPtr);
3551 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3552 }
3553 infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
3554 }
3555 return (oldredraw) ? -1 : 0;
3556 }
3557
3558
3559 static LRESULT
3560 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3561 {
3562 TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
3563
3564 /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
3565 if (infoPtr->fStatus & SELF_RESIZE) {
3566 infoPtr->fStatus &= ~SELF_RESIZE;
3567 TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
3568 infoPtr->fStatus, lParam);
3569 return 0;
3570 }
3571
3572 if (infoPtr->dwStyle & RBS_AUTOSIZE)
3573 REBAR_AutoSize(infoPtr, TRUE);
3574 else
3575 REBAR_Layout(infoPtr);
3576
3577 return 0;
3578 }
3579
3580
3581 static LRESULT
3582 REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
3583 {
3584 TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
3585 infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
3586 if (nType == GWL_STYLE)
3587 {
3588 infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
3589 if (GetWindowTheme (infoPtr->hwndSelf))
3590 infoPtr->dwStyle &= ~WS_BORDER;
3591 /* maybe it should be COMMON_STYLES like in toolbar */
3592 if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
3593 REBAR_Layout(infoPtr);
3594 }
3595 return FALSE;
3596 }
3597
3598 /* update theme after a WM_THEMECHANGED message */
3599 static LRESULT theme_changed (REBAR_INFO* infoPtr)
3600 {
3601 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
3602 CloseThemeData (theme);
3603 theme = OpenThemeData (infoPtr->hwndSelf, themeClass);
3604 /* WS_BORDER disappears when theming is enabled and reappears when
3605 * disabled... */
3606 infoPtr->dwStyle &= ~WS_BORDER;
3607 infoPtr->dwStyle |= theme ? 0 : (infoPtr->orgStyle & WS_BORDER);
3608 return 0;
3609 }
3610
3611 static LRESULT
3612 REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3613 {
3614 LRESULT ret;
3615 RECT rc;
3616
3617 ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
3618 wParam, lParam);
3619 GetWindowRect(infoPtr->hwndSelf, &rc);
3620 TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
3621 return ret;
3622 }
3623
3624
3625 static LRESULT WINAPI
3626 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3627 {
3628 REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
3629
3630 TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
3631 hwnd, uMsg, wParam, lParam);
3632 if (!infoPtr && (uMsg != WM_NCCREATE))
3633 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3634 switch (uMsg)
3635 {
3636 /* case RB_BEGINDRAG: */
3637
3638 case RB_DELETEBAND:
3639 return REBAR_DeleteBand (infoPtr, wParam);
3640
3641 /* case RB_DRAGMOVE: */
3642 /* case RB_ENDDRAG: */
3643
3644 case RB_GETBANDBORDERS:
3645 return REBAR_GetBandBorders (infoPtr, wParam, (LPRECT)lParam);
3646
3647 case RB_GETBANDCOUNT:
3648 return REBAR_GetBandCount (infoPtr);
3649
3650 case RB_GETBANDINFO_OLD:
3651 case RB_GETBANDINFOA:
3652 case RB_GETBANDINFOW:
3653 return REBAR_GetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3654 uMsg == RB_GETBANDINFOW);
3655 case RB_GETBARHEIGHT:
3656 return REBAR_GetBarHeight (infoPtr);
3657
3658 case RB_GETBARINFO:
3659 return REBAR_GetBarInfo (infoPtr, (LPREBARINFO)lParam);
3660
3661 case RB_GETBKCOLOR:
3662 return REBAR_GetBkColor (infoPtr);
3663
3664 /* case RB_GETCOLORSCHEME: */
3665 /* case RB_GETDROPTARGET: */
3666
3667 case RB_GETPALETTE:
3668 return REBAR_GetPalette (infoPtr);
3669
3670 case RB_GETRECT:
3671 return REBAR_GetRect (infoPtr, wParam, (LPRECT)lParam);
3672
3673 case RB_GETROWCOUNT:
3674 return REBAR_GetRowCount (infoPtr);
3675
3676 case RB_GETROWHEIGHT:
3677 return REBAR_GetRowHeight (infoPtr, wParam);
3678
3679 case RB_GETTEXTCOLOR:
3680 return REBAR_GetTextColor (infoPtr);
3681
3682 case RB_GETTOOLTIPS:
3683 return REBAR_GetToolTips (infoPtr);
3684
3685 case RB_GETUNICODEFORMAT:
3686 return REBAR_GetUnicodeFormat (infoPtr);
3687
3688 case CCM_GETVERSION:
3689 return REBAR_GetVersion (infoPtr);
3690
3691 case RB_HITTEST:
3692 return REBAR_HitTest (infoPtr, (LPRBHITTESTINFO)lParam);
3693
3694 case RB_IDTOINDEX:
3695 return REBAR_IdToIndex (infoPtr, wParam);
3696
3697 case RB_INSERTBANDA:
3698 case RB_INSERTBANDW:
3699 return REBAR_InsertBandT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3700 uMsg == RB_INSERTBANDW);
3701 case RB_MAXIMIZEBAND:
3702 return REBAR_MaximizeBand (infoPtr, wParam, lParam);
3703
3704 case RB_MINIMIZEBAND:
3705 return REBAR_MinimizeBand (infoPtr, wParam);
3706
3707 case RB_MOVEBAND:
3708 return REBAR_MoveBand (infoPtr, wParam, lParam);
3709
3710 case RB_PUSHCHEVRON:
3711 return REBAR_PushChevron (infoPtr, wParam, lParam);
3712
3713 case RB_SETBANDINFOA:
3714 case RB_SETBANDINFOW:
3715 return REBAR_SetBandInfoT(infoPtr, wParam, (LPREBARBANDINFOW)lParam,
3716 uMsg == RB_SETBANDINFOW);
3717 case RB_SETBARINFO:
3718 return REBAR_SetBarInfo (infoPtr, (LPREBARINFO)lParam);
3719
3720 case RB_SETBKCOLOR:
3721 return REBAR_SetBkColor (infoPtr, lParam);
3722
3723 /* case RB_SETCOLORSCHEME: */
3724 /* case RB_SETPALETTE: */
3725
3726 case RB_SETPARENT:
3727 return REBAR_SetParent (infoPtr, (HWND)wParam);
3728
3729 case RB_SETTEXTCOLOR:
3730 return REBAR_SetTextColor (infoPtr, lParam);
3731
3732 /* case RB_SETTOOLTIPS: */
3733
3734 case RB_SETUNICODEFORMAT:
3735 return REBAR_SetUnicodeFormat (infoPtr, wParam);
3736
3737 case CCM_SETVERSION:
3738 return REBAR_SetVersion (infoPtr, (INT)wParam);
3739
3740 case RB_SHOWBAND:
3741 return REBAR_ShowBand (infoPtr, wParam, lParam);
3742
3743 case RB_SIZETORECT:
3744 #ifdef __REACTOS__
3745 return REBAR_SizeToRect (infoPtr, wParam, (LPRECT)lParam);
3746 #else
3747 return REBAR_SizeToRect (infoPtr, (LPCRECT)lParam);
3748 #endif
3749
3750
3751 /* Messages passed to parent */
3752 case WM_COMMAND:
3753 case WM_DRAWITEM:
3754 case WM_NOTIFY:
3755 case WM_MEASUREITEM:
3756 return SendMessageW(REBAR_GetNotifyParent (infoPtr), uMsg, wParam, lParam);
3757
3758
3759 /* case WM_CHARTOITEM: supported according to ControlSpy */
3760
3761 case WM_CREATE:
3762 return REBAR_Create (infoPtr, (LPCREATESTRUCTW)lParam);
3763
3764 case WM_DESTROY:
3765 return REBAR_Destroy (infoPtr);
3766
3767 case WM_ERASEBKGND:
3768 return REBAR_EraseBkGnd (infoPtr, (HDC)wParam);
3769
3770 case WM_GETFONT:
3771 return REBAR_GetFont (infoPtr);
3772
3773 /* case WM_LBUTTONDBLCLK: supported according to ControlSpy */
3774
3775 case WM_LBUTTONDOWN:
3776 return REBAR_LButtonDown (infoPtr, lParam);
3777
3778 case WM_LBUTTONUP:
3779 return REBAR_LButtonUp (infoPtr);
3780
3781 case WM_MOUSEMOVE:
3782 return REBAR_MouseMove (infoPtr, lParam);
3783
3784 case WM_MOUSELEAVE:
3785 return REBAR_MouseLeave (infoPtr);
3786
3787 case WM_NCCALCSIZE:
3788 return REBAR_NCCalcSize (infoPtr, (RECT*)lParam);
3789
3790 case WM_NCCREATE:
3791 return REBAR_NCCreate (hwnd, (LPCREATESTRUCTW)lParam);
3792
3793 case WM_NCHITTEST:
3794 return REBAR_NCHitTest (infoPtr, lParam);
3795
3796 case WM_NCPAINT:
3797 return REBAR_NCPaint (infoPtr);
3798
3799 case WM_NOTIFYFORMAT:
3800 return REBAR_NotifyFormat (infoPtr, lParam);
3801
3802 case WM_PRINTCLIENT:
3803 case WM_PAINT:
3804 return REBAR_Paint (infoPtr, (HDC)wParam);
3805
3806 /* case WM_PALETTECHANGED: supported according to ControlSpy */
3807 /* case WM_QUERYNEWPALETTE:supported according to ControlSpy */
3808 /* case WM_RBUTTONDOWN: supported according to ControlSpy */
3809 /* case WM_RBUTTONUP: supported according to ControlSpy */
3810
3811 case WM_SETCURSOR:
3812 return REBAR_SetCursor (infoPtr, lParam);
3813
3814 case WM_SETFONT:
3815 return REBAR_SetFont (infoPtr, (HFONT)wParam);
3816
3817 case WM_SETREDRAW:
3818 return REBAR_SetRedraw (infoPtr, wParam);
3819
3820 case WM_SIZE:
3821 return REBAR_Size (infoPtr, wParam, lParam);
3822
3823 case WM_STYLECHANGED:
3824 return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3825
3826 case WM_THEMECHANGED:
3827 return theme_changed (infoPtr);
3828
3829 case WM_SYSCOLORCHANGE:
3830 COMCTL32_RefreshSysColors();
3831 #ifdef __REACTOS__
3832 /* r51522 - Properly support WM_SYSCOLORCHANGE */
3833 infoPtr->clrBtnText = comctl32_color.clrBtnText;
3834 infoPtr->clrBtnFace = comctl32_color.clrBtnFace;
3835 #endif
3836 return 0;
3837
3838 /* case WM_VKEYTOITEM: supported according to ControlSpy */
3839 /* case WM_WININICHANGE: */
3840
3841 case WM_WINDOWPOSCHANGED:
3842 return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
3843
3844 default:
3845 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3846 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
3847 uMsg, wParam, lParam);
3848 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
3849 }
3850 }
3851
3852
3853 VOID
3854 REBAR_Register (void)
3855 {
3856 WNDCLASSW wndClass;
3857
3858 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
3859 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
3860 wndClass.lpfnWndProc = REBAR_WindowProc;
3861 wndClass.cbClsExtra = 0;
3862 wndClass.cbWndExtra = sizeof(REBAR_INFO *);
3863 wndClass.hCursor = 0;
3864 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
3865 #if GLATESTING
3866 wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
3867 #endif
3868 wndClass.lpszClassName = REBARCLASSNAMEW;
3869
3870 RegisterClassW (&wndClass);
3871
3872 mindragx = GetSystemMetrics (SM_CXDRAG);
3873 mindragy = GetSystemMetrics (SM_CYDRAG);
3874
3875 }
3876
3877
3878 VOID
3879 REBAR_Unregister (void)
3880 {
3881 UnregisterClassW (REBARCLASSNAMEW, NULL);
3882 }