server: Define a generic context structure instead of using the platform-specific...
[wine] / dlls / comctl32 / rebar.c
index 3ea8fe9..089da39 100644 (file)
@@ -2,6 +2,7 @@
  * Rebar control
  *
  * Copyright 1998, 1999 Eric Kohl
+ * Copyright 2007, 2008 Mikolaj Zalewski
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -32,7 +33,6 @@
  *   - RBS_FIXEDORDER
  *   - RBS_REGISTERDROP
  *   - RBS_TOOLTIPS
- *   - RBS_AUTOSIZE
  *   Messages:
  *   - RB_BEGINDRAG
  *   - RB_DRAGMOVE
@@ -74,7 +74,7 @@
 
 /*
  * 3. REBAR_MoveChildWindows should have a loop because more than
- *    one pass is made (together with the RBN_CHILDSIZEs) is made on
+ *    one pass (together with the RBN_CHILDSIZEs) is made on
  *    at least RB_INSERTBAND
  */
 
@@ -116,10 +116,12 @@ typedef struct
     LPARAM    lParam;
     UINT    cxHeader;
 
-    INT     cxEffective;     /* current cx for band */
-    UINT    lcx;            /* minimum cx for band */
-    UINT    lcy;            /* minimum cy for band */
+    INT     cxEffective;    /* current cx for band */
+    UINT    cyHeader;       /* the height of the header */
+    UINT    cxMinBand;      /* minimum cx for band */
+    UINT    cyMinBand;      /* minimum cy for band */
 
+    UINT    cyRowSoFar;     /* for RBS_VARHEIGHT - the height of the row if it would break on this band (set by _Layout) */
     INT     iRow;           /* zero-based index of the row this band assigned to */
     UINT    fStatus;        /* status flags, reset only by _Validate */
     UINT    fDraw;          /* drawing flags, reset only by _Layout */
@@ -167,7 +169,7 @@ typedef struct
     DWORD    orgStyle;    /* original style (dwStyle may change) */
     SIZE     calcSize;    /* calculated rebar size - coordinates swapped for CCS_VERT */
     BOOL     bUnicode;    /* TRUE if parent wants notify in W format */
-    BOOL     DoRedraw;    /* TRUE to acutally draw bands */
+    BOOL     DoRedraw;    /* TRUE to actually draw bands */
     UINT     fStatus;     /* Status flags (see below)  */
     HCURSOR  hcurArrow;   /* handle to the arrow cursor */
     HCURSOR  hcurHorz;    /* handle to the EW cursor */
@@ -186,7 +188,7 @@ typedef struct
 
 /* fStatus flags */
 #define BEGIN_DRAG_ISSUED   0x00000001
-#define AUTO_RESIZE         0x00000002
+#define SELF_RESIZE         0x00000002
 #define BAND_NEEDS_REDRAW   0x00000020
 
 /* used by Windows to mark that the header size has been set by the user and shouldn't be changed */
@@ -233,7 +235,7 @@ typedef struct
 /* height of a rebar without a child */
 #define REBAR_NO_CHILD_HEIGHT 4
 
-/* minimium vertical height of a normal bar                        */
+/* minimum vertical height of a normal bar                        */
 /*   or minimum width of a CCS_VERT bar - from experiment on Win2k */
 #define REBAR_MINSIZE  23
 
@@ -251,8 +253,8 @@ typedef struct
 
 #define REBAR_GetInfoPtr(wndPtr) ((REBAR_INFO *)GetWindowLongPtrW (hwnd, 0))
 
-static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
-
+static LRESULT REBAR_NotifyFormat(REBAR_INFO *infoPtr, LPARAM lParam);
+static void REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout);
 
 /* "constant values" retrieved when DLL was initialized    */
 /* FIXME we do this when the classes are registered.       */
@@ -326,7 +328,7 @@ REBAR_FmtMask( UINT mask)
 
 
 static VOID
-REBAR_DumpBandInfo(LPREBARBANDINFOW pB)
+REBAR_DumpBandInfo(const REBARBANDINFOW *pB)
 {
     if( !TRACE_ON(rebar) ) return;
     TRACE("band info: ");
@@ -359,7 +361,7 @@ REBAR_DumpBandInfo(LPREBARBANDINFOW pB)
 }
 
 static VOID
-REBAR_DumpBand (REBAR_INFO *iP)
+REBAR_DumpBand (const REBAR_INFO *iP)
 {
     REBAR_BAND *pB;
     UINT i;
@@ -407,23 +409,20 @@ REBAR_DumpBand (REBAR_INFO *iP)
        if (pB->fMask & RBBIM_TEXT)
            TRACE("band # %u: text=%s\n",
                  i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
-       TRACE("band # %u: lcx=%u, cxEffective=%u, lcy=%u\n",
-             i, pB->lcx, pB->cxEffective, pB->lcy);
-       TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%d,%d)-(%d,%d), Grip=(%d,%d)-(%d,%d)\n",
-             i, pB->fStatus, pB->fDraw,
-             pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
-             pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
-       TRACE("band # %u: Img=(%d,%d)-(%d,%d), Txt=(%d,%d)-(%d,%d), Child=(%d,%d)-(%d,%d)\n",
-             i,
-             pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
-             pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
-             pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
+        TRACE("band # %u: cxMinBand=%u, cxEffective=%u, cyMinBand=%u\n",
+              i, pB->cxMinBand, pB->cxEffective, pB->cyMinBand);
+        TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%s), Grip=(%s)\n",
+              i, pB->fStatus, pB->fDraw, wine_dbgstr_rect(&pB->rcBand),
+              wine_dbgstr_rect(&pB->rcGripper));
+        TRACE("band # %u: Img=(%s), Txt=(%s), Child=(%s)\n",
+              i, wine_dbgstr_rect(&pB->rcCapImage),
+              wine_dbgstr_rect(&pB->rcCapText), wine_dbgstr_rect(&pB->rcChild));
     }
 
 }
 
 /* dest can be equal to src */
-static void translate_rect(REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
+static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
 {
     if (infoPtr->dwStyle & CCS_VERT) {
         int tmp;
@@ -439,29 +438,35 @@ static void translate_rect(REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
     }
 }
 
-static int get_rect_cx(REBAR_INFO *infoPtr, RECT *lpRect)
+static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
 {
     if (infoPtr->dwStyle & CCS_VERT)
         return lpRect->bottom - lpRect->top;
     return lpRect->right - lpRect->left;
 }
 
-static int get_rect_cy(REBAR_INFO *infoPtr, RECT *lpRect)
+static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
 {
     if (infoPtr->dwStyle & CCS_VERT)
         return lpRect->right - lpRect->left;
     return lpRect->bottom - lpRect->top;
 }
 
-static void round_child_height(REBAR_BAND *lpBand, int cyHeight)
+static int round_child_height(REBAR_BAND *lpBand, int cyHeight)
 {
     int cy = 0;
     if (lpBand->cyIntegral == 0)
-        return;
+        return cyHeight;
     cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
     cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
     cy = min(cy, lpBand->cyMaxChild);
-    lpBand->cyChild = cy;
+    return cy;
+}
+
+static void update_min_band_height(const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
+{
+    lpBand->cyMinBand = max(lpBand->cyHeader,
+        (lpBand->hwndChild ? lpBand->cyChild + REBARSPACE(lpBand) : REBAR_NO_CHILD_HEIGHT));
 }
 
 static void
@@ -479,13 +484,13 @@ REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
     MoveToEx (hdc, x, y, NULL);
     LineTo (hdc, x+3, y++); x++;
     MoveToEx (hdc, x, y, NULL);
-    LineTo (hdc, x+1, y++);
+    LineTo (hdc, x+1, y);
     SelectObject( hdc, hOldPen );
     DeleteObject( hPen );
 }
 
 static HWND
-REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
+REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
 {
     HWND parent, owner;
 
@@ -500,7 +505,7 @@ REBAR_GetNotifyParent (REBAR_INFO *infoPtr)
 
 
 static INT
-REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
+REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
 {
     HWND parent;
 
@@ -511,11 +516,11 @@ REBAR_Notify (NMHDR *nmhdr, REBAR_INFO *infoPtr, UINT code)
 
     TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
 
-    return SendMessageW(parent, WM_NOTIFY, (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
+    return SendMessageW(parent, WM_NOTIFY, nmhdr->idFrom, (LPARAM)nmhdr);
 }
 
 static INT
-REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
+REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
 {
     NMREBAR notify_rebar;
     REBAR_BAND *lpBand;
@@ -541,7 +546,7 @@ REBAR_Notify_NMREBAR (REBAR_INFO *infoPtr, UINT uBand, UINT code)
 }
 
 static VOID
-REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
+REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
 {
     HFONT hOldFont = 0;
     INT oldBkMode = 0;
@@ -667,7 +672,7 @@ REBAR_DrawBand (HDC hdc, REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
 
 
 static VOID
-REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
+REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
 {
     REBAR_BAND *lpBand;
     UINT i;
@@ -689,7 +694,7 @@ REBAR_Refresh (REBAR_INFO *infoPtr, HDC hdc)
 
 
 static void
-REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend)
+REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
      /* Function: this routine initializes all the rectangles in */
      /*  each band in a row to fit in the adjusted rcBand rect.  */
      /* *** Supports only Horizontal bars. ***                   */
@@ -790,6 +795,7 @@ REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend)
          work.right += SEP_WIDTH;
          work.bottom += SEP_WIDTH;
          InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
+         InvalidateRect(lpBand->hwndChild, NULL, TRUE);
       }
 
     }
@@ -798,7 +804,7 @@ REBAR_CalcHorzBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend)
 
 
 static VOID
-REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend)
+REBAR_CalcVertBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
      /* Function: this routine initializes all the rectangles in */
      /*  each band in a row to fit in the adjusted rcBand rect.  */
      /* *** Supports only Vertical bars. ***                     */
@@ -910,6 +916,7 @@ REBAR_CalcVertBand (REBAR_INFO *infoPtr, UINT rstart, UINT rend)
            work.bottom += SEP_WIDTH;
            work.right += SEP_WIDTH;
            InvalidateRect(infoPtr->hwndSelf, &work, TRUE);
+           InvalidateRect(lpBand->hwndChild, NULL, TRUE);
        }
 
     }
