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