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