@@ -976,17 +983,17 @@ REBAR_ForceResize (REBAR_INFO *infoPtr)
        infoPtr->hwndSelf, infoPtr->dwStyle, x, y, width, height);
 
     /* Set flag to ignore next WM_SIZE message and resize the window */
-    infoPtr->fStatus |= AUTO_RESIZE;
+    infoPtr->fStatus |= SELF_RESIZE;
     if ((infoPtr->dwStyle & CCS_VERT) == 0)
         SetWindowPos(infoPtr->hwndSelf, 0, x, y, width, height, SWP_NOZORDER);
     else
         SetWindowPos(infoPtr->hwndSelf, 0, y, x, height, width, SWP_NOZORDER);
-    infoPtr->fStatus &= ~AUTO_RESIZE;
+    infoPtr->fStatus &= ~SELF_RESIZE;
 }
 
 
 static VOID
-REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
+REBAR_MoveChildWindows (const REBAR_INFO *infoPtr, UINT start, UINT endplus)
 {
     static const WCHAR strComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
     REBAR_BAND *lpBand;
@@ -1005,7 +1012,7 @@ REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
        if (lpBand->hwndChild) {
            TRACE("hwndChild = %p\n", lpBand->hwndChild);
 
-           /* Always geterate the RBN_CHILDSIZE even it child
+           /* Always generate the RBN_CHILDSIZE even if child
                   did not change */
            rbcz.uBand = i;
            rbcz.wID = lpBand->wID;
@@ -1018,11 +1025,9 @@ REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
            REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
            if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
                TRACE("Child rect changed by NOTIFY for band %u\n", i);
-               TRACE("    from (%d,%d)-(%d,%d)  to (%d,%d)-(%d,%d)\n",
-                     lpBand->rcChild.left, lpBand->rcChild.top,
-                     lpBand->rcChild.right, lpBand->rcChild.bottom,
-                     rbcz.rcChild.left, rbcz.rcChild.top,
-                     rbcz.rcChild.right, rbcz.rcChild.bottom);
+                TRACE("    from (%s)  to (%s)\n",
+                      wine_dbgstr_rect(&lpBand->rcChild),
+                      wine_dbgstr_rect(&rbcz.rcChild));
                lpBand->rcChild = rbcz.rcChild;  /* *** ??? */
             }
 
@@ -1096,7 +1101,9 @@ REBAR_MoveChildWindows (REBAR_INFO *infoPtr, UINT start, UINT endplus)
 
 }
 
-static int next_band(REBAR_INFO *infoPtr, int i)
+/* Returns the next visible band (the first visible band in [i+1; infoPtr->uNumBands) )
+ * or infoPtr->uNumBands if none */
+static int next_visible(const REBAR_INFO *infoPtr, int i)
 {
     int n;
     for (n = i + 1; n < infoPtr->uNumBands; n++)
@@ -1105,7 +1112,9 @@ static int next_band(REBAR_INFO *infoPtr, int i)
     return n;
 }
 
-static int prev_band(REBAR_INFO *infoPtr, int i)
+/* Returns the previous visible band (the last visible band in [0; i) )
+ * or -1 if none */
+static int prev_visible(const REBAR_INFO *infoPtr, int i)
 {
     int n;
     for (n = i - 1; n >= 0; n--)
@@ -1114,11 +1123,18 @@ static int prev_band(REBAR_INFO *infoPtr, int i)
     return n;
 }
 
