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