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