-static int get_row_begin_for_band(REBAR_INFO *infoPtr, INT iBand)
+/* Returns the first visible band or infoPtr->uNumBands if none */
+static int first_visible(const REBAR_INFO *infoPtr)
+{
+    return next_visible(infoPtr, -1); /* this works*/
+}
+
+/* Returns the first visible band for the given row (or iBand if none) */
+static int get_row_begin_for_band(const REBAR_INFO *infoPtr, INT iBand)
 {
     int iLastBand = iBand;
     int iRow = infoPtr->bands[iBand].iRow;
-    while ((iBand = prev_band(infoPtr, iBand)) >= 0) {
+    while ((iBand = prev_visible(infoPtr, iBand)) >= 0) {
         if (infoPtr->bands[iBand].iRow != iRow)
             break;
         else
@@ -1127,19 +1143,22 @@ static int get_row_begin_for_band(REBAR_INFO *infoPtr, INT iBand)
     return iLastBand;
 }
 
-static int get_row_end_for_band(REBAR_INFO *infoPtr, INT iBand)
+/* Returns the first visible band for the next row (or infoPtr->uNumBands if none) */
+static int get_row_end_for_band(const REBAR_INFO *infoPtr, INT iBand)
 {
     int iRow = infoPtr->bands[iBand].iRow;
-    while ((iBand = next_band(infoPtr, iBand)) < infoPtr->uNumBands)
+    while ((iBand = next_visible(infoPtr, iBand)) < infoPtr->uNumBands)
         if (infoPtr->bands[iBand].iRow != iRow)
             break;
     return iBand;
 }
 
-static void REBAR_SetRowRectsX(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
+/* Compute the rcBand.{left,right} from the cxEffective bands widths computed earlier.
+ * iBeginBand must be visible */
+static void REBAR_SetRowRectsX(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
 {
     int xPos = 0, i;
-    for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
     {
         REBAR_BAND *lpBand = &infoPtr->bands[i];
 
@@ -1160,36 +1179,37 @@ static void REBAR_SetRowRectsX(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand
  * For some reason "big enough" is defined as bigger than the minimum size of the
  * first band in the row
  */
-static REBAR_BAND *REBAR_FindBandToGrow(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
+static REBAR_BAND *REBAR_FindBandToGrow(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand)
 {
-    INT iLcx = 0, i;
+    INT cxMinFirstBand = 0, i;
 
-    iLcx = infoPtr->bands[iBeginBand].lcx;
+    cxMinFirstBand = infoPtr->bands[iBeginBand].cxMinBand;
 
-    for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
-        if (infoPtr->bands[i].cxEffective > iLcx && !(infoPtr->bands[i].fStyle&RBBS_FIXEDSIZE))
+    for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
+        if (infoPtr->bands[i].cxEffective > cxMinFirstBand && !(infoPtr->bands[i].fStyle&RBBS_FIXEDSIZE))
             break;
 
     if (i < iBeginBand)
-        for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
-            if (infoPtr->bands[i].lcx == iLcx)
+        for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
+            if (infoPtr->bands[i].cxMinBand == cxMinFirstBand)
                 break;
 
     TRACE("Extra space for row [%d..%d) should be added to band %d\n", iBeginBand, iEndBand, i);
     return &infoPtr->bands[i];
 }
 
-static int REBAR_ShrinkBandsRTL(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
+/* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the right */
+static int REBAR_ShrinkBandsRTL(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
 {
     REBAR_BAND *lpBand;
     INT width, i;
 
     TRACE("Shrinking bands [%d..%d) by %d, right-to-left\n", iBeginBand, iEndBand, cxShrink);
-    for (i = prev_band(infoPtr, iEndBand); i >= iBeginBand; i = prev_band(infoPtr, i))
+    for (i = prev_visible(infoPtr, iEndBand); i >= iBeginBand; i = prev_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
 
-        width = max(lpBand->cxEffective - cxShrink, (int)lpBand->lcx);
+        width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
         cxShrink -= lpBand->cxEffective - width;
         lpBand->cxEffective = width;
         if (bEnforce && lpBand->cx > lpBand->cxEffective)
@@ -1201,17 +1221,19 @@ static int REBAR_ShrinkBandsRTL(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBan
 }
 
 
-static int REBAR_ShrinkBandsLTR(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
+/* Try to shrink the visible bands in [iBeginBand; iEndBand) by cxShrink, starting from the left.
+ * iBeginBand must be visible */
+static int REBAR_ShrinkBandsLTR(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT cxShrink, BOOL bEnforce)
 {
     REBAR_BAND *lpBand;
     INT width, i;
 
     TRACE("Shrinking bands [%d..%d) by %d, left-to-right\n", iBeginBand, iEndBand, cxShrink);
-    for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
 
-        width = max(lpBand->cxEffective - cxShrink, (int)lpBand->lcx);
+        width = max(lpBand->cxEffective - cxShrink, (int)lpBand->cxMinBand);
         cxShrink -= lpBand->cxEffective - width;
         lpBand->cxEffective = width;
         if (bEnforce)
@@ -1222,21 +1244,23 @@ static int REBAR_ShrinkBandsLTR(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBan
     return cxShrink;
 }
 
-static int REBAR_SetBandsHeight(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
+/* Set the heights of the visible bands in [iBeginBand; iEndBand) to the max height. iBeginBand must be visible */
+static int REBAR_SetBandsHeight(const REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBand, INT yStart)
 {
     REBAR_BAND *lpBand;
     int yMaxHeight = 0;
     int yPos = yStart;
     int row = infoPtr->bands[iBeginBand].iRow;
     int i;
-    for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
-        yMaxHeight = max(yMaxHeight, lpBand->lcy);
+        lpBand->cyRowSoFar = yMaxHeight;
+        yMaxHeight = max(yMaxHeight, lpBand->cyMinBand);
     }
     TRACE("Bands [%d; %d) height: %d\n", iBeginBand, iEndBand, yMaxHeight);
 
-    for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
         /* we may be called for multiple rows if RBS_VARHEIGHT not set */
@@ -1255,7 +1279,8 @@ static int REBAR_SetBandsHeight(REBAR_INFO *infoPtr, INT iBeginBand, INT iEndBan
     return yPos + yMaxHeight;
 }
 
-static void REBAR_LayoutRow(REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
+/* Layout the row [iBeginBand; iEndBand). iBeginBand must be visible */
+static void REBAR_LayoutRow(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int cx, int *piRow, int *pyPos)
 {
     REBAR_BAND *lpBand;
     int i, extra;
@@ -1266,12 +1291,12 @@ static void REBAR_LayoutRow(REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, i
         infoPtr->bands[i].iRow = *piRow;
 
     /* compute the extra space */
-    for (i = iBeginBand; i < iEndBand; i = next_band(infoPtr, i))
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
         if (i > iBeginBand)
             width += SEP_WIDTH;
-        lpBand->cxEffective = max(lpBand->lcx, lpBand->cx);
+        lpBand->cxEffective = max(lpBand->cxMinBand, lpBand->cx);
         width += lpBand->cxEffective;
     }
 
@@ -1279,7 +1304,7 @@ static void REBAR_LayoutRow(REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, i
     TRACE("Extra space: %d\n", extra);
     if (extra < 0) {
         int ret = REBAR_ShrinkBandsRTL(infoPtr, iBeginBand, iEndBand, -extra, FALSE);
-        if (ret > 0 && next_band(infoPtr, iBeginBand) != iEndBand)  /* one band may be longer than expected... */
+        if (ret > 0 && next_visible(infoPtr, iBeginBand) != iEndBand)  /* one band may be longer than expected... */
             ERR("Error layouting row %d - couldn't shrink for %d pixels (%d total shrink)\n", *piRow, ret, -extra);
     } else
     if (extra > 0) {
@@ -1298,30 +1323,23 @@ static void REBAR_LayoutRow(REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, i
 }
 
 static VOID
-REBAR_Layout(REBAR_INFO *infoPtr, LPRECT lpRect)
+REBAR_Layout(REBAR_INFO *infoPtr)
 {
     REBAR_BAND *lpBand;
     RECT rcAdj;
     SIZE oldSize;
-    INT adjcx, adjcy, i;
-    INT rowstart = 0;
+    INT adjcx, i;
+    INT rowstart;
     INT row = 0;
     INT xMin, yPos;
-    INT cyTarget;
-    const INT yInit = 0;
-
-    cyTarget = 0;
-    if (lpRect) {
-        rcAdj = *lpRect;
-        cyTarget = get_rect_cy(infoPtr, lpRect);
-    } else if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
+
+    if (infoPtr->dwStyle & (CCS_NORESIZE | CCS_NOPARENTALIGN) || GetParent(infoPtr->hwndSelf) == NULL)
         GetClientRect(infoPtr->hwndSelf, &rcAdj);
     else
         GetClientRect(GetParent(infoPtr->hwndSelf), &rcAdj);
-    TRACE("adjustment rect is (%d,%d)-(%d,%d)\n", rcAdj.left, rcAdj.top, rcAdj.right, rcAdj.bottom);
+    TRACE("adjustment rect is (%s)\n", wine_dbgstr_rect(&rcAdj));
 
     adjcx = get_rect_cx(infoPtr, &rcAdj);
-    adjcy = get_rect_cy(infoPtr, &rcAdj);
 
     if (infoPtr->uNumBands == 0) {
         TRACE("No bands - setting size to (0,%d), vert: %lx\n", adjcx, infoPtr->dwStyle & CCS_VERT);
@@ -1332,16 +1350,15 @@ REBAR_Layout(REBAR_INFO *infoPtr, LPRECT lpRect)
         return;
     }
 
-    yPos = yInit;
+    yPos = 0;
     xMin = 0;
+    rowstart = first_visible(infoPtr);
     /* divide rows */
-    i = 0;
-    for (i = 0; i < infoPtr->uNumBands; i++)
+    for (i = rowstart; i < infoPtr->uNumBands; i = next_visible(infoPtr, i))
     {
         lpBand = &infoPtr->bands[i];
-        if (HIDDENBAND(lpBand)) continue;
 
-        if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->lcx > adjcx)) {
+        if (i > rowstart && (lpBand->fStyle & RBBS_BREAK || xMin + lpBand->cxMinBand > adjcx)) {
             TRACE("%s break on band %d\n", (lpBand->fStyle & RBBS_BREAK ? "Hard" : "Soft"), i - 1);
             REBAR_LayoutRow(infoPtr, rowstart, i, adjcx, &row, &yPos);
             rowstart = i;
@@ -1350,12 +1367,12 @@ REBAR_Layout(REBAR_INFO *infoPtr, LPRECT lpRect)
         else
             xMin += SEP_WIDTH;
 
-        xMin += lpBand->lcx;
+        xMin += lpBand->cxMinBand;
     }
     REBAR_LayoutRow(infoPtr, rowstart, infoPtr->uNumBands, adjcx, &row, &yPos);
 
     if (!(infoPtr->dwStyle & RBS_VARHEIGHT))
-        yPos = REBAR_SetBandsHeight(infoPtr, 0, infoPtr->uNumBands, yInit);
+        yPos = REBAR_SetBandsHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, 0);
 
     infoPtr->uNumRows = row;
 
@@ -1382,24 +1399,150 @@ REBAR_Layout(REBAR_INFO *infoPtr, LPRECT lpRect)
     {
         NMHDR heightchange;
         REBAR_Notify(&heightchange, infoPtr, RBN_HEIGHTCHANGE);
+        REBAR_AutoSize(infoPtr, FALSE);
+    }
+}
+
+/* iBeginBand must be visible */
+static int
+REBAR_SizeChildrenToHeight(const REBAR_INFO *infoPtr, int iBeginBand, int iEndBand, int extra, BOOL *fChanged)
+{
+    int cyBandsOld;
+    int cyBandsNew = 0;
+    int i;
+
+    TRACE("[%d;%d) by %d\n", iBeginBand, iEndBand, extra);
+
+    cyBandsOld = infoPtr->bands[iBeginBand].rcBand.bottom - infoPtr->bands[iBeginBand].rcBand.top;
+    for (i = iBeginBand; i < iEndBand; i = next_visible(infoPtr, i))
+    {
+        REBAR_BAND *lpBand = &infoPtr->bands[i];
+        int cyMaxChild = cyBandsOld - REBARSPACE(lpBand) + extra;
+        int cyChild = round_child_height(lpBand, cyMaxChild);
+
+        if (lpBand->hwndChild && cyChild != lpBand->cyChild && (lpBand->fStyle & RBBS_VARIABLEHEIGHT))
+        {
+            TRACE("Resizing %d: %d -> %d [%d]\n", i, lpBand->cyChild, cyChild, lpBand->cyMaxChild);
+            *fChanged = TRUE;
+            lpBand->cyChild = cyChild;
+            lpBand->fDraw |= NTF_INVALIDATE;
+            update_min_band_height(infoPtr, lpBand);
+        }
+        cyBandsNew = max(cyBandsNew, lpBand->cyMinBand);
+    }
+    return cyBandsNew - cyBandsOld;
+}
+
+/* worker function for RB_SIZETORECT and RBS_AUTOSIZE */
+static VOID
+REBAR_SizeToHeight(REBAR_INFO *infoPtr, int height)
+{
+    int extra = height - infoPtr->calcSize.cy;  /* may be negative */
+    BOOL fChanged = FALSE;
+    UINT uNumRows = infoPtr->uNumRows;
+    int i;
+
+    if (uNumRows == 0)  /* avoid division by 0 */
+        return;
+
+    /* That's not exactly what Windows does but should be similar */
+
+    /* Pass one: break-up/glue rows */
+    if (extra > 0)
+    {
+        for (i = prev_visible(infoPtr, infoPtr->uNumBands); i > 0; i = prev_visible(infoPtr, i))
+        {
+            REBAR_BAND *lpBand = &infoPtr->bands[i];
+            int height = lpBand->rcBand.bottom - lpBand->rcBand.top;
+            int cyBreakExtra;  /* additional cy for the rebar after a RBBS_BREAK on this band */
+
+            if (infoPtr->dwStyle & RBS_VARHEIGHT)
+                cyBreakExtra = lpBand->cyRowSoFar; /* 'height' => 'lpBand->cyRowSoFar' + 'height'*/
+            else
+                cyBreakExtra = height;             /* 'height' => 'height' + 'height'*/
+            cyBreakExtra += SEP_WIDTH;
+
+            if (extra <= cyBreakExtra / 2)
+                break;
+
+            if (!(lpBand->fStyle & RBBS_BREAK))
+            {
+                TRACE("Adding break on band %d - extra %d -> %d\n", i, extra, extra - cyBreakExtra);
+                lpBand->fStyle |= RBBS_BREAK;
+                lpBand->fDraw |= NTF_INVALIDATE;
+                fChanged = TRUE;
+                extra -= cyBreakExtra;
+                uNumRows++;
+                /* temporary change for _SizeControlsToHeight. The true values will be computed in _Layout */
+                if (infoPtr->dwStyle & RBS_VARHEIGHT)
+                    lpBand->rcBand.bottom = lpBand->rcBand.top + lpBand->cyMinBand;
+            }
+        }
+    }
+    /* TODO: else if (extra < 0) { try to remove some RBBS_BREAKs } */
+
+    /* Pass two: increase/decrease control height */
+    if (infoPtr->dwStyle & RBS_VARHEIGHT)
+    {
+        int i = first_visible(infoPtr);
+        int iRow = 0;
+        while (i < infoPtr->uNumBands)
+        {
+            REBAR_BAND *lpBand = &infoPtr->bands[i];
+            int extraForRow = extra / (int)(uNumRows - iRow);
+            int rowEnd;
+
+            /* we can't use get_row_end_for_band as we might have added RBBS_BREAK in the first phase */
+            for (rowEnd = next_visible(infoPtr, i); rowEnd < infoPtr->uNumBands; rowEnd = next_visible(infoPtr, rowEnd))
+                if (infoPtr->bands[rowEnd].iRow != lpBand->iRow || (infoPtr->bands[rowEnd].fStyle & RBBS_BREAK))
+                    break;
+
+            extra -= REBAR_SizeChildrenToHeight(infoPtr, i, rowEnd, extraForRow, &fChanged);
+            TRACE("extra = %d\n", extra);
+            i = rowEnd;
+            iRow++;
+        }
     }
+    else
+        extra -= REBAR_SizeChildrenToHeight(infoPtr, first_visible(infoPtr), infoPtr->uNumBands, extra / infoPtr->uNumRows, &fChanged);
+
+    if (fChanged)
+        REBAR_Layout(infoPtr);
 }
 
+static VOID
+REBAR_AutoSize(REBAR_INFO *infoPtr, BOOL needsLayout)
+{
+    RECT rc, rcNew;
+    NMRBAUTOSIZE autosize;
+
+    if (needsLayout)
+        REBAR_Layout(infoPtr);
+    GetClientRect(infoPtr->hwndSelf, &rc);
+    REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, &rc));
+    GetClientRect(infoPtr->hwndSelf, &rcNew);
+
+    GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
+    autosize.fChanged = (memcmp(&rc, &rcNew, sizeof(RECT)) == 0);
+    autosize.rcTarget = rc;
+    autosize.rcActual = rcNew;
+    REBAR_Notify((NMHDR *)&autosize, infoPtr, RBN_AUTOSIZE);
+}
 
 static VOID
-REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
+REBAR_ValidateBand (const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
      /* Function:  This routine evaluates the band specs supplied */
      /*  by the user and updates the following 5 fields in        */
-     /*  the internal band structure: cxHeader, lcx, lcy, hcx, hcy*/
+     /*  the internal band structure: cxHeader, cyHeader, cxMinBand, cyMinBand, fStatus */
 {
     UINT header=0;
-    UINT textheight=0;
+    UINT textheight=0, imageheight = 0;
     UINT i, nonfixed;
     REBAR_BAND *tBand;
 
     lpBand->fStatus = 0;
-    lpBand->lcx = 0;
-    lpBand->lcy = 0;
+    lpBand->cxMinBand = 0;
+    lpBand->cyMinBand = 0;
 
     /* Data coming in from users into the cx... and cy... fields   */
     /* may be bad, just garbage, because the user never clears     */
@@ -1452,15 +1595,15 @@ REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
     }
 
     /* image is visible */
-    if ((lpBand->fMask & RBBIM_IMAGE) && (infoPtr->himl)) {
+    if (lpBand->iImage != -1 && (infoPtr->himl)) {
        lpBand->fStatus |= HAS_IMAGE;
         if (infoPtr->dwStyle & CCS_VERT) {
           header += (infoPtr->imageSize.cy + REBAR_POST_IMAGE);
-          lpBand->lcy = infoPtr->imageSize.cx + 2;
+           imageheight = infoPtr->imageSize.cx + 4;
        }
        else {
           header += (infoPtr->imageSize.cx + REBAR_POST_IMAGE);
-          lpBand->lcy = infoPtr->imageSize.cy + 2;
+           imageheight = infoPtr->imageSize.cy + 4;
        }
     }
 
@@ -1490,30 +1633,23 @@ REBAR_ValidateBand (REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
     /* check if user overrode the header value */
     if (!(lpBand->fStyle & RBBS_UNDOC_FIXEDHEADER))
         lpBand->cxHeader = header;
-
+    lpBand->cyHeader = max(textheight, imageheight);
 
     /* Now compute minimum size of child window */
-    lpBand->lcy = textheight;
-    if (lpBand->hwndChild != NULL) {
-       /* Set the .cy values for CHILDSIZE case */
-        lpBand->lcy = max(lpBand->lcy, lpBand->cyChild + REBARSPACE(lpBand));
-        TRACE("_CHILDSIZE\n");
-    }
-    else
-        lpBand->lcy = max(lpBand->lcy, REBAR_NO_CHILD_HEIGHT);
+    update_min_band_height(infoPtr, lpBand);       /* update lpBand->cyMinBand from cyHeader and cyChild*/
 
-    lpBand->lcx = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
+    lpBand->cxMinBand = lpBand->cxMinChild + lpBand->cxHeader + REBAR_POST_CHILD;
     if (lpBand->fStyle & RBBS_USECHEVRON && lpBand->cxMinChild < lpBand->cxIdeal)
-        lpBand->lcx += CHEVRON_WIDTH;
+        lpBand->cxMinBand += CHEVRON_WIDTH;
 }
 
-static BOOL
-REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
+static UINT
+REBAR_CommonSetupBand(HWND hwnd, const REBARBANDINFOW *lprbbi, REBAR_BAND *lpBand)
      /* Function:  This routine copies the supplied values from   */
      /*  user input (lprbbi) to the internal band structure.      */
-     /*  It returns true if something changed and false if not.   */
+     /*  It returns the mask of what changed.   */
 {
-    BOOL bChanged = FALSE;
+    UINT uChanged = 0x0;
 
     lpBand->fMask |= lprbbi->fMask;
 
@@ -1521,7 +1657,7 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
         (lpBand->fStyle != lprbbi->fStyle ) )
     {
        lpBand->fStyle = lprbbi->fStyle;
-        bChanged = TRUE;
+        uChanged |= RBBIM_STYLE;
     }
 
     if( (lprbbi->fMask & RBBIM_COLORS) &&
@@ -1530,14 +1666,14 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
     {
        lpBand->clrFore = lprbbi->clrFore;
        lpBand->clrBack = lprbbi->clrBack;
-        bChanged = TRUE;
+        uChanged |= RBBIM_COLORS;
     }
 
     if( (lprbbi->fMask & RBBIM_IMAGE) &&
        ( lpBand->iImage != lprbbi->iImage ) )
     {
        lpBand->iImage = lprbbi->iImage;
-        bChanged = TRUE;
+        uChanged |= RBBIM_IMAGE;
     }
 
     if( (lprbbi->fMask & RBBIM_CHILD) &&
@@ -1557,13 +1693,13 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
            lpBand->hwndChild = 0;
            lpBand->hwndPrevParent = 0;
        }
-        bChanged = TRUE;
+        uChanged |= RBBIM_CHILD;
     }
 
     if( (lprbbi->fMask & RBBIM_CHILDSIZE) &&
         ( (lpBand->cxMinChild != lprbbi->cxMinChild) ||
           (lpBand->cyMinChild != lprbbi->cyMinChild ) ||
-          ( (lprbbi->cbSize >= sizeof (REBARBANDINFOA)) &&
+          ( (lprbbi->cbSize >= sizeof (REBARBANDINFOA) && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) &&
             ( (lpBand->cyChild    != lprbbi->cyChild ) ||
               (lpBand->cyMaxChild != lprbbi->cyMaxChild ) ||
               (lpBand->cyIntegral != lprbbi->cyIntegral ) ) ) ||
@@ -1575,40 +1711,39 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
        lpBand->cxMinChild = lprbbi->cxMinChild;
        lpBand->cyMinChild = lprbbi->cyMinChild;
         /* These fields where added in WIN32_IE == 0x400 and are set only for RBBS_VARIABLEHEIGHT bands */
-        if (lprbbi->cbSize >= sizeof (REBARBANDINFOA) && (lprbbi->fStyle & RBBS_VARIABLEHEIGHT)) {
+        if (lprbbi->cbSize >= sizeof (REBARBANDINFOA) && (lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
            lpBand->cyMaxChild = lprbbi->cyMaxChild;
             lpBand->cyIntegral = lprbbi->cyIntegral;
 
-            lpBand->cyChild = lpBand->cyMinChild;
-            round_child_height(lpBand, lprbbi->cyChild);  /* try to increase cyChild */
+            lpBand->cyChild = round_child_height(lpBand, lprbbi->cyChild);  /* make (cyChild - cyMinChild) a multiple of cyIntergral */
         }
        else {
            lpBand->cyChild    = lpBand->cyMinChild;
            lpBand->cyMaxChild = 0x7fffffff;
            lpBand->cyIntegral = 0;
        }
-        bChanged = TRUE;
+        uChanged |= RBBIM_CHILDSIZE;
     }
 
     if( (lprbbi->fMask & RBBIM_SIZE) &&
         (lpBand->cx != lprbbi->cx ) )
     {
        lpBand->cx = lprbbi->cx;
-        bChanged = TRUE;
+        uChanged |= RBBIM_SIZE;
     }
 
     if( (lprbbi->fMask & RBBIM_BACKGROUND) &&
        ( lpBand->hbmBack != lprbbi->hbmBack ) )
     {
        lpBand->hbmBack = lprbbi->hbmBack;
-        bChanged = TRUE;
+        uChanged |= RBBIM_BACKGROUND;
     }
 
     if( (lprbbi->fMask & RBBIM_ID) &&
         (lpBand->wID != lprbbi->wID ) )
     {
        lpBand->wID = lprbbi->wID;
-        bChanged = TRUE;
+        uChanged |= RBBIM_ID;
     }
 
     /* check for additional data */
@@ -1617,14 +1752,14 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
             ( lpBand->cxIdeal != lprbbi->cxIdeal ) )
         {
            lpBand->cxIdeal = lprbbi->cxIdeal;
-            bChanged = TRUE;
+            uChanged |= RBBIM_IDEALSIZE;
         }
 
        if( (lprbbi->fMask & RBBIM_LPARAM) &&
             (lpBand->lParam != lprbbi->lParam ) )
         {
            lpBand->lParam = lprbbi->lParam;
-            bChanged = TRUE;
+            uChanged |= RBBIM_LPARAM;
         }
 
        if( (lprbbi->fMask & RBBIM_HEADERSIZE) &&
@@ -1632,15 +1767,15 @@ REBAR_CommonSetupBand(HWND hwnd, LPREBARBANDINFOW lprbbi, REBAR_BAND *lpBand)
         {
            lpBand->cxHeader = lprbbi->cxHeader;
             lpBand->fStyle |= RBBS_UNDOC_FIXEDHEADER;
-            bChanged = TRUE;
+            uChanged |= RBBIM_HEADERSIZE;
         }
     }
 
-    return bChanged;
+    return uChanged;
 }
 
 static LRESULT
-REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, RECT *clip)
+REBAR_InternalEraseBkGnd (const REBAR_INFO *infoPtr, WPARAM wParam, const RECT *clip)
      /* Function:  This erases the background rectangle by drawing  */
      /*  each band with its background color (or the default) and   */
      /*  draws each bands right separator if necessary. The row     */
@@ -1685,9 +1820,8 @@ REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, REC
                     else
                        DrawEdge (hdc, &rcRowSep, EDGE_ETCHED, BF_BOTTOM);
                }
-               TRACE ("drawing band separator bottom (%d,%d)-(%d,%d)\n",
-                      rcRowSep.left, rcRowSep.top,
-                      rcRowSep.right, rcRowSep.bottom);
+                TRACE ("drawing band separator bottom (%s)\n",
+                       wine_dbgstr_rect(&rcRowSep));
            }
        }
 
@@ -1711,8 +1845,8 @@ REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, REC
                 else
                    DrawEdge (hdc, &rcSep, EDGE_ETCHED, BF_RIGHT);
            }
-            TRACE("drawing band separator right (%d,%d)-(%d,%d)\n",
-                 rcSep.left, rcSep.top, rcSep.right, rcSep.bottom);
+            TRACE("drawing band separator right (%s)\n",
+                  wine_dbgstr_rect(&rcSep));
        }
 
        /* draw the actual background */
@@ -1762,7 +1896,7 @@ REBAR_InternalEraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, REC
 }
 
 static void
-REBAR_InternalHitTest (REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
+REBAR_InternalHitTest (const REBAR_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pBand)
 {
     REBAR_BAND *lpBand;
     RECT rect;
@@ -1882,7 +2016,7 @@ REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
         hitBand->cx = hitBand->cxEffective;
     } else if (movement > 0) {
         int cxLeft = REBAR_ShrinkBandsLTR(infoPtr, iHitBand, iRowEnd, movement, TRUE);
-        REBAR_BAND *lpPrev = &infoPtr->bands[prev_band(infoPtr, iHitBand)];
+        REBAR_BAND *lpPrev = &infoPtr->bands[prev_visible(infoPtr, iHitBand)];
         lpPrev->cxEffective += movement - cxLeft;
         lpPrev->cx = lpPrev->cxEffective;
     }
@@ -1901,7 +2035,7 @@ REBAR_HandleLRDrag (REBAR_INFO *infoPtr, const POINT *ptsmove)
 
 
 static LRESULT
-REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam)
 {
     UINT uBand = (UINT)wParam;
     REBAR_BAND *lpBand;
@@ -1929,7 +2063,7 @@ REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     if (infoPtr->uNumBands == 1)
       REBAR_ValidateBand (infoPtr, &infoPtr->bands[0]);
 
-    REBAR_Layout(infoPtr, NULL);
+    REBAR_Layout(infoPtr);
 
     return TRUE;
 }
@@ -1940,7 +2074,7 @@ REBAR_DeleteBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetBandBorders (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     LPRECT lpRect = (LPRECT)lParam;
     REBAR_BAND *lpBand;
@@ -1978,8 +2112,8 @@ REBAR_GetBandBorders (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 
-inline static LRESULT
-REBAR_GetBandCount (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetBandCount (const REBAR_INFO *infoPtr)
 {
     TRACE("band count %u!\n", infoPtr->uNumBands);
 
@@ -1988,7 +2122,7 @@ REBAR_GetBandCount (REBAR_INFO *infoPtr)
 
 
 static LRESULT
-REBAR_GetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
+REBAR_GetBandInfoT(const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnicode)
 {
     LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
     REBAR_BAND *lpBand;
@@ -2068,7 +2202,7 @@ REBAR_GetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
 
 
 static LRESULT
-REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetBarHeight (const REBAR_INFO *infoPtr)
 {
     INT nHeight;
 
@@ -2081,7 +2215,7 @@ REBAR_GetBarHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetBarInfo (const REBAR_INFO *infoPtr, LPARAM lParam)
 {
     LPREBARINFO lpInfo = (LPREBARINFO)lParam;
 
@@ -2102,8 +2236,8 @@ REBAR_GetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 
-inline static LRESULT
-REBAR_GetBkColor (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetBkColor (const REBAR_INFO *infoPtr)
 {
     COLORREF clr = infoPtr->clrBk;
 
@@ -2121,7 +2255,7 @@ REBAR_GetBkColor (REBAR_INFO *infoPtr)
 
 
 static LRESULT
-REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetPalette (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     FIXME("empty stub!\n");
 
@@ -2130,7 +2264,7 @@ REBAR_GetPalette (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetRect (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     INT iBand = (INT)wParam;
     LPRECT lprc = (LPRECT)lParam;
@@ -2142,18 +2276,17 @@ REBAR_GetRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
        return FALSE;
 
     lpBand = &infoPtr->bands[iBand];
-    /* For CCS_VERT the coordintes will be swapped - like on Windows */
+    /* For CCS_VERT the coordinates will be swapped - like on Windows */
     CopyRect (lprc, &lpBand->rcBand);
 
-    TRACE("band %d, (%d,%d)-(%d,%d)\n", iBand,
-         lprc->left, lprc->top, lprc->right, lprc->bottom);
+    TRACE("band %d, (%s)\n", iBand, wine_dbgstr_rect(lprc));
 
     return TRUE;
 }
 
 
-inline static LRESULT
-REBAR_GetRowCount (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetRowCount (const REBAR_INFO *infoPtr)
 {
     TRACE("%u\n", infoPtr->uNumRows);
 
@@ -2162,7 +2295,7 @@ REBAR_GetRowCount (REBAR_INFO *infoPtr)
 
 
 static LRESULT
-REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetRowHeight (const REBAR_INFO *infoPtr, WPARAM wParam)
 {
     INT iRow = (INT)wParam;
     int j = 0, ret = 0;
@@ -2183,8 +2316,8 @@ REBAR_GetRowHeight (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 
-inline static LRESULT
-REBAR_GetTextColor (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetTextColor (const REBAR_INFO *infoPtr)
 {
     TRACE("text color 0x%06x!\n", infoPtr->clrText);
 
@@ -2192,15 +2325,15 @@ REBAR_GetTextColor (REBAR_INFO *infoPtr)
 }
 
 
-inline static LRESULT
-REBAR_GetToolTips (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetToolTips (const REBAR_INFO *infoPtr)
 {
     return (LRESULT)infoPtr->hwndToolTip;
 }
 
 
-inline static LRESULT
-REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetUnicodeFormat (const REBAR_INFO *infoPtr)
 {
     TRACE("%s hwnd=%p\n",
          infoPtr->bUnicode ? "TRUE" : "FALSE", infoPtr->hwndSelf);
@@ -2209,8 +2342,8 @@ REBAR_GetUnicodeFormat (REBAR_INFO *infoPtr)
 }
 
 
-inline static LRESULT
-REBAR_GetVersion (REBAR_INFO *infoPtr)
+static inline LRESULT
+REBAR_GetVersion (const REBAR_INFO *infoPtr)
 {
     TRACE("version %d\n", infoPtr->iVersion);
     return infoPtr->iVersion;
@@ -2218,7 +2351,7 @@ REBAR_GetVersion (REBAR_INFO *infoPtr)
 
 
 static LRESULT
-REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_HitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
 {
     LPRBHITTESTINFO lprbht = (LPRBHITTESTINFO)lParam;
 
@@ -2232,7 +2365,7 @@ REBAR_HitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_IdToIndex (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_IdToIndex (const REBAR_INFO *infoPtr, WPARAM wParam)
 {
     UINT i;
 
@@ -2289,6 +2422,14 @@ REBAR_InsertBandT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnico
     lpBand->iImage = -1;
 
     REBAR_CommonSetupBand(infoPtr->hwndSelf, lprbbi, lpBand);
+
+    /* Make sure the defaults for these are correct */
+    if (lprbbi->cbSize < sizeof (REBARBANDINFOA) || !(lpBand->fStyle & RBBS_VARIABLEHEIGHT)) {
+        lpBand->cyChild    = lpBand->cyMinChild;
+        lpBand->cyMaxChild = 0x7fffffff;
+        lpBand->cyIntegral = 0;
+    }
+
     if ((lprbbi->fMask & RBBIM_TEXT) && (lprbbi->lpText)) {
         if (bUnicode)
             Str_SetPtrW(&lpBand->lpText, lprbbi->lpText);
@@ -2303,7 +2444,7 @@ REBAR_InsertBandT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnico
 
     REBAR_DumpBand (infoPtr);
 
-    REBAR_Layout(infoPtr, NULL);
+    REBAR_Layout(infoPtr);
     InvalidateRect(infoPtr->hwndSelf, 0, TRUE);
 
     return TRUE;
@@ -2311,7 +2452,7 @@ REBAR_InsertBandT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnico
 
 
 static LRESULT
-REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_MaximizeBand (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     REBAR_BAND *lpBand;
     UINT uBand = (UINT) wParam;
@@ -2330,6 +2471,13 @@ REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
     lpBand = &infoPtr->bands[uBand];
 
+    if (lpBand->fStyle & RBBS_HIDDEN)
+    {
+        /* Windows is buggy and creates a hole */
+        WARN("Ignoring maximize request on a hidden band (%d)\n", uBand);
+        return FALSE;
+    }
+
     cxIdealBand = lpBand->cxIdeal + lpBand->cxHeader + REBAR_POST_CHILD;
     if (lParam && (lpBand->cxEffective < cxIdealBand))
         cxDesired = cxIdealBand;
@@ -2342,10 +2490,10 @@ REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     if (extra > 0)
         extra = REBAR_ShrinkBandsRTL(infoPtr, iRowBegin, uBand, extra, TRUE);
     if (extra > 0)
-        extra = REBAR_ShrinkBandsLTR(infoPtr, next_band(infoPtr, uBand), iRowEnd, extra, TRUE);
+        extra = REBAR_ShrinkBandsLTR(infoPtr, next_visible(infoPtr, uBand), iRowEnd, extra, TRUE);
     lpBand->cxEffective += extraOrig - extra;
     lpBand->cx = lpBand->cxEffective;
-    TRACE("(%d, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", wParam, lParam, cxDesired, lpBand->cx, extraOrig, extra);
+    TRACE("(%ld, %ld): Wanted size %d, obtained %d (shrink %d, %d)\n", wParam, lParam, cxDesired, lpBand->cx, extraOrig, extra);
     REBAR_SetRowRectsX(infoPtr, iRowBegin, iRowEnd);
 
     if (infoPtr->dwStyle & CCS_VERT)
@@ -2359,7 +2507,7 @@ REBAR_MaximizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_MinimizeBand (const REBAR_INFO *infoPtr, WPARAM wParam)
 {
     REBAR_BAND *lpBand;
     UINT uBand = (UINT) wParam;
@@ -2381,22 +2529,30 @@ REBAR_MinimizeBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
     /* compute amount of movement and validate */
     lpBand = &infoPtr->bands[uBand];
-    iPrev = prev_band(infoPtr, uBand);
+
+    if (lpBand->fStyle & RBBS_HIDDEN)
+    {
+        /* Windows is buggy and creates a hole/overlap */
+        WARN("Ignoring minimize request on a hidden band (%d)\n", uBand);
+        return FALSE;
+    }
+
+    iPrev = prev_visible(infoPtr, uBand);
     /* if first band in row */
     if (iPrev < 0 || infoPtr->bands[iPrev].iRow != lpBand->iRow) {
-        int iNext = next_band(infoPtr, uBand);
+        int iNext = next_visible(infoPtr, uBand);
         if (iNext < infoPtr->uNumBands && infoPtr->bands[iNext].iRow == lpBand->iRow) {
-            TRACE("(%d): Minimizing the first band in row is by maximizing the second\n", wParam);
+            TRACE("(%ld): Minimizing the first band in row is by maximizing the second\n", wParam);
             REBAR_MaximizeBand(infoPtr, iNext, FALSE);
         }
         else
-            TRACE("(%d): Only one band in row - nothing to do\n", wParam);
+            TRACE("(%ld): Only one band in row - nothing to do\n", wParam);
         return TRUE;
     }
 
-    infoPtr->bands[iPrev].cxEffective += lpBand->cxEffective - lpBand->lcx;
+    infoPtr->bands[iPrev].cxEffective += lpBand->cxEffective - lpBand->cxMinBand;
     infoPtr->bands[iPrev].cx = infoPtr->bands[iPrev].cxEffective;
-    lpBand->cx = lpBand->cxEffective = lpBand->lcx;
+    lpBand->cx = lpBand->cxEffective = lpBand->cxMinBand;
 
     iRowBegin = get_row_begin_for_band(infoPtr, uBand);
     iRowEnd = get_row_end_for_band(infoPtr, uBand);
@@ -2430,7 +2586,7 @@ REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     }
 
     /* save one to be moved */
-    memcpy (&holder, &oldBands[uFrom], sizeof(REBAR_BAND));
+    holder = oldBands[uFrom];
 
     /* close up rest of bands (pseudo delete) */
     if (uFrom < infoPtr->uNumBands - 1) {
@@ -2439,8 +2595,7 @@ REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     }
 
     /* allocate new space and copy rest of bands into it */
-    infoPtr->bands =
-       (REBAR_BAND *)Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
+    infoPtr->bands = Alloc ((infoPtr->uNumBands)*sizeof(REBAR_BAND));
 
     /* pre insert copy */
     if (uTo > 0) {
@@ -2449,7 +2604,7 @@ REBAR_MoveBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     }
 
     /* set moved band */
-    memcpy (&infoPtr->bands[uTo], &holder, sizeof(REBAR_BAND));
+    infoPtr->bands[uTo] = holder;
 
     /* post copy */
     if (uTo < infoPtr->uNumBands - 1) {
@@ -2487,7 +2642,7 @@ REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
 {
     LPREBARBANDINFOW lprbbi = (LPREBARBANDINFOW)lParam;
     REBAR_BAND *lpBand;
-    BOOL bChanged;
+    UINT uChanged;
 
     if (lprbbi == NULL)
        return FALSE;
@@ -2502,7 +2657,7 @@ REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
     /* set band information */
     lpBand = &infoPtr->bands[(UINT)wParam];
 
-    bChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
+    uChanged = REBAR_CommonSetupBand (infoPtr->hwndSelf, lprbbi, lpBand);
     if (lprbbi->fMask & RBBIM_TEXT) {
         LPWSTR wstr = NULL;
         if (bUnicode)
@@ -2510,10 +2665,10 @@ REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
         else
             Str_SetPtrAtoW(&wstr, (LPSTR)lprbbi->lpText);
 
-        if (REBAR_strdifW(wstr, lprbbi->lpText)) {
+        if (REBAR_strdifW(wstr, lpBand->lpText)) {
             Free(lpBand->lpText);
             lpBand->lpText = wstr;
-            bChanged = TRUE;
+            uChanged |= RBBIM_TEXT;
         }
         else
             Free(wstr);
@@ -2523,8 +2678,8 @@ REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
 
     REBAR_DumpBand (infoPtr);
 
-    if (bChanged && (lprbbi->fMask & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE))) {
-         REBAR_Layout(infoPtr, NULL);
+    if (uChanged & (RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IMAGE)) {
+         REBAR_Layout(infoPtr);
          InvalidateRect(infoPtr->hwndSelf, 0, 1);
     }
 
@@ -2533,7 +2688,7 @@ REBAR_SetBandInfoT(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam, BOOL bUnic
 
 
 static LRESULT
-REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetBarInfo (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     LPREBARINFO lpInfo = (LPREBARINFO)lParam;
     REBAR_BAND *lpBand;
@@ -2574,7 +2729,7 @@ REBAR_SetBarInfo (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetBkColor (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     COLORREF clrTemp;
 
@@ -2592,7 +2747,7 @@ REBAR_SetBkColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam)
 {
     HWND hwndTemp = infoPtr->hwndNotify;
 
@@ -2603,7 +2758,7 @@ REBAR_SetParent (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetTextColor (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     COLORREF clrTemp;
 
@@ -2619,7 +2774,7 @@ REBAR_SetTextColor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 /* << REBAR_SetTooltips >> */
 
 
-inline static LRESULT
+static inline LRESULT
 REBAR_SetUnicodeFormat (REBAR_INFO *infoPtr, WPARAM wParam)
 {
     BOOL bTemp = infoPtr->bUnicode;
@@ -2673,7 +2828,7 @@ REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
            ShowWindow (lpBand->hwndChild, SW_HIDE);
     }
 
-    REBAR_Layout(infoPtr, NULL);
+    REBAR_Layout(infoPtr);
     InvalidateRect(infoPtr->hwndSelf, 0, 1);
 
     return TRUE;
@@ -2681,52 +2836,37 @@ REBAR_ShowBand (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_SizeToRect (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SizeToRect (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     LPRECT lpRect = (LPRECT)lParam;
-    RECT t1;
 
     if (lpRect == NULL)
        return FALSE;
 
-    TRACE("[%d %d %d %d]\n",
-         lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
-
-    /*  what is going on???? */
-    GetWindowRect(infoPtr->hwndSelf, &t1);
-    TRACE("window rect [%d %d %d %d]\n",
-         t1.left, t1.top, t1.right, t1.bottom);
-    GetClientRect(infoPtr->hwndSelf, &t1);
-    TRACE("client rect [%d %d %d %d]\n",
-         t1.left, t1.top, t1.right, t1.bottom);
-
-    /* force full _Layout processing */
-    REBAR_Layout(infoPtr, lpRect);
-    InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
+    TRACE("[%s]\n", wine_dbgstr_rect(lpRect));
+    REBAR_SizeToHeight(infoPtr, get_rect_cy(infoPtr, lpRect));
     return TRUE;
 }
 
 
 
 static LRESULT
-REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_Create (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     LPCREATESTRUCTW cs = (LPCREATESTRUCTW) lParam;
     RECT wnrc1, clrc1;
-    HTHEME theme;
 
     if (TRACE_ON(rebar)) {
        GetWindowRect(infoPtr->hwndSelf, &wnrc1);
        GetClientRect(infoPtr->hwndSelf, &clrc1);
-       TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
-             wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
-             clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
+        TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
+              wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
              cs->x, cs->y, cs->cx, cs->cy);
     }
 
     TRACE("created!\n");
-    
-    if ((theme = OpenThemeData (infoPtr->hwndSelf, themeClass)))
+
+    if (OpenThemeData (infoPtr->hwndSelf, themeClass))
     {
         /* native seems to clear WS_BORDER when themed */
         infoPtr->dwStyle &= ~WS_BORDER;
@@ -2737,7 +2877,7 @@ REBAR_Create (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_Destroy (REBAR_INFO *infoPtr)
 {
     REBAR_BAND *lpBand;
     UINT i;
@@ -2750,10 +2890,8 @@ REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
            lpBand = &infoPtr->bands[i];
 
            /* delete text strings */
-           if (lpBand->lpText) {
-               Free (lpBand->lpText);
-               lpBand->lpText = NULL;
-           }
+            Free (lpBand->lpText);
+            lpBand->lpText = NULL;
            /* destroy child window */
            DestroyWindow (lpBand->hwndChild);
        }
@@ -2780,31 +2918,31 @@ REBAR_Destroy (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_EraseBkGnd (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_EraseBkGnd (const REBAR_INFO *infoPtr, WPARAM wParam)
 {
     RECT cliprect;
 
     if (GetClipBox ( (HDC)wParam, &cliprect))
-        return REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &cliprect);
+        return REBAR_InternalEraseBkGnd (infoPtr, wParam, &cliprect);
     return 0;
 }
 
 
 static LRESULT
-REBAR_GetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_GetFont (const REBAR_INFO *infoPtr)
 {
     return (LRESULT)infoPtr->hFont;
 }
 
 static LRESULT
-REBAR_PushChevron(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_PushChevron(const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
-    if (wParam >= 0 && (UINT)wParam < infoPtr->uNumBands)
+    if ((UINT)wParam < infoPtr->uNumBands)
     {
         NMREBARCHEVRON nmrbc;
         REBAR_BAND *lpBand = &infoPtr->bands[wParam];
 
-        TRACE("Pressed chevron on band %d\n", wParam);
+        TRACE("Pressed chevron on band %ld\n", wParam);
 
         /* redraw chevron in pushed state */
         lpBand->fDraw |= DRAW_CHEVRONPUSHED;
@@ -2829,7 +2967,7 @@ REBAR_PushChevron(REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 static LRESULT
-REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_LButtonDown (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     REBAR_BAND *lpBand;
     UINT htFlags;
@@ -2865,7 +3003,7 @@ REBAR_LButtonDown (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 static LRESULT
-REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_LButtonUp (REBAR_INFO *infoPtr)
 {
     if (infoPtr->iGrabbedBand >= 0)
     {
@@ -2894,7 +3032,7 @@ REBAR_LButtonUp (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 static LRESULT
-REBAR_MouseLeave (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_MouseLeave (REBAR_INFO *infoPtr)
 {
     if (infoPtr->ichevronhotBand >= 0)
     {
@@ -2912,7 +3050,7 @@ REBAR_MouseLeave (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 static LRESULT
-REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_MouseMove (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     REBAR_BAND *lpChevronBand;
     POINT ptMove;
@@ -3001,8 +3139,8 @@ REBAR_MouseMove (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 }
 
 
-inline static LRESULT
-REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+static inline LRESULT
+REBAR_NCCalcSize (const REBAR_INFO *infoPtr, LPARAM lParam)
 {
     HTHEME theme;
     RECT *rect = (RECT *)lParam;
@@ -3018,13 +3156,13 @@ REBAR_NCCalcSize (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
         /* FIXME: should use GetThemeInt */
         rect->top = min(rect->top + 1, rect->bottom);
     }
-    TRACE("new client=(%d,%d)-(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
+    TRACE("new client=(%s)\n", wine_dbgstr_rect(rect));
     return 0;
 }
 
 
 static LRESULT
-REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
+REBAR_NCCreate (HWND hwnd, LPARAM lParam)
 {
     LPCREATESTRUCTW cs = (LPCREATESTRUCTW) lParam;
     REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
@@ -3040,14 +3178,13 @@ REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
     if (TRACE_ON(rebar)) {
        GetWindowRect(hwnd, &wnrc1);
        GetClientRect(hwnd, &clrc1);
-       TRACE("window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) cs=(%d,%d %dx%d)\n",
-             wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
-             clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
+        TRACE("window=(%s) client=(%s) cs=(%d,%d %dx%d)\n",
+              wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
              cs->x, cs->y, cs->cx, cs->cy);
     }
 
     /* allocate memory for info structure */
-    infoPtr = (REBAR_INFO *)Alloc (sizeof(REBAR_INFO));
+    infoPtr = Alloc (sizeof(REBAR_INFO));
     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
 
     /* initialize info structure - initial values are 0 */
@@ -3068,7 +3205,7 @@ REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
     infoPtr->hFont = GetStockObject (SYSTEM_FONT);
 
     /* issue WM_NOTIFYFORMAT to get unicode status of parent */
-    REBAR_NotifyFormat(infoPtr, 0, NF_REQUERY);
+    REBAR_NotifyFormat(infoPtr, NF_REQUERY);
 
     /* Stow away the original style */
     infoPtr->orgStyle = cs->style;
@@ -3118,7 +3255,7 @@ REBAR_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_NCHitTest (const REBAR_INFO *infoPtr, LPARAM lParam)
 {
     NMMOUSE nmmouse;
     POINT clpt;
@@ -3153,7 +3290,7 @@ REBAR_NCHitTest (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_NCPaint (const REBAR_INFO *infoPtr)
 {
     RECT rcWindow;
     HDC hdc;
@@ -3169,9 +3306,7 @@ REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
            return 0;
        GetWindowRect (infoPtr->hwndSelf, &rcWindow);
        OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
-       TRACE("rect (%d,%d)-(%d,%d)\n",
-             rcWindow.left, rcWindow.top,
-             rcWindow.right, rcWindow.bottom);
+        TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
        DrawEdge (hdc, &rcWindow, EDGE_ETCHED, BF_RECT);
        ReleaseDC( infoPtr->hwndSelf, hdc );
     }
@@ -3182,9 +3317,7 @@ REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
             return 0;
         GetWindowRect (infoPtr->hwndSelf, &rcWindow);
         OffsetRect (&rcWindow, -rcWindow.left, -rcWindow.top);
-        TRACE("rect (%d,%d)-(%d,%d)\n",
-              rcWindow.left, rcWindow.top,
-              rcWindow.right, rcWindow.bottom);
+        TRACE("rect (%s)\n", wine_dbgstr_rect(&rcWindow));
         DrawThemeEdge (theme, hdc, 0, 0, &rcWindow, BDR_RAISEDINNER, BF_TOP, NULL);
         ReleaseDC( infoPtr->hwndSelf, hdc );
     }
@@ -3194,7 +3327,7 @@ REBAR_NCPaint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_NotifyFormat (REBAR_INFO *infoPtr, LPARAM lParam)
 {
     INT i;
 
@@ -3213,34 +3346,31 @@ REBAR_NotifyFormat (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_Paint (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_Paint (const REBAR_INFO *infoPtr, WPARAM wParam)
 {
-    HDC hdc;
-    PAINTSTRUCT ps;
-    RECT rc;
-
-    GetClientRect(infoPtr->hwndSelf, &rc);
-    hdc = wParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : (HDC)wParam;
-
-    TRACE("painting (%d,%d)-(%d,%d) client (%d,%d)-(%d,%d)\n",
-         ps.rcPaint.left, ps.rcPaint.top,
-         ps.rcPaint.right, ps.rcPaint.bottom,
-         rc.left, rc.top, rc.right, rc.bottom);
+    HDC hdc = (HDC)wParam;
 
-    if (ps.fErase) {
-       /* Erase area of paint if requested */
-        REBAR_InternalEraseBkGnd (infoPtr, wParam, lParam, &ps.rcPaint);
+    if (hdc) {
+        TRACE("painting\n");
+        REBAR_Refresh (infoPtr, hdc);
+    } else {
+        PAINTSTRUCT ps;
+        hdc = BeginPaint (infoPtr->hwndSelf, &ps);
+        TRACE("painting (%s)\n", wine_dbgstr_rect(&ps.rcPaint));
+        if (ps.fErase) {
+            /* Erase area of paint if requested */
+            REBAR_InternalEraseBkGnd (infoPtr, wParam, &ps.rcPaint);
+        }
+        REBAR_Refresh (infoPtr, hdc);
+       EndPaint (infoPtr->hwndSelf, &ps);
     }
 
-    REBAR_Refresh (infoPtr, hdc);
-    if (!wParam)
-       EndPaint (infoPtr->hwndSelf, &ps);
     return 0;
 }
 
 
 static LRESULT
-REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetCursor (const REBAR_INFO *infoPtr, LPARAM lParam)
 {
     POINT pt;
     UINT  flags;
@@ -3267,7 +3397,7 @@ REBAR_SetCursor (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 
 
 static LRESULT
-REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam)
 {
     REBAR_BAND *lpBand;
     UINT i;
@@ -3280,13 +3410,13 @@ REBAR_SetFont (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
        REBAR_ValidateBand (infoPtr, lpBand);
     }
 
-    REBAR_Layout(infoPtr, NULL);
+    REBAR_Layout(infoPtr);
     return 0;
 }
 
 
-inline static LRESULT
-REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+static inline LRESULT
+REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam)
      /*****************************************************
       *
       * Function;
@@ -3319,48 +3449,39 @@ REBAR_SetRedraw (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 static LRESULT
 REBAR_Size (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
-    TRACE("wParam=%x, lParam=%lx\n", wParam, lParam);
+    TRACE("wParam=%lx, lParam=%lx\n", wParam, lParam);
 
-    /* avoid auto resize infinite recursion */
-    if (infoPtr->fStatus & AUTO_RESIZE) {
-       infoPtr->fStatus &= ~AUTO_RESIZE;
-       TRACE("AUTO_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
+    /* avoid _Layout resize recursion (but it shouldn't be infinite and it seems Windows does recurse) */
+    if (infoPtr->fStatus & SELF_RESIZE) {
+       infoPtr->fStatus &= ~SELF_RESIZE;
+       TRACE("SELF_RESIZE was set, reset, fStatus=%08x lparam=%08lx\n",
              infoPtr->fStatus, lParam);
        return 0;
     }
     
-    /* FIXME: wrong */
-    if (infoPtr->dwStyle & RBS_AUTOSIZE) {
-       NMRBAUTOSIZE autosize;
-
-       GetClientRect(infoPtr->hwndSelf, &autosize.rcTarget);
-       autosize.fChanged = 0;  /* ??? */
-       autosize.rcActual = autosize.rcTarget;  /* ??? */
-       REBAR_Notify((NMHDR *) &autosize, infoPtr, RBN_AUTOSIZE);
-       TRACE("RBN_AUTOSIZE client=(%d,%d), lp=%08lx\n",
-             autosize.rcTarget.right, autosize.rcTarget.bottom, lParam);
-    }
-
-    REBAR_Layout(infoPtr, NULL);
+    if (infoPtr->dwStyle & RBS_AUTOSIZE)
+        REBAR_AutoSize(infoPtr, TRUE);
+    else
+        REBAR_Layout(infoPtr);
 
     return 0;
 }
 
 
 static LRESULT
-REBAR_StyleChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_StyleChanged (REBAR_INFO *infoPtr, INT nType, const STYLESTRUCT *lpStyle)
 {
-    STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
-
     TRACE("current style=%08x, styleOld=%08x, style being set to=%08x\n",
-         infoPtr->dwStyle, ss->styleOld, ss->styleNew);
-    infoPtr->orgStyle = infoPtr->dwStyle = ss->styleNew;
-    if (GetWindowTheme (infoPtr->hwndSelf))
-        infoPtr->dwStyle &= ~WS_BORDER;
-    /* maybe it should be COMMON_STYLES like in toolbar */
-    if ((ss->styleNew ^ ss->styleOld) & CCS_VERT)
-        REBAR_Layout(infoPtr, NULL);
-
+         infoPtr->dwStyle, lpStyle->styleOld, lpStyle->styleNew);
+    if (nType == GWL_STYLE)
+    {
+        infoPtr->orgStyle = infoPtr->dwStyle = lpStyle->styleNew;
+        if (GetWindowTheme (infoPtr->hwndSelf))
+            infoPtr->dwStyle &= ~WS_BORDER;
+        /* maybe it should be COMMON_STYLES like in toolbar */
+        if ((lpStyle->styleNew ^ lpStyle->styleOld) & CCS_VERT)
+            REBAR_Layout(infoPtr);
+    }
     return FALSE;
 }
 
@@ -3378,7 +3499,7 @@ static LRESULT theme_changed (REBAR_INFO* infoPtr)
 }
 
 static LRESULT
-REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+REBAR_WindowPosChanged (const REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 {
     LRESULT ret;
     RECT rc;
@@ -3386,8 +3507,7 @@ REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     ret = DefWindowProcW(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
                         wParam, lParam);
     GetWindowRect(infoPtr->hwndSelf, &rc);
-    TRACE("hwnd %p new pos (%d,%d)-(%d,%d)\n",
-         infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
+    TRACE("hwnd %p new pos (%s)\n", infoPtr->hwndSelf, wine_dbgstr_rect(&rc));
     return ret;
 }
 
@@ -3397,7 +3517,7 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     REBAR_INFO *infoPtr = REBAR_GetInfoPtr (hwnd);
 
-    TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n",
+    TRACE("hwnd=%p msg=%x wparam=%lx lparam=%lx\n",
          hwnd, uMsg, wParam, lParam);
     if (!infoPtr && (uMsg != WM_NCCREATE))
         return DefWindowProcW (hwnd, uMsg, wParam, lParam);
@@ -3406,7 +3526,7 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 /*     case RB_BEGINDRAG: */
 
        case RB_DELETEBAND:
-           return REBAR_DeleteBand (infoPtr, wParam, lParam);
+           return REBAR_DeleteBand (infoPtr, wParam);
 
 /*     case RB_DRAGMOVE: */
 /*     case RB_ENDDRAG: */
@@ -3425,10 +3545,10 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_GetBandInfoT(infoPtr, wParam, lParam, TRUE);
 
        case RB_GETBARHEIGHT:
-           return REBAR_GetBarHeight (infoPtr, wParam, lParam);
+           return REBAR_GetBarHeight (infoPtr);
 
        case RB_GETBARINFO:
-           return REBAR_GetBarInfo (infoPtr, wParam, lParam);
+           return REBAR_GetBarInfo (infoPtr, lParam);
 
        case RB_GETBKCOLOR:
            return REBAR_GetBkColor (infoPtr);
@@ -3446,7 +3566,7 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_GetRowCount (infoPtr);
 
        case RB_GETROWHEIGHT:
-           return REBAR_GetRowHeight (infoPtr, wParam, lParam);
+           return REBAR_GetRowHeight (infoPtr, wParam);
 
        case RB_GETTEXTCOLOR:
            return REBAR_GetTextColor (infoPtr);
@@ -3461,10 +3581,10 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_GetVersion (infoPtr);
 
        case RB_HITTEST:
-           return REBAR_HitTest (infoPtr, wParam, lParam);
+           return REBAR_HitTest (infoPtr, lParam);
 
        case RB_IDTOINDEX:
-           return REBAR_IdToIndex (infoPtr, wParam, lParam);
+           return REBAR_IdToIndex (infoPtr, wParam);
 
        case RB_INSERTBANDA:
            return REBAR_InsertBandT(infoPtr, wParam, lParam, FALSE);
@@ -3476,7 +3596,7 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_MaximizeBand (infoPtr, wParam, lParam);
 
        case RB_MINIMIZEBAND:
-           return REBAR_MinimizeBand (infoPtr, wParam, lParam);
+           return REBAR_MinimizeBand (infoPtr, wParam);
 
        case RB_MOVEBAND:
            return REBAR_MoveBand (infoPtr, wParam, lParam);
@@ -3491,20 +3611,20 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_SetBandInfoT(infoPtr, wParam, lParam, TRUE);
 
        case RB_SETBARINFO:
-           return REBAR_SetBarInfo (infoPtr, wParam, lParam);
+           return REBAR_SetBarInfo (infoPtr, lParam);
 
        case RB_SETBKCOLOR:
-           return REBAR_SetBkColor (infoPtr, wParam, lParam);
+           return REBAR_SetBkColor (infoPtr, lParam);
 
 /*     case RB_SETCOLORSCHEME: */
 /*     case RB_SETPALETTE: */
 /*         return REBAR_GetPalette (infoPtr, wParam, lParam); */
 
        case RB_SETPARENT:
-           return REBAR_SetParent (infoPtr, wParam, lParam);
+           return REBAR_SetParent (infoPtr, wParam);
 
        case RB_SETTEXTCOLOR:
-           return REBAR_SetTextColor (infoPtr, wParam, lParam);
+           return REBAR_SetTextColor (infoPtr, lParam);
 
 /*     case RB_SETTOOLTIPS: */
 
@@ -3518,7 +3638,7 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_ShowBand (infoPtr, wParam, lParam);
 
        case RB_SIZETORECT:
-           return REBAR_SizeToRect (infoPtr, wParam, lParam);
+           return REBAR_SizeToRect (infoPtr, lParam);
 
 
 /*    Messages passed to parent */
@@ -3531,51 +3651,51 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 /*      case WM_CHARTOITEM:     supported according to ControlSpy */
 
        case WM_CREATE:
-           return REBAR_Create (infoPtr, wParam, lParam);
+           return REBAR_Create (infoPtr, lParam);
 
        case WM_DESTROY:
-           return REBAR_Destroy (infoPtr, wParam, lParam);
+           return REBAR_Destroy (infoPtr);
 
         case WM_ERASEBKGND:
-           return REBAR_EraseBkGnd (infoPtr, wParam, lParam);
+           return REBAR_EraseBkGnd (infoPtr, wParam);
 
        case WM_GETFONT:
-           return REBAR_GetFont (infoPtr, wParam, lParam);
+           return REBAR_GetFont (infoPtr);
 
 /*      case WM_LBUTTONDBLCLK:  supported according to ControlSpy */
 
        case WM_LBUTTONDOWN:
-           return REBAR_LButtonDown (infoPtr, wParam, lParam);
+           return REBAR_LButtonDown (infoPtr, lParam);
 
        case WM_LBUTTONUP:
-           return REBAR_LButtonUp (infoPtr, wParam, lParam);
+           return REBAR_LButtonUp (infoPtr);
 
 /*      case WM_MEASUREITEM:    supported according to ControlSpy */
 
        case WM_MOUSEMOVE:
-           return REBAR_MouseMove (infoPtr, wParam, lParam);
+           return REBAR_MouseMove (infoPtr, lParam);
 
        case WM_MOUSELEAVE:
-           return REBAR_MouseLeave (infoPtr, wParam, lParam);
+           return REBAR_MouseLeave (infoPtr);
 
        case WM_NCCALCSIZE:
-           return REBAR_NCCalcSize (infoPtr, wParam, lParam);
+           return REBAR_NCCalcSize (infoPtr, lParam);
 
         case WM_NCCREATE:
-           return REBAR_NCCreate (hwnd, wParam, lParam);
+           return REBAR_NCCreate (hwnd, lParam);
 
         case WM_NCHITTEST:
-           return REBAR_NCHitTest (infoPtr, wParam, lParam);
+           return REBAR_NCHitTest (infoPtr, lParam);
 
        case WM_NCPAINT:
-           return REBAR_NCPaint (infoPtr, wParam, lParam);
+           return REBAR_NCPaint (infoPtr);
 
         case WM_NOTIFYFORMAT:
-           return REBAR_NotifyFormat (infoPtr, wParam, lParam);
+           return REBAR_NotifyFormat (infoPtr, lParam);
 
        case WM_PRINTCLIENT:
        case WM_PAINT:
-           return REBAR_Paint (infoPtr, wParam, lParam);
+           return REBAR_Paint (infoPtr, wParam);
 
 /*      case WM_PALETTECHANGED: supported according to ControlSpy */
 /*      case WM_QUERYNEWPALETTE:supported according to ControlSpy */
@@ -3583,19 +3703,19 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 /*      case WM_RBUTTONUP:      supported according to ControlSpy */
 
        case WM_SETCURSOR:
-           return REBAR_SetCursor (infoPtr, wParam, lParam);
+           return REBAR_SetCursor (infoPtr, lParam);
 
        case WM_SETFONT:
-           return REBAR_SetFont (infoPtr, wParam, lParam);
+           return REBAR_SetFont (infoPtr, wParam);
 
         case WM_SETREDRAW:
-           return REBAR_SetRedraw (infoPtr, wParam, lParam);
+           return REBAR_SetRedraw (infoPtr, wParam);
 
        case WM_SIZE:
            return REBAR_Size (infoPtr, wParam, lParam);
 
         case WM_STYLECHANGED:
-           return REBAR_StyleChanged (infoPtr, wParam, lParam);
+           return REBAR_StyleChanged (infoPtr, wParam, (LPSTYLESTRUCT)lParam);
 
         case WM_THEMECHANGED:
             return theme_changed (infoPtr);
@@ -3612,8 +3732,8 @@ REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
 
        default:
-           if ((uMsg >= WM_USER) && (uMsg < WM_APP))
-               ERR("unknown msg %04x wp=%08x lp=%08lx\n",
+           if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
+               ERR("unknown msg %04x wp=%08lx lp=%08lx\n",
                     uMsg, wParam, lParam);
            return DefWindowProcW (hwnd, uMsg, wParam, lParam);
     }