Implemented NtCreatelFile using the new symlink scheme.
[wine] / dlls / comctl32 / rebar.c
1 /*
2  * Testing: set to 1 to make background brush *always* green
3  */
4 #define GLATESTING 0
5
6 /*
7  *
8  * 2.  At "FIXME:  problem # 2" WinRAR:
9  *   if "#if 1" then last band draws in separate row
10  *   if "#if 0" then last band draws in previous row *** just like native ***
11  *
12  */
13 #define PROBLEM2 0
14
15 /*
16  * 3. REBAR_MoveChildWindows should have a loop because more than
17  *    one pass is made (together with the RBN_CHILDSIZEs) is made on
18  *    at least RB_INSERTBAND
19  */
20
21
22 /*
23  * Rebar control    rev 8e
24  *
25  * Copyright 1998, 1999 Eric Kohl
26  *
27  * This library is free software; you can redistribute it and/or
28  * modify it under the terms of the GNU Lesser General Public
29  * License as published by the Free Software Foundation; either
30  * version 2.1 of the License, or (at your option) any later version.
31  *
32  * This library is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
35  * Lesser General Public License for more details.
36  *
37  * You should have received a copy of the GNU Lesser General Public
38  * License along with this library; if not, write to the Free Software
39  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
40  *
41  * NOTES
42  *   An author is needed! Any volunteers?
43  *   I will only improve this control once in a while.
44  *     Eric <ekohl@abo.rhein-zeitung.de>
45  *
46  * TODO:
47  *   - vertical placement
48  *   - ComboBox and ComboBoxEx placement
49  *   - center image
50  *   - Layout code.
51  *   - Display code.
52  *   - Some messages.
53  *   - All notifications.
54
55  * Changes Guy Albertelli <galberte@neo.lrun.com>
56  *  rev 2,3,4
57  *   - Implement initial version of row grouping, row separators,
58  *     text and background colors. Support additional messages.
59  *     Support RBBS_BREAK. Implement ERASEBKGND and improve painting.
60  *  rev 5
61  *   - implement support for dragging Gripper left or right in a row. Supports
62  *     WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE. Also support
63  *     RBS_BANDBORDERS.
64  *  rev 6
65  *   - Fix or implement notifications for RBN_HEIGHTCHANGE, RBN_CHILDSIZE.
66  *   - Correct styles RBBS_NOGRIPPER, RBBS_GRIPPERALWAYS, and RBBS_FIXEDSIZE.
67  *   - Fix algorithm for Layout and AdjustBand.
68  *
69  * rev 7
70  *   - Fix algorithm for _Layout and _AdjustBand.
71  *   - Fix or implement RBN_ENDDRAG, RB_MOVEBAND, WM_SETREDRAW,
72  *     WM_STYLECHANGED, RB_MINIMIZEBAND, RBBS_VARIABLEHEIGHT, RBS_VARHEIGHT,
73  *     RBBS_HIDDEN, WM_NOTIFYFORMAT, NM_NCHITTEST, WM_SETREDRAW, RBS_AUTOSIZE,
74  *     WM_SETFONT, RBS_BORDERS
75  *   - Create structures in WM_NCCREATE
76  *   - Additional performance enhancements.
77  *
78  * rev 8
79  *  1. Create array of start and end band indexes by row and use.
80  *  2. Fix problem with REBAR_Layout Phase 2b to process only if only
81  *     band in row.
82  *  3. Set the Caption Font (Regular) as default font for text.
83  *  4. Delete font handle on control distruction.
84  *  5. Add UpdateWindow call in _MoveChildWindows to match repainting done
85  *     by native control
86  *  6. Improve some traces.
87  *  7. Invalidate window rectangles after SetBandInfo, InsertBand, ShowBand
88  *     so that repainting is correct.
89  *  8. Implement RB_MAXIMIZEBAND for the "ideal=TRUE" case.
90  *  9. Implement item custom draw notifications partially. Only done for
91  *     ITEMPREPAINT and ITEMPOSTPAINT. (Used by IE4 for "Favorites" frame
92  *     to draw the word "Favorites").
93  * rev 8a
94  * 10. Handle CCS_NODIVIDER and fix WS_BORDER code.
95  * 11. Fix logic error in _AdjustBands where flag was set to valid band
96  *     number (0) to indicate *no* band.
97  * 12. Fix CCS_VERT errors in _ForceResize, _NCCalcSize, and _NCPaint.
98  * 13. Support some special cases of CCS_TOP (and therefore CCS_LEFT),
99  *     CCS_BOTTOM (and therefore CCS_RIGHT) and CCS_NOPARENTALIGN. Not
100  *     at all sure whether this is all cases.
101  * 14. Handle returned value for the RBN_CHILDSIZE notify.
102  * 15. Implement RBBS_CHILDEDGE, and set each bands "offChild" at _Layout
103  *     time.
104  * 16. Fix REBARSPACE. It should depend on CCS_NODIVIDER.
105  * rev 8b
106  * 17. Fix determination of whether Gripper is needed in _ValidateBand.
107  * 18. Fix _AdjustBand processing of RBBS_FIXEDSIZE.
108  * rev 8c
109  * 19. Fix problem in _Layout when all lengths are 0.
110  * 20. If CLR_NONE specified, we will use default BtnFace color when drawing.
111  * 21. Fix test in REBAR_Layout.
112  * rev 8d
113  * 22. Add support for WM_WINDOWPOSCHANGED to save new origin of window.
114  * 23. Correct RBN_CHILDSIZE rect value for CCS_VERT rebar.
115  * 24. Do UpdateWindow only if doing redraws.
116  * rev 8e
117  * 25. Adjust setting of offChild.cx based on RBBS_CHILDEDGE.
118  *
119  *
120  *    Still to do:
121  *  2. Following still not handled: RBBS_FIXEDBMP,
122  *            CCS_NORESIZE,
123  *            CCS_NOMOVEX, CCS_NOMOVEY
124  *  3. Following are only partially handled:
125  *            RBS_AUTOSIZE, RBBS_VARIABLEHEIGHT
126  *  5. Native uses (on each draw!!) SM_CYBORDER (or SM_CXBORDER for CCS_VERT)
127  *     to set the size of the separator width (the value SEP_WIDTH_SIZE
128  *     in here). Should be fixed!!
129  *  6. The following messages are not implemented:
130  *        RB_BEGINDRAG, RB_DRAGMOVE, RB_ENDDRAG, RB_GETCOLORSCHEME,
131  *        RB_GETDROPTARGET, RB_MAXIMIZEBAND,
132  *        RB_SETCOLORSCHEME, RB_SETPALETTE, RB_SETTOOLTIPS
133  *        WM_CHARTOITEM, WM_LBUTTONDBLCLK, WM_MEASUREITEM,
134  *        WM_PALETTECHANGED, WM_PRINTCLIENT, WM_QUERYNEWPALETTE,
135  *        WM_RBUTTONDOWN, WM_RBUTTONUP,
136  *        WM_SYSCOLORCHANGE, WM_VKEYTOITEM, WM_WININICHANGE
137  *  7. The following notifications are not implemented:
138  *        NM_CUSTOMDRAW, NM_RELEASEDCAPTURE
139  *        RBN_MINMAX
140  */
141
142 #include <stdarg.h>
143 #include <stdlib.h>
144 #include <string.h>
145
146 #include "windef.h"
147 #include "winbase.h"
148 #include "wingdi.h"
149 #include "wine/unicode.h"
150 #include "winuser.h"
151 #include "winnls.h"
152 #include "commctrl.h"
153 #include "comctl32.h"
154 #include "wine/debug.h"
155
156 WINE_DEFAULT_DEBUG_CHANNEL(rebar);
157
158 typedef struct
159 {
160     UINT    fStyle;
161     UINT    fMask;
162     COLORREF  clrFore;
163     COLORREF  clrBack;
164     INT     iImage;
165     HWND    hwndChild;
166     UINT    cxMinChild;     /* valid if _CHILDSIZE */
167     UINT    cyMinChild;     /* valid if _CHILDSIZE */
168     UINT    cx;             /* valid if _SIZE */
169     HBITMAP hbmBack;
170     UINT    wID;
171     UINT    cyChild;        /* valid if _CHILDSIZE */
172     UINT    cyMaxChild;     /* valid if _CHILDSIZE */
173     UINT    cyIntegral;     /* valid if _CHILDSIZE */
174     UINT    cxIdeal;
175     LPARAM    lParam;
176     UINT    cxHeader;
177
178     UINT    lcx;            /* minimum cx for band */
179     UINT    ccx;            /* current cx for band */
180     UINT    hcx;            /* maximum cx for band */
181     UINT    lcy;            /* minimum cy for band */
182     UINT    ccy;            /* current cy for band */
183     UINT    hcy;            /* maximum cy for band */
184
185     SIZE    offChild;       /* x,y offset if child is not FIXEDSIZE */
186     UINT    uMinHeight;
187     INT     iRow;           /* row this band assigned to */
188     UINT    fStatus;        /* status flags, reset only by _Validate */
189     UINT    fDraw;          /* drawing flags, reset only by _Layout */
190     UINT    uCDret;         /* last return from NM_CUSTOMDRAW */
191     RECT    rcoldBand;      /* previous calculated band rectangle */
192     RECT    rcBand;         /* calculated band rectangle */
193     RECT    rcGripper;      /* calculated gripper rectangle */
194     RECT    rcCapImage;     /* calculated caption image rectangle */
195     RECT    rcCapText;      /* calculated caption text rectangle */
196     RECT    rcChild;        /* calculated child rectangle */
197     RECT    rcChevron;      /* calculated chevron rectangle */
198
199     LPWSTR    lpText;
200     HWND    hwndPrevParent;
201 } REBAR_BAND;
202
203 /* fStatus flags */
204 #define HAS_GRIPPER    0x00000001
205 #define HAS_IMAGE      0x00000002
206 #define HAS_TEXT       0x00000004
207
208 /* fDraw flags */
209 #define DRAW_GRIPPER    0x00000001
210 #define DRAW_IMAGE      0x00000002
211 #define DRAW_TEXT       0x00000004
212 #define DRAW_RIGHTSEP   0x00000010
213 #define DRAW_BOTTOMSEP  0x00000020
214 #define DRAW_CHEVRONHOT 0x00000040
215 #define DRAW_CHEVRONPUSHED 0x00000080
216 #define DRAW_LAST_IN_ROW   0x00000100
217 #define DRAW_FIRST_IN_ROW  0x00000200
218 #define NTF_INVALIDATE  0x01000000
219
220 typedef struct
221 {
222     COLORREF   clrBk;       /* background color */
223     COLORREF   clrText;     /* text color */
224     COLORREF   clrBtnText;  /* system color for BTNTEXT */
225     COLORREF   clrBtnFace;  /* system color for BTNFACE */
226     HIMAGELIST himl;        /* handle to imagelist */
227     UINT     uNumBands;   /* # of bands in rebar (first=0, last=uNumBands-1 */
228     UINT     uNumRows;    /* # of rows of bands (first=1, last=uNumRows */
229     HWND     hwndSelf;    /* handle of REBAR window itself */
230     HWND     hwndToolTip; /* handle to the tool tip control */
231     HWND     hwndNotify;  /* notification window (parent) */
232     HFONT    hDefaultFont;
233     HFONT    hFont;       /* handle to the rebar's font */
234     SIZE     imageSize;   /* image size (image list) */
235     DWORD    dwStyle;     /* window style */
236     SIZE     calcSize;    /* calculated rebar size */
237     SIZE     oldSize;     /* previous calculated rebar size */
238     BOOL     bUnicode;    /* TRUE if this window is W type */
239     BOOL     NtfUnicode;  /* TRUE if parent wants notify in W format */
240     BOOL     DoRedraw;    /* TRUE to acutally draw bands */
241     UINT     fStatus;     /* Status flags (see below)  */
242     HCURSOR  hcurArrow;   /* handle to the arrow cursor */
243     HCURSOR  hcurHorz;    /* handle to the EW cursor */
244     HCURSOR  hcurVert;    /* handle to the NS cursor */
245     HCURSOR  hcurDrag;    /* handle to the drag cursor */
246     INT      iVersion;    /* version number */
247     POINTS   dragStart;   /* x,y of button down */
248     POINTS   dragNow;     /* x,y of this MouseMove */
249     INT      iOldBand;    /* last band that had the mouse cursor over it */
250     INT      ihitoffset;  /* offset of hotspot from gripper.left */
251     POINT    origin;      /* left/upper corner of client */
252     INT      ichevronhotBand; /* last band that had a hot chevron */
253     INT      iGrabbedBand;/* band number of band whose gripper was grabbed */
254
255     REBAR_BAND *bands;      /* pointer to the array of rebar bands */
256 } REBAR_INFO;
257
258 /* fStatus flags */
259 #define BEGIN_DRAG_ISSUED   0x00000001
260 #define AUTO_RESIZE         0x00000002
261 #define RESIZE_ANYHOW       0x00000004
262 #define NTF_HGHTCHG         0x00000008
263 #define BAND_NEEDS_LAYOUT   0x00000010
264 #define BAND_NEEDS_REDRAW   0x00000020
265 #define CREATE_RUNNING      0x00000040
266
267 /* ----   REBAR layout constants. Mostly determined by        ---- */
268 /* ----   experiment on WIN 98.                               ---- */
269
270 /* Width (or height) of separators between bands (either horz. or  */
271 /* vert.). True only if RBS_BANDBORDERS is set                     */
272 #define SEP_WIDTH_SIZE  2
273 #define SEP_WIDTH       ((infoPtr->dwStyle & RBS_BANDBORDERS) ? SEP_WIDTH_SIZE : 0)
274
275 /* Blank (background color) space between Gripper (if present)     */
276 /* and next item (image, text, or window). Always present          */
277 #define REBAR_ALWAYS_SPACE  4
278
279 /* Blank (background color) space after Image (if present).        */
280 #define REBAR_POST_IMAGE  2
281
282 /* Blank (background color) space after Text (if present).         */
283 #define REBAR_POST_TEXT  4
284
285 /* Height of vertical gripper in a CCS_VERT rebar.                 */
286 #define GRIPPER_HEIGHT  16
287
288 /* Blank (background color) space before Gripper (if present).     */
289 #define REBAR_PRE_GRIPPER   2
290
291 /* Width (of normal vertical gripper) or height (of horz. gripper) */
292 /* if present.                                                     */
293 #define GRIPPER_WIDTH  3
294
295 /* Width of the chevron button if present */
296 #define CHEVRON_WIDTH  10
297
298 /* Height of divider for Rebar if not disabled (CCS_NODIVIDER)     */
299 /* either top or bottom                                            */
300 #define REBAR_DIVIDER  2
301
302 /* minimium vertical height of a normal bar                        */
303 /*   or minimum width of a CCS_VERT bar - from experiment on Win2k */
304 #define REBAR_MINSIZE  23
305
306 /* This is the increment that is used over the band height         */
307 #define REBARSPACE(a)     ((a->fStyle & RBBS_CHILDEDGE) ? 2*REBAR_DIVIDER : 0)
308
309 /* ----   End of REBAR layout constants.                      ---- */
310
311 #define RB_GETBANDINFO_OLD (WM_USER+5) /* obsoleted after IE3, but we have to support it anyway */
312
313 /*  The following 6 defines return the proper rcBand element       */
314 /*  depending on whether CCS_VERT was set.                         */
315 #define rcBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.top : b->rcBand.left)
316 #define rcBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.bottom : b->rcBand.right)
317 #define rcBw(b)  ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.bottom - b->rcBand.top) : \
318                   (b->rcBand.right - b->rcBand.left))
319 #define ircBlt(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.left : b->rcBand.top)
320 #define ircBrb(b) ((infoPtr->dwStyle & CCS_VERT) ? b->rcBand.right : b->rcBand.bottom)
321 #define ircBw(b)  ((infoPtr->dwStyle & CCS_VERT) ? (b->rcBand.right - b->rcBand.left) : \
322                   (b->rcBand.bottom - b->rcBand.top))
323
324 /*  The following define determines if a given band is hidden      */
325 #define HIDDENBAND(a)  (((a)->fStyle & RBBS_HIDDEN) ||   \
326                         ((infoPtr->dwStyle & CCS_VERT) &&         \
327                          ((a)->fStyle & RBBS_NOVERT)))
328
329 /*  The following defines adjust the right or left end of a rectangle */
330 #define READJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.bottom+=(i); \
331                     else b->rcBand.right += (i); } while(0)
332 #define LEADJ(b,i) do { if(infoPtr->dwStyle & CCS_VERT) b->rcBand.top+=(i); \
333                     else b->rcBand.left += (i); } while(0)
334
335
336 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongA (hwnd, 0))
337
338
339 /* "constant values" retrieved when DLL was initialized    */
340 /* FIXME we do this when the classes are registered.       */
341 static UINT mindragx = 0;
342 static UINT mindragy = 0;
343
344 static const char *band_stylename[] = {
345     "RBBS_BREAK",              /* 0001 */
346     "RBBS_FIXEDSIZE",          /* 0002 */
347     "RBBS_CHILDEDGE",          /* 0004 */
348     "RBBS_HIDDEN",             /* 0008 */
349     "RBBS_NOVERT",             /* 0010 */
350     "RBBS_FIXEDBMP",           /* 0020 */
351     "RBBS_VARIABLEHEIGHT",     /* 0040 */
352     "RBBS_GRIPPERALWAYS",      /* 0080 */
353     "RBBS_NOGRIPPER",          /* 0100 */
354     NULL };
355
356 static const char *band_maskname[] = {
357     "RBBIM_STYLE",         /*    0x00000001 */
358     "RBBIM_COLORS",        /*    0x00000002 */
359     "RBBIM_TEXT",          /*    0x00000004 */
360     "RBBIM_IMAGE",         /*    0x00000008 */
361     "RBBIM_CHILD",         /*    0x00000010 */
362     "RBBIM_CHILDSIZE",     /*    0x00000020 */
363     "RBBIM_SIZE",          /*    0x00000040 */
364     "RBBIM_BACKGROUND",    /*    0x00000080 */
365     "RBBIM_ID",            /*    0x00000100 */
366     "RBBIM_IDEALSIZE",     /*    0x00000200 */
367     "RBBIM_LPARAM",        /*    0x00000400 */
368     "RBBIM_HEADERSIZE",    /*    0x00000800 */
369     NULL };
370
371
372 static CHAR line[200];
373
374
375 static CHAR *
376 REBAR_FmtStyle( UINT style)
377 {
378     INT i = 0;
379
380     *line = 0;
381     while (band_stylename[i]) {
382         if (style & (1<<i)) {
383             if (*line != 0) strcat(line, " | ");
384             strcat(line, band_stylename[i]);
385         }
386         i++;
387     }
388     return line;
389 }
390
391
392 static CHAR *
393 REBAR_FmtMask( UINT mask)
394 {
395     INT i = 0;
396
397     *line = 0;
398     while (band_maskname[i]) {
399         if (mask & (1<<i)) {
400             if (*line != 0) strcat(line, " | ");
401             strcat(line, band_maskname[i]);
402         }
403         i++;
404     }
405     return line;
406 }
407
408
409 static VOID
410 REBAR_DumpBandInfo( LPREBARBANDINFOA pB)
411 {
412     if( !TRACE_ON(rebar) ) return;
413     TRACE("band info: ID=%u, size=%u, child=%p, clrF=0x%06lx, clrB=0x%06lx\n",
414           pB->wID, pB->cbSize, pB->hwndChild, pB->clrFore, pB->clrBack);
415     TRACE("band info: mask=0x%08x (%s)\n", pB->fMask, REBAR_FmtMask(pB->fMask));
416     if (pB->fMask & RBBIM_STYLE)
417         TRACE("band info: style=0x%08x (%s)\n", pB->fStyle, REBAR_FmtStyle(pB->fStyle));
418     if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_HEADERSIZE | RBBIM_LPARAM )) {
419         TRACE("band info:");
420         if (pB->fMask & RBBIM_SIZE)
421             TRACE(" cx=%u", pB->cx);
422         if (pB->fMask & RBBIM_IDEALSIZE)
423             TRACE(" xIdeal=%u", pB->cxIdeal);
424         if (pB->fMask & RBBIM_HEADERSIZE)
425             TRACE(" xHeader=%u", pB->cxHeader);
426         if (pB->fMask & RBBIM_LPARAM)
427             TRACE(" lParam=0x%08lx", pB->lParam);
428         TRACE("\n");
429     }
430     if (pB->fMask & RBBIM_CHILDSIZE)
431         TRACE("band info: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
432               pB->cxMinChild,
433               pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
434 }
435
436 static VOID
437 REBAR_DumpBand (REBAR_INFO *iP)
438 {
439     REBAR_BAND *pB;
440     UINT i;
441
442     if(! TRACE_ON(rebar) ) return;
443
444     TRACE("hwnd=%p: color=%08lx/%08lx, bands=%u, rows=%u, cSize=%ld,%ld\n",
445           iP->hwndSelf, iP->clrText, iP->clrBk, iP->uNumBands, iP->uNumRows,
446           iP->calcSize.cx, iP->calcSize.cy);
447     TRACE("hwnd=%p: flags=%08x, dragStart=%d,%d, dragNow=%d,%d, iGrabbedBand=%d\n",
448           iP->hwndSelf, iP->fStatus, iP->dragStart.x, iP->dragStart.y,
449           iP->dragNow.x, iP->dragNow.y,
450           iP->iGrabbedBand);
451     TRACE("hwnd=%p: style=%08lx, I'm Unicode=%s, notify in Unicode=%s, redraw=%s\n",
452           iP->hwndSelf, iP->dwStyle, (iP->bUnicode)?"TRUE":"FALSE",
453           (iP->NtfUnicode)?"TRUE":"FALSE", (iP->DoRedraw)?"TRUE":"FALSE");
454     for (i = 0; i < iP->uNumBands; i++) {
455         pB = &iP->bands[i];
456         TRACE("band # %u: ID=%u, child=%p, row=%u, clrF=0x%06lx, clrB=0x%06lx\n",
457               i, pB->wID, pB->hwndChild, pB->iRow, pB->clrFore, pB->clrBack);
458         TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
459         if (pB->fMask & RBBIM_STYLE)
460             TRACE("band # %u: style=0x%08x (%s)\n",
461                   i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
462         TRACE("band # %u: uMinH=%u xHeader=%u",
463               i, pB->uMinHeight, pB->cxHeader);
464         if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
465             if (pB->fMask & RBBIM_SIZE)
466                 TRACE(" cx=%u", pB->cx);
467             if (pB->fMask & RBBIM_IDEALSIZE)
468                 TRACE(" xIdeal=%u", pB->cxIdeal);
469             if (pB->fMask & RBBIM_LPARAM)
470                 TRACE(" lParam=0x%08lx", pB->lParam);
471         }
472         TRACE("\n");
473         if (RBBIM_CHILDSIZE)
474             TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
475                   i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
476         if (pB->fMask & RBBIM_TEXT)
477             TRACE("band # %u: text=%s\n",
478                   i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
479         TRACE("band # %u: lcx=%u, ccx=%u, hcx=%u, lcy=%u, ccy=%u, hcy=%u, offChild=%ld,%ld\n",
480               i, pB->lcx, pB->ccx, pB->hcx, pB->lcy, pB->ccy, pB->hcy, pB->offChild.cx, pB->offChild.cy);
481         TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%ld,%ld)-(%ld,%ld), Grip=(%ld,%ld)-(%ld,%ld)\n",
482               i, pB->fStatus, pB->fDraw,
483               pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
484               pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
485         TRACE("band # %u: Img=(%ld,%ld)-(%ld,%ld), Txt=(%ld,%ld)-(%ld,%ld), Child=(%ld,%ld)-(%ld,%ld)\n",
486               i,
487               pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
488               pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
489               pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
490     }
491
492 }
493
494 static void
495 REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
496 {
497     INT x, y;
498     HPEN hPen, hOldPen;
499
500     if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
501     hOldPen = SelectObject ( hdc, hPen );
502     x = left + 2;
503     y = top;
504     MoveToEx (hdc, x, y, NULL);
505     LineTo (hdc, x+5, y++); x++;
506     MoveToEx (hdc, x, y, NULL);
507     LineTo (hdc, x+3, y++); x++;
508     MoveToEx (hdc, x, y, NULL);
509     LineTo (hdc, x+1, y++);
510     SelectObject( hdc, hOldPen );
511     DeleteObject( hPen );
512 }
513
514 static HWND
515 REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
516 {
517     HWND parent, owner;
518
519     parent = infoPtr->hwndNotify;
520     if (!parent) {
521         parent = GetParent (infoPtr->hwndSelf);
522         owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
523         if (owner) parent = owner;
524     }
525     return parent;
526 }
527
528
529 static INT
530 REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
531 {
532     HWND parent;
533
534     parent = REBAR_GetNotifyParent (infoPtr);
535     nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
536     nmhdr->hwndFrom = infoPtr->hwndSelf;
537     nmhdr->code = code;
538
539     TRACE("window %p, code=%08x, %s\n", parent, code,
540           (infoPtr->NtfUnicode) ? "via Unicode" : "via ANSI");
541
542     if (infoPtr->NtfUnicode)
543         return SendMessageW (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
544                              (LPARAM)nmhdr);
545     else
546         return SendMessageA (parent, WM_NOTIFY, (WPARAM) nmhdr->idFrom,
547                              (LPARAM)nmhdr);
548 }
549
550 static INT
551 REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
552 {
553     NMREBAR notify_rebar;
554     REBAR_BAND *lpBand;
555
556     notify_rebar.dwMask = 0;
557     if (uBand!=-1) {
558         lpBand = &infoPtr->bands[uBand];
559         if (lpBand->fMask & RBBIM_ID) {
560             notify_rebar.dwMask |= RBNM_ID;
561             notify_rebar.wID = lpBand->wID;
562         }
563         if (lpBand->fMask & RBBIM_LPARAM) {
564             notify_rebar.dwMask |= RBNM_LPARAM;
565             notify_rebar.lParam = lpBand->lParam;
566         }
567         if (lpBand->fMask & RBBIM_STYLE) {
568             notify_rebar.dwMask |= RBNM_STYLE;
569             notify_rebar.fStyle = lpBand->fStyle;
570         }
571     }
572     notify_rebar.uBand = uBand;
573     return REBAR_Notify ((NMHDR *)&notify_rebar, infoPtr, code);
574 }
575
576 static VOID
577 REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
578 {
579     HFONT hOldFont = 0;
580     INT oldBkMode = 0;
581     NMCUSTOMDRAW nmcd;
582
583     if (lpBand->fDraw & DRAW_TEXT) {
584         hOldFont = SelectObject (hdc, infoPtr->hFont);
585         oldBkMode = SetBkMode (hdc, TRANSPARENT);
586     }
587
588     /* should test for CDRF_NOTIFYITEMDRAW here */
589     nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
590     nmcd.hdc = hdc;
591     nmcd.rc = lpBand->rcBand;
592     nmcd.rc.right = lpBand->rcCapText.right;
593     nmcd.rc.bottom = lpBand->rcCapText.bottom;
594     nmcd.dwItemSpec = lpBand->wID;
595     nmcd.uItemState = 0;
596     nmcd.lItemlParam = lpBand->lParam;
597     lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
598     if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
599         if (oldBkMode != TRANSPARENT)
600             SetBkMode (hdc, oldBkMode);
601         SelectObject (hdc, hOldFont);
602         return;
603     }
604
605     /* draw gripper */
606     if (lpBand->fDraw & DRAW_GRIPPER)
607         DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
608
609     /* draw caption image */
610     if (lpBand->fDraw & DRAW_IMAGE) {
611         POINT pt;
612
613         /* center image */
614         pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
615         pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
616
617         ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
618                         pt.x, pt.y,
619                         ILD_TRANSPARENT);
620     }
621
622     /* draw caption text */
623     if (lpBand->fDraw & DRAW_TEXT) {
624         /* need to handle CDRF_NEWFONT here */
625         INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
626         COLORREF oldcolor = CLR_NONE;
627         COLORREF new;
628         if (lpBand->clrFore != CLR_NONE) {
629             new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
630                     lpBand->clrFore;
631             oldcolor = SetTextColor (hdc, new);
632         }
633         DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
634                    DT_CENTER | DT_VCENTER | DT_SINGLELINE);
635         if (oldBkMode != TRANSPARENT)
636             SetBkMode (hdc, oldBkMode);
637         if (lpBand->clrFore != CLR_NONE)
638             SetTextColor (hdc, oldcolor);
639         SelectObject (hdc, hOldFont);
640     }
641
642     if (!IsRectEmpty(&lpBand->rcChevron))
643     {
644         if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
645         {
646             DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
647             REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
648         }
649         else if (lpBand->fDraw & DRAW_CHEVRONHOT)
650         {
651             DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
652             REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
653         }
654         else
655             REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
656     }
657
658     if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
659         nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
660         nmcd.hdc = hdc;
661         nmcd.rc = lpBand->rcBand;
662         nmcd.rc.right = lpBand->rcCapText.right;
663         nmcd.rc.bottom = lpBand->rcCapText.bottom;
664         nmcd.dwItemSpec = lpBand->wID;
665         nmcd.uItemState = 0;
666         nmcd.lItemlParam = lpBand->lParam;
667         lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
668     }
669 }
670
671
672 static VOID
673 REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
674 {
675     REBAR_BAND *lpBand;
676     UINT i;
677
678     if (!infoPtr->DoRedraw) return;
679
680     for (i = 0; i < infoPtr->uNumBands; i++) {
681         lpBand = &infoPtr->bands[i];
682
683         if (HIDDENBAND(lpBand)) continue;
684
685         /* now draw the band */
686         TRACE("[%p] drawing band %i, flags=%08x\n",
687               infoPtr->hwndSelf, i, lpBand->fDraw);
688         REBAR_DrawBand (hdc, infoPtr, lpBand);
689
690     }
691 }
692
693
694 static void
695 REBAR_FixVert (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
696                    INT mcy)
697      /* Function:                                                    */
698      /*   Cycle through bands in row and fix height of each band.    */
699      /*   Also determine whether each band has changed.              */
700      /* On entry:                                                    */
701      /*   all bands at desired size.                                 */
702      /*   start and end bands are *not* hidden                       */
703 {
704     REBAR_BAND *lpBand;
705     INT i;
706
707     for (i = (INT)rowstart; i<=(INT)rowend; i++) {
708         lpBand = &infoPtr->bands[i];
709         if (HIDDENBAND(lpBand)) continue;
710
711         /* adjust height of bands in row to "mcy" value */
712         if (infoPtr->dwStyle & CCS_VERT) {
713             if (lpBand->rcBand.right != lpBand->rcBand.left + mcy)
714                 lpBand->rcBand.right = lpBand->rcBand.left + mcy;
715         }
716         else {
717             if (lpBand->rcBand.bottom != lpBand->rcBand.top + mcy)
718                 lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
719
720         }
721
722         /* mark whether we need to invalidate this band and trace */
723         if ((lpBand->rcoldBand.left !=lpBand->rcBand.left) ||
724             (lpBand->rcoldBand.top !=lpBand->rcBand.top) ||
725             (lpBand->rcoldBand.right !=lpBand->rcBand.right) ||
726             (lpBand->rcoldBand.bottom !=lpBand->rcBand.bottom)) {
727             lpBand->fDraw |= NTF_INVALIDATE;
728             TRACE("band %d row=%d: changed to (%ld,%ld)-(%ld,%ld) from (%ld,%ld)-(%ld,%ld)\n",
729                   i, lpBand->iRow,
730                   lpBand->rcBand.left, lpBand->rcBand.top,
731                   lpBand->rcBand.right, lpBand->rcBand.bottom,
732                   lpBand->rcoldBand.left, lpBand->rcoldBand.top,
733                   lpBand->rcoldBand.right, lpBand->rcoldBand.bottom);
734         }
735         else
736             TRACE("band %d row=%d: unchanged (%ld,%ld)-(%ld,%ld)\n",
737                   i, lpBand->iRow,
738                   lpBand->rcBand.left, lpBand->rcBand.top,
739                   lpBand->rcBand.right, lpBand->rcBand.bottom);
740     }
741 }
742
743
744 static void
745 REBAR_AdjustBands (REBAR_INFO *infoPtr, UINT rowstart, UINT rowend,
746                    INT maxx, INT mcy)
747      /* Function: This routine distributes the extra space in a row. */
748      /*  See algorithm below.                                        */
749      /* On entry:                                                    */
750      /*   all bands @ ->cxHeader size                                */
751      /*   start and end bands are *not* hidden                       */
752 {
753     REBAR_BAND *lpBand;
754     UINT x, xsep, extra, curwidth, fudge;
755     INT i, last_adjusted;
756
757     TRACE("start=%u, end=%u, max x=%d, max y=%d\n",
758           rowstart, rowend, maxx, mcy);
759
760     /* *******************  Phase 1  ************************ */
761     /* Alg:                                                   */
762     /*  For each visible band with valid child                */
763     /*      a. inflate band till either all extra space used  */
764     /*         or band's ->ccx reached.                       */
765     /*  If any band modified, add any space left to last band */
766     /*  adjusted.                                             */
767     /*                                                        */
768     /* ****************************************************** */
769     lpBand = &infoPtr->bands[rowend];
770     extra = maxx - rcBrb(lpBand);
771     x = 0;
772     last_adjusted = -1;
773     for (i=(INT)rowstart; i<=(INT)rowend; i++) {
774         lpBand = &infoPtr->bands[i];
775         if (HIDDENBAND(lpBand)) continue;
776         xsep = (x == 0) ? 0 : SEP_WIDTH;
777         curwidth = rcBw(lpBand);
778
779         /* set new left/top point */
780         if (infoPtr->dwStyle & CCS_VERT)
781             lpBand->rcBand.top = x + xsep;
782         else
783             lpBand->rcBand.left = x + xsep;
784
785         /* compute new width */
786         if ((lpBand->hwndChild && extra) && !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
787             /* set to the "current" band size less the header */
788             fudge = lpBand->ccx;
789             last_adjusted = i;
790             if ((lpBand->fMask & RBBIM_SIZE) && (lpBand->cx > 0) &&
791                 (fudge > curwidth)) {
792                 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d, extra=%d\n",
793                       i, fudge-curwidth, fudge, curwidth, extra);
794                 if ((fudge - curwidth) > extra)
795                     fudge = curwidth + extra;
796                 extra -= (fudge - curwidth);
797                 curwidth = fudge;
798             }
799             else {
800                 TRACE("adjusting band %d by %d, fudge=%d, curwidth=%d\n",
801                       i, extra, fudge, curwidth);
802                 curwidth += extra;
803                 extra = 0;
804             }
805         }
806
807         /* set new right/bottom point */
808         if (infoPtr->dwStyle & CCS_VERT)
809             lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
810         else
811             lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
812         TRACE("Phase 1 band %d, (%ld,%ld)-(%ld,%ld), orig x=%d, xsep=%d\n",
813               i, lpBand->rcBand.left, lpBand->rcBand.top,
814               lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
815         x = rcBrb(lpBand);
816     }
817     if ((x >= maxx) || (last_adjusted != -1)) {
818         if (x > maxx) {
819             ERR("Phase 1 failed, x=%d, maxx=%d, start=%u, end=%u\n",
820                 x, maxx,  rowstart, rowend);
821         }
822         /* done, so spread extra space */
823         if (x < maxx) {
824             fudge = maxx - x;
825             TRACE("Need to spread %d on last adjusted band %d\n",
826                 fudge, last_adjusted);
827             for (i=(INT)last_adjusted; i<=(INT)rowend; i++) {
828                 lpBand = &infoPtr->bands[i];
829                 if (HIDDENBAND(lpBand)) continue;
830
831                 /* set right/bottom point */
832                 if (i != last_adjusted) {
833                     if (infoPtr->dwStyle & CCS_VERT)
834                         lpBand->rcBand.top += fudge;
835                     else
836                         lpBand->rcBand.left += fudge;
837                 }
838
839                 /* set left/bottom point */
840                 if (infoPtr->dwStyle & CCS_VERT)
841                     lpBand->rcBand.bottom += fudge;
842                 else
843                     lpBand->rcBand.right += fudge;
844             }
845         }
846         TRACE("Phase 1 succeeded, used x=%d\n", x);
847         REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
848         return;
849     }
850
851     /* *******************  Phase 2  ************************ */
852     /* Alg:                                                   */
853     /*  Find first visible band, put all                      */
854     /*    extra space there.                                  */
855     /*                                                        */
856     /* ****************************************************** */
857
858     x = 0;
859     for (i=(INT)rowstart; i<=(INT)rowend; i++) {
860         lpBand = &infoPtr->bands[i];
861         if (HIDDENBAND(lpBand)) continue;
862         xsep = (x == 0) ? 0 : SEP_WIDTH;
863         curwidth = rcBw(lpBand);
864
865         /* set new left/top point */
866         if (infoPtr->dwStyle & CCS_VERT)
867             lpBand->rcBand.top = x + xsep;
868         else
869             lpBand->rcBand.left = x + xsep;
870
871         /* compute new width */
872         if (extra) {
873             curwidth += extra;
874             extra = 0;
875         }
876
877         /* set new right/bottom point */
878         if (infoPtr->dwStyle & CCS_VERT)
879             lpBand->rcBand.bottom = lpBand->rcBand.top + curwidth;
880         else
881             lpBand->rcBand.right = lpBand->rcBand.left + curwidth;
882         TRACE("Phase 2 band %d, (%ld,%ld)-(%ld,%ld), orig x=%d, xsep=%d\n",
883               i, lpBand->rcBand.left, lpBand->rcBand.top,
884               lpBand->rcBand.right, lpBand->rcBand.bottom, x, xsep);
885         x = rcBrb(lpBand);
886     }
887     if (x >= maxx) {
888         if (x > maxx) {
889             ERR("Phase 2 failed, x=%d, maxx=%d, start=%u, end=%u\n",
890                 x, maxx,  rowstart, rowend);
891         }
892         /* done, so spread extra space */
893         TRACE("Phase 2 succeeded, used x=%d\n", x);
894         REBAR_FixVert (infoPtr, rowstart, rowend, mcy);
895         return;
896     }
897
898     /* *******************  Phase 3  ************************ */
899     /* at this point everything is back to ->cxHeader values  */
900     /* and should not have gotten here.                       */
901     /* ****************************************************** */
902
903     lpBand = &infoPtr->bands[rowstart];
904     ERR("Serious problem adjusting row %d, start band %d, end band %d\n",
905         lpBand->iRow, rowstart, rowend);
906     REBAR_DumpBand (infoPtr);
907     return;
908 }
909
910
911 static void
912 REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
913      /* Function: this routine initializes all the rectangles in */
914      /*  each band in a row to fit in the adjusted rcBand rect.  */
915      /* *** Supports only Horizontal bars. ***                   */
916 {
917     REBAR_BAND *lpBand;
918     UINT i, xoff, yoff;
919     HWND parenthwnd;
920     RECT oldChild, work;
921
922     /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
923     parenthwnd = GetParent (infoPtr->hwndSelf);
924
925     for(i=rstart; i<rend; i++){
926       lpBand = &infoPtr->bands[i];
927       if (HIDDENBAND(lpBand)) {
928           SetRect (&lpBand->rcChild,
929                    lpBand->rcBand.right, lpBand->rcBand.top,
930                    lpBand->rcBand.right, lpBand->rcBand.bottom);
931           continue;
932       }
933
934       oldChild = lpBand->rcChild;
935
936       /* set initial gripper rectangle */
937       SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
938                lpBand->rcBand.left, lpBand->rcBand.bottom);
939
940       /* calculate gripper rectangle */
941       if ( lpBand->fStatus & HAS_GRIPPER) {
942           lpBand->fDraw |= DRAW_GRIPPER;
943           lpBand->rcGripper.left   += REBAR_PRE_GRIPPER;
944           lpBand->rcGripper.right  = lpBand->rcGripper.left + GRIPPER_WIDTH;
945           lpBand->rcGripper.top    += 2;
946           lpBand->rcGripper.bottom -= 2;
947
948           SetRect (&lpBand->rcCapImage,
949                    lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
950                    lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
951       }
952       else {  /* no gripper will be drawn */
953           xoff = 0;
954           if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
955               /* if no gripper but either image or text, then leave space */
956               xoff = REBAR_ALWAYS_SPACE;
957           SetRect (&lpBand->rcCapImage,
958                    lpBand->rcBand.left+xoff, lpBand->rcBand.top,
959                    lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
960       }
961
962       /* image is visible */
963       if (lpBand->fStatus & HAS_IMAGE) {
964           lpBand->fDraw |= DRAW_IMAGE;
965           lpBand->rcCapImage.right  += infoPtr->imageSize.cx;
966           lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
967
968           /* set initial caption text rectangle */
969           SetRect (&lpBand->rcCapText,
970                    lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
971                    lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
972           /* update band height
973           if (lpBand->uMinHeight < infoPtr->imageSize.cy + 2) {
974               lpBand->uMinHeight = infoPtr->imageSize.cy + 2;
975               lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->uMinHeight;
976           }  */
977       }
978       else {
979           /* set initial caption text rectangle */
980           SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
981                    lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
982       }
983
984       /* text is visible */
985       if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
986           lpBand->fDraw |= DRAW_TEXT;
987           lpBand->rcCapText.right = max(lpBand->rcCapText.left,
988                                         lpBand->rcCapText.right-REBAR_POST_TEXT);
989       }
990
991       /* set initial child window rectangle if there is a child */
992       if (lpBand->fMask & RBBIM_CHILD) {
993           xoff = lpBand->offChild.cx;
994           yoff = lpBand->offChild.cy;
995           SetRect (&lpBand->rcChild,
996                    lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top+yoff,
997                    lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
998           if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
999           {
1000               lpBand->rcChild.right -= CHEVRON_WIDTH;
1001               SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
1002                       lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
1003                       lpBand->rcChild.bottom);
1004           }
1005       }
1006       else {
1007           SetRect (&lpBand->rcChild,
1008                    lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.top,
1009                    lpBand->rcBand.right, lpBand->rcBand.bottom);
1010       }
1011
1012       /* flag if notify required and invalidate rectangle */
1013       if (notify &&
1014           ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1015            (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1016           TRACE("Child rectangle changed for band %u\n", i);
1017           TRACE("    from (%ld,%ld)-(%ld,%ld)  to (%ld,%ld)-(%ld,%ld)\n",
1018                 oldChild.left, oldChild.top,
1019                 oldChild.right, oldChild.bottom,
1020                 lpBand->rcChild.left, lpBand->rcChild.top,
1021                 lpBand->rcChild.right, lpBand->rcChild.bottom);
1022       }
1023       if (lpBand->fDraw & NTF_INVALIDATE) {
1024           TRACE("invalidating (%ld,%ld)-(%ld,%ld)\n",
1025                 lpBand->rcBand.left,
1026                 lpBand->rcBand.top,
1027                 lpBand->rcBand.right + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0),
1028                 lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0));
1029           lpBand->fDraw &= ~NTF_INVALIDATE;
1030           work = lpBand->rcBand;
1031           if (lpBand->fDraw & DRAW_RIGHTSEP) work.right += SEP_WIDTH_SIZE;
1032           if (lpBand->fDraw & DRAW_BOTTOMSEP) work.bottom += SEP_WIDTH_SIZE;
1033           InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1034       }
1035
1036     }
1037
1038 }
1039
1040
1041 static VOID
1042 REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend, BOOL notify)
1043      /* Function: this routine initializes all the rectangles in */
1044      /*  each band in a row to fit in the adjusted rcBand rect.  */
1045      /* *** Supports only Vertical bars. ***                     */
1046 {
1047     REBAR_BAND *lpBand;
1048     UINT i, xoff, yoff;
1049     HWND parenthwnd;
1050     RECT oldChild, work;
1051
1052     /* MS seems to use GetDlgCtrlID() for above GetWindowLong call */
1053     parenthwnd = GetParent (infoPtr->hwndSelf);
1054
1055     for(i=rstart; i<rend; i++){
1056         lpBand = &infoPtr->bands[i];
1057         if (HIDDENBAND(lpBand)) continue;
1058         oldChild = lpBand->rcChild;
1059
1060         /* set initial gripper rectangle */
1061         SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
1062                  lpBand->rcBand.right, lpBand->rcBand.top);
1063
1064         /* calculate gripper rectangle */
1065         if (lpBand->fStatus & HAS_GRIPPER) {
1066             lpBand->fDraw |= DRAW_GRIPPER;
1067
1068             if (infoPtr->dwStyle & RBS_VERTICALGRIPPER) {
1069                 /*  vertical gripper  */
1070                 lpBand->rcGripper.left   += 3;
1071                 lpBand->rcGripper.right  = lpBand->rcGripper.left + GRIPPER_WIDTH;
1072                 lpBand->rcGripper.top    += REBAR_PRE_GRIPPER;
1073                 lpBand->rcGripper.bottom = lpBand->rcGripper.top + GRIPPER_HEIGHT;
1074
1075                 /* initialize Caption image rectangle  */
1076                 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1077                          lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1078                          lpBand->rcBand.right,
1079                          lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1080             }
1081             else {
1082                 /*  horizontal gripper  */
1083                 lpBand->rcGripper.left   += 2;
1084                 lpBand->rcGripper.right  -= 2;
1085                 lpBand->rcGripper.top    += REBAR_PRE_GRIPPER;
1086                 lpBand->rcGripper.bottom  = lpBand->rcGripper.top + GRIPPER_WIDTH;
1087
1088                 /* initialize Caption image rectangle  */
1089                 SetRect (&lpBand->rcCapImage, lpBand->rcBand.left,
1090                          lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE,
1091                          lpBand->rcBand.right,
1092                          lpBand->rcGripper.bottom + REBAR_ALWAYS_SPACE);
1093             }
1094         }
1095         else {  /* no gripper will be drawn */
1096             xoff = 0;
1097             if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
1098                 /* if no gripper but either image or text, then leave space */
1099                 xoff = REBAR_ALWAYS_SPACE;
1100             /* initialize Caption image rectangle  */
1101             SetRect (&lpBand->rcCapImage,
1102                      lpBand->rcBand.left, lpBand->rcBand.top+xoff,
1103                      lpBand->rcBand.right, lpBand->rcBand.top+xoff);
1104         }
1105
1106         /* image is visible */
1107         if (lpBand->fStatus & HAS_IMAGE) {
1108             lpBand->fDraw |= DRAW_IMAGE;
1109
1110             lpBand->rcCapImage.right  = lpBand->rcCapImage.left + infoPtr->imageSize.cx;
1111             lpBand->rcCapImage.bottom += infoPtr->imageSize.cy;
1112
1113             /* set initial caption text rectangle */
1114             SetRect (&lpBand->rcCapText,
1115                      lpBand->rcBand.left, lpBand->rcCapImage.bottom+REBAR_POST_IMAGE,
1116                      lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1117             /* update band height *
1118                if (lpBand->uMinHeight < infoPtr->imageSize.cx + 2) {
1119                lpBand->uMinHeight = infoPtr->imageSize.cx + 2;
1120                lpBand->rcBand.right = lpBand->rcBand.left + lpBand->uMinHeight;
1121                } */
1122         }
1123         else {
1124             /* set initial caption text rectangle */
1125             SetRect (&lpBand->rcCapText,
1126                      lpBand->rcBand.left, lpBand->rcCapImage.bottom,
1127                      lpBand->rcBand.right, lpBand->rcBand.top+lpBand->cxHeader);
1128         }
1129
1130         /* text is visible */
1131         if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
1132             lpBand->fDraw |= DRAW_TEXT;
1133             lpBand->rcCapText.bottom = max(lpBand->rcCapText.top,
1134                                            lpBand->rcCapText.bottom);
1135         }
1136
1137         /* set initial child window rectangle if there is a child */
1138         if (lpBand->fMask & RBBIM_CHILD) {
1139             yoff = lpBand->offChild.cx;
1140             xoff = lpBand->offChild.cy;
1141             SetRect (&lpBand->rcChild,
1142                      lpBand->rcBand.left+xoff, lpBand->rcBand.top+lpBand->cxHeader,
1143                      lpBand->rcBand.right-xoff, lpBand->rcBand.bottom-yoff);
1144         }
1145         else {
1146             SetRect (&lpBand->rcChild,
1147                      lpBand->rcBand.left, lpBand->rcBand.top+lpBand->cxHeader,
1148                      lpBand->rcBand.right, lpBand->rcBand.bottom);
1149         }
1150
1151         /* flag if notify required and invalidate rectangle */
1152         if (notify &&
1153             ((oldChild.right-oldChild.left != lpBand->rcChild.right-lpBand->rcChild.left) ||
1154              (oldChild.bottom-oldChild.top != lpBand->rcChild.bottom-lpBand->rcChild.top))) {
1155             TRACE("Child rectangle changed for band %u\n", i);
1156             TRACE("    from (%ld,%ld)-(%ld,%ld)  to (%ld,%ld)-(%ld,%ld)\n",
1157                   oldChild.left, oldChild.top,
1158                   oldChild.right, oldChild.bottom,
1159                   lpBand->rcChild.left, lpBand->rcChild.top,
1160                   lpBand->rcChild.right, lpBand->rcChild.bottom);
1161         }
1162         if (lpBand->fDraw & NTF_INVALIDATE) {
1163             TRACE("invalidating (%ld,%ld)-(%ld,%ld)\n",
1164                   lpBand->rcBand.left,
1165                   lpBand->rcBand.top,
1166                   lpBand->rcBand.right + ((lpBand->fDraw & DRAW_BOTTOMSEP) ? SEP_WIDTH_SIZE : 0),
1167                   lpBand->rcBand.bottom + ((lpBand->fDraw & DRAW_RIGHTSEP) ? SEP_WIDTH_SIZE : 0));
1168             lpBand->fDraw &= ~NTF_INVALIDATE;
1169             work = lpBand->rcBand;
1170             if (lpBand->fDraw & DRAW_RIGHTSEP) work.bottom += SEP_WIDTH_SIZE;
1171             if (lpBand->fDraw & DRAW_BOTTOMSEP) work.right += SEP_WIDTH_SIZE;
1172             InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
1173         }
1174
1175     }
1176 }
1177
1178
1179 static VOID
1180 REBAR_ForceResize (REBAR_INFO *infoPtr)
1181      /* Function: This changes the size of the REBAR window to that */
1182      /*  calculated by REBAR_Layout.                                */
1183 {
1184     RECT rc;
1185     INT x, y, width, height;
1186     INT xedge = GetSystemMetrics(SM_CXEDGE);
1187     INT yedge = GetSystemMetrics(SM_CYEDGE);
1188
1189     /* TEST TEST TEST */
1190     GetWindowRect (infoPtr->hwndSelf, &rc);
1191     /* END TEST END TEST END TEST */
1192
1193
1194     GetClientRect (infoPtr->hwndSelf, &rc);
1195
1196     TRACE( " old [%ld x %ld], new [%ld x %ld], client [%ld x %ld]\n",
1197            infoPtr->oldSize.cx, infoPtr->oldSize.cy,
1198            infoPtr->calcSize.cx, infoPtr->calcSize.cy,
1199            rc.right, rc.bottom);
1200
1201     /* If we need to shrink client, then skip size test */
1202     if ((infoPtr->calcSize.cy >= rc.bottom) &&
1203         (infoPtr->calcSize.cx >= rc.right)) {
1204
1205         /* if size did not change then skip process */
1206         if ((infoPtr->oldSize.cx == infoPtr->calcSize.cx) &&
1207             (infoPtr->oldSize.cy == infoPtr->calcSize.cy) &&
1208             !(infoPtr->fStatus & RESIZE_ANYHOW))
1209             {
1210                 TRACE("skipping reset\n");
1211                 return;
1212             }
1213     }
1214
1215     infoPtr->fStatus &= ~RESIZE_ANYHOW;
1216     /* Set flag to ignore next WM_SIZE message */
1217     infoPtr->fStatus |= AUTO_RESIZE;
1218
1219     width = 0;
1220     height = 0;
1221     x = 0;
1222     y = 0;
1223
1224     if (infoPtr->dwStyle & WS_BORDER) {
1225         width = 2 * xedge;
1226         height = 2 * yedge;
1227     }
1228
1229     if (!(infoPtr->dwStyle & CCS_NOPARENTALIGN)) {
1230         INT mode = infoPtr->dwStyle & (CCS_VERT | CCS_TOP | CCS_BOTTOM);
1231         RECT rcPcl;
1232
1233         GetClientRect(GetParent(infoPtr->hwndSelf), &rcPcl);
1234         switch (mode) {
1235         case CCS_TOP:
1236             /* _TOP sets width to parents width */
1237             width += (rcPcl.right - rcPcl.left);
1238             height += infoPtr->calcSize.cy;
1239             x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1240             y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1241             y += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1242             break;
1243         case CCS_BOTTOM:
1244             /* FIXME: wrong wrong wrong */
1245             /* _BOTTOM sets width to parents width */
1246             width += (rcPcl.right - rcPcl.left);
1247             height += infoPtr->calcSize.cy;
1248             x += -xedge;
1249             y = rcPcl.bottom - height + 1;
1250             break;
1251         case CCS_LEFT:
1252             /* _LEFT sets height to parents height */
1253             width += infoPtr->calcSize.cx;
1254             height += (rcPcl.bottom - rcPcl.top);
1255             x += ((infoPtr->dwStyle & WS_BORDER) ? -xedge : 0);
1256             x += ((infoPtr->dwStyle & CCS_NODIVIDER) ? 0 : REBAR_DIVIDER);
1257             y += ((infoPtr->dwStyle & WS_BORDER) ? -yedge : 0);
1258             break;
1259         case CCS_RIGHT:
1260             /* FIXME: wrong wrong wrong */
1261             /* _RIGHT sets height to parents height */
1262             width += infoPtr->calcSize.cx;
1263             height += (rcPcl.bottom - rcPcl.top);
1264             x = rcPcl.right - width + 1;
1265             y = -yedge;
1266             break;
1267         default:
1268             width += infoPtr->calcSize.cx;
1269             height += infoPtr->calcSize.cy;
1270         }
1271     }
1272     else {
1273         width += infoPtr->calcSize.cx;
1274         height += infoPtr->calcSize.cy;
1275         x = infoPtr->origin.x;
1276         y = infoPtr->origin.y;
1277     }
1278
1279     TRACE("hwnd %p, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
1280         infoPtr->hwndSelf, infoPtr->dwStyle,
1281         x, y, width, height);
1282     SetWindowPos (infoPtr->hwndSelf, 0, x, y, width, height,
1283                     SWP_NOZORDER);
1284 }
1285
1286
1287 static VOID
1288 REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
1289 {
1290     REBAR_BAND *lpBand;
1291     CHAR szClassName[40];
1292     UINT i;
1293     NMREBARCHILDSIZE  rbcz;
1294     NMHDR heightchange;
1295     HDWP deferpos;
1296
1297     if (!(deferpos = BeginDeferWindowPos(infoPtr->uNumBands)))
1298         ERR("BeginDeferWindowPos returned NULL\n");
1299
1300     for (i = start; i < endplus; i++) {
1301         lpBand = &infoPtr->bands[i];
1302
1303         if (HIDDENBAND(lpBand)) continue;
1304         if (lpBand->hwndChild) {
1305             TRACE("hwndChild = %p\n", lpBand->hwndChild);
1306
1307             /* Always geterate the RBN_CHILDSIZE even it child
1308                    did not change */
1309             rbcz.uBand = i;
1310             rbcz.wID = lpBand->wID;
1311             rbcz.rcChild = lpBand->rcChild;
1312             rbcz.rcBand = lpBand->rcBand;
1313             if (infoPtr->dwStyle & CCS_VERT)
1314                 rbcz.rcBand.top += lpBand->cxHeader;
1315             else
1316                 rbcz.rcBand.left += lpBand->cxHeader;
1317             REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
1318             if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
1319                 TRACE("Child rect changed by NOTIFY for band %u\n", i);
1320                 TRACE("    from (%ld,%ld)-(%ld,%ld)  to (%ld,%ld)-(%ld,%ld)\n",
1321                       lpBand->rcChild.left, lpBand->rcChild.top,
1322                       lpBand->rcChild.right, lpBand->rcChild.bottom,
1323                       rbcz.rcChild.left, rbcz.rcChild.top,
1324                       rbcz.rcChild.right, rbcz.rcChild.bottom);
1325                 lpBand->rcChild = rbcz.rcChild;  /* *** ??? */
1326             }
1327
1328             /* native (IE4 in "Favorites" frame **1) does:
1329              *   SetRect (&rc, -1, -1, -1, -1)
1330              *   EqualRect (&rc,band->rc???)
1331              *   if ret==0
1332              *     CopyRect (band->rc????, &rc)
1333              *     set flag outside of loop
1334              */
1335
1336             GetClassNameA (lpBand->hwndChild, szClassName, 40);
1337             if (!lstrcmpA (szClassName, "ComboBox") ||
1338                 !lstrcmpA (szClassName, WC_COMBOBOXEXA)) {
1339                 INT nEditHeight, yPos;
1340                 RECT rc;
1341
1342                 /* special placement code for combo or comboex box */
1343
1344
1345                 /* get size of edit line */
1346                 GetWindowRect (lpBand->hwndChild, &rc);
1347                 nEditHeight = rc.bottom - rc.top;
1348                 yPos = (lpBand->rcChild.bottom + lpBand->rcChild.top - nEditHeight)/2;
1349
1350                 /* center combo box inside child area */
1351                 TRACE("moving child (Combo(Ex)) %p to (%ld,%d) for (%ld,%d)\n",
1352                       lpBand->hwndChild,
1353                       lpBand->rcChild.left, yPos,
1354                       lpBand->rcChild.right - lpBand->rcChild.left,
1355                       nEditHeight);
1356                 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1357                                            lpBand->rcChild.left,
1358                                            /*lpBand->rcChild.top*/ yPos,
1359                                            lpBand->rcChild.right - lpBand->rcChild.left,
1360                                            nEditHeight,
1361                                            SWP_NOZORDER);
1362                 if (!deferpos)
1363                     ERR("DeferWindowPos returned NULL\n");
1364             }
1365             else {
1366                 TRACE("moving child (Other) %p to (%ld,%ld) for (%ld,%ld)\n",
1367                       lpBand->hwndChild,
1368                       lpBand->rcChild.left, lpBand->rcChild.top,
1369                       lpBand->rcChild.right - lpBand->rcChild.left,
1370                       lpBand->rcChild.bottom - lpBand->rcChild.top);
1371                 deferpos = DeferWindowPos (deferpos, lpBand->hwndChild, HWND_TOP,
1372                                            lpBand->rcChild.left,
1373                                            lpBand->rcChild.top,
1374                                            lpBand->rcChild.right - lpBand->rcChild.left,
1375                                            lpBand->rcChild.bottom - lpBand->rcChild.top,
1376                                            SWP_NOZORDER);
1377                 if (!deferpos)
1378                     ERR("DeferWindowPos returned NULL\n");
1379             }
1380         }
1381     }
1382     if (!EndDeferWindowPos(deferpos))
1383         ERR("EndDeferWindowPos returned NULL\n");
1384
1385     if (infoPtr->DoRedraw)
1386         UpdateWindow (infoPtr->hwndSelf);
1387
1388     if (infoPtr->fStatus & NTF_HGHTCHG) {
1389         infoPtr->fStatus &= ~NTF_HGHTCHG;
1390         REBAR_Notify (&heightchange, infoPtr, RBN_HEIGHTCHANGE);
1391     }
1392
1393     /* native (from **1 above) does:
1394      *      UpdateWindow(rebar)
1395      *      REBAR_ForceResize
1396      *      RBN_HEIGHTCHANGE if necessary
1397      *      if ret from any EqualRect was 0
1398      *         Goto "BeginDeferWindowPos"
1399      */
1400
1401 }
1402
1403
1404 static VOID
1405 REBAR_Layout (REBAR_INFO *infoPtr, LPRECT lpRect, BOOL notify, BOOL resetclient)
1406      /* Function: This routine is resposible for laying out all */
1407      /*  the bands in a rebar. It assigns each band to a row and*/
1408      /*  determines when to start a new row.                    */
1409 {
1410     REBAR_BAND *lpBand, *prevBand;
1411     RECT rcClient, rcAdj;
1412     INT initx, inity, x, y, cx, cxsep, mmcy, mcy, clientcx, clientcy;
1413     INT adjcx, adjcy, row, rightx, bottomy, origheight;
1414     UINT i, j, rowstart, origrows, cntonrow;
1415     BOOL dobreak;
1416
1417     if (!(infoPtr->fStatus & BAND_NEEDS_LAYOUT)) {
1418         TRACE("no layout done. No band changed.\n");
1419         REBAR_DumpBand (infoPtr);
1420         return;
1421     }
1422     infoPtr->fStatus &= ~BAND_NEEDS_LAYOUT;
1423     if (!infoPtr->DoRedraw) infoPtr->fStatus |= BAND_NEEDS_REDRAW;
1424
1425     GetClientRect (infoPtr->hwndSelf, &rcClient);
1426     TRACE("Client is (%ld,%ld)-(%ld,%ld)\n",
1427           rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
1428
1429     if (lpRect) {
1430         rcAdj = *lpRect;
1431         TRACE("adjustment rect is (%ld,%ld)-(%ld,%ld)\n",
1432               rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
1433     }
1434     else {
1435         CopyRect (&rcAdj, &rcClient);
1436     }
1437
1438     clientcx = rcClient.right - rcClient.left;
1439     clientcy = rcClient.bottom - rcClient.top;
1440     adjcx = rcAdj.right - rcAdj.left;
1441     adjcy = rcAdj.bottom - rcAdj.top;
1442     if (resetclient) {
1443         TRACE("window client rect will be set to adj rect\n");
1444         clientcx = adjcx;
1445         clientcy = adjcy;
1446     }
1447
1448     if (!infoPtr->DoRedraw && (clientcx == 0) && (clientcy == 0)) {
1449         ERR("no redraw and client is zero, skip layout\n");
1450         infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1451         return;
1452     }
1453
1454     /* save height of original control */
1455     if (infoPtr->dwStyle & CCS_VERT)
1456         origheight = infoPtr->calcSize.cx;
1457     else
1458         origheight = infoPtr->calcSize.cy;
1459     origrows = infoPtr->uNumRows;
1460
1461     initx = 0;
1462     inity = 0;
1463
1464     /* ******* Start Phase 1 - all bands on row at minimum size ******* */
1465
1466     TRACE("band loop constants, clientcx=%d, clientcy=%d, adjcx=%d, adjcy=%d\n",
1467           clientcx, clientcy, adjcx, adjcy);
1468     x = initx;
1469     y = inity;
1470     row = 1;
1471     cx = 0;
1472     mcy = 0;
1473     rowstart = 0;
1474     prevBand = NULL;
1475     cntonrow = 0;
1476
1477     for (i = 0; i < infoPtr->uNumBands; i++) {
1478         lpBand = &infoPtr->bands[i];
1479         lpBand->fDraw = 0;
1480         lpBand->iRow = row;
1481
1482         SetRectEmpty(&lpBand->rcChevron);
1483
1484         if (HIDDENBAND(lpBand)) continue;
1485
1486         lpBand->rcoldBand = lpBand->rcBand;
1487
1488         /* Set the offset of the child window */
1489         if ((lpBand->fMask & RBBIM_CHILD) &&
1490             !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
1491             lpBand->offChild.cx = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 4 : 0);
1492         }
1493         lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
1494
1495         /* separator from previous band */
1496         cxsep = (cntonrow == 0) ? 0 : SEP_WIDTH;
1497         cx = lpBand->lcx;
1498
1499         if (infoPtr->dwStyle & CCS_VERT)
1500             dobreak = (y + cx + cxsep > adjcy);
1501         else
1502             dobreak = (x + cx + cxsep > adjcx);
1503
1504         /* This is the check for whether we need to start a new row */
1505         if ( ( (lpBand->fStyle & RBBS_BREAK) && (i != 0) ) ||
1506              ( ((infoPtr->dwStyle & CCS_VERT) ? (y != 0) : (x != 0)) && dobreak)) {
1507
1508             for (j = rowstart; j < i; j++) {
1509                 REBAR_BAND *lpB;
1510                 lpB = &infoPtr->bands[j];
1511                 if (infoPtr->dwStyle & CCS_VERT) {
1512                     lpB->rcBand.right  = lpB->rcBand.left + mcy;
1513                 }
1514                 else {
1515                     lpB->rcBand.bottom = lpB->rcBand.top + mcy;
1516                 }
1517             }
1518
1519             TRACE("P1 Spliting to new row %d on band %u\n", row+1, i);
1520             if (infoPtr->dwStyle & CCS_VERT) {
1521                 y = inity;
1522                 x += (mcy + SEP_WIDTH);
1523             }
1524             else {
1525                 x = initx;
1526                 y += (mcy + SEP_WIDTH);
1527             }
1528
1529             mcy = 0;
1530             cxsep = 0;
1531             row++;
1532             lpBand->iRow = row;
1533             prevBand = NULL;
1534             rowstart = i;
1535             cntonrow = 0;
1536         }
1537
1538         if (mcy < lpBand->lcy + REBARSPACE(lpBand))
1539             mcy = lpBand->lcy + REBARSPACE(lpBand);
1540
1541         /* if boundary rect specified then limit mcy */
1542         if (lpRect) {
1543             if (infoPtr->dwStyle & CCS_VERT) {
1544                 if (x+mcy > adjcx) {
1545                     mcy = adjcx - x;
1546                     TRACE("P1 row %u limiting mcy=%d, adjcx=%d, x=%d\n",
1547                           i, mcy, adjcx, x);
1548                 }
1549             }
1550             else {
1551                 if (y+mcy > adjcy) {
1552                     mcy = adjcy - y;
1553                     TRACE("P1 row %u limiting mcy=%d, adjcy=%d, y=%d\n",
1554                           i, mcy, adjcy, y);
1555                 }
1556             }
1557         }
1558
1559         TRACE("P1 band %u, row %d, x=%d, y=%d, cxsep=%d, cx=%d\n",
1560               i, row,
1561               x, y, cxsep, cx);
1562         if (infoPtr->dwStyle & CCS_VERT) {
1563             /* bound the bottom side if we have a bounding rectangle */
1564             rightx = clientcx;
1565             bottomy = (lpRect) ? min(clientcy, y+cxsep+cx) : y+cxsep+cx;
1566             lpBand->rcBand.left   = x;
1567             lpBand->rcBand.right  = x + min(mcy,
1568                                             lpBand->lcy+REBARSPACE(lpBand));
1569             lpBand->rcBand.top    = min(bottomy, y + cxsep);
1570             lpBand->rcBand.bottom = bottomy;
1571             lpBand->uMinHeight = lpBand->lcy;
1572             y = bottomy;
1573         }
1574         else {
1575             /* bound the right side if we have a bounding rectangle */
1576             rightx = (lpRect) ? min(clientcx, x+cxsep+cx) : x+cxsep+cx;
1577             bottomy = clientcy;
1578             lpBand->rcBand.left   = min(rightx, x + cxsep);
1579             lpBand->rcBand.right  = rightx;
1580             lpBand->rcBand.top    = y;
1581             lpBand->rcBand.bottom = y + min(mcy,
1582                                             lpBand->lcy+REBARSPACE(lpBand));
1583             lpBand->uMinHeight = lpBand->lcy;
1584             x = rightx;
1585         }
1586         TRACE("P1 band %u, row %d, (%ld,%ld)-(%ld,%ld)\n",
1587               i, row,
1588               lpBand->rcBand.left, lpBand->rcBand.top,
1589               lpBand->rcBand.right, lpBand->rcBand.bottom);
1590         prevBand = lpBand;
1591         cntonrow++;
1592
1593     } /* for (i = 0; i < infoPtr->uNumBands... */
1594
1595     if (infoPtr->dwStyle & CCS_VERT)
1596         x += mcy;
1597     else
1598         y += mcy;
1599
1600     for (j = rowstart; j < infoPtr->uNumBands; j++) {
1601         lpBand = &infoPtr->bands[j];
1602         if (infoPtr->dwStyle & CCS_VERT) {
1603             lpBand->rcBand.right  = lpBand->rcBand.left + mcy;
1604         }
1605         else {
1606             lpBand->rcBand.bottom = lpBand->rcBand.top + mcy;
1607         }
1608     }
1609
1610     if (infoPtr->uNumBands)
1611         infoPtr->uNumRows = row;
1612
1613     /* ******* End Phase 1 - all bands on row at minimum size ******* */
1614
1615
1616     /* ******* Start Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1617
1618     mmcy = 0;
1619     if (!(infoPtr->dwStyle & RBS_VARHEIGHT)) {
1620         INT xy;
1621
1622         /* get the max height of all bands */
1623         for (i=0; i<infoPtr->uNumBands; i++) {
1624             lpBand = &infoPtr->bands[i];
1625             if (HIDDENBAND(lpBand)) continue;
1626             if (infoPtr->dwStyle & CCS_VERT)
1627                 mmcy = max(mmcy, lpBand->rcBand.right - lpBand->rcBand.left);
1628             else
1629                 mmcy = max(mmcy, lpBand->rcBand.bottom - lpBand->rcBand.top);
1630         }
1631
1632         /* now adjust all rectangles by using the height found above */
1633         xy = 0;
1634         row = 1;
1635         for (i=0; i<infoPtr->uNumBands; i++) {
1636             lpBand = &infoPtr->bands[i];
1637             if (HIDDENBAND(lpBand)) continue;
1638             if (lpBand->iRow != row)
1639                 xy += (mmcy + SEP_WIDTH);
1640             if (infoPtr->dwStyle & CCS_VERT) {
1641                 lpBand->rcBand.left = xy;
1642                 lpBand->rcBand.right = xy + mmcy;
1643             }
1644             else {
1645                 lpBand->rcBand.top = xy;
1646                 lpBand->rcBand.bottom = xy + mmcy;
1647             }
1648         }
1649
1650         /* set the x/y values to the correct maximum */
1651         if (infoPtr->dwStyle & CCS_VERT)
1652             x = xy + mmcy;
1653         else
1654             y = xy + mmcy;
1655     }
1656
1657     /* ******* End Phase 1a - Adjust heights for RBS_VARHEIGHT off ******* */
1658
1659
1660     /* ******* Start Phase 2 - split rows till adjustment height full ******* */
1661
1662     /* assumes that the following variables contain:                 */
1663     /*   y/x     current height/width of all rows                    */
1664     if (lpRect) {
1665         INT i, prev_rh, new_rh, adj_rh, prev_idx, current_idx;
1666         REBAR_BAND *prev, *current, *walk;
1667         UINT j;
1668
1669 /* FIXME:  problem # 2 */
1670         if (((infoPtr->dwStyle & CCS_VERT) ?
1671 #if PROBLEM2
1672              (x < adjcx) : (y < adjcy)
1673 #else
1674              (adjcx - x > 5) : (adjcy - y > 4)
1675 #endif
1676              ) &&
1677             (infoPtr->uNumBands > 1)) {
1678             for (i=(INT)infoPtr->uNumBands-2; i>=0; i--) {
1679                 TRACE("P2 adjcx=%d, adjcy=%d, x=%d, y=%d\n",
1680                       adjcx, adjcy, x, y);
1681
1682                 /* find the current band (starts at i+1) */
1683                 current = &infoPtr->bands[i+1];
1684                 current_idx = i+1;
1685                 while (HIDDENBAND(current)) {
1686                     i--;
1687                     if (i < 0) break; /* out of bands */
1688                     current = &infoPtr->bands[i+1];
1689                     current_idx = i+1;
1690                 }
1691                 if (i < 0) break; /* out of bands */
1692
1693                 /* now find the prev band (starts at i) */
1694                 prev = &infoPtr->bands[i];
1695                 prev_idx = i;
1696                 while (HIDDENBAND(prev)) {
1697                     i--;
1698                     if (i < 0) break; /* out of bands */
1699                     prev = &infoPtr->bands[i];
1700                     prev_idx = i;
1701                 }
1702                 if (i < 0) break; /* out of bands */
1703
1704                 prev_rh = ircBw(prev);
1705                 if (prev->iRow == current->iRow) {
1706                     new_rh = (infoPtr->dwStyle & RBS_VARHEIGHT) ?
1707                         current->lcy + REBARSPACE(current) :
1708                         mmcy;
1709                     adj_rh = new_rh + SEP_WIDTH;
1710                     infoPtr->uNumRows++;
1711                     current->fDraw |= NTF_INVALIDATE;
1712                     current->iRow++;
1713                     if (infoPtr->dwStyle & CCS_VERT) {
1714                         current->rcBand.top = inity;
1715                         current->rcBand.bottom = clientcy;
1716                         current->rcBand.left += (prev_rh + SEP_WIDTH);
1717                         current->rcBand.right = current->rcBand.left + new_rh;
1718                         x += adj_rh;
1719                     }
1720                     else {
1721                         current->rcBand.left = initx;
1722                         current->rcBand.right = clientcx;
1723                         current->rcBand.top += (prev_rh + SEP_WIDTH);
1724                         current->rcBand.bottom = current->rcBand.top + new_rh;
1725                         y += adj_rh;
1726                     }
1727                     TRACE("P2 moving band %d to own row at (%ld,%ld)-(%ld,%ld)\n",
1728                           current_idx,
1729                           current->rcBand.left, current->rcBand.top,
1730                           current->rcBand.right, current->rcBand.bottom);
1731                     TRACE("P2 prev band %d at (%ld,%ld)-(%ld,%ld)\n",
1732                           prev_idx,
1733                           prev->rcBand.left, prev->rcBand.top,
1734                           prev->rcBand.right, prev->rcBand.bottom);
1735                     TRACE("P2 values: prev_rh=%d, new_rh=%d, adj_rh=%d\n",
1736                           prev_rh, new_rh, adj_rh);
1737                     /* for bands below current adjust row # and top/bottom */
1738                     for (j = current_idx+1; j<infoPtr->uNumBands; j++) {
1739                         walk = &infoPtr->bands[j];
1740                         if (HIDDENBAND(walk)) continue;
1741                         walk->fDraw |= NTF_INVALIDATE;
1742                         walk->iRow++;
1743                         if (infoPtr->dwStyle & CCS_VERT) {
1744                             walk->rcBand.left += adj_rh;
1745                             walk->rcBand.right += adj_rh;
1746                         }
1747                         else {
1748                             walk->rcBand.top += adj_rh;
1749                             walk->rcBand.bottom += adj_rh;
1750                         }
1751                     }
1752                     if ((infoPtr->dwStyle & CCS_VERT) ? (x >= adjcx) : (y >= adjcy))
1753                         break; /* all done */
1754                 }
1755             }
1756         }
1757     }
1758
1759     /* ******* End Phase 2 - split rows till adjustment height full ******* */
1760
1761
1762     /* ******* Start Phase 2a - mark first and last band in each ******* */
1763
1764     prevBand = NULL;
1765     for (i = 0; i < infoPtr->uNumBands; i++) {   
1766         lpBand = &infoPtr->bands[i];     
1767         if (HIDDENBAND(lpBand))
1768             continue;
1769         if( !prevBand ) {
1770             lpBand->fDraw |= DRAW_FIRST_IN_ROW;
1771             prevBand = lpBand;
1772         }
1773         else if( prevBand->iRow == lpBand->iRow )
1774             prevBand = lpBand;
1775         else {
1776             prevBand->fDraw |= DRAW_LAST_IN_ROW;
1777             lpBand->fDraw |= DRAW_FIRST_IN_ROW;
1778             prevBand = lpBand;
1779         }
1780     }
1781     if( prevBand )
1782         prevBand->fDraw |= DRAW_LAST_IN_ROW;
1783
1784     /* ******* End Phase 2a - mark first and last band in each ******* */
1785
1786
1787     /* ******* Start Phase 2b - adjust all bands for height full ******* */
1788     /* assumes that the following variables contain:                 */
1789     /*   y/x     current height/width of all rows                    */
1790     /*   clientcy/clientcx     height/width of client area           */
1791
1792     if (((infoPtr->dwStyle & CCS_VERT) ? clientcx > x : clientcy > y) &&
1793         infoPtr->uNumBands) {
1794         INT diff, i;
1795         UINT j;
1796
1797         diff = (infoPtr->dwStyle & CCS_VERT) ? clientcx - x : clientcy - y;
1798
1799         /* iterate backwards thru the rows */
1800         for (i = infoPtr->uNumBands-1; i>=0; i--) {
1801             lpBand = &infoPtr->bands[i];
1802             if(HIDDENBAND(lpBand)) continue;
1803
1804             /* if row has more than 1 band, ignore it */
1805             if( !(lpBand->fDraw&DRAW_FIRST_IN_ROW) )
1806                 continue;
1807             if( !(lpBand->fDraw&DRAW_LAST_IN_ROW) )
1808                 continue;
1809
1810             if (lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
1811             if (((INT)lpBand->cyMaxChild < 1) ||
1812                 ((INT)lpBand->cyIntegral < 1)) {
1813                 if (lpBand->cyMaxChild + lpBand->cyIntegral == 0) continue;
1814                 ERR("P2b band %u RBBS_VARIABLEHEIGHT set but cyMax=%d, cyInt=%d\n",
1815                     i, lpBand->cyMaxChild, lpBand->cyIntegral);
1816                 continue;
1817             }
1818             /* j is now the maximum height/width in the client area */
1819             j = ((diff / lpBand->cyIntegral) * lpBand->cyIntegral) +
1820                 ircBw(lpBand);
1821             if (j > lpBand->cyMaxChild + REBARSPACE(lpBand))
1822                 j = lpBand->cyMaxChild + REBARSPACE(lpBand);
1823             diff -= (j - ircBw(lpBand));
1824             if (infoPtr->dwStyle & CCS_VERT)
1825                 lpBand->rcBand.right = lpBand->rcBand.left + j;
1826             else
1827                 lpBand->rcBand.bottom = lpBand->rcBand.top + j;
1828             TRACE("P2b band %d, row %d changed to (%ld,%ld)-(%ld,%ld)\n",
1829                   i, lpBand->iRow,
1830                   lpBand->rcBand.left, lpBand->rcBand.top,
1831                   lpBand->rcBand.right, lpBand->rcBand.bottom);
1832             if (diff <= 0) break;
1833         }
1834         if (diff < 0) {
1835             ERR("P2b allocated more than available, diff=%d\n", diff);
1836             diff = 0;
1837         }
1838         if (infoPtr->dwStyle & CCS_VERT)
1839             x = clientcx - diff;
1840         else
1841             y = clientcy - diff;
1842     }
1843
1844     /* ******* End Phase 2b - adjust all bands for height full ******* */
1845
1846
1847     /* ******* Start Phase 3 - adjust all bands for width full ******* */
1848
1849     if (infoPtr->uNumBands) {
1850         int startband;
1851
1852         /* If RBS_BANDBORDERS set then indicate to draw bottom separator */
1853         /* on all bands in all rows but last row.                        */
1854         /* Also indicate to draw the right separator for each band in    */
1855         /* each row but the rightmost band.                              */
1856         if (infoPtr->dwStyle & RBS_BANDBORDERS) {
1857
1858             for (i=0; i<infoPtr->uNumBands; i++) {
1859                 lpBand = &infoPtr->bands[i];
1860                 if (HIDDENBAND(lpBand))
1861                     continue;
1862
1863                 /* not righthand bands */
1864                 if( !(lpBand->fDraw & DRAW_LAST_IN_ROW) )
1865                     lpBand->fDraw |= DRAW_RIGHTSEP;
1866
1867                 /* not the last row */
1868                 if( lpBand->iRow != infoPtr->uNumRows )
1869                     lpBand->fDraw |= DRAW_BOTTOMSEP;
1870             }
1871         }
1872
1873         /* Distribute the extra space on the horizontal and adjust  */
1874         /* all bands in row to same height.                         */
1875         mcy = 0;
1876         startband = -1;
1877         for (i=0; i<infoPtr->uNumBands; i++) {
1878
1879             lpBand = &infoPtr->bands[i];
1880
1881             if( lpBand->fDraw & DRAW_FIRST_IN_ROW )
1882             {
1883                 startband = i;
1884                 mcy = 0;
1885             }
1886
1887             if ( (mcy < ircBw(lpBand)) && !HIDDENBAND(lpBand) )
1888                 mcy = ircBw(lpBand);
1889
1890             if( lpBand->fDraw & DRAW_LAST_IN_ROW )
1891             {
1892                 TRACE("P3 processing row %d, starting band %d, ending band %d\n",
1893                       lpBand->iRow, startband, i);
1894                 if( startband < 0 )
1895                     ERR("Last band %d with no first, row %d\n", i, lpBand->iRow);
1896
1897                 REBAR_AdjustBands (infoPtr, startband, i,
1898                                (infoPtr->dwStyle & CCS_VERT) ?
1899                                clientcy : clientcx, mcy);
1900             }
1901         }
1902
1903         /* Calculate the other rectangles in each band */
1904         if (infoPtr->dwStyle & CCS_VERT) {
1905             REBAR_CalcVertBand (infoPtr, 0, infoPtr->uNumBands,
1906                                 notify);
1907         }
1908         else {
1909             REBAR_CalcHorzBand (infoPtr, 0, infoPtr->uNumBands,
1910                                 notify);
1911         }
1912     }
1913
1914     /* ******* End Phase 3 - adjust all bands for width full ******* */
1915
1916     /* now compute size of Rebar itself */
1917     infoPtr->oldSize = infoPtr->calcSize;
1918     if (infoPtr->uNumBands == 0) {
1919         /* we have no bands, so make size the size of client */
1920         x = clientcx;
1921         y = clientcy;
1922     }
1923     if (infoPtr->dwStyle & CCS_VERT) {
1924         if( x < REBAR_MINSIZE )
1925             x = REBAR_MINSIZE;
1926         infoPtr->calcSize.cx = x;
1927         infoPtr->calcSize.cy = clientcy;
1928         TRACE("vert, notify=%d, x=%d, origheight=%d\n",
1929               notify, x, origheight);
1930         if (notify && (x != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1931     }
1932     else {
1933         if( y < REBAR_MINSIZE )
1934             y = REBAR_MINSIZE;
1935         infoPtr->calcSize.cx = clientcx;
1936         infoPtr->calcSize.cy = y;
1937         TRACE("horz, notify=%d, y=%d, origheight=%d\n",
1938               notify, y, origheight);
1939         if (notify && (y != origheight)) infoPtr->fStatus |= NTF_HGHTCHG;
1940     }
1941
1942     REBAR_DumpBand (infoPtr);
1943
1944     REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
1945
1946     REBAR_ForceResize (infoPtr);
1947 }
1948
1949
1950 static VOID
1951 REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
1952      /* Function:  This routine evaluates the band specs supplied */
1953      /*  by the user and updates the following 5 fields in        */
1954      /*  the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
1955 {
1956     UINT header=0;
1957     UINT textheight=0;
1958     UINT i, nonfixed;
1959     REBAR_BAND *tBand;
1960
1961     lpBand->fStatus = 0;
1962     lpBand->lcx = 0;
1963     lpBand->lcy = 0;
1964     lpBand->ccx = 0;
1965     lpBand->ccy = 0;
1966     lpBand->hcx = 0;
1967     lpBand->hcy = 0;
1968
1969     /* Data comming in from users into the cx... and cy... fields  */
1970     /* may be bad, just garbage, because the user never clears     */
1971     /* the fields. RB_{SET|INSERT}BAND{A|W} just passes the data   */
1972     /* along if the fields exist in the input area. Here we must   */
1973     /* determine if the data is valid. I have no idea how MS does  */
1974     /* the validation, but it does because the RB_GETBANDINFO      */
1975     /* returns a 0 when I know the sample program passed in an     */
1976     /* address. Here I will use the algorithim that if the value   */
1977     /* is greater than 65535 then it is bad and replace it with    */
1978     /* a zero. Feel free to improve the algorithim.  -  GA 12/2000 */
1979     if (lpBand->cxMinChild > 65535) lpBand->cxMinChild = 0;
1980     if (lpBand->cyMinChild > 65535) lpBand->cyMinChild = 0;
1981     if (lpBand->cx         > 65535) lpBand->cx         = 0;
1982     if (lpBand->cyChild    > 65535) lpBand->cyChild    = 0;
1983     if (lpBand->cyMaxChild > 65535) lpBand->cyMaxChild = 0;
1984     if (lpBand->cyIntegral > 65535) lpBand->cyIntegral = 0;
1985     if (lpBand->cxIdeal    > 65535) lpBand->cxIdeal    = 0;
1986     if (lpBand->cxHeader   > 65535) lpBand->cxHeader   = 0;
1987
1988     /* FIXME: probably should only set NEEDS_LAYOUT flag when */
1989     /*        values change. Till then always set it.         */
1990     TRACE("setting NEEDS_LAYOUT\n");
1991     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
1992
1993     /* Header is where the image, text and gripper exist  */
1994     /* in the band and preceed the child window.          */
1995
1996     /* count number of non-FIXEDSIZE and non-Hidden bands */
1997     nonfixed = 0;
1998     for (i=0; i<infoPtr->uNumBands; i++){
1999         tBand = &infoPtr->bands[i];
2000         if (!HIDDENBAND(tBand) && !(tBand->fStyle & RBBS_FIXEDSIZE))
2001             nonfixed++;
2002     }
2003
2004     /* calculate gripper rectangle */
2005     if (  (!(lpBand->fStyle & RBBS_NOGRIPPER)) &&
2006           ( (lpBand->fStyle & RBBS_GRIPPERALWAYS) ||
2007             ( !(lpBand->fStyle & RBBS_FIXEDSIZE) && (nonfixed > 1)))
2008        ) {
2009         lpBand->fStatus |= HAS_GRIPPER;
2010         if (infoPtr->dwStyle & CCS_VERT)
2011             if (infoPtr->dwStyle & RBS_VERTICALGRIPPER)
2012                 header += (GRIPPER_HEIGHT + REBAR_PRE_GRIPPER);
2013             else
2014                 header += (GRIPPER_WIDTH + REBAR_PRE_GRIPPER);
2015         else
2016             header += (REBAR_PRE_GRIPPER + GRIPPER_WIDTH);
2017         /* Always have 4 pixels before anything else */
2018         header += REBAR_ALWAYS_SPACE;
2019     }
2020
2021     /* image is visible */
2022     if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
2023         lpBand->fStatus |= HAS_IMAGE;
2024         if (infoPtr->dwStyle & CCS_VERT) {
2025            header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
2026            lpBand->lcy = infoPtr->imageSize.cx + 2;
2027         }
2028         else {
2029            header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
2030            lpBand->lcy = infoPtr->imageSize.cy + 2;
2031         }
2032     }
2033
2034     /* text is visible */
2035     if ((lpBand->fMask & RBBIM_TEXT) && (lpBand->lpText) &&
2036         !(lpBand->fStyle & RBBS_HIDETITLE)) {
2037         HDC hdc = GetDC (0);
2038         HFONT hOldFont = SelectObject (hdc, infoPtr->hFont);
2039         SIZE size;
2040
2041         lpBand->fStatus |= HAS_TEXT;
2042         GetTextExtentPoint32W (hdc, lpBand->lpText,
2043                                lstrlenW (lpBand->lpText), &size);
2044         header += ((infoPtr->dwStyle & CCS_VERT) ? (size.cy + REBAR_POST_TEXT) : (size.cx + REBAR_POST_TEXT));
2045         textheight = (infoPtr->dwStyle & CCS_VERT) ? 0 : size.cy;
2046
2047         SelectObject (hdc, hOldFont);
2048         ReleaseDC (0, hdc);
2049     }
2050
2051     /* if no gripper but either image or text, then leave space */
2052     if ((lpBand->fStatus & (HAS_IMAGE | HAS_TEXT)) &&
2053         !(lpBand->fStatus & HAS_GRIPPER)) {
2054         header += REBAR_ALWAYS_SPACE;
2055     }
2056
2057     /* check if user overrode the header value */
2058     if (!(lpBand->fMask & RBBIM_HEADERSIZE))
2059         lpBand->cxHeader = header;
2060
2061
2062     /* Now compute minimum size of child window */
2063     lpBand->offChild.cx = 0;
2064     lpBand->offChild.cy = 0;
2065     lpBand->lcy = textheight;
2066     lpBand->ccy = lpBand->lcy;
2067     if (lpBand->fMask & RBBIM_CHILDSIZE) {
2068         lpBand->lcx = lpBand->cxMinChild;
2069
2070         /* Set the .cy values for CHILDSIZE case */
2071         lpBand->lcy = max(lpBand->lcy, lpBand->cyMinChild);
2072         lpBand->ccy = lpBand->lcy;
2073         lpBand->hcy = lpBand->lcy;
2074         if (lpBand->cyMaxChild != 0xffffffff) {
2075             lpBand->hcy = lpBand->cyMaxChild;
2076         }
2077         if (lpBand->cyChild != 0xffffffff)
2078             lpBand->ccy = max (lpBand->cyChild, lpBand->lcy);
2079
2080         TRACE("_CHILDSIZE\n");
2081     }
2082     if (lpBand->fMask & RBBIM_SIZE) {
2083         lpBand->hcx = max (lpBand->cx-lpBand->cxHeader, lpBand->lcx);
2084         TRACE("_SIZE\n");
2085     }
2086     else
2087         lpBand->hcx = lpBand->lcx;
2088     lpBand->ccx = lpBand->hcx;
2089
2090     /* make ->.cx include header size for _Layout */
2091     lpBand->lcx += lpBand->cxHeader;
2092     lpBand->ccx += lpBand->cxHeader;
2093     lpBand->hcx += lpBand->cxHeader;
2094
2095 }
2096
2097 static BOOL
2098 REBAR_CommonSetupBand (HWND hwnd, LPREBARBANDINFOA lprbbi, REBAR_BAND *lpBand)
2099      /* Function:  This routine copies the supplied values from   */
2100      /*  user input (lprbbi) to the internal band structure.      */
2101      /*  It returns true if something changed and false if not.   */
2102 {
2103     BOOL bChanged = FALSE;
2104
2105     lpBand->fMask |= lprbbi->fMask;
2106
2107     if( (lprbbi->fMask & RBBIM_STYLE) &&
2108         (lpBand->fStyle != lprbbi->fStyle ) )
2109     {
2110         lpBand->fStyle = lprbbi->fStyle;
2111         bChanged = TRUE;
2112     }
2113
2114     if( (lprbbi->fMask & RBBIM_COLORS) &&
2115        ( ( lpBand->clrFore != lprbbi->clrFore ) ||
2116          ( lpBand->clrBack != lprbbi->clrBack ) ) )
2117     {
2118         lpBand->clrFore = lprbbi->clrFore;
2119         lpBand->clrBack = lprbbi->clrBack;
2120         bChanged = TRUE;
2121     }
2122
2123     if( (lprbbi->fMask & RBBIM_IMAGE) &&
2124        ( lpBand->iImage != lprbbi->iImage ) )
2125     {
2126         lpBand->iImage = lprbbi->iImage;
2127         bChanged = TRUE;
2128     }
2129
2130     if( (lprbbi->fMask & RBBIM_CHILD) &&
2131        (lprbbi->hwndChild != lpBand->hwndChild ) )
2132     {
2133         if (lprbbi->hwndChild) {
2134             lpBand->hwndChild = lprbbi->hwndChild;
2135             lpBand->hwndPrevParent =
2136                 SetParent (lpBand->hwndChild, hwnd);
2137             /* below in trace fro WinRAR */
2138             ShowWindow(lpBand->hwndChild, SW_SHOWNOACTIVATE | SW_SHOWNORMAL);
2139             /* above in trace fro WinRAR */
2140         }
2141         else {
2142             TRACE("child: %p  prev parent: %p\n",
2143                    lpBand->hwndChild, lpBand->hwndPrevParent);
2144             lpBand->hwndChild = 0;
2145             lpBand->hwndPrevParent = 0;
2146         }
2147         bChanged = TRUE;
2148     }
2149
2150     if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
2151         ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
2152           (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
2153           ( (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) &&
2154             ( (lpBand->cyChild    != lprbbi->cyChild ) ||
2155               (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
2156               (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
2157           ( (lprbbi->cbSize < sizeof (REBARBANDINFOA)) &&
2158             ( (lpBand->cyChild || 
2159                lpBand->cyMaxChild || 
2160                lpBand->cyIntegral ) ) ) ) )
2161     {
2162         lpBand->cxMinChild = lprbbi->cxMinChild;
2163         lpBand->cyMinChild = lprbbi->cyMinChild;
2164         if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2165             lpBand->cyChild    = lprbbi->cyChild;
2166             lpBand->cyMaxChild = lprbbi->cyMaxChild;
2167             lpBand->cyIntegral = lprbbi->cyIntegral;
2168         }
2169         else { /* special case - these should be zeroed out since   */
2170                /* RBBIM_CHILDSIZE added these in WIN32_IE >= 0x0400 */
2171             lpBand->cyChild    = 0;
2172             lpBand->cyMaxChild = 0;
2173             lpBand->cyIntegral = 0;
2174         }
2175         bChanged = TRUE;
2176     }
2177
2178     if( (lprbbi->fMask & RBBIM_SIZE) &&
2179         (lpBand->cx != lprbbi->cx ) )
2180     {
2181         lpBand->cx = lprbbi->cx;
2182         bChanged = TRUE;
2183     }
2184
2185     if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
2186        ( lpBand->hbmBack != lprbbi->hbmBack ) )
2187     {
2188         lpBand->hbmBack = lprbbi->hbmBack;
2189         bChanged = TRUE;
2190     }
2191
2192     if( (lprbbi->fMask & RBBIM_ID) &&
2193         (lpBand->wID != lprbbi->wID ) )
2194     {
2195         lpBand->wID = lprbbi->wID;
2196         bChanged = TRUE;
2197     }
2198
2199     /* check for additional data */
2200     if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2201         if( (lprbbi->fMask & RBBIM_IDEALSIZE) &&
2202             ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
2203         {
2204             lpBand->cxIdeal = lprbbi->cxIdeal;
2205             bChanged = TRUE;
2206         }
2207
2208         if( (lprbbi->fMask & RBBIM_LPARAM) &&
2209             (lpBand->lParam != lprbbi->lParam ) )
2210         {
2211             lpBand->lParam = lprbbi->lParam;
2212             bChanged = TRUE;
2213         }
2214
2215         if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
2216             (lpBand->cxHeader != lprbbi->cxHeader ) )
2217         {
2218             lpBand->cxHeader = lprbbi->cxHeader;
2219             bChanged = TRUE;
2220         }
2221     }
2222
2223     return bChanged;
2224 }
2225
2226 static LRESULT
2227 REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
2228      /* Function:  This erases the background rectangle by drawing  */
2229      /*  each band with its background color (or the default) and   */
2230      /*  draws each bands right separator if necessary. The row     */
2231      /*  separators are drawn on the first band of the next row.    */
2232 {
2233     REBAR_BAND *lpBand;
2234     UINT i;
2235     INT oldrow;
2236     HDC hdc = (HDC)wParam;
2237     RECT rect;
2238     COLORREF old = CLR_NONE, new;
2239
2240     oldrow = -1;
2241     for(i=0; i<infoPtr->uNumBands; i++) {
2242         lpBand = &infoPtr->bands[i];
2243         if (HIDDENBAND(lpBand)) continue;
2244
2245         /* draw band separator between rows */
2246         if (lpBand->iRow != oldrow) {
2247             oldrow = lpBand->iRow;
2248             if (lpBand->fDraw & DRAW_BOTTOMSEP) {
2249                 RECT rcRowSep;
2250                 rcRowSep = lpBand->rcBand;
2251                 if (infoPtr->dwStyle & CCS_VERT) {
2252                     rcRowSep.right += SEP_WIDTH_SIZE;
2253                     rcRowSep.bottom = infoPtr->calcSize.cy;
2254                     DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_RIGHT);
2255                 }
2256                 else {
2257                     rcRowSep.bottom += SEP_WIDTH_SIZE;
2258                     rcRowSep.right = infoPtr->calcSize.cx;
2259                     DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
2260                 }
2261                 TRACE ("drawing band separator bottom (%ld,%ld)-(%ld,%ld)\n",
2262                        rcRowSep.left, rcRowSep.top,
2263                        rcRowSep.right, rcRowSep.bottom);
2264             }
2265         }
2266
2267         /* draw band separator between bands in a row */
2268         if (lpBand->fDraw & DRAW_RIGHTSEP) {
2269             RECT rcSep;
2270             rcSep = lpBand->rcBand;
2271             if (infoPtr->dwStyle & CCS_VERT) {
2272                 rcSep.bottom += SEP_WIDTH_SIZE;
2273                 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_BOTTOM);
2274             }
2275             else {
2276                 rcSep.right += SEP_WIDTH_SIZE;
2277                 DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
2278             }
2279             TRACE("drawing band separator right (%ld,%ld)-(%ld,%ld)\n",
2280                   rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
2281         }
2282
2283         /* draw the actual background */
2284         if (lpBand->clrBack != CLR_NONE) {
2285             new = (lpBand->clrBack == CLR_DEFAULT) ? infoPtr->clrBtnFace :
2286                     lpBand->clrBack;
2287 #if GLATESTING
2288             /* testing only - make background green to see it */
2289             new = RGB(0,128,0);
2290 #endif
2291         }
2292         else {
2293             /* In the absence of documentation for Rebar vs. CLR_NONE,
2294              * we will use the default BtnFace color. Note documentation
2295              * exists for Listview and Imagelist.
2296              */
2297             new = infoPtr->clrBtnFace;
2298 #if GLATESTING
2299             /* testing only - make background green to see it */
2300             new = RGB(0,128,0);
2301 #endif
2302         }
2303         old = SetBkColor (hdc, new);
2304
2305         rect = lpBand->rcBand;
2306         TRACE("%s background color=0x%06lx, band (%ld,%ld)-(%ld,%ld), clip (%ld,%ld)-(%ld,%ld)\n",
2307               (lpBand->clrBack == CLR_NONE) ? "none" :
2308                 ((lpBand->clrBack == CLR_DEFAULT) ? "dft" : ""),
2309               GetBkColor(hdc),
2310               lpBand->rcBand.left,lpBand->rcBand.top,
2311               lpBand->rcBand.right,lpBand->rcBand.bottom,
2312               clip->left, clip->top,
2313               clip->right, clip->bottom);
2314         ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0);
2315         if (lpBand->clrBack != CLR_NONE)
2316             SetBkColor (hdc, old);
2317     }
2318     return TRUE;
2319 }
2320
2321 static void
2322 REBAR_InternalHitTest (REBAR_INFO *infoPtr, const LPPOINT lpPt, UINT *pFlags, INT *pBand)
2323 {
2324     REBAR_BAND *lpBand;
2325     RECT rect;
2326     UINT  iCount;
2327
2328     GetClientRect (infoPtr->hwndSelf, &rect);
2329
2330     *pFlags = RBHT_NOWHERE;
2331     if (PtInRect (&rect, *lpPt))
2332     {
2333         if (infoPtr->uNumBands == 0) {
2334             *pFlags = RBHT_NOWHERE;
2335             if (pBand)
2336                 *pBand = -1;
2337             TRACE("NOWHERE\n");
2338             return;
2339         }
2340         else {
2341             /* somewhere inside */
2342             for (iCount = 0; iCount < infoPtr->uNumBands; iCount++) {
2343                 lpBand = &infoPtr->bands[iCount];
2344                 if (HIDDENBAND(lpBand)) continue;
2345                 if (PtInRect (&lpBand->rcBand, *lpPt)) {
2346                     if (pBand)
2347                         *pBand = iCount;
2348                     if (PtInRect (&lpBand->rcGripper, *lpPt)) {
2349                         *pFlags = RBHT_GRABBER;
2350                         TRACE("ON GRABBER %d\n", iCount);
2351                         return;
2352                     }
2353                     else if (PtInRect (&lpBand->rcCapImage, *lpPt)) {
2354                         *pFlags = RBHT_CAPTION;
2355                         TRACE("ON CAPTION %d\n", iCount);
2356                         return;
2357                     }
2358                     else if (PtInRect (&lpBand->rcCapText, *lpPt)) {
2359                         *pFlags = RBHT_CAPTION;
2360                         TRACE("ON CAPTION %d\n", iCount);
2361                         return;
2362                     }
2363                     else if (PtInRect (&lpBand->rcChild, *lpPt)) {
2364                         *pFlags = RBHT_CLIENT;
2365                         TRACE("ON CLIENT %d\n", iCount);
2366                         return;
2367                     }
2368                     else if (PtInRect (&lpBand->rcChevron, *lpPt)) {
2369                         *pFlags = RBHT_CHEVRON;
2370                         TRACE("ON CHEVRON %d\n", iCount);
2371                         return;
2372                     }
2373                     else {
2374                         *pFlags = RBHT_NOWHERE;
2375                         TRACE("NOWHERE %d\n", iCount);
2376                         return;
2377                     }
2378                 }
2379             }
2380
2381             *pFlags = RBHT_NOWHERE;
2382             if (pBand)
2383                 *pBand = -1;
2384
2385             TRACE("NOWHERE\n");
2386             return;
2387         }
2388     }
2389     else {
2390         *pFlags = RBHT_NOWHERE;
2391         if (pBand)
2392             *pBand = -1;
2393         TRACE("NOWHERE\n");
2394         return;
2395     }
2396 }
2397
2398
2399 static INT
2400 REBAR_Shrink (REBAR_INFO *infoPtr, REBAR_BAND *band, INT movement, INT i)
2401      /* Function:  This attempts to shrink the given band by the  */
2402      /*  the amount in "movement". A shrink to the left is indi-  */
2403      /*  cated by "movement" being negative. "i" is merely the    */
2404      /*  band index for trace messages.                           */
2405 {
2406     INT Leadjust, Readjust, avail, ret;
2407
2408     /* Note: a left drag is indicated by "movement" being negative.  */
2409     /*       Similarly, a right drag is indicated by "movement"      */
2410     /*       being positive. "movement" should never be 0, but if    */
2411     /*       it is then the band does not move.                      */
2412
2413     avail = rcBw(band) - band->lcx;
2414
2415     /* now compute the Left End adjustment factor and Right End */
2416     /* adjustment factor. They may be different if shrinking.   */
2417     if (avail <= 0) {
2418         /* if this band is not shrinkable, then just move it */
2419         Leadjust = Readjust = movement;
2420         ret = movement;
2421     }
2422     else {
2423         if (movement < 0) {
2424             /* Drag to left */
2425             if (avail <= abs(movement)) {
2426                 Readjust = movement;
2427                 Leadjust = movement + avail;
2428                 ret = Leadjust;
2429             }
2430             else {
2431                 Readjust = movement;
2432                 Leadjust = 0;
2433                 ret = 0;
2434             }
2435         }
2436         else {
2437             /* Drag to right */
2438             if (avail <= abs(movement)) {
2439                 Leadjust = movement;
2440                 Readjust = movement - avail;
2441                 ret = Readjust;
2442             }
2443             else {
2444                 Leadjust = movement;
2445                 Readjust = 0;
2446                 ret = 0;
2447             }
2448         }
2449     }
2450
2451     /* Reasonability Check */
2452     if (rcBlt(band) + Leadjust < 0) {
2453         ERR("adjustment will fail, band %d: left=%d, right=%d, move=%d, rtn=%d\n",
2454             i, Leadjust, Readjust, movement, ret);
2455     }
2456
2457     LEADJ(band, Leadjust);
2458     READJ(band, Readjust);
2459
2460     TRACE("band %d:  left=%d, right=%d, move=%d, rtn=%d, rcBand=(%ld,%ld)-(%ld,%ld)\n",
2461           i, Leadjust, Readjust, movement, ret,
2462           band->rcBand.left, band->rcBand.top,
2463           band->rcBand.right, band->rcBand.bottom);
2464     return ret;
2465 }
2466
2467
2468 static void
2469 REBAR_HandleLRDrag (REBAR_INFO *infoPtr, POINTS *ptsmove)
2470      /* Function:  This will implement the functionality of a     */
2471      /*  Gripper drag within a row. It will not implement "out-   */
2472      /*  of-row" drags. (They are detected and handled in         */
2473      /*  REBAR_MouseMove.)                                        */
2474      /*  **** FIXME Switching order of bands in a row not   ****  */
2475      /*  ****       yet implemented.                        ****  */
2476 {
2477     REBAR_BAND *hitBand, *band, *mindBand, *maxdBand;
2478     RECT newrect;
2479     INT imindBand = -1, imaxdBand, ihitBand, i, movement;
2480     INT RHeaderSum = 0, LHeaderSum = 0;
2481     INT compress;
2482
2483     /* on first significant mouse movement, issue notify */
2484
2485     if (!(infoPtr->fStatus & BEGIN_DRAG_ISSUED)) {
2486         if (REBAR_Notify_NMREBAR (infoPtr, -1, RBN_BEGINDRAG)) {
2487             /* Notify returned TRUE - abort drag */
2488             infoPtr->dragStart.x = 0;
2489             infoPtr->dragStart.y = 0;
2490             infoPtr->dragNow = infoPtr->dragStart;
2491             infoPtr->iGrabbedBand = -1;
2492             ReleaseCapture ();
2493             return ;
2494         }
2495         infoPtr->fStatus |= BEGIN_DRAG_ISSUED;
2496     }
2497
2498     ihitBand = infoPtr->iGrabbedBand;
2499     hitBand = &infoPtr->bands[ihitBand];
2500     imaxdBand = ihitBand; /* to suppress warning message */
2501
2502     /* find all the bands in the row of the one whose Gripper was seized */
2503     for (i=0; i<infoPtr->uNumBands; i++) {
2504         band = &infoPtr->bands[i];
2505         if (HIDDENBAND(band)) continue;
2506         if (band->iRow == hitBand->iRow) {
2507             imaxdBand = i;
2508             if (imindBand == -1) imindBand = i;
2509             /* minimum size of each band is size of header plus            */
2510             /* size of minimum child plus offset of child from header plus */
2511             /* a one to separate each band.                                */
2512             if (i < ihitBand)
2513                 LHeaderSum += (band->lcx + SEP_WIDTH);
2514             else
2515                 RHeaderSum += (band->lcx + SEP_WIDTH);
2516
2517         }
2518     }
2519     if (RHeaderSum) RHeaderSum -= SEP_WIDTH; /* no separator after last band */
2520
2521     mindBand = &infoPtr->bands[imindBand];
2522     maxdBand = &infoPtr->bands[imaxdBand];
2523
2524     if (imindBand == imaxdBand) return; /* nothing to drag against */
2525     if (imindBand == ihitBand) return; /* first band in row, can't drag */
2526
2527     /* limit movement to inside adjustable bands - Left */
2528     if ( (ptsmove->x < mindBand->rcBand.left) ||
2529          (ptsmove->x > maxdBand->rcBand.right) ||
2530          (ptsmove->y < mindBand->rcBand.top) ||
2531          (ptsmove->y > maxdBand->rcBand.bottom))
2532         return; /* should swap bands */
2533
2534     if (infoPtr->dwStyle & CCS_VERT)
2535         movement = ptsmove->y - ((hitBand->rcBand.top+REBAR_PRE_GRIPPER) -
2536                              infoPtr->ihitoffset);
2537     else
2538         movement = ptsmove->x - ((hitBand->rcBand.left+REBAR_PRE_GRIPPER) -
2539                              infoPtr->ihitoffset);
2540     infoPtr->dragNow = *ptsmove;
2541
2542     TRACE("before: movement=%d (%d,%d), imindBand=%d, ihitBand=%d, imaxdBand=%d, LSum=%d, RSum=%d\n",
2543           movement, ptsmove->x, ptsmove->y, imindBand, ihitBand,
2544           imaxdBand, LHeaderSum, RHeaderSum);
2545     REBAR_DumpBand (infoPtr);
2546
2547     if (movement < 0) {
2548
2549         /* ***  Drag left/up *** */
2550         compress = rcBlt(hitBand) - rcBlt(mindBand) -
2551                    LHeaderSum;
2552         if (compress < abs(movement)) {
2553             TRACE("limiting left drag, was %d changed to %d\n",
2554                   movement, -compress);
2555             movement = -compress;
2556         }
2557
2558         for (i=ihitBand; i>=imindBand; i--) {
2559             band = &infoPtr->bands[i];
2560             if (HIDDENBAND(band)) continue;
2561             if (i == ihitBand) {
2562                 LEADJ(band, movement);
2563             }
2564             else
2565                 movement = REBAR_Shrink (infoPtr, band, movement, i);
2566             band->ccx = rcBw(band);
2567         }
2568     }
2569     else {
2570         BOOL first = TRUE;
2571
2572         /* ***  Drag right/down *** */
2573         compress = rcBrb(maxdBand) - rcBlt(hitBand) -
2574                    RHeaderSum;
2575         if (compress < abs(movement)) {
2576             TRACE("limiting right drag, was %d changed to %d\n",
2577                   movement, compress);
2578             movement = compress;
2579         }
2580         for (i=ihitBand-1; i<=imaxdBand; i++) {
2581             band = &infoPtr->bands[i];
2582             if (HIDDENBAND(band)) continue;
2583             if (first) {
2584                 first = FALSE;
2585                 READJ(band, movement);
2586             }
2587             else
2588                 movement = REBAR_Shrink (infoPtr, band, movement, i);
2589             band->ccx = rcBw(band);
2590         }
2591     }
2592
2593     /* recompute all rectangles */
2594     if (infoPtr->dwStyle & CCS_VERT) {
2595         REBAR_CalcVertBand (infoPtr, imindBand, imaxdBand+1,
2596                             FALSE);
2597     }
2598     else {
2599         REBAR_CalcHorzBand (infoPtr, imindBand, imaxdBand+1,
2600                             FALSE);
2601     }
2602
2603     TRACE("bands after adjustment, see band # %d, %d\n",
2604           imindBand, imaxdBand);
2605     REBAR_DumpBand (infoPtr);
2606
2607     SetRect (&newrect,
2608              mindBand->rcBand.left,
2609              mindBand->rcBand.top,
2610              maxdBand->rcBand.right,
2611              maxdBand->rcBand.bottom);
2612
2613     REBAR_MoveChildWindows (infoPtr, imindBand, imaxdBand+1);
2614
2615     InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
2616     UpdateWindow (infoPtr->hwndSelf);
2617
2618 }
2619
2620
2621
2622 /* << REBAR_BeginDrag >> */
2623
2624
2625 static LRESULT
2626 REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2627 {
2628     UINT uBand = (UINT)wParam;
2629     HWND childhwnd = 0;
2630     REBAR_BAND *lpBand;
2631
2632     if (uBand >= infoPtr->uNumBands)
2633         return FALSE;
2634
2635     TRACE("deleting band %u!\n", uBand);
2636     lpBand = &infoPtr->bands[uBand];
2637     REBAR_Notify_NMREBAR (infoPtr, uBand, RBN_DELETINGBAND);
2638
2639     if (infoPtr->uNumBands == 1) {
2640         TRACE(" simple delete!\n");
2641         if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2642             childhwnd = lpBand->hwndChild;
2643         Free (infoPtr->bands);
2644         infoPtr->bands = NULL;
2645         infoPtr->uNumBands = 0;
2646     }
2647     else {
2648         REBAR_BAND *oldBands = infoPtr->bands;
2649         TRACE("complex delete! [uBand=%u]\n", uBand);
2650
2651         if ((lpBand->fMask & RBBIM_CHILD) && lpBand->hwndChild)
2652             childhwnd = lpBand->hwndChild;
2653
2654         infoPtr->uNumBands--;
2655         infoPtr->bands = Alloc (sizeof (REBAR_BAND) * infoPtr->uNumBands);
2656         if (uBand > 0) {
2657             memcpy (&infoPtr->bands[0], &oldBands[0],
2658                     uBand * sizeof(REBAR_BAND));
2659         }
2660
2661         if (uBand < infoPtr->uNumBands) {
2662             memcpy (&infoPtr->bands[uBand], &oldBands[uBand+1],
2663                     (infoPtr->uNumBands - uBand) * sizeof(REBAR_BAND));
2664         }
2665
2666         Free (oldBands);
2667     }
2668
2669     if (childhwnd)
2670         ShowWindow (childhwnd, SW_HIDE);
2671
2672     REBAR_Notify_NMREBAR (infoPtr, -1, RBN_DELETEDBAND);
2673
2674     /* if only 1 band left the re-validate to possible eliminate gripper */
2675     if (infoPtr->uNumBands == 1)
2676       REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
2677
2678     TRACE("setting NEEDS_LAYOUT\n");
2679     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
2680     infoPtr->fStatus |= RESIZE_ANYHOW;
2681     REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
2682
2683     return TRUE;
2684 }
2685
2686
2687 /* << REBAR_DragMove >> */
2688 /* << REBAR_EndDrag >> */
2689
2690
2691 static LRESULT
2692 REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2693 {
2694     LPRECT lpRect = (LPRECT)lParam;
2695     REBAR_BAND *lpBand;
2696
2697     if (!lParam)
2698         return 0;
2699     if ((UINT)wParam >= infoPtr->uNumBands)
2700         return 0;
2701
2702     lpBand = &infoPtr->bands[(UINT)wParam];
2703
2704     /* FIXME - the following values were determined by experimentation */
2705     /* with the REBAR Control Spy. I have guesses as to what the 4 and */
2706     /* 1 are, but I am not sure. There doesn't seem to be any actual   */
2707     /* difference in size of the control area with and without the     */
2708     /* style.  -  GA                                                   */
2709     if (infoPtr->dwStyle & RBS_BANDBORDERS) {
2710         if (infoPtr->dwStyle & CCS_VERT) {
2711             lpRect->left = 1;
2712             lpRect->top = lpBand->cxHeader + 4;
2713             lpRect->right = 1;
2714             lpRect->bottom = 0;
2715         }
2716         else {
2717             lpRect->left = lpBand->cxHeader + 4;
2718             lpRect->top = 1;
2719             lpRect->right = 0;
2720             lpRect->bottom = 1;
2721         }
2722     }
2723     else {
2724         lpRect->left = lpBand->cxHeader;
2725     }
2726     return 0;
2727 }
2728
2729
2730 inline static LRESULT
2731 REBAR_GetBandCount (REBAR_INFO *infoPtr)
2732 {
2733     TRACE("band count %u!\n", infoPtr->uNumBands);
2734
2735     return infoPtr->uNumBands;
2736 }
2737
2738
2739 static LRESULT
2740 REBAR_GetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2741 {
2742     LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
2743     REBAR_BAND *lpBand;
2744
2745     if (lprbbi == NULL)
2746         return FALSE;
2747     if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
2748         return FALSE;
2749     if ((UINT)wParam >= infoPtr->uNumBands)
2750         return FALSE;
2751
2752     TRACE("index %u\n", (UINT)wParam);
2753
2754     /* copy band information */
2755     lpBand = &infoPtr->bands[(UINT)wParam];
2756
2757     if (lprbbi->fMask & RBBIM_STYLE)
2758         lprbbi->fStyle = lpBand->fStyle;
2759
2760     if (lprbbi->fMask & RBBIM_COLORS) {
2761         lprbbi->clrFore = lpBand->clrFore;
2762         lprbbi->clrBack = lpBand->clrBack;
2763         if (lprbbi->clrBack == CLR_DEFAULT)
2764             lprbbi->clrBack = infoPtr->clrBtnFace;
2765     }
2766
2767     if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2768       if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2769       {
2770           if (!WideCharToMultiByte( CP_ACP, 0, lpBand->lpText, -1,
2771                                     lprbbi->lpText, lprbbi->cch, NULL, NULL ))
2772               lprbbi->lpText[lprbbi->cch-1] = 0;
2773       }
2774       else
2775         *lprbbi->lpText = 0;
2776     }
2777
2778     if (lprbbi->fMask & RBBIM_IMAGE) {
2779       if (lpBand->fMask & RBBIM_IMAGE)
2780         lprbbi->iImage = lpBand->iImage;
2781       else
2782         lprbbi->iImage = -1;
2783     }
2784
2785     if (lprbbi->fMask & RBBIM_CHILD)
2786         lprbbi->hwndChild = lpBand->hwndChild;
2787
2788     if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2789         lprbbi->cxMinChild = lpBand->cxMinChild;
2790         lprbbi->cyMinChild = lpBand->cyMinChild;
2791         if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2792             lprbbi->cyChild    = lpBand->cyChild;
2793             lprbbi->cyMaxChild = lpBand->cyMaxChild;
2794             lprbbi->cyIntegral = lpBand->cyIntegral;
2795         }
2796     }
2797
2798     if (lprbbi->fMask & RBBIM_SIZE)
2799         lprbbi->cx = lpBand->cx;
2800
2801     if (lprbbi->fMask & RBBIM_BACKGROUND)
2802         lprbbi->hbmBack = lpBand->hbmBack;
2803
2804     if (lprbbi->fMask & RBBIM_ID)
2805         lprbbi->wID = lpBand->wID;
2806
2807     /* check for additional data */
2808     if (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) {
2809         if (lprbbi->fMask & RBBIM_IDEALSIZE)
2810             lprbbi->cxIdeal = lpBand->cxIdeal;
2811
2812         if (lprbbi->fMask & RBBIM_LPARAM)
2813             lprbbi->lParam = lpBand->lParam;
2814
2815         if (lprbbi->fMask & RBBIM_HEADERSIZE)
2816             lprbbi->cxHeader = lpBand->cxHeader;
2817     }
2818
2819     REBAR_DumpBandInfo (lprbbi);
2820
2821     return TRUE;
2822 }
2823
2824
2825 static LRESULT
2826 REBAR_GetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2827 {
2828     LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
2829     REBAR_BAND *lpBand;
2830
2831     if (lprbbi == NULL)
2832         return FALSE;
2833     if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
2834         return FALSE;
2835     if ((UINT)wParam >= infoPtr->uNumBands)
2836         return FALSE;
2837
2838     TRACE("index %u\n", (UINT)wParam);
2839
2840     /* copy band information */
2841     lpBand = &infoPtr->bands[(UINT)wParam];
2842
2843     if (lprbbi->fMask & RBBIM_STYLE)
2844         lprbbi->fStyle = lpBand->fStyle;
2845
2846     if (lprbbi->fMask & RBBIM_COLORS) {
2847         lprbbi->clrFore = lpBand->clrFore;
2848         lprbbi->clrBack = lpBand->clrBack;
2849         if (lprbbi->clrBack == CLR_DEFAULT)
2850             lprbbi->clrBack = infoPtr->clrBtnFace;
2851     }
2852
2853     if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
2854       if (lpBand->lpText && (lpBand->fMask & RBBIM_TEXT))
2855         lstrcpynW (lprbbi->lpText, lpBand->lpText, lprbbi->cch);
2856       else
2857         *lprbbi->lpText = 0;
2858     }
2859
2860     if (lprbbi->fMask & RBBIM_IMAGE) {
2861       if (lpBand->fMask & RBBIM_IMAGE)
2862         lprbbi->iImage = lpBand->iImage;
2863       else
2864         lprbbi->iImage = -1;
2865     }
2866
2867     if (lprbbi->fMask & RBBIM_CHILD)
2868         lprbbi->hwndChild = lpBand->hwndChild;
2869
2870     if (lprbbi->fMask & RBBIM_CHILDSIZE) {
2871         lprbbi->cxMinChild = lpBand->cxMinChild;
2872         lprbbi->cyMinChild = lpBand->cyMinChild;
2873         if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2874             lprbbi->cyChild    = lpBand->cyChild;
2875             lprbbi->cyMaxChild = lpBand->cyMaxChild;
2876             lprbbi->cyIntegral = lpBand->cyIntegral;
2877         }
2878     }
2879
2880     if (lprbbi->fMask & RBBIM_SIZE)
2881         lprbbi->cx = lpBand->cx;
2882
2883     if (lprbbi->fMask & RBBIM_BACKGROUND)
2884         lprbbi->hbmBack = lpBand->hbmBack;
2885
2886     if (lprbbi->fMask & RBBIM_ID)
2887         lprbbi->wID = lpBand->wID;
2888
2889     /* check for additional data */
2890     if (lprbbi->cbSize >= sizeof (REBARBANDINFOW)) {
2891         if (lprbbi->fMask & RBBIM_IDEALSIZE)
2892             lprbbi->cxIdeal = lpBand->cxIdeal;
2893
2894         if (lprbbi->fMask & RBBIM_LPARAM)
2895             lprbbi->lParam = lpBand->lParam;
2896
2897         if (lprbbi->fMask & RBBIM_HEADERSIZE)
2898             lprbbi->cxHeader = lpBand->cxHeader;
2899     }
2900
2901     REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
2902
2903     return TRUE;
2904 }
2905
2906
2907 static LRESULT
2908 REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2909 {
2910     INT nHeight;
2911
2912     nHeight = (infoPtr->dwStyle & CCS_VERT) ? infoPtr->calcSize.cx : infoPtr->calcSize.cy;
2913
2914     TRACE("height = %d\n", nHeight);
2915
2916     return nHeight;
2917 }
2918
2919
2920 static LRESULT
2921 REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2922 {
2923     LPREBARINFO lpInfo = (LPREBARINFO)lParam;
2924
2925     if (lpInfo == NULL)
2926         return FALSE;
2927
2928     if (lpInfo->cbSize < sizeof (REBARINFO))
2929         return FALSE;
2930
2931     TRACE("getting bar info!\n");
2932
2933     if (infoPtr->himl) {
2934         lpInfo->himl = infoPtr->himl;
2935         lpInfo->fMask |= RBIM_IMAGELIST;
2936     }
2937
2938     return TRUE;
2939 }
2940
2941
2942 inline static LRESULT
2943 REBAR_GetBkColor (REBAR_INFO *infoPtr)
2944 {
2945     COLORREF clr = infoPtr->clrBk;
2946
2947     if (clr == CLR_DEFAULT)
2948       clr = infoPtr->clrBtnFace;
2949
2950     TRACE("background color 0x%06lx!\n", clr);
2951
2952     return clr;
2953 }
2954
2955
2956 /* << REBAR_GetColorScheme >> */
2957 /* << REBAR_GetDropTarget >> */
2958
2959
2960 static LRESULT
2961 REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2962 {
2963     FIXME("empty stub!\n");
2964
2965     return 0;
2966 }
2967
2968
2969 static LRESULT
2970 REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
2971 {
2972     INT iBand = (INT)wParam;
2973     LPRECT lprc = (LPRECT)lParam;
2974     REBAR_BAND *lpBand;
2975
2976     if ((iBand < 0) && ((UINT)iBand >= infoPtr->uNumBands))
2977         return FALSE;
2978     if (!lprc)
2979         return FALSE;
2980
2981     lpBand = &infoPtr->bands[iBand];
2982     CopyRect (lprc, &lpBand->rcBand);
2983
2984     TRACE("band %d, (%ld,%ld)-(%ld,%ld)\n", iBand,
2985           lprc->left, lprc->top, lprc->right, lprc->bottom);
2986
2987     return TRUE;
2988 }
2989
2990
2991 inline static LRESULT
2992 REBAR_GetRowCount (REBAR_INFO *infoPtr)
2993 {
2994     TRACE("%u\n", infoPtr->uNumRows);
2995
2996     return infoPtr->uNumRows;
2997 }
2998
2999
3000 static LRESULT
3001 REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3002 {
3003     INT iRow = (INT)wParam;
3004     int j = 0, ret = 0;
3005     UINT i;
3006     REBAR_BAND *lpBand;
3007
3008     for (i=0; i<infoPtr->uNumBands; i++) {
3009         lpBand = &infoPtr->bands[i];
3010         if (HIDDENBAND(lpBand)) continue;
3011         if (lpBand->iRow != iRow) continue;
3012         if (infoPtr->dwStyle & CCS_VERT)
3013             j = lpBand->rcBand.right - lpBand->rcBand.left;
3014         else
3015             j = lpBand->rcBand.bottom - lpBand->rcBand.top;
3016         if (j > ret) ret = j;
3017     }
3018
3019     TRACE("row %d, height %d\n", iRow, ret);
3020
3021     return ret;
3022 }
3023
3024
3025 inline static LRESULT
3026 REBAR_GetTextColor (REBAR_INFO *infoPtr)
3027 {
3028     TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3029
3030     return infoPtr->clrText;
3031 }
3032
3033
3034 inline static LRESULT
3035 REBAR_GetToolTips (REBAR_INFO *infoPtr)
3036 {
3037     return (LRESULT)infoPtr->hwndToolTip;
3038 }
3039
3040
3041 inline static LRESULT
3042 REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
3043 {
3044     TRACE("%s hwnd=%p\n",
3045           infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
3046
3047     return infoPtr->bUnicode;
3048 }
3049
3050
3051 inline static LRESULT
3052 REBAR_GetVersion (REBAR_INFO *infoPtr)
3053 {
3054     TRACE("version %d\n", infoPtr->iVersion);
3055     return infoPtr->iVersion;
3056 }
3057
3058
3059 static LRESULT
3060 REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3061 {
3062     LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
3063
3064     if (!lprbht)
3065         return -1;
3066
3067     REBAR_InternalHitTest (infoPtr, &lprbht->pt, &lprbht->flags, &lprbht->iBand);
3068
3069     return lprbht->iBand;
3070 }
3071
3072
3073 static LRESULT
3074 REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3075 {
3076     UINT i;
3077
3078     if (infoPtr == NULL)
3079         return -1;
3080
3081     if (infoPtr->uNumBands < 1)
3082         return -1;
3083
3084     for (i = 0; i < infoPtr->uNumBands; i++) {
3085         if (infoPtr->bands[i].wID == (UINT)wParam) {
3086             TRACE("id %u is band %u found!\n", (UINT)wParam, i);
3087             return i;
3088         }
3089     }
3090
3091     TRACE("id %u is not found\n", (UINT)wParam);
3092     return -1;
3093 }
3094
3095
3096 static LRESULT
3097 REBAR_InsertBandA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3098 {
3099     LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3100     UINT uIndex = (UINT)wParam;
3101     REBAR_BAND *lpBand;
3102
3103     if (infoPtr == NULL)
3104         return FALSE;
3105     if (lprbbi == NULL)
3106         return FALSE;
3107     if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
3108         return FALSE;
3109
3110     /* trace the index as signed to see the -1 */
3111     TRACE("insert band at %d!\n", (INT)uIndex);
3112     REBAR_DumpBandInfo (lprbbi);
3113
3114     if (infoPtr->uNumBands == 0) {
3115         infoPtr->bands = (REBAR_BAND *)Alloc (sizeof (REBAR_BAND));
3116         uIndex = 0;
3117     }
3118     else {
3119         REBAR_BAND *oldBands = infoPtr->bands;
3120         infoPtr->bands =
3121             (REBAR_BAND *)Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3122         if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3123             uIndex = infoPtr->uNumBands;
3124
3125         /* pre insert copy */
3126         if (uIndex > 0) {
3127             memcpy (&infoPtr->bands[0], &oldBands[0],
3128                     uIndex * sizeof(REBAR_BAND));
3129         }
3130
3131         /* post copy */
3132         if (uIndex < infoPtr->uNumBands - 1) {
3133             memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3134                     (infoPtr->uNumBands - uIndex - 1) * sizeof(REBAR_BAND));
3135         }
3136
3137         Free (oldBands);
3138     }
3139
3140     infoPtr->uNumBands++;
3141
3142     TRACE("index %u!\n", uIndex);
3143
3144     /* initialize band (infoPtr->bands[uIndex])*/
3145     lpBand = &infoPtr->bands[uIndex];
3146     lpBand->fMask = 0;
3147     lpBand->fStatus = 0;
3148     lpBand->clrFore = infoPtr->clrText;
3149     lpBand->clrBack = infoPtr->clrBk;
3150     lpBand->hwndChild = 0;
3151     lpBand->hwndPrevParent = 0;
3152
3153     REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3154     lpBand->lpText = NULL;
3155     if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3156         INT len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3157         if (len > 1) {
3158             lpBand->lpText = (LPWSTR)Alloc (len*sizeof(WCHAR));
3159             MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, lpBand->lpText, len );
3160         }
3161     }
3162
3163     REBAR_ValidateBand (infoPtr, lpBand);
3164     /* On insert of second band, revalidate band 1 to possible add gripper */
3165     if (infoPtr->uNumBands == 2)
3166         REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
3167
3168     REBAR_DumpBand (infoPtr);
3169
3170     REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3171     InvalidateRect(infoPtr->hwndSelf, 0, 1);
3172
3173     return TRUE;
3174 }
3175
3176
3177 static LRESULT
3178 REBAR_InsertBandW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3179 {
3180     LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3181     UINT uIndex = (UINT)wParam;
3182     REBAR_BAND *lpBand;
3183
3184     if (infoPtr == NULL)
3185         return FALSE;
3186     if (lprbbi == NULL)
3187         return FALSE;
3188     if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
3189         return FALSE;
3190
3191     /* trace the index as signed to see the -1 */
3192     TRACE("insert band at %d!\n", (INT)uIndex);
3193     REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3194
3195     if (infoPtr->uNumBands == 0) {
3196         infoPtr->bands = (REBAR_BAND *)Alloc (sizeof (REBAR_BAND));
3197         uIndex = 0;
3198     }
3199     else {
3200         REBAR_BAND *oldBands = infoPtr->bands;
3201         infoPtr->bands =
3202             (REBAR_BAND *)Alloc ((infoPtr->uNumBands+1)*sizeof(REBAR_BAND));
3203         if (((INT)uIndex == -1) || (uIndex > infoPtr->uNumBands))
3204             uIndex = infoPtr->uNumBands;
3205
3206         /* pre insert copy */
3207         if (uIndex > 0) {
3208             memcpy (&infoPtr->bands[0], &oldBands[0],
3209                     uIndex * sizeof(REBAR_BAND));
3210         }
3211
3212         /* post copy */
3213         if (uIndex <= infoPtr->uNumBands - 1) {
3214             memcpy (&infoPtr->bands[uIndex+1], &oldBands[uIndex],
3215                     (infoPtr->uNumBands - uIndex) * sizeof(REBAR_BAND));
3216         }
3217
3218         Free (oldBands);
3219     }
3220
3221     infoPtr->uNumBands++;
3222
3223     TRACE("index %u!\n", uIndex);
3224
3225     /* initialize band (infoPtr->bands[uIndex])*/
3226     lpBand = &infoPtr->bands[uIndex];
3227     lpBand->fMask = 0;
3228     lpBand->fStatus = 0;
3229     lpBand->clrFore = infoPtr->clrText;
3230     lpBand->clrBack = infoPtr->clrBk;
3231     lpBand->hwndChild = 0;
3232     lpBand->hwndPrevParent = 0;
3233
3234     REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3235     lpBand->lpText = NULL;
3236     if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
3237         INT len = lstrlenW (lprbbi->lpText);
3238         if (len > 0) {
3239             lpBand->lpText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
3240             strcpyW (lpBand->lpText, lprbbi->lpText);
3241         }
3242     }
3243
3244     REBAR_ValidateBand (infoPtr, lpBand);
3245     /* On insert of second band, revalidate band 1 to possible add gripper */
3246     if (infoPtr->uNumBands == 2)
3247         REBAR_ValidateBand (infoPtr, &infoPtr->bands[uIndex ? 0 : 1]);
3248
3249     REBAR_DumpBand (infoPtr);
3250
3251     REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3252     InvalidateRect(infoPtr->hwndSelf, 0, 1);
3253
3254     return TRUE;
3255 }
3256
3257
3258 static LRESULT
3259 REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3260 {
3261     REBAR_BAND *lpBand;
3262     UINT uBand = (UINT) wParam;
3263
3264     /* Validate */
3265     if ((infoPtr->uNumBands == 0) ||
3266         ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3267         /* error !!! */
3268         ERR("Illegal MaximizeBand, requested=%d, current band count=%d\n",
3269               (INT)uBand, infoPtr->uNumBands);
3270         return FALSE;
3271     }
3272
3273     lpBand = &infoPtr->bands[uBand];
3274
3275     if (lParam && (lpBand->fMask & RBBIM_IDEALSIZE)) {
3276         /* handle setting ideal size */
3277         lpBand->ccx = lpBand->cxIdeal;
3278     }
3279     else {
3280         /* handle setting to max */
3281         FIXME("(uBand = %u fIdeal = %s) case not coded\n",
3282               (UINT)wParam, lParam ? "TRUE" : "FALSE");
3283         return FALSE;
3284     }
3285
3286     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3287     REBAR_Layout (infoPtr, 0, TRUE, TRUE);
3288     InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
3289
3290     return TRUE;
3291
3292 }
3293
3294
3295 static LRESULT
3296 REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3297 {
3298     REBAR_BAND *band, *lpBand;
3299     UINT uBand = (UINT) wParam;
3300     RECT newrect;
3301     INT imindBand, imaxdBand, iprevBand, startBand, endBand;
3302     INT movement, i;
3303
3304     /* A "minimize" band is equivalent to "dragging" the gripper
3305      * of than band to the right till the band is only the size
3306      * of the cxHeader.
3307      */
3308
3309     /* Validate */
3310     if ((infoPtr->uNumBands == 0) ||
3311         ((INT)uBand < 0) || (uBand >= infoPtr->uNumBands)) {
3312         /* error !!! */
3313         ERR("Illegal MinimizeBand, requested=%d, current band count=%d\n",
3314               (INT)uBand, infoPtr->uNumBands);
3315         return FALSE;
3316     }
3317
3318     /* compute amount of movement and validate */
3319     lpBand = &infoPtr->bands[uBand];
3320
3321     if (infoPtr->dwStyle & CCS_VERT)
3322         movement = lpBand->rcBand.bottom - lpBand->rcBand.top -
3323             lpBand->cxHeader;
3324     else
3325         movement = lpBand->rcBand.right - lpBand->rcBand.left -
3326             lpBand->cxHeader;
3327     if (movement < 0) {
3328         ERR("something is wrong, band=(%ld,%ld)-(%ld,%ld), cxheader=%d\n",
3329             lpBand->rcBand.left, lpBand->rcBand.top,
3330             lpBand->rcBand.right, lpBand->rcBand.bottom,
3331             lpBand->cxHeader);
3332         return FALSE;
3333     }
3334
3335     imindBand = -1;
3336     imaxdBand = -1;
3337     iprevBand = -1; /* to suppress warning message */
3338
3339     /* find the first band in row of the one whose is being minimized */
3340     for (i=0; i<infoPtr->uNumBands; i++) {
3341         band = &infoPtr->bands[i];
3342         if (HIDDENBAND(band)) continue;
3343         if (band->iRow == lpBand->iRow) {
3344             imaxdBand = i;
3345             if (imindBand == -1) imindBand = i;
3346         }
3347     }
3348
3349     /* if the selected band is first in row then need to expand */
3350     /* next visible band                                        */
3351     if (imindBand == uBand) {
3352         band = NULL;
3353         movement = -movement;
3354         /* find the first visible band to the right of the selected band */
3355         for (i=uBand+1; i<=imaxdBand; i++) {
3356             band = &infoPtr->bands[i];
3357             if (!HIDDENBAND(band)) {
3358                 iprevBand = i;
3359                 LEADJ(band, movement);
3360                 band->ccx = rcBw(band);
3361                 break;
3362             }
3363         }
3364         /* what case is this */
3365         if (iprevBand == -1) {
3366             ERR("no previous visible band\n");
3367             return FALSE;
3368         }
3369         startBand = uBand;
3370         endBand = iprevBand;
3371         SetRect (&newrect,
3372                  lpBand->rcBand.left,
3373                  lpBand->rcBand.top,
3374                  band->rcBand.right,
3375                  band->rcBand.bottom);
3376     }
3377     /* otherwise expand previous visible band                   */
3378     else {
3379         band = NULL;
3380         /* find the first visible band to the left of the selected band */
3381         for (i=uBand-1; i>=imindBand; i--) {
3382             band = &infoPtr->bands[i];
3383             if (!HIDDENBAND(band)) {
3384                 iprevBand = i;
3385                 READJ(band, movement);
3386                 band->ccx = rcBw(band);
3387                 break;
3388             }
3389         }
3390         /* what case is this */
3391         if (iprevBand == -1) {
3392             ERR("no previous visible band\n");
3393             return FALSE;
3394         }
3395         startBand = iprevBand;
3396         endBand = uBand;
3397         SetRect (&newrect,
3398                  band->rcBand.left,
3399                  band->rcBand.top,
3400                  lpBand->rcBand.right,
3401                  lpBand->rcBand.bottom);
3402     }
3403
3404     REBAR_Shrink (infoPtr, lpBand, movement, uBand);
3405
3406     /* recompute all rectangles */
3407     if (infoPtr->dwStyle & CCS_VERT) {
3408         REBAR_CalcVertBand (infoPtr, startBand, endBand+1,
3409                             FALSE);
3410     }
3411     else {
3412         REBAR_CalcHorzBand (infoPtr, startBand, endBand+1,
3413                             FALSE);
3414     }
3415
3416     TRACE("bands after minimize, see band # %d, %d\n",
3417           startBand, endBand);
3418     REBAR_DumpBand (infoPtr);
3419
3420     REBAR_MoveChildWindows (infoPtr, startBand, endBand+1);
3421
3422     InvalidateRect (infoPtr->hwndSelf, &newrect, TRUE);
3423     UpdateWindow (infoPtr->hwndSelf);
3424     return FALSE;
3425 }
3426
3427
3428 static LRESULT
3429 REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3430 {
3431     REBAR_BAND *oldBands = infoPtr->bands;
3432     REBAR_BAND holder;
3433     UINT uFrom = (UINT)wParam;
3434     UINT uTo = (UINT)lParam;
3435
3436     /* Validate */
3437     if ((infoPtr->uNumBands == 0) ||
3438         ((INT)uFrom < 0) || (uFrom >= infoPtr->uNumBands) ||
3439         ((INT)uTo < 0)   || (uTo >= infoPtr->uNumBands)) {
3440         /* error !!! */
3441         ERR("Illegal MoveBand, from=%d, to=%d, current band count=%d\n",
3442               (INT)uFrom, (INT)uTo, infoPtr->uNumBands);
3443         return FALSE;
3444     }
3445
3446     /* save one to be moved */
3447     memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
3448
3449     /* close up rest of bands (pseudo delete) */
3450     if (uFrom < infoPtr->uNumBands - 1) {
3451         memcpy (&oldBands[uFrom], &oldBands[uFrom+1],
3452                 (infoPtr->uNumBands - uFrom - 1) * sizeof(REBAR_BAND));
3453     }
3454
3455     /* allocate new space and copy rest of bands into it */
3456     infoPtr->bands =
3457         (REBAR_BAND *)Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
3458
3459     /* pre insert copy */
3460     if (uTo > 0) {
3461         memcpy (&infoPtr->bands[0], &oldBands[0],
3462                 uTo * sizeof(REBAR_BAND));
3463     }
3464
3465     /* set moved band */
3466     memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
3467
3468     /* post copy */
3469     if (uTo < infoPtr->uNumBands - 1) {
3470         memcpy (&infoPtr->bands[uTo+1], &oldBands[uTo],
3471                 (infoPtr->uNumBands - uTo - 1) * sizeof(REBAR_BAND));
3472     }
3473
3474     Free (oldBands);
3475
3476     TRACE("moved band %d to index %d\n", uFrom, uTo);
3477     REBAR_DumpBand (infoPtr);
3478
3479     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3480     /* **************************************************** */
3481     /*                                                      */
3482     /* We do not do a REBAR_Layout here because the native  */
3483     /* control does not do that. The actual layout and      */
3484     /* repaint is done by the *next* real action, ex.:      */
3485     /* RB_INSERTBAND, RB_DELETEBAND, RB_SIZETORECT, etc.    */
3486     /*                                                      */
3487     /* **************************************************** */
3488
3489     return TRUE;
3490 }
3491
3492
3493 /* return TRUE if two strings are different */
3494 static BOOL
3495 REBAR_strdifW( LPCWSTR a, LPCWSTR b )
3496 {
3497     return ( (a && !b) || (b && !a) || (a && b && lstrcmpW(a, b) ) );
3498 }
3499
3500 static LRESULT
3501 REBAR_SetBandInfoA (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3502 {
3503     LPREBARBANDINFOA lprbbi = (LPREBARBANDINFOA)lParam;
3504     REBAR_BAND *lpBand;
3505     BOOL bChanged;
3506
3507     if (lprbbi == NULL)
3508         return FALSE;
3509     if (lprbbi->cbSize < REBARBANDINFOA_V3_SIZE)
3510         return FALSE;
3511     if ((UINT)wParam >= infoPtr->uNumBands)
3512         return FALSE;
3513
3514     TRACE("index %u\n", (UINT)wParam);
3515     REBAR_DumpBandInfo (lprbbi);
3516
3517     /* set band information */
3518     lpBand = &infoPtr->bands[(UINT)wParam];
3519
3520     bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
3521     if (lprbbi->fMask & RBBIM_TEXT) {
3522         LPWSTR wstr = NULL;
3523
3524         if (lprbbi->lpText)
3525         {
3526             INT len;
3527             len = MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, NULL, 0 );
3528             if (len > 1)
3529                 wstr = (LPWSTR)Alloc (len*sizeof(WCHAR));
3530             if (wstr)
3531                 MultiByteToWideChar( CP_ACP, 0, lprbbi->lpText, -1, wstr, len );
3532         }
3533         if (REBAR_strdifW(lpBand->lpText, wstr)) {
3534             if (lpBand->lpText) {
3535                 Free (lpBand->lpText);
3536                 lpBand->lpText = NULL;
3537             }
3538             if (wstr) {
3539                 lpBand->lpText = wstr;
3540                 wstr = NULL;
3541             }
3542             bChanged = TRUE;
3543         }
3544         if (wstr)
3545             Free (wstr);
3546     }
3547
3548     REBAR_ValidateBand (infoPtr, lpBand);
3549
3550     REBAR_DumpBand (infoPtr);
3551
3552     if (bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE))) {
3553           REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3554           InvalidateRect(infoPtr->hwndSelf, 0, 1);
3555     }
3556
3557     return TRUE;
3558 }
3559
3560 static LRESULT
3561 REBAR_SetBandInfoW (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3562 {
3563     LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
3564     REBAR_BAND *lpBand;
3565     BOOL bChanged;
3566
3567     if (lprbbi == NULL)
3568         return FALSE;
3569     if (lprbbi->cbSize < REBARBANDINFOW_V3_SIZE)
3570         return FALSE;
3571     if ((UINT)wParam >= infoPtr->uNumBands)
3572         return FALSE;
3573
3574     TRACE("index %u\n", (UINT)wParam);
3575     REBAR_DumpBandInfo ((LPREBARBANDINFOA)lprbbi);
3576
3577     /* set band information */
3578     lpBand = &infoPtr->bands[(UINT)wParam];
3579
3580     bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, (LPREBARBANDINFOA)lprbbi, lpBand);
3581     if( (lprbbi->fMask & RBBIM_TEXT) && 
3582         REBAR_strdifW( lpBand->lpText, lprbbi->lpText ) ) {
3583         if (lpBand->lpText) {
3584             Free (lpBand->lpText);
3585             lpBand->lpText = NULL;
3586         }
3587         if (lprbbi->lpText) {
3588             INT len = lstrlenW (lprbbi->lpText);
3589             if (len > 0)
3590             {
3591                 lpBand->lpText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
3592                 strcpyW (lpBand->lpText, lprbbi->lpText);
3593             }
3594         }
3595         bChanged = TRUE;
3596     }
3597
3598     REBAR_ValidateBand (infoPtr, lpBand);
3599
3600     REBAR_DumpBand (infoPtr);
3601
3602     if ( bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE)) ) {
3603       REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3604       InvalidateRect(infoPtr->hwndSelf, 0, 1);
3605     }
3606
3607     return TRUE;
3608 }
3609
3610
3611 static LRESULT
3612 REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3613 {
3614     LPREBARINFO lpInfo = (LPREBARINFO)lParam;
3615     REBAR_BAND *lpBand;
3616     UINT i;
3617
3618     if (lpInfo == NULL)
3619         return FALSE;
3620
3621     if (lpInfo->cbSize < sizeof (REBARINFO))
3622         return FALSE;
3623
3624     TRACE("setting bar info!\n");
3625
3626     if (lpInfo->fMask & RBIM_IMAGELIST) {
3627         infoPtr->himl = lpInfo->himl;
3628         if (infoPtr->himl) {
3629             INT cx, cy;
3630             ImageList_GetIconSize (infoPtr->himl, &cx, &cy);
3631             infoPtr->imageSize.cx = cx;
3632             infoPtr->imageSize.cy = cy;
3633         }
3634         else {
3635             infoPtr->imageSize.cx = 0;
3636             infoPtr->imageSize.cy = 0;
3637         }
3638         TRACE("new image cx=%ld, cy=%ld\n", infoPtr->imageSize.cx,
3639               infoPtr->imageSize.cy);
3640     }
3641
3642     /* revalidate all bands to reset flags for images in headers of bands */
3643     for (i=0; i<infoPtr->uNumBands; i++) {
3644         lpBand = &infoPtr->bands[i];
3645         REBAR_ValidateBand (infoPtr, lpBand);
3646     }
3647
3648     return TRUE;
3649 }
3650
3651
3652 static LRESULT
3653 REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3654 {
3655     COLORREF clrTemp;
3656
3657     clrTemp = infoPtr->clrBk;
3658     infoPtr->clrBk = (COLORREF)lParam;
3659
3660     TRACE("background color 0x%06lx!\n", infoPtr->clrBk);
3661
3662     return clrTemp;
3663 }
3664
3665
3666 /* << REBAR_SetColorScheme >> */
3667 /* << REBAR_SetPalette >> */
3668
3669
3670 static LRESULT
3671 REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3672 {
3673     HWND hwndTemp = infoPtr->hwndNotify;
3674
3675     infoPtr->hwndNotify = (HWND)wParam;
3676
3677     return (LRESULT)hwndTemp;
3678 }
3679
3680
3681 static LRESULT
3682 REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3683 {
3684     COLORREF clrTemp;
3685
3686     clrTemp = infoPtr->clrText;
3687     infoPtr->clrText = (COLORREF)lParam;
3688
3689     TRACE("text color 0x%06lx!\n", infoPtr->clrText);
3690
3691     return clrTemp;
3692 }
3693
3694
3695 /* << REBAR_SetTooltips >> */
3696
3697
3698 inline static LRESULT
3699 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
3700 {
3701     BOOL bTemp = infoPtr->bUnicode;
3702
3703     TRACE("to %s hwnd=%p, was %s\n",
3704           ((BOOL)wParam) ? "TRUE" : "FALSE", infoPtr->hwndSelf,
3705           (bTemp) ? "TRUE" : "FALSE");
3706
3707     infoPtr->bUnicode = (BOOL)wParam;
3708
3709    return bTemp;
3710 }
3711
3712
3713 static LRESULT
3714 REBAR_SetVersion (REBAR_INFO *infoPtr, INT iVersion)
3715 {
3716     INT iOldVersion = infoPtr->iVersion;
3717
3718     if (iVersion > COMCTL32_VERSION)
3719         return -1;
3720
3721     infoPtr->iVersion = iVersion;
3722
3723     TRACE("new version %d\n", iVersion);
3724
3725     return iOldVersion;
3726 }
3727
3728
3729 static LRESULT
3730 REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3731 {
3732     REBAR_BAND *lpBand;
3733
3734     if (((INT)wParam < 0) || ((INT)wParam > infoPtr->uNumBands))
3735         return FALSE;
3736
3737     lpBand = &infoPtr->bands[(INT)wParam];
3738
3739     if ((BOOL)lParam) {
3740         TRACE("show band %d\n", (INT)wParam);
3741         lpBand->fStyle = lpBand->fStyle & ~RBBS_HIDDEN;
3742         if (IsWindow (lpBand->hwndChild))
3743             ShowWindow (lpBand->hwndChild, SW_SHOW);
3744     }
3745     else {
3746         TRACE("hide band %d\n", (INT)wParam);
3747         lpBand->fStyle = lpBand->fStyle | RBBS_HIDDEN;
3748         if (IsWindow (lpBand->hwndChild))
3749             ShowWindow (lpBand->hwndChild, SW_HIDE);
3750     }
3751
3752     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3753     REBAR_Layout (infoPtr, NULL, TRUE, FALSE);
3754     InvalidateRect(infoPtr->hwndSelf, 0, 1);
3755
3756     return TRUE;
3757 }
3758
3759
3760 static LRESULT
3761 REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3762 {
3763     LPRECT lpRect = (LPRECT)lParam;
3764     RECT t1;
3765
3766     if (lpRect == NULL)
3767        return FALSE;
3768
3769     TRACE("[%ld %ld %ld %ld]\n",
3770           lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
3771
3772     /*  what is going on???? */
3773     GetWindowRect(infoPtr->hwndSelf, &t1);
3774     TRACE("window rect [%ld %ld %ld %ld]\n",
3775           t1.left, t1.top, t1.right, t1.bottom);
3776     GetClientRect(infoPtr->hwndSelf, &t1);
3777     TRACE("client rect [%ld %ld %ld %ld]\n",
3778           t1.left, t1.top, t1.right, t1.bottom);
3779
3780     /* force full _Layout processing */
3781     TRACE("setting NEEDS_LAYOUT\n");
3782     infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
3783     REBAR_Layout (infoPtr, lpRect, TRUE, FALSE);
3784     InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
3785     return TRUE;
3786 }
3787
3788
3789
3790 static LRESULT
3791 REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3792 {
3793     LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
3794     RECT wnrc1, clrc1;
3795
3796     if (TRACE_ON(rebar)) {
3797         GetWindowRect(infoPtr->hwndSelf, &wnrc1);
3798         GetClientRect(infoPtr->hwndSelf, &clrc1);
3799         TRACE("window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) cs=(%d,%d %dx%d)\n",
3800               wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
3801               clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
3802               cs->x, cs->y, cs->cx, cs->cy);
3803     }
3804
3805     TRACE("created!\n");
3806     return 0;
3807 }
3808
3809
3810 static LRESULT
3811 REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3812 {
3813     REBAR_BAND *lpBand;
3814     UINT i;
3815
3816
3817     /* free rebar bands */
3818     if ((infoPtr->uNumBands > 0) && infoPtr->bands) {
3819         /* clean up each band */
3820         for (i = 0; i < infoPtr->uNumBands; i++) {
3821             lpBand = &infoPtr->bands[i];
3822
3823             /* delete text strings */
3824             if (lpBand->lpText) {
3825                 Free (lpBand->lpText);
3826                 lpBand->lpText = NULL;
3827             }
3828             /* destroy child window */
3829             DestroyWindow (lpBand->hwndChild);
3830         }
3831
3832         /* free band array */
3833         Free (infoPtr->bands);
3834         infoPtr->bands = NULL;
3835     }
3836
3837     DeleteObject (infoPtr->hcurArrow);
3838     DeleteObject (infoPtr->hcurHorz);
3839     DeleteObject (infoPtr->hcurVert);
3840     DeleteObject (infoPtr->hcurDrag);
3841     if(infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
3842     SetWindowLongA (infoPtr->hwndSelf, 0, 0);
3843
3844     /* free rebar info data */
3845     Free (infoPtr);
3846     TRACE("destroyed!\n");
3847     return 0;
3848 }
3849
3850
3851 static LRESULT
3852 REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3853 {
3854     RECT cliprect;
3855
3856     if (GetClipBox ( (HDC)wParam, &cliprect))
3857         return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
3858     return 0;
3859 }
3860
3861
3862 static LRESULT
3863 REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3864 {
3865     return (LRESULT)infoPtr->hFont;
3866 }
3867
3868 static LRESULT
3869 REBAR_PushChevron(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3870 {
3871     if (wParam >= 0 && (UINT)wParam < infoPtr->uNumBands)
3872     {
3873         NMREBARCHEVRON nmrbc;
3874         REBAR_BAND *lpBand = &infoPtr->bands[wParam];
3875
3876         TRACE("Pressed chevron on band %d\n", wParam);
3877
3878         /* redraw chevron in pushed state */
3879         lpBand->fDraw |= DRAW_CHEVRONPUSHED;
3880         RedrawWindow(infoPtr->hwndSelf, &lpBand->rcChevron,0,
3881           RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW);
3882
3883         /* notify app so it can display a popup menu or whatever */
3884         nmrbc.uBand = wParam;
3885         nmrbc.wID = lpBand->wID;
3886         nmrbc.lParam = lpBand->lParam;
3887         nmrbc.rc = lpBand->rcChevron;
3888         nmrbc.lParamNM = lParam;
3889         REBAR_Notify((NMHDR*)&nmrbc, infoPtr, RBN_CHEVRONPUSHED);
3890
3891         /* redraw chevron in previous state */
3892         lpBand->fDraw &= ~DRAW_CHEVRONPUSHED;
3893         InvalidateRect(infoPtr->hwndSelf, &lpBand->rcChevron, TRUE);
3894
3895         return TRUE;
3896     }
3897     return FALSE;
3898 }
3899
3900 static LRESULT
3901 REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3902 {
3903     REBAR_BAND *lpBand;
3904     UINT htFlags;
3905     UINT iHitBand;
3906     POINT ptMouseDown;
3907     ptMouseDown.x = (INT)LOWORD(lParam);
3908     ptMouseDown.y = (INT)HIWORD(lParam);
3909
3910     REBAR_InternalHitTest(infoPtr, &ptMouseDown, &htFlags, &iHitBand);
3911     lpBand = &infoPtr->bands[iHitBand];
3912
3913     if (htFlags == RBHT_CHEVRON)
3914     {
3915         REBAR_PushChevron(infoPtr, iHitBand, 0);
3916     }
3917     else if (htFlags == RBHT_GRABBER || htFlags == RBHT_CAPTION)
3918     {
3919         TRACE("Starting drag\n");
3920
3921         SetCapture (infoPtr->hwndSelf);
3922         infoPtr->iGrabbedBand = iHitBand;
3923
3924         /* save off the LOWORD and HIWORD of lParam as initial x,y */
3925         infoPtr->dragStart = MAKEPOINTS(lParam);
3926         infoPtr->dragNow = infoPtr->dragStart;
3927         if (infoPtr->dwStyle & CCS_VERT)
3928             infoPtr->ihitoffset = infoPtr->dragStart.y - (lpBand->rcBand.top+REBAR_PRE_GRIPPER);
3929         else
3930             infoPtr->ihitoffset = infoPtr->dragStart.x - (lpBand->rcBand.left+REBAR_PRE_GRIPPER);
3931     }
3932     return 0;
3933 }
3934
3935 static LRESULT
3936 REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3937 {
3938     if (infoPtr->iGrabbedBand >= 0)
3939     {
3940         NMHDR layout;
3941         RECT rect;
3942
3943         infoPtr->dragStart.x = 0;
3944         infoPtr->dragStart.y = 0;
3945         infoPtr->dragNow = infoPtr->dragStart;
3946
3947         ReleaseCapture ();
3948
3949         if (infoPtr->fStatus & BEGIN_DRAG_ISSUED) {
3950             REBAR_Notify(&layout, infoPtr, RBN_LAYOUTCHANGED);
3951             REBAR_Notify_NMREBAR (infoPtr, infoPtr->iGrabbedBand, RBN_ENDDRAG);
3952             infoPtr->fStatus &= ~BEGIN_DRAG_ISSUED;
3953         }
3954
3955         infoPtr->iGrabbedBand = -1;
3956
3957         GetClientRect(infoPtr->hwndSelf, &rect);
3958         InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
3959     }
3960
3961     return 0;
3962 }
3963
3964 static LRESULT
3965 REBAR_MouseLeave (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3966 {
3967     if (infoPtr->ichevronhotBand >= 0)
3968     {
3969         REBAR_BAND *lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
3970         if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
3971         {
3972             lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
3973             InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
3974         }
3975     }
3976     infoPtr->iOldBand = -1;
3977     infoPtr->ichevronhotBand = -2;
3978
3979     return TRUE;
3980 }
3981
3982 static LRESULT
3983 REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3984 {
3985     REBAR_BAND *lpChevronBand;
3986     POINTS ptsmove;
3987
3988     ptsmove = MAKEPOINTS(lParam);
3989
3990     /* if we are currently dragging a band */
3991     if (infoPtr->iGrabbedBand >= 0)
3992     {
3993         REBAR_BAND *band1, *band2;
3994     
3995         if (GetCapture() != infoPtr->hwndSelf)
3996             ERR("We are dragging but haven't got capture?!?\n");
3997
3998         band1 = &infoPtr->bands[infoPtr->iGrabbedBand-1];
3999         band2 = &infoPtr->bands[infoPtr->iGrabbedBand];
4000
4001         /* if mouse did not move much, exit */
4002         if ((abs(ptsmove.x - infoPtr->dragNow.x) <= mindragx) &&
4003             (abs(ptsmove.y - infoPtr->dragNow.y) <= mindragy)) return 0;
4004
4005         /* Test for valid drag case - must not be first band in row */
4006         if (infoPtr->dwStyle & CCS_VERT) {
4007             if ((ptsmove.x < band2->rcBand.left) ||
4008               (ptsmove.x > band2->rcBand.right) ||
4009               ((infoPtr->iGrabbedBand > 0) && (band1->iRow != band2->iRow))) {
4010                 FIXME("Cannot drag to other rows yet!!\n");
4011             }
4012             else {
4013                 REBAR_HandleLRDrag (infoPtr, &ptsmove);
4014             }
4015         }
4016         else {
4017             if ((ptsmove.y < band2->rcBand.top) ||
4018               (ptsmove.y > band2->rcBand.bottom) ||
4019               ((infoPtr->iGrabbedBand > 0) && (band1->iRow != band2->iRow))) {
4020                 FIXME("Cannot drag to other rows yet!!\n");
4021             }
4022             else {
4023                 REBAR_HandleLRDrag (infoPtr, &ptsmove);
4024             }
4025         }
4026     }
4027     else
4028     {
4029         POINT ptMove;
4030         INT iHitBand;
4031         UINT htFlags;
4032         TRACKMOUSEEVENT trackinfo;
4033
4034         ptMove.x = (INT)ptsmove.x;
4035         ptMove.y = (INT)ptsmove.y;
4036         REBAR_InternalHitTest(infoPtr, &ptMove, &htFlags, &iHitBand);
4037
4038         if (infoPtr->iOldBand >= 0 && infoPtr->iOldBand == infoPtr->ichevronhotBand)
4039         {
4040             lpChevronBand = &infoPtr->bands[infoPtr->ichevronhotBand];
4041             if (lpChevronBand->fDraw & DRAW_CHEVRONHOT)
4042             {
4043                 lpChevronBand->fDraw &= ~DRAW_CHEVRONHOT;
4044                 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
4045             }
4046             infoPtr->ichevronhotBand = -2;
4047         }
4048
4049         if (htFlags == RBHT_CHEVRON)
4050         {
4051             /* fill in the TRACKMOUSEEVENT struct */
4052             trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
4053             trackinfo.dwFlags = TME_QUERY;
4054             trackinfo.hwndTrack = infoPtr->hwndSelf;
4055             trackinfo.dwHoverTime = 0;
4056
4057             /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
4058             _TrackMouseEvent(&trackinfo);
4059
4060             /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
4061             if(!(trackinfo.dwFlags & TME_LEAVE))
4062             {
4063                 trackinfo.dwFlags = TME_LEAVE; /* notify upon leaving */
4064
4065                 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
4066                 /* and can properly deactivate the hot chevron */
4067                 _TrackMouseEvent(&trackinfo);
4068             }
4069
4070             lpChevronBand = &infoPtr->bands[iHitBand];
4071             if (!(lpChevronBand->fDraw & DRAW_CHEVRONHOT))
4072             {
4073                 lpChevronBand->fDraw |= DRAW_CHEVRONHOT;
4074                 InvalidateRect(infoPtr->hwndSelf, &lpChevronBand->rcChevron, TRUE);
4075                 infoPtr->ichevronhotBand = iHitBand;
4076             }
4077         }
4078         infoPtr->iOldBand = iHitBand;
4079     }
4080
4081     return 0;
4082 }
4083
4084
4085 inline static LRESULT
4086 REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4087 {
4088     if (infoPtr->dwStyle & WS_BORDER) {
4089         InflateRect((LPRECT)lParam, -GetSystemMetrics(SM_CXEDGE),
4090                     -GetSystemMetrics(SM_CYEDGE));
4091     }
4092     TRACE("new client=(%ld,%ld)-(%ld,%ld)\n",
4093           ((LPRECT)lParam)->left, ((LPRECT)lParam)->top,
4094           ((LPRECT)lParam)->right, ((LPRECT)lParam)->bottom);
4095     return 0;
4096 }
4097
4098
4099 static LRESULT
4100 REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
4101 {
4102     LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
4103     REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4104     RECT wnrc1, clrc1;
4105     NONCLIENTMETRICSA ncm;
4106     HFONT tfont;
4107     INT i;
4108
4109     if (infoPtr != NULL) {
4110         ERR("Strange info structure pointer *not* NULL\n");
4111         return FALSE;
4112     }
4113
4114     if (TRACE_ON(rebar)) {
4115         GetWindowRect(hwnd, &wnrc1);
4116         GetClientRect(hwnd, &clrc1);
4117         TRACE("window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) cs=(%d,%d %dx%d)\n",
4118               wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
4119               clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
4120               cs->x, cs->y, cs->cx, cs->cy);
4121     }
4122
4123     /* allocate memory for info structure */
4124     infoPtr = (REBAR_INFO *)Alloc (sizeof(REBAR_INFO));
4125     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
4126
4127     /* initialize info structure - initial values are 0 */
4128     infoPtr->clrBk = CLR_NONE;
4129     infoPtr->clrText = CLR_NONE;
4130     infoPtr->clrBtnText = GetSysColor (COLOR_BTNTEXT);
4131     infoPtr->clrBtnFace = GetSysColor (COLOR_BTNFACE);
4132     infoPtr->iOldBand = -1;
4133     infoPtr->ichevronhotBand = -2;
4134     infoPtr->iGrabbedBand = -1;
4135     infoPtr->hwndSelf = hwnd;
4136     infoPtr->DoRedraw = TRUE;
4137     infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
4138     infoPtr->hcurHorz  = LoadCursorA (0, (LPSTR)IDC_SIZEWE);
4139     infoPtr->hcurVert  = LoadCursorA (0, (LPSTR)IDC_SIZENS);
4140     infoPtr->hcurDrag  = LoadCursorA (0, (LPSTR)IDC_SIZE);
4141     infoPtr->bUnicode = IsWindowUnicode (hwnd);
4142     infoPtr->fStatus = CREATE_RUNNING;
4143     infoPtr->hFont = GetStockObject (SYSTEM_FONT);
4144
4145     /* issue WM_NOTIFYFORMAT to get unicode status of parent */
4146     i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4147                      WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
4148     if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4149         ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4150             i);
4151         i = NFR_ANSI;
4152     }
4153     infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4154
4155     /* add necessary styles to the requested styles */
4156     infoPtr->dwStyle = cs->style | WS_VISIBLE | CCS_TOP;
4157     SetWindowLongA (hwnd, GWL_STYLE, infoPtr->dwStyle);
4158
4159     /* get font handle for Caption Font */
4160     ncm.cbSize = sizeof(NONCLIENTMETRICSA);
4161     SystemParametersInfoA (SPI_GETNONCLIENTMETRICS,
4162                           ncm.cbSize, &ncm, 0);
4163     /* if the font is bold, set to normal */
4164     if (ncm.lfCaptionFont.lfWeight > FW_NORMAL) {
4165         ncm.lfCaptionFont.lfWeight = FW_NORMAL;
4166     }
4167     tfont = CreateFontIndirectA (&ncm.lfCaptionFont);
4168     if (tfont) {
4169         infoPtr->hFont = infoPtr->hDefaultFont = tfont;
4170     }
4171
4172 /* native does:
4173             GetSysColor (numerous);
4174             GetSysColorBrush (numerous) (see WM_SYSCOLORCHANGE);
4175            *GetStockObject (SYSTEM_FONT);
4176            *SetWindowLong (hwnd, 0, info ptr);
4177            *WM_NOTIFYFORMAT;
4178            *SetWindowLong (hwnd, GWL_STYLE, style+0x10000001);
4179                                     WS_VISIBLE = 0x10000000;
4180                                     CCS_TOP    = 0x00000001;
4181            *SystemParametersInfo (SPI_GETNONCLIENTMETRICS...);
4182            *CreateFontIndirect (lfCaptionFont from above);
4183             GetDC ();
4184             SelectObject (hdc, fontabove);
4185             GetTextMetrics (hdc, );    guessing is tmHeight
4186             SelectObject (hdc, oldfont);
4187             ReleaseDC ();
4188             GetWindowRect ();
4189             MapWindowPoints (0, parent, rectabove, 2);
4190             GetWindowRect ();
4191             GetClientRect ();
4192             ClientToScreen (clientrect);
4193             SetWindowPos (hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER);
4194  */
4195     return TRUE;
4196 }
4197
4198
4199 static LRESULT
4200 REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4201 {
4202     NMMOUSE nmmouse;
4203     POINTS shortpt;
4204     POINT clpt, pt;
4205     INT i;
4206     UINT scrap;
4207     LRESULT ret = HTCLIENT;
4208
4209     /*
4210      * Differences from doc at MSDN (as observed with version 4.71 of
4211      *      comctl32.dll
4212      * 1. doc says nmmouse.pt is in screen coord, trace shows client coord.
4213      * 2. if band is not identified .dwItemSpec is 0xffffffff.
4214      * 3. native always seems to return HTCLIENT if notify return is 0.
4215      */
4216
4217     shortpt = MAKEPOINTS (lParam);
4218     POINTSTOPOINT(pt, shortpt);
4219     clpt = pt;
4220     ScreenToClient (infoPtr->hwndSelf, &clpt);
4221     REBAR_InternalHitTest (infoPtr, &clpt, &scrap,
4222                            (INT *)&nmmouse.dwItemSpec);
4223     nmmouse.dwItemData = 0;
4224     nmmouse.pt = clpt;
4225     nmmouse.dwHitInfo = 0;
4226     if ((i = REBAR_Notify((NMHDR *) &nmmouse, infoPtr, NM_NCHITTEST))) {
4227         TRACE("notify changed return value from %ld to %d\n",
4228               ret, i);
4229         ret = (LRESULT) i;
4230     }
4231     TRACE("returning %ld, client point (%ld,%ld)\n", ret, clpt.x, clpt.y);
4232     return ret;
4233 }
4234
4235
4236 static LRESULT
4237 REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4238 {
4239     RECT rcWindow;
4240     HDC hdc;
4241
4242     if (infoPtr->dwStyle & WS_MINIMIZE)
4243         return 0; /* Nothing to do */
4244
4245     if (infoPtr->dwStyle & WS_BORDER) {
4246
4247         /* adjust rectangle and draw the necessary edge */
4248         if (!(hdc = GetDCEx( infoPtr->hwndSelf, 0, DCX_USESTYLE | DCX_WINDOW )))
4249             return 0;
4250         GetWindowRect (infoPtr->hwndSelf, &rcWindow);
4251         OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
4252         TRACE("rect (%ld,%ld)-(%ld,%ld)\n",
4253               rcWindow.left, rcWindow.top,
4254               rcWindow.right, rcWindow.bottom);
4255         DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
4256         ReleaseDC( infoPtr->hwndSelf, hdc );
4257     }
4258
4259     return 0;
4260 }
4261
4262
4263 static LRESULT
4264 REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4265 {
4266     INT i;
4267
4268     if (lParam == NF_REQUERY) {
4269         i = SendMessageA(REBAR_GetNotifyParent (infoPtr),
4270                          WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
4271         if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
4272             ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
4273                 i);
4274             i = NFR_ANSI;
4275         }
4276         infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
4277         return (LRESULT)i;
4278     }
4279     return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
4280 }
4281
4282
4283 static LRESULT
4284 REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4285 {
4286     HDC hdc;
4287     PAINTSTRUCT ps;
4288     RECT rc;
4289
4290     GetClientRect(infoPtr->hwndSelf, &rc);
4291     hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
4292
4293     TRACE("painting (%ld,%ld)-(%ld,%ld) client (%ld,%ld)-(%ld,%ld)\n",
4294           ps.rcPaint.left, ps.rcPaint.top,
4295           ps.rcPaint.right, ps.rcPaint.bottom,
4296           rc.left, rc.top, rc.right, rc.bottom);
4297
4298     if (ps.fErase) {
4299         /* Erase area of paint if requested */
4300         REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
4301     }
4302
4303     REBAR_Refresh (infoPtr, hdc);
4304     if (!wParam)
4305         EndPaint (infoPtr->hwndSelf, &ps);
4306     return 0;
4307 }
4308
4309
4310 static LRESULT
4311 REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4312 {
4313     POINT pt;
4314     UINT  flags;
4315
4316     TRACE("code=0x%X  id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
4317
4318     GetCursorPos (&pt);
4319     ScreenToClient (infoPtr->hwndSelf, &pt);
4320
4321     REBAR_InternalHitTest (infoPtr, &pt, &flags, NULL);
4322
4323     if (flags == RBHT_GRABBER) {
4324         if ((infoPtr->dwStyle & CCS_VERT) &&
4325             !(infoPtr->dwStyle & RBS_VERTICALGRIPPER))
4326             SetCursor (infoPtr->hcurVert);
4327         else
4328             SetCursor (infoPtr->hcurHorz);
4329     }
4330     else if (flags != RBHT_CLIENT)
4331         SetCursor (infoPtr->hcurArrow);
4332
4333     return 0;
4334 }
4335
4336
4337 static LRESULT
4338 REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4339 {
4340     RECT rcClient;
4341     REBAR_BAND *lpBand;
4342     UINT i;
4343
4344     infoPtr->hFont = (HFONT)wParam;
4345
4346     /* revalidate all bands to change sizes of text in headers of bands */
4347     for (i=0; i<infoPtr->uNumBands; i++) {
4348         lpBand = &infoPtr->bands[i];
4349         REBAR_ValidateBand (infoPtr, lpBand);
4350     }
4351
4352
4353     if (LOWORD(lParam)) {
4354         GetClientRect (infoPtr->hwndSelf, &rcClient);
4355         REBAR_Layout (infoPtr, &rcClient, FALSE, TRUE);
4356     }
4357
4358     return 0;
4359 }
4360
4361
4362 inline static LRESULT
4363 REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4364      /*****************************************************
4365       *
4366       * Function;
4367       *  Handles the WM_SETREDRAW message.
4368       *
4369       * Documentation:
4370       *  According to testing V4.71 of COMCTL32 returns the
4371       *  *previous* status of the redraw flag (either 0 or -1)
4372       *  instead of the MSDN documented value of 0 if handled
4373       *
4374       *****************************************************/
4375 {
4376     BOOL oldredraw = infoPtr->DoRedraw;
4377
4378     TRACE("set to %s, fStatus=%08x\n",
4379           (wParam) ? "TRUE" : "FALSE", infoPtr->fStatus);
4380     infoPtr->DoRedraw = (BOOL) wParam;
4381     if (wParam) {
4382         if (infoPtr->fStatus & BAND_NEEDS_REDRAW) {
4383             REBAR_MoveChildWindows (infoPtr, 0, infoPtr->uNumBands);
4384             REBAR_ForceResize (infoPtr);
4385             InvalidateRect (infoPtr->hwndSelf, 0, TRUE);
4386         }
4387         infoPtr->fStatus &= ~BAND_NEEDS_REDRAW;
4388     }
4389     return (oldredraw) ? -1 : 0;
4390 }
4391
4392
4393 static LRESULT
4394 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4395 {
4396     RECT rcClient;
4397
4398     /* auto resize deadlock check */
4399     if (infoPtr->fStatus & AUTO_RESIZE) {
4400         infoPtr->fStatus &= ~AUTO_RESIZE;
4401         TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
4402               infoPtr->fStatus, lParam);
4403         return 0;
4404     }
4405
4406     if (infoPtr->fStatus & CREATE_RUNNING) {
4407         /* still in CreateWindow */
4408         RECT rcWin;
4409
4410         if ((INT)wParam != SIZE_RESTORED) {
4411             ERR("WM_SIZE in create and flags=%08x, lParam=%08lx\n",
4412                 wParam, lParam);
4413         }
4414
4415         TRACE("still in CreateWindow\n");
4416         infoPtr->fStatus &= ~CREATE_RUNNING;
4417         GetWindowRect ( infoPtr->hwndSelf, &rcWin);
4418         TRACE("win rect (%ld,%ld)-(%ld,%ld)\n",
4419               rcWin.left, rcWin.top, rcWin.right, rcWin.bottom);
4420
4421         if ((lParam == 0) && (rcWin.right-rcWin.left == 0) &&
4422             (rcWin.bottom-rcWin.top == 0)) {
4423             /* native control seems to do this */
4424             GetClientRect (GetParent(infoPtr->hwndSelf), &rcClient);
4425             TRACE("sizing rebar, message and client zero, parent client (%ld,%ld)\n",
4426                   rcClient.right, rcClient.bottom);
4427         }
4428         else {
4429             INT cx, cy;
4430
4431             cx = rcWin.right - rcWin.left;
4432             cy = rcWin.bottom - rcWin.top;
4433             if ((cx == LOWORD(lParam)) && (cy == HIWORD(lParam))) {
4434                 return 0;
4435             }
4436
4437             /* do the actual WM_SIZE request */
4438             GetClientRect (infoPtr->hwndSelf, &rcClient);
4439             TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%ld,%ld)\n",
4440                   infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4441                   LOWORD(lParam), HIWORD(lParam),
4442                   rcClient.right, rcClient.bottom);
4443         }
4444     }
4445     else {
4446         if ((INT)wParam != SIZE_RESTORED) {
4447             ERR("WM_SIZE out of create and flags=%08x, lParam=%08lx\n",
4448                 wParam, lParam);
4449         }
4450
4451         /* Handle cases when outside of the CreateWindow process */
4452
4453         GetClientRect (infoPtr->hwndSelf, &rcClient);
4454         if ((lParam == 0) && (rcClient.right + rcClient.bottom != 0) &&
4455             (infoPtr->dwStyle & RBS_AUTOSIZE)) {
4456             /* on a WM_SIZE to zero and current client not zero and AUTOSIZE */
4457             /* native seems to use the current client rect for the size      */
4458             infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4459             TRACE("sizing rebar to client (%ld,%ld) size is zero but AUTOSIZE set\n",
4460                   rcClient.right, rcClient.bottom);
4461         }
4462         else {
4463             TRACE("sizing rebar from (%ld,%ld) to (%d,%d), client (%ld,%ld)\n",
4464                   infoPtr->calcSize.cx, infoPtr->calcSize.cy,
4465                   LOWORD(lParam), HIWORD(lParam),
4466                   rcClient.right, rcClient.bottom);
4467         }
4468     }
4469
4470     if (infoPtr->dwStyle & RBS_AUTOSIZE) {
4471         NMRBAUTOSIZE autosize;
4472
4473         GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
4474         autosize.fChanged = 0;  /* ??? */
4475         autosize.rcActual = autosize.rcTarget;  /* ??? */
4476         REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
4477         TRACE("RBN_AUTOSIZE client=(%ld,%ld), lp=%08lx\n",
4478               autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
4479     }
4480
4481     if ((infoPtr->calcSize.cx != rcClient.right) ||
4482         (infoPtr->calcSize.cy != rcClient.bottom))
4483         infoPtr->fStatus |= BAND_NEEDS_LAYOUT;
4484
4485     REBAR_Layout (infoPtr, &rcClient, TRUE, TRUE);
4486     infoPtr->fStatus &= ~AUTO_RESIZE;
4487
4488     return 0;
4489 }
4490
4491
4492 static LRESULT
4493 REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4494 {
4495     STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
4496
4497     TRACE("current style=%08lx, styleOld=%08lx, style being set to=%08lx\n",
4498           infoPtr->dwStyle, ss->styleOld, ss->styleNew);
4499     infoPtr->dwStyle = ss->styleNew;
4500
4501     return FALSE;
4502 }
4503
4504
4505 static LRESULT
4506 REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4507 {
4508     WINDOWPOS *lpwp = (WINDOWPOS *)lParam;
4509     LRESULT ret;
4510     RECT rc;
4511
4512     /* Save the new origin of this window - used by _ForceResize */
4513     infoPtr->origin.x = lpwp->x;
4514     infoPtr->origin.y = lpwp->y;
4515     ret = DefWindowProcA(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
4516                          wParam, lParam);
4517     GetWindowRect(infoPtr->hwndSelf, &rc);
4518     TRACE("hwnd %p new pos (%ld,%ld)-(%ld,%ld)\n",
4519           infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
4520     return ret;
4521 }
4522
4523
4524 static LRESULT WINAPI
4525 REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
4526 {
4527     REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
4528
4529     TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
4530           hwnd, uMsg, wParam, lParam);
4531     if (!infoPtr && (uMsg != WM_NCCREATE))
4532             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4533     switch (uMsg)
4534     {
4535 /*      case RB_BEGINDRAG: */
4536
4537         case RB_DELETEBAND:
4538             return REBAR_DeleteBand (infoPtr, wParam, lParam);
4539
4540 /*      case RB_DRAGMOVE: */
4541 /*      case RB_ENDDRAG: */
4542
4543         case RB_GETBANDBORDERS:
4544             return REBAR_GetBandBorders (infoPtr, wParam, lParam);
4545
4546         case RB_GETBANDCOUNT:
4547             return REBAR_GetBandCount (infoPtr);
4548
4549         case RB_GETBANDINFO_OLD:
4550         case RB_GETBANDINFOA:
4551             return REBAR_GetBandInfoA (infoPtr, wParam, lParam);
4552
4553         case RB_GETBANDINFOW:
4554             return REBAR_GetBandInfoW (infoPtr, wParam, lParam);
4555
4556         case RB_GETBARHEIGHT:
4557             return REBAR_GetBarHeight (infoPtr, wParam, lParam);
4558
4559         case RB_GETBARINFO:
4560             return REBAR_GetBarInfo (infoPtr, wParam, lParam);
4561
4562         case RB_GETBKCOLOR:
4563             return REBAR_GetBkColor (infoPtr);
4564
4565 /*      case RB_GETCOLORSCHEME: */
4566 /*      case RB_GETDROPTARGET: */
4567
4568         case RB_GETPALETTE:
4569             return REBAR_GetPalette (infoPtr, wParam, lParam);
4570
4571         case RB_GETRECT:
4572             return REBAR_GetRect (infoPtr, wParam, lParam);
4573
4574         case RB_GETROWCOUNT:
4575             return REBAR_GetRowCount (infoPtr);
4576
4577         case RB_GETROWHEIGHT:
4578             return REBAR_GetRowHeight (infoPtr, wParam, lParam);
4579
4580         case RB_GETTEXTCOLOR:
4581             return REBAR_GetTextColor (infoPtr);
4582
4583         case RB_GETTOOLTIPS:
4584             return REBAR_GetToolTips (infoPtr);
4585
4586         case RB_GETUNICODEFORMAT:
4587             return REBAR_GetUnicodeFormat (infoPtr);
4588
4589         case CCM_GETVERSION:
4590             return REBAR_GetVersion (infoPtr);
4591
4592         case RB_HITTEST:
4593             return REBAR_HitTest (infoPtr, wParam, lParam);
4594
4595         case RB_IDTOINDEX:
4596             return REBAR_IdToIndex (infoPtr, wParam, lParam);
4597
4598         case RB_INSERTBANDA:
4599             return REBAR_InsertBandA (infoPtr, wParam, lParam);
4600
4601         case RB_INSERTBANDW:
4602             return REBAR_InsertBandW (infoPtr, wParam, lParam);
4603
4604         case RB_MAXIMIZEBAND:
4605             return REBAR_MaximizeBand (infoPtr, wParam, lParam);
4606
4607         case RB_MINIMIZEBAND:
4608             return REBAR_MinimizeBand (infoPtr, wParam, lParam);
4609
4610         case RB_MOVEBAND:
4611             return REBAR_MoveBand (infoPtr, wParam, lParam);
4612
4613         case RB_PUSHCHEVRON:
4614             return REBAR_PushChevron (infoPtr, wParam, lParam);
4615
4616         case RB_SETBANDINFOA:
4617             return REBAR_SetBandInfoA (infoPtr, wParam, lParam);
4618
4619         case RB_SETBANDINFOW:
4620             return REBAR_SetBandInfoW (infoPtr, wParam, lParam);
4621
4622         case RB_SETBARINFO:
4623             return REBAR_SetBarInfo (infoPtr, wParam, lParam);
4624
4625         case RB_SETBKCOLOR:
4626             return REBAR_SetBkColor (infoPtr, wParam, lParam);
4627
4628 /*      case RB_SETCOLORSCHEME: */
4629 /*      case RB_SETPALETTE: */
4630 /*          return REBAR_GetPalette (infoPtr, wParam, lParam); */
4631
4632         case RB_SETPARENT:
4633             return REBAR_SetParent (infoPtr, wParam, lParam);
4634
4635         case RB_SETTEXTCOLOR:
4636             return REBAR_SetTextColor (infoPtr, wParam, lParam);
4637
4638 /*      case RB_SETTOOLTIPS: */
4639
4640         case RB_SETUNICODEFORMAT:
4641             return REBAR_SetUnicodeFormat (infoPtr, wParam);
4642
4643         case CCM_SETVERSION:
4644             return REBAR_SetVersion (infoPtr, (INT)wParam);
4645
4646         case RB_SHOWBAND:
4647             return REBAR_ShowBand (infoPtr, wParam, lParam);
4648
4649         case RB_SIZETORECT:
4650             return REBAR_SizeToRect (infoPtr, wParam, lParam);
4651
4652
4653 /*    Messages passed to parent */
4654         case WM_COMMAND:
4655         case WM_DRAWITEM:
4656         case WM_NOTIFY:
4657             if (infoPtr->NtfUnicode)
4658                 return SendMessageW (REBAR_GetNotifyParent (infoPtr),
4659                                      uMsg, wParam, lParam);
4660             else
4661                 return SendMessageA (REBAR_GetNotifyParent (infoPtr),
4662                                      uMsg, wParam, lParam);
4663
4664
4665 /*      case WM_CHARTOITEM:     supported according to ControlSpy */
4666
4667         case WM_CREATE:
4668             return REBAR_Create (infoPtr, wParam, lParam);
4669
4670         case WM_DESTROY:
4671             return REBAR_Destroy (infoPtr, wParam, lParam);
4672
4673         case WM_ERASEBKGND:
4674             return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
4675
4676         case WM_GETFONT:
4677             return REBAR_GetFont (infoPtr, wParam, lParam);
4678
4679 /*      case WM_LBUTTONDBLCLK:  supported according to ControlSpy */
4680
4681         case WM_LBUTTONDOWN:
4682             return REBAR_LButtonDown (infoPtr, wParam, lParam);
4683
4684         case WM_LBUTTONUP:
4685             return REBAR_LButtonUp (infoPtr, wParam, lParam);
4686
4687 /*      case WM_MEASUREITEM:    supported according to ControlSpy */
4688
4689         case WM_MOUSEMOVE:
4690             return REBAR_MouseMove (infoPtr, wParam, lParam);
4691
4692         case WM_MOUSELEAVE:
4693             return REBAR_MouseLeave (infoPtr, wParam, lParam);
4694
4695         case WM_NCCALCSIZE:
4696             return REBAR_NCCalcSize (infoPtr, wParam, lParam);
4697
4698         case WM_NCCREATE:
4699             return REBAR_NCCreate (hwnd, wParam, lParam);
4700
4701         case WM_NCHITTEST:
4702             return REBAR_NCHitTest (infoPtr, wParam, lParam);
4703
4704         case WM_NCPAINT:
4705             return REBAR_NCPaint (infoPtr, wParam, lParam);
4706
4707         case WM_NOTIFYFORMAT:
4708             return REBAR_NotifyFormat (infoPtr, wParam, lParam);
4709
4710         case WM_PAINT:
4711             return REBAR_Paint (infoPtr, wParam, lParam);
4712
4713 /*      case WM_PALETTECHANGED: supported according to ControlSpy */
4714 /*      case WM_PRINTCLIENT:    supported according to ControlSpy */
4715 /*      case WM_QUERYNEWPALETTE:supported according to ControlSpy */
4716 /*      case WM_RBUTTONDOWN:    supported according to ControlSpy */
4717 /*      case WM_RBUTTONUP:      supported according to ControlSpy */
4718
4719         case WM_SETCURSOR:
4720             return REBAR_SetCursor (infoPtr, wParam, lParam);
4721
4722         case WM_SETFONT:
4723             return REBAR_SetFont (infoPtr, wParam, lParam);
4724
4725         case WM_SETREDRAW:
4726             return REBAR_SetRedraw (infoPtr, wParam, lParam);
4727
4728         case WM_SIZE:
4729             return REBAR_Size (infoPtr, wParam, lParam);
4730
4731         case WM_STYLECHANGED:
4732             return REBAR_StyleChanged (infoPtr, wParam, lParam);
4733
4734 /*      case WM_SYSCOLORCHANGE: supported according to ControlSpy */
4735 /*      "Applications that have brushes using the existing system colors
4736          should delete those brushes and recreate them using the new
4737          system colors."  per MSDN                                */
4738
4739 /*      case WM_VKEYTOITEM:     supported according to ControlSpy */
4740 /*      case WM_WININICHANGE: */
4741
4742         case WM_WINDOWPOSCHANGED:
4743             return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
4744
4745         default:
4746             if ((uMsg >= WM_USER) && (uMsg < WM_APP))
4747                 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
4748                      uMsg, wParam, lParam);
4749             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
4750     }
4751     return 0;
4752 }
4753
4754
4755 VOID
4756 REBAR_Register (void)
4757 {
4758     WNDCLASSA wndClass;
4759
4760     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
4761     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
4762     wndClass.lpfnWndProc   = (WNDPROC)REBAR_WindowProc;
4763     wndClass.cbClsExtra    = 0;
4764     wndClass.cbWndExtra    = sizeof(REBAR_INFO *);
4765     wndClass.hCursor       = 0;
4766     wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
4767 #if GLATESTING
4768     wndClass.hbrBackground = CreateSolidBrush(RGB(0,128,0));
4769 #endif
4770     wndClass.lpszClassName = REBARCLASSNAMEA;
4771
4772     RegisterClassA (&wndClass);
4773
4774     mindragx = GetSystemMetrics (SM_CXDRAG);
4775     mindragy = GetSystemMetrics (SM_CYDRAG);
4776
4777 }
4778
4779
4780 VOID
4781 REBAR_Unregister (void)
4782 {
4783     UnregisterClassA (REBARCLASSNAMEA, NULL);
4784 }