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