Author: toshok
Date: 2006-06-27 15:43:08 -0400 (Tue, 27 Jun 2006)
New Revision: 62092

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTableStyle.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
Log:
2006-06-27  Chris Toshok  <[EMAIL PROTECTED]>

        * DataGridTableStyle.cs: clean up the constructors, and build the
        list of child relations for this table.  I have no idea if this is
        where we should be doing it (it probably isn't), but since we're
        already iterating over the properties..

        * DataGrid.cs: add row resizing.  for now we add a DataGridRow
        struct and array for keeping track of row information, similar to
        what's shown in a hack on
        http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx.

        * Theme.cs: be consistent about the naming of DataGrid methods,
        prefering ColumnWidths and RowHeights over columnsWidths and
        RowsHeights.

        * ThemeWin32Classic.cs: same, and also add support for variable
        sized rows (and the +/- expansion icons for related rows).



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-06-27 19:10:14 UTC (rev 62091)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-06-27 19:43:08 UTC (rev 62092)
@@ -1,3 +1,22 @@
+2006-06-27  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * DataGridTableStyle.cs: clean up the constructors, and build the
+       list of child relations for this table.  I have no idea if this is
+       where we should be doing it (it probably isn't), but since we're
+       already iterating over the properties..
+
+       * DataGrid.cs: add row resizing.  for now we add a DataGridRow
+       struct and array for keeping track of row information, similar to
+       what's shown in a hack on
+       http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx.
+
+       * Theme.cs: be consistent about the naming of DataGrid methods,
+       prefering ColumnWidths and RowHeights over columnsWidths and
+       RowsHeights.
+
+       * ThemeWin32Classic.cs: same, and also add support for variable
+       sized rows (and the +/- expansion icons for related rows).
+
 2006-06-27  Peter Dennis Bartok  <[EMAIL PROTECTED]>
 
        * TextBoxBase.cs: Applied Eno's patch from #78660

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-06-27 19:10:14 UTC (rev 62091)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-06-27 19:43:08 UTC (rev 62092)
@@ -36,6 +36,13 @@
 
 namespace System.Windows.Forms
 {
+       internal struct DataGridRow {
+               public bool IsSelected;
+               public bool IsExpanded;
+               public int VerticalOffset;
+               public int Height;
+       }
+
        [DefaultEvent("Navigate")]
        [DefaultProperty("DataSource")]
        [Designer("System.Windows.Forms.Design.DataGridDesigner, " + 
Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
@@ -169,7 +176,7 @@
                internal HScrollBar horiz_scrollbar;
                internal VScrollBar vert_scrollbar;
                internal DataGridDrawing grid_drawing;
-               internal int first_visiblerow;
+               private int first_visiblerow;
                internal int horz_pixeloffset;
                bool is_adding;                 // Indicates when we are adding 
a row
                bool is_editing;                // Current cell is edit mode
@@ -180,12 +187,18 @@
                private bool begininit;
                private CurrencyManager list_manager;
                private bool accept_listmgrevents;
+               internal DataGridRow[] rows;
 
                bool column_resize_active;
                int resize_column_x;
                int resize_column_width_delta;
                int resize_column;
                
+               bool row_resize_active;
+               int resize_row_y;
+               int resize_row_height_delta;
+               int resize_row;
+
                bool from_positionchanged_handler;
 
                Stack memberHistory;
@@ -244,6 +257,7 @@
                        expanded_rows = new Hashtable ();
                        preferredrow_height = def_preferredrow_height = 
FontHeight + 3;
                        list_manager = null;
+                       rows = new DataGridRow[0];
                        accept_listmgrevents = true;
 
                        default_style = new DataGridTableStyle (true);
@@ -534,6 +548,7 @@
                public object DataSource {
                        get { return datasource; }
                        set {
+                               SetDataMember ("");
                                SetDataSource (value);
                                SetNewDataSource ();                            
        
                        }
@@ -680,6 +695,12 @@
                                if (list_manager != null)
                                        ConnectListManagerEvents ();
 
+                               rows = new DataGridRow [list_manager.Count + 1];
+                               for (int i = 0; i < rows.Length; i ++) {
+                                       rows[i].Height = RowHeight;
+                                       if (i > 0)
+                                               rows[i].VerticalOffset = 
rows[i-1].VerticalOffset + rows[i-1].Height;
+                               }
                                return list_manager;
                        }
                        set { throw new NotSupportedException ("Operation is 
not supported."); }
@@ -849,7 +870,7 @@
                        get { return visiblecolumn_count; }
                }
 
-               // Calculated at DataGridDrawing.CalcRowsHeaders
+               // Calculated at DataGridDrawing.CalcRowHeaders
                [Browsable(false)]
                public int VisibleRowCount {
                        get { return visiblerow_count; }
@@ -964,8 +985,12 @@
                [MonoTODO]
                public void Collapse (int row)
                {
+                       if (!expanded_rows.ContainsKey (row))
+                               return;
+
                        expanded_rows.Remove (row);
                        /* XX need to redraw from @row down */
+                       CalcAreasAndInvalidate ();                      
                }
 
                protected internal virtual void ColumnStartedEditing (Control 
editingControl)
@@ -1040,8 +1065,12 @@
 
                public void Expand (int row)
                {
+                       if (expanded_rows.ContainsKey (row))
+                               return;
+
                        expanded_rows[row] = true;
                        /* XX need to redraw from @row down */
+                       CalcAreasAndInvalidate ();                      
                }
 
                public Rectangle GetCellBounds (DataGridCell cell)
@@ -1301,11 +1330,28 @@
                        }
                        case HitTestType.RowHeader:
                        {
-                               if (ctrl_pressed == false && shift_pressed == 
false) {
+                               bool expansion_click = false;
+                               if (CurrentTableStyle.HasRelations) {
+                                       if (e.X > grid_drawing.rowhdrs_area.X + 
grid_drawing.rowhdrs_area.Width / 2) {
+                                               /* it's in the +/- space */
+                                               if (IsExpanded (testinfo.Row))
+                                                       Collapse (testinfo.Row);
+                                               else
+                                                       Expand (testinfo.Row);
+
+                                               expansion_click = true;
+                                       }
+                               }
+
+                               if (!ctrl_pressed &&
+                                   !shift_pressed &&
+                                   !expansion_click) {
                                        ResetSelection (); // Invalidates 
selected rows
                                }
 
-                               if (shift_pressed == true && selection_start != 
-1) {
+                               if ((shift_pressed ||
+                                    expansion_click)
+                                   && selection_start != -1) {
                                        ShiftSelection (testinfo.Row);
                                } else { // ctrl_pressed or single item
                                        selection_start = testinfo.Row;
@@ -1358,10 +1404,20 @@
                                column_resize_active = true;
                                resize_column_x = e.X;
                                resize_column_width_delta = 0;
-                               grid_drawing.DrawResizeLine (resize_column_x);
+                               grid_drawing.DrawResizeLineVert 
(resize_column_x);
                                break;
                        }
 
+                       case HitTestType.RowResize:
+                       {
+                               resize_row = testinfo.Row;
+                               row_resize_active = true;
+                               resize_row_y = e.Y;
+                               resize_row_height_delta = 0;
+                               grid_drawing.DrawResizeLineHoriz (resize_row_y);
+                               break;
+                       }
+
                        default:
                                break;
                        }
@@ -1378,14 +1434,24 @@
 
                        if (column_resize_active) {
                                /* erase the old line */
-                               grid_drawing.DrawResizeLine (resize_column_x + 
resize_column_width_delta);
+                               grid_drawing.DrawResizeLineVert 
(resize_column_x + resize_column_width_delta);
 
                                resize_column_width_delta = e.X - 
resize_column_x;
 
                                /* draw the new line */
-                               grid_drawing.DrawResizeLine (resize_column_x + 
resize_column_width_delta);
+                               grid_drawing.DrawResizeLineVert 
(resize_column_x + resize_column_width_delta);
                                return;
                        }
+                       else if (row_resize_active) {
+                               /* erase the old line */
+                               grid_drawing.DrawResizeLineHoriz (resize_row_y 
+ resize_row_height_delta);
+
+                               resize_row_height_delta = e.Y - resize_row_y;
+
+                               /* draw the new line */
+                               grid_drawing.DrawResizeLineHoriz (resize_row_y 
+ resize_row_height_delta);
+                               return;
+                       }
                        else {
                                HitTestInfo testinfo;
                                testinfo = HitTest (e.X, e.Y);
@@ -1416,6 +1482,18 @@
                                
CurrentTableStyle.GridColumnStyles[resize_column].Width = new_width;
                                Invalidate ();
                        }
+                       else if (row_resize_active) {
+                               row_resize_active = false;
+
+                               if (resize_row_height_delta + 
rows[resize_row].Height < 0)
+                                       resize_row_height_delta = 
-rows[resize_row].Height;
+
+                               rows[resize_row].Height = 
rows[resize_row].Height + resize_row_height_delta;
+                               for (int i = resize_row + 1; i < rows.Length; i 
++)
+                                       rows[i].VerticalOffset += 
resize_row_height_delta;
+
+                               CalcAreasAndInvalidate ();
+                       }
                }
 
                protected override void OnMouseWheel (MouseEventArgs e)
@@ -1865,7 +1943,6 @@
 
                public void SubObjectsSiteChange (bool site)
                {
-
                }
 
                public void UnSelect (int row)
@@ -2101,8 +2178,8 @@
                        grid_drawing.UpdateVisibleColumn ();
 
                        if (columnheaders_visible == true) {
-                               area.Y -= 
grid_drawing.ColumnsHeadersArea.Height;
-                               area.Height += 
grid_drawing.ColumnsHeadersArea.Height;
+                               area.Y -= grid_drawing.ColumnHeadersArea.Height;
+                               area.Height += 
grid_drawing.ColumnHeadersArea.Height;
                        }
 
                        XplatUI.ScrollWindow (Handle, area, pixels, 0, false);
@@ -2110,13 +2187,16 @@
 
                private void ScrollToRow (int old_row, int new_row)
                {
-                       int pixels;
+                       int pixels = 0;
+                       int i;
 
                        if (new_row > old_row) { // Scrolldown
-                               pixels = -1 * (new_row - old_row) * RowHeight;
+                               for (i = old_row; i < new_row; i ++)
+                                       pixels -= rows[i].Height;
                        }
                        else {
-                               pixels = (old_row - new_row) * RowHeight;
+                               for (i = new_row; i < old_row; i ++)
+                                       pixels += rows[i].Height;
                        }
 
                        Rectangle rows_area = grid_drawing.CellsArea; // Cells 
area - partial rows space

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
  2006-06-27 19:10:14 UTC (rev 62091)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
  2006-06-27 19:43:08 UTC (rev 62092)
@@ -41,10 +41,10 @@
                // Areas
                internal Rectangle caption_area;
                internal Rectangle parent_rows;
-               internal Rectangle columnshdrs_area;    // Used columns header 
area
-               internal int columnshdrs_maxwidth;      // Total width (max 
width) for columns headrs
-               internal Rectangle rowshdrs_area;       // Used Headers rows 
area
-               internal int rowshdrs_maxheight;        // Total height for 
rows (max height)
+               internal Rectangle columnhdrs_area;     // Used columns header 
area
+               internal int columnhdrs_maxwidth;       // Total width (max 
width) for columns headrs
+               internal Rectangle rowhdrs_area;        // Used Headers rows 
area
+               internal int rowhdrs_maxheight;         // Total height for 
rows (max height)
                internal Rectangle cells_area;
                internal Font font_newrow = new Font 
(FontFamily.GenericSansSerif, 16);
                #endregion // Local Variables
@@ -81,8 +81,8 @@
                                return 0;
                                
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
-                               width += rowshdrs_area.X + rowshdrs_area.Width;
-                               column_x += rowshdrs_area.X + 
rowshdrs_area.Width;
+                               width += rowhdrs_area.X + rowhdrs_area.Width;
+                               column_x += rowhdrs_area.X + rowhdrs_area.Width;
                        }
 
                        for (int col = 0; col < cnt; col++) {
@@ -150,8 +150,9 @@
                        grid.horz_pixeloffset = 0;                      
                        CalcCaption ();
                        CalcParentRows ();
-                       CalcRowsHeaders (grid.visiblerow_count);
-                       CalcColumnsHeader ();
+                       UpdateVisibleRowCount ();
+                       CalcRowHeaders (grid.visiblerow_count);
+                       CalcColumnHeaders ();
                        CalcCellsArea ();
 
                        bool needHoriz = false;
@@ -199,8 +200,8 @@
                                }
 
                                if (!ShowingColumnHeaders) {
-                                       if (columnshdrs_area.X + 
columnshdrs_area.Width > grid.vert_scrollbar.Location.X) {
-                                               columnshdrs_area.Width -= 
grid.vert_scrollbar.Width;
+                                       if (columnhdrs_area.X + 
columnhdrs_area.Width > grid.vert_scrollbar.Location.X) {
+                                               columnhdrs_area.Width -= 
grid.vert_scrollbar.Width;
                                        }
                                }
 
@@ -209,9 +210,9 @@
                        }
 
                        if (needVert) {
-                               if (rowshdrs_area.Y + rowshdrs_area.Height > 
grid.ClientRectangle.Y + grid.ClientRectangle.Height) {
-                                       rowshdrs_area.Height -= 
grid.horiz_scrollbar.Height;
-                                       rowshdrs_maxheight -= 
grid.horiz_scrollbar.Height;
+                               if (rowhdrs_area.Y + rowhdrs_area.Height > 
grid.ClientRectangle.Y + grid.ClientRectangle.Height) {
+                                       rowhdrs_area.Height -= 
grid.horiz_scrollbar.Height;
+                                       rowhdrs_maxheight -= 
grid.horiz_scrollbar.Height;
                                }
 
                                grid.vert_scrollbar.Height = 
vert_scrollbar_height;
@@ -240,8 +241,8 @@
 
                        //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
caption_area:{0}", caption_area);
                        //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
parent_rows:{0}", parent_rows);
-                       //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
rowshdrs_area:{0}", rowshdrs_area);
-                       //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
columnshdrs_area:{0}", columnshdrs_area);
+                       //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
rowhdrs_area:{0}", rowhdrs_area);
+                       //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
columnhdrs_area:{0}", columnhdrs_area);
                        //Console.WriteLine ("DataGridDrawing.CalcGridAreas 
cells:{0}", cells_area);
 
                        in_calc_grid_areas = false;
@@ -275,58 +276,58 @@
                        }
 
                        if (ShowingColumnHeaders) {
-                               cells_area.Y += columnshdrs_area.Height;
+                               cells_area.Y += columnhdrs_area.Height;
                        }
 
-                       cells_area.X = grid.ClientRectangle.X + 
rowshdrs_area.Width;
+                       cells_area.X = grid.ClientRectangle.X + 
rowhdrs_area.Width;
                        cells_area.Width = grid.ClientRectangle.X + 
grid.ClientRectangle.Width - cells_area.X;
                        cells_area.Height = grid.ClientRectangle.Y + 
grid.ClientRectangle.Height - cells_area.Y;
 
                        //Console.WriteLine ("DataGridDrawing.CalcCellsArea 
{0}", cells_area);
                }
 
-               private void CalcColumnsHeader ()
+               private void CalcColumnHeaders ()
                {
                        int width_all_cols, max_width_cols;
                        
                        if (!ShowingColumnHeaders) {
-                               columnshdrs_area = Rectangle.Empty;             
                
+                               columnhdrs_area = Rectangle.Empty;              
                
                                return;
                        }
 
                        if (grid.caption_visible) {
-                               columnshdrs_area.Y = caption_area.Y + 
caption_area.Height;
+                               columnhdrs_area.Y = caption_area.Y + 
caption_area.Height;
                        } else {
-                               columnshdrs_area.Y = grid.ClientRectangle.Y;
+                               columnhdrs_area.Y = grid.ClientRectangle.Y;
                        }
 
                        if (grid.ShowParentRowsVisible) {
-                               columnshdrs_area.Y += parent_rows.Height;
+                               columnhdrs_area.Y += parent_rows.Height;
                        }
 
-                       columnshdrs_area.X = grid.ClientRectangle.X;
-                       columnshdrs_area.Height = ColumnsHeaderHeight;
+                       columnhdrs_area.X = grid.ClientRectangle.X;
+                       columnhdrs_area.Height = ColumnHeadersHeight;
                        width_all_cols = CalcAllColumnsWidth ();
 
                        // TODO: take into account Scrollbars
-                       columnshdrs_maxwidth = grid.ClientRectangle.X + 
grid.ClientRectangle.Width - columnshdrs_area.X;
-                       max_width_cols = columnshdrs_maxwidth;
+                       columnhdrs_maxwidth = grid.ClientRectangle.X + 
grid.ClientRectangle.Width - columnhdrs_area.X;
+                       max_width_cols = columnhdrs_maxwidth;
 
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
                                max_width_cols -= grid.RowHeaderWidth;
                        }
 
                        if (width_all_cols > max_width_cols) {
-                               columnshdrs_area.Width = columnshdrs_maxwidth;
+                               columnhdrs_area.Width = columnhdrs_maxwidth;
                        } else {
-                               columnshdrs_area.Width = width_all_cols;
+                               columnhdrs_area.Width = width_all_cols;
 
                                if 
(grid.CurrentTableStyle.CurrentRowHeadersVisible) {
-                                       columnshdrs_area.Width += 
grid.RowHeaderWidth;
+                                       columnhdrs_area.Width += 
grid.RowHeaderWidth;
                                }
                        }
 
-                       //Console.WriteLine ("DataGridDrawing.CalcColumnsHeader 
{0}", columnshdrs_area);
+                       //Console.WriteLine ("DataGridDrawing.CalcColumnHeaders 
{0}", columnhdrs_area);
                }
 
                private void CalcParentRows ()
@@ -350,61 +351,67 @@
                        //Console.WriteLine ("DataGridDrawing.CalcParentRows 
{0}", parent_rows);
                }
 
-               private void CalcRowsHeaders (int visiblerow_count)
+               private void CalcRowHeaders (int visiblerow_count)
                {
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible == 
false) {
-                               rowshdrs_area = Rectangle.Empty;
+                               rowhdrs_area = Rectangle.Empty;
                                return;
                        }
 
                        if (grid.caption_visible) {
-                               rowshdrs_area.Y = caption_area.Y + 
caption_area.Height;
+                               rowhdrs_area.Y = caption_area.Y + 
caption_area.Height;
                        } else {
-                               rowshdrs_area.Y = grid.ClientRectangle.Y;
+                               rowhdrs_area.Y = grid.ClientRectangle.Y;
                        }
 
                        if (grid.ShowParentRowsVisible) {
-                               rowshdrs_area.Y += parent_rows.Height;
+                               rowhdrs_area.Y += parent_rows.Height;
                        }
 
                        if (ShowingColumnHeaders) { // first block is painted 
by ColumnHeader
-                               rowshdrs_area.Y += ColumnsHeaderHeight;
+                               rowhdrs_area.Y += ColumnHeadersHeight;
                        }
 
-                       rowshdrs_area.X = grid.ClientRectangle.X;
-                       rowshdrs_area.Width = grid.RowHeaderWidth;
-                       rowshdrs_area.Height = visiblerow_count * 
grid.RowHeight;
-                       rowshdrs_maxheight = grid.ClientRectangle.Height + 
grid.ClientRectangle.Y - rowshdrs_area.Y;
+                       rowhdrs_area.X = grid.ClientRectangle.X;
+                       rowhdrs_area.Width = grid.RowHeaderWidth;
+                       if (visiblerow_count == 0)
+                               rowhdrs_area.Height = 0;
+                       else
+                               rowhdrs_area.Height = 
(grid.rows[visiblerow_count + grid.FirstVisibleRow - 1].VerticalOffset - 
grid.rows[grid.FirstVisibleRow].VerticalOffset
+                                                      + 
grid.rows[visiblerow_count + grid.FirstVisibleRow - 1].Height);
+                       rowhdrs_maxheight = grid.ClientRectangle.Height + 
grid.ClientRectangle.Y - rowhdrs_area.Y;
 
-                       //Console.WriteLine ("DataGridDrawing.CalcRowsHeaders 
{0} {1}", rowshdrs_area,
-                       //      rowshdrs_maxheight);
+                       //Console.WriteLine ("DataGridDrawing.CalcRowHeaders 
{0} {1}", rowhdrs_area,
+                       //      rowhdrs_maxheight);
                }
 
                private int GetVisibleRowCount (int visibleHeight)
                {
-                       int rv;
+                       //                      Console.Write 
("GetVisibleRowCount ({0}) - ", visibleHeight);
                        int total_rows = grid.RowsCount;
                        
                        if (grid.ShowEditRow && grid.RowsCount > 0) {
                                total_rows++;
                        }
 
-                       int rows_height = (total_rows - grid.first_visiblerow) 
* grid.RowHeight;
-                       int max_rows = visibleHeight / grid.RowHeight;
-                                               
-                       if (max_rows > total_rows) {
-                               max_rows = total_rows;
+                       int rows_height = 0;
+                       int r;
+                       for (r = grid.FirstVisibleRow; r < grid.RowsCount; r 
++) {
+                               //                              Console.Write 
("{0},", grid.rows[r].Height);
+                               if (rows_height + grid.rows[r].Height >= 
visibleHeight)
+                                       break;
+                               rows_height += grid.rows[r].Height;
                        }
 
-                       if (rows_height > cells_area.Height) {
-                               rv = max_rows;
-                       } else {
-                               rv = total_rows;
-                       }       
+                       /* add in the edit row if it'll fit */
+                       if (grid.ShowEditRow && grid.RowsCount > 0 && 
visibleHeight - rows_height > grid.RowHeight)
+                               r ++;
 
-                       if (rv + grid.first_visiblerow > total_rows)
-                               rv = total_rows - grid.first_visiblerow;
-                       return rv;
+                       if (r < grid.rows.Length - 1)
+                               r ++;
+                       //                      Console.WriteLine (" 
rows_height = {0}, returning {1}", rows_height, r - grid.FirstVisibleRow);
+
+                       return r - grid.FirstVisibleRow;
                }
 
                public void UpdateVisibleColumn ()
@@ -431,44 +438,28 @@
 
                public void UpdateVisibleRowCount ()
                {
-                       int max_height = cells_area.Height;
-                       int max_rows = max_height / grid.RowHeight;
+                       grid.visiblerow_count = GetVisibleRowCount 
(cells_area.Height);
 
-                       int total_rows = grid.RowsCount;
-                       
-                       if (grid.ShowEditRow && grid.RowsCount > 0) {
-                               total_rows++;
-                       }
+                       CalcRowHeaders (grid.visiblerow_count); // Height 
depends on num of visible rows
 
-                       if (max_rows > total_rows) {
-                               max_rows = total_rows;
-                       }
-
-                       grid.visiblerow_count = GetVisibleRowCount (max_height);
-
-                       CalcRowsHeaders (grid.visiblerow_count); // Height 
depends on num of visible rows               
-
-                       if (grid.visiblerow_count < max_rows) {
-                               grid.visiblerow_count = max_rows;
-                               grid.first_visiblerow = total_rows - max_rows;
-                               grid.Invalidate ();
-                       }
-                       
+                       // XXX
+                       grid.Invalidate ();
                }
 
-               const int RESIZE_AREA_SIZE = 5;
+               const int RESIZE_HANDLE_HORIZ_SIZE = 5;
+               const int RESIZE_HANDLE_VERT_SIZE = 3;
 
                // From Point to Cell
                public DataGrid.HitTestInfo HitTest (int x, int y)
                {
                        DataGrid.HitTestInfo hit = new DataGrid.HitTestInfo ();
 
-                       if (columnshdrs_area.Contains (x, y)) {
+                       if (columnhdrs_area.Contains (x, y)) {
                                int offset_x = x + grid.horz_pixeloffset;
                                int column_x;
                                int column_under_mouse = FromPixelToColumn 
(offset_x, out column_x);
                                
-                               if ((column_x + 
grid.CurrentTableStyle.GridColumnStyles[column_under_mouse].Width - offset_x < 
RESIZE_AREA_SIZE)
+                               if ((column_x + 
grid.CurrentTableStyle.GridColumnStyles[column_under_mouse].Width - offset_x < 
RESIZE_HANDLE_HORIZ_SIZE)
                                    && column_under_mouse < 
grid.CurrentTableStyle.GridColumnStyles.Count) {
                                        hit.type = 
DataGrid.HitTestType.ColumnResize;
                                        hit.column = column_under_mouse;
@@ -480,14 +471,18 @@
                                return hit;
                        }
 
-                       // TODO: Add missing RowResize checks
-                       if (rowshdrs_area.Contains (x, y)) {
-                               hit.type = DataGrid.HitTestType.RowHeader;
+                       if (rowhdrs_area.Contains (x, y)) {
                                int posy;
                                int rcnt = grid.FirstVisibleRow + 
grid.VisibleRowCount;
                                for (int r = grid.FirstVisibleRow; r < rcnt; 
r++) {
-                                       posy = cells_area.Y + ((r - 
grid.FirstVisibleRow) * grid.RowHeight);
-                                       if (y <= posy + grid.RowHeight) { // 
Found row
+                                       posy = cells_area.Y + 
grid.rows[r].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
+                                       if (y <= posy + grid.rows[r].Height) {
+                                               if ((posy + 
grid.rows[r].Height) - y < RESIZE_HANDLE_VERT_SIZE) {
+                                                       hit.type = 
DataGrid.HitTestType.RowResize;
+                                               }
+                                               else {
+                                                       hit.type = 
DataGrid.HitTestType.RowHeader;
+                                               }
                                                hit.row = r;
                                                break;
                                        }
@@ -508,9 +503,9 @@
                        int pos_y, pos_x, width;
                        int rowcnt = grid.FirstVisibleRow + 
grid.VisibleRowCount;
                        for (int row = grid.FirstVisibleRow; row < rowcnt; 
row++) {
-                               pos_y = cells_area.Y + ((row - 
grid.FirstVisibleRow) * grid.RowHeight);
 
-                               if (y <= pos_y + grid.RowHeight) { // Found row
+                               pos_y = cells_area.Y + 
grid.rows[row].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
+                               if (y <= pos_y + grid.rows[row].Height) {
                                        hit.row = row;
                                        hit.type = DataGrid.HitTestType.Cell;   
                                
                                        int col_pixel;
@@ -540,8 +535,8 @@
                        int col_pixel;
 
                        bounds.Width = 
grid.CurrentTableStyle.GridColumnStyles[col].Width;
-                       bounds.Height = grid.RowHeight;
-                       bounds.Y = cells_area.Y + ((row - grid.FirstVisibleRow) 
* grid.RowHeight);
+                       bounds.Height = grid.rows[row].Height;
+                       bounds.Y = cells_area.Y + grid.rows[row].VerticalOffset 
- grid.rows[grid.FirstVisibleRow].VerticalOffset;
                        col_pixel = GetColumnStartingPixel (col);
                        bounds.X = cells_area.X + col_pixel - 
grid.horz_pixeloffset;
                        return bounds;
@@ -576,18 +571,18 @@
                                row_width = cells_area.Width;
                        rect_row.X = cells_area.X;
                        rect_row.Width = row_width;
-                       rect_row.Height = grid.RowHeight;
-                       rect_row.Y = cells_area.Y + ((row - 
grid.FirstVisibleRow) * grid.RowHeight);
+                       rect_row.Height = grid.rows[row].Height;
+                       rect_row.Y = cells_area.Y + 
grid.rows[row].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
                        grid.Invalidate (rect_row);
                }
 
                public void InvalidateRowHeader (int row)
                {
                        Rectangle rect_rowhdr = new Rectangle ();
-                       rect_rowhdr.X = rowshdrs_area.X;
-                       rect_rowhdr.Width = rowshdrs_area.Width;
-                       rect_rowhdr.Height = grid.RowHeight;
-                       rect_rowhdr.Y = rowshdrs_area.Y + ((row - 
grid.FirstVisibleRow) * grid.RowHeight);
+                       rect_rowhdr.X = rowhdrs_area.X;
+                       rect_rowhdr.Width = rowhdrs_area.Width;
+                       rect_rowhdr.Height = grid.rows[row].Height;
+                       rect_rowhdr.Y = rowhdrs_area.Y + 
grid.rows[row].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
                        grid.Invalidate (rect_rowhdr);
                }       
 
@@ -611,13 +606,20 @@
                        grid.Invalidate (rect_col);
                }
 
-               public void DrawResizeLine (int x)
+               public void DrawResizeLineVert (int x)
                {
                        XplatUI.DrawReversibleRectangle (grid.Handle,
-                                                        new Rectangle (x, 
CellsArea.Y, 1, CellsArea.Height),
-                                                        3);
+                                                        new Rectangle (x, 
cells_area.Y, 1, cells_area.Height - 3),
+                                                        2);
                }
 
+               public void DrawResizeLineHoriz (int y)
+               {
+                       XplatUI.DrawReversibleRectangle (grid.Handle,
+                                                        new Rectangle 
(cells_area.X, y, cells_area.Width - 3, 1),
+                                                        2);
+               }
+
                void SetUpHorizontalScrollBar (out int maximum)
                {
                        maximum = CalcAllColumnsWidth ();
@@ -668,10 +670,10 @@
                        }
                }
 
-               // Returns the ColumnsHeader area excluding the rectangle 
shared with RowsHeader
-               public Rectangle ColumnsHeadersArea {
+               // Returns the ColumnHeaders area excluding the rectangle 
shared with RowHeaders
+               public Rectangle ColumnHeadersArea {
                        get {
-                               Rectangle columns_area = columnshdrs_area;
+                               Rectangle columns_area = columnhdrs_area;
 
                                if 
(grid.CurrentTableStyle.CurrentRowHeadersVisible) {
                                        columns_area.X += grid.RowHeaderWidth;
@@ -685,21 +687,21 @@
                        get { return grid.columnheaders_visible != false && 
grid.CurrentTableStyle.GridColumnStyles.Count > 0; }
                }
 
-               int ColumnsHeaderHeight {
+               int ColumnHeadersHeight {
                        get {
                                return grid.CurrentTableStyle.HeaderFont.Height 
+ 6;
                        }
                }
 
-               public Rectangle RowsHeadersArea {
+               public Rectangle RowHeadersArea {
                        get {
-                               return rowshdrs_area;
+                               return rowhdrs_area;
                        }
                }
 
                public int VLargeChange {
                        get {
-                               return cells_area.Height / grid.RowHeight;
+                               return grid.VisibleRowCount;
                        }
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTableStyle.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTableStyle.cs
    2006-06-27 19:10:14 UTC (rev 62091)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTableStyle.cs
    2006-06-27 19:43:08 UTC (rev 62092)
@@ -28,6 +28,7 @@
 // NOT COMPLETE
 //
 
+using System.Collections;
 using System.ComponentModel;
 using System.Drawing;
 using System.Runtime.InteropServices;
@@ -79,36 +80,24 @@
                private Color                           backcolor;
                private Color                           forecolor;
                private bool                            is_default;
+               internal ArrayList                      table_relations;
                CurrencyManager                         manager;
                #endregion      // Local Variables
 
                #region Constructors
                public DataGridTableStyle ()
+                       : this (false)
                {
-                       CommonConstructor ();
-                       is_default = false;
                }
 
                public DataGridTableStyle (bool isDefaultTableStyle)
                {
-                       CommonConstructor ();
                        is_default = isDefaultTableStyle;
-               }
-
-               // TODO: What to do with the CurrencyManager
-               public DataGridTableStyle (CurrencyManager listManager)
-               {
-                       CommonConstructor ();
-                       is_default = false;
-                       manager = listManager;
-               }
-
-               private void CommonConstructor ()
-               {
                        allow_sorting = true;
                        datagrid = null;
                        header_forecolor = def_header_forecolor;
                        mapping_name = string.Empty;
+                       table_relations = new ArrayList ();
                        column_styles = new GridColumnStylesCollection (this);
 
                        alternating_backcolor = def_alternating_backcolor;
@@ -129,6 +118,12 @@
                        backcolor = def_backcolor;
                        forecolor = def_forecolor;
                }
+
+               public DataGridTableStyle (CurrencyManager listManager)
+                       : this (false)
+               {
+                       manager = listManager;
+               }
                #endregion
 
                #region Public Instance Properties
@@ -563,7 +558,18 @@
                        }
                }
 
+               internal bool HasRelations {
+                       get { return table_relations.Count > 0; }
+               }
 
+               internal string[] Relations {
+                       get {
+                               string[] rel = new 
string[table_relations.Count];
+                               table_relations.CopyTo (rel, 0);
+                               return rel;
+                       }
+               }
+
                #endregion Private Instance Properties
 
                #region Public Instance Methods
@@ -869,14 +875,17 @@
                // Create column styles for this TableStyle
                internal void CreateColumnsForTable (bool onlyBind)
                {
-                       CurrencyManager mgr = null;
+                       CurrencyManager mgr = manager;
                        DataGridColumnStyle st;
-                       mgr = datagrid.ListManager;
 
                        if (mgr == null) {
-                               return;
+                               mgr = datagrid.ListManager;
+
+                               if (mgr == null)
+                                       return;
                        }
 
+                       table_relations.Clear ();
                        PropertyDescriptorCollection propcol = 
mgr.GetItemProperties ();
 
                        for (int i = 0; i < propcol.Count; i++)
@@ -894,11 +903,9 @@
                                        continue;
                                }
 
-
-                               // TODO: What to do with relations?
-                               if (propcol[i].ComponentType.ToString () == 
"System.Data.DataTablePropertyDescriptor") {
-                                       Console.WriteLine 
("CreateColumnsForTable::System.Data.DataTablePropertyDescriptor");
-
+                               if (typeof (IBindingList).IsAssignableFrom 
(propcol[i].PropertyType)) {
+                                       Console.WriteLine ("adding relation 
{0}", propcol[i].Name);
+                                       table_relations.Add (propcol[i].Name);
                                } else {
                                        st = CreateGridColumn (propcol[i],  
true);
                                        st.grid = datagrid;

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs 
2006-06-27 19:10:14 UTC (rev 62091)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs 
2006-06-27 19:43:08 UTC (rev 62092)
@@ -695,14 +695,13 @@
                // Paint                
                public abstract void DataGridPaint (PaintEventArgs pe, DataGrid 
grid);
                public abstract void DataGridPaintCaption (Graphics g, 
Rectangle clip, DataGrid grid);
-               public abstract void DataGridPaintColumnsHdrs (Graphics g, 
Rectangle clip, DataGrid grid);
-               public abstract void DataGridPaintRowsHeaders (Graphics g, 
Rectangle clip, DataGrid grid);
+               public abstract void DataGridPaintColumnHeaders (Graphics g, 
Rectangle clip, DataGrid grid);
+               public abstract void DataGridPaintRowHeaders (Graphics g, 
Rectangle clip, DataGrid grid);
                public abstract void DataGridPaintRowHeader (Graphics g, 
Rectangle bounds, int row, DataGrid grid);
                public abstract void DataGridPaintRowHeaderArrow (Graphics g, 
Rectangle bounds, DataGrid grid);
                public abstract void DataGridPaintRows (Graphics g, Rectangle 
cells, Rectangle clip, DataGrid grid);
                public abstract void DataGridPaintRow (Graphics g, int row, 
Rectangle row_rect, bool is_newrow, Rectangle clip, DataGrid grid);
                
-               
                #endregion // Datagrid
 
                #region DateTimePicker

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2006-06-27 19:10:14 UTC (rev 62091)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2006-06-27 19:43:08 UTC (rev 62092)
@@ -837,8 +837,8 @@
                        }
 
                        DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, 
grid);
-                       DataGridPaintColumnsHdrs (pe.Graphics, 
pe.ClipRectangle, grid);
-                       DataGridPaintRowsHeaders (pe.Graphics, 
pe.ClipRectangle, grid);
+                       DataGridPaintColumnHeaders (pe.Graphics, 
pe.ClipRectangle, grid);
+                       DataGridPaintRowHeaders (pe.Graphics, pe.ClipRectangle, 
grid);
                        DataGridPaintRows (pe.Graphics, 
grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
 
                        // Paint scrollBar corner
@@ -868,14 +868,14 @@
                                grid.grid_drawing.caption_area);                
                }
 
-               public override void DataGridPaintColumnsHdrs (Graphics g, 
Rectangle clip, DataGrid grid)
+               public override void DataGridPaintColumnHeaders (Graphics g, 
Rectangle clip, DataGrid grid)
                {
-                       Rectangle columns_area = 
grid.grid_drawing.columnshdrs_area;
+                       Rectangle columns_area = 
grid.grid_drawing.columnhdrs_area;
 
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { 
// Paint corner shared between row and column header
-                               Rectangle rect_bloc = 
grid.grid_drawing.columnshdrs_area;
+                               Rectangle rect_bloc = 
grid.grid_drawing.columnhdrs_area;
                                rect_bloc.Width = grid.RowHeaderWidth;
-                               rect_bloc.Height = 
grid.grid_drawing.columnshdrs_area.Height;
+                               rect_bloc.Height = 
grid.grid_drawing.columnhdrs_area.Height;
                                if (clip.IntersectsWith (rect_bloc)) {
                                        if (grid.visiblecolumn_count > 0) {
                                                g.FillRectangle 
(ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), 
rect_bloc);
@@ -889,11 +889,11 @@
                        }
 
                        // Set unused area
-                       Rectangle columnshdrs_area_complete = columns_area;
-                       columnshdrs_area_complete.Width = 
grid.grid_drawing.columnshdrs_maxwidth;
+                       Rectangle columnhdrs_area_complete = columns_area;
+                       columnhdrs_area_complete.Width = 
grid.grid_drawing.columnhdrs_maxwidth;
                        
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
-                               columnshdrs_area_complete.Width -= 
grid.RowHeaderWidth;
+                               columnhdrs_area_complete.Width -= 
grid.RowHeaderWidth;
                        }               
 
                        // Set column painting
@@ -925,32 +925,32 @@
 
                        g.ResetClip ();
                                
-                       Rectangle not_usedarea = columnshdrs_area_complete;     
                        
+                       Rectangle not_usedarea = columnhdrs_area_complete;      
                        
                        not_usedarea.X = rect_columnhdr.X + 
rect_columnhdr.Width;
                        not_usedarea.Width = grid.ClientRectangle.X + 
grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;          
  
                        g.FillRectangle (ResPool.GetSolidBrush 
(grid.BackgroundColor), not_usedarea);
                        
                }
 
-               public override void DataGridPaintRowsHeaders (Graphics g, 
Rectangle clip, DataGrid grid)
+               public override void DataGridPaintRowHeaders (Graphics g, 
Rectangle clip, DataGrid grid)
                {
-                       Rectangle rowshdrs_area_complete = 
grid.grid_drawing.rowshdrs_area;
-                       rowshdrs_area_complete.Height = 
grid.grid_drawing.rowshdrs_maxheight;
+                       Rectangle rowhdrs_area_complete = 
grid.grid_drawing.rowhdrs_area;
+                       rowhdrs_area_complete.Height = 
grid.grid_drawing.rowhdrs_maxheight;
                        Rectangle rect_row = new Rectangle ();
-                       rect_row.X = grid.grid_drawing.rowshdrs_area.X;         
        
+                       rect_row.X = grid.grid_drawing.rowhdrs_area.X;          
        
                        int rowcnt = grid.FirstVisibleRow + 
grid.VisibleRowCount;
-                       Rectangle not_usedarea = rowshdrs_area_complete;        
                
+                       Rectangle not_usedarea = rowhdrs_area_complete;         
        
 
                        if (rowcnt < grid.RowsCount) { // Paint one row more 
for partial rows
                                rowcnt++;
                        }
 
-                       g.SetClip (grid.grid_drawing.rowshdrs_area);
+                       g.SetClip (grid.grid_drawing.rowhdrs_area);
                        for (int row = grid.FirstVisibleRow; row < rowcnt; 
row++) {
 
-                               rect_row.Width = 
grid.grid_drawing.rowshdrs_area.Width;
-                               rect_row.Height = grid.RowHeight;
-                               rect_row.Y = grid.grid_drawing.rowshdrs_area.Y 
+ ((row - grid.FirstVisibleRow) * grid.RowHeight);
+                               rect_row.Width = 
grid.grid_drawing.rowhdrs_area.Width;
+                               rect_row.Height = grid.rows[row].Height;
+                               rect_row.Y = grid.grid_drawing.rowhdrs_area.Y + 
grid.rows[row].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
 
                                if (clip.IntersectsWith (rect_row)) {
                                        DataGridPaintRowHeader (g, rect_row, 
row, grid);                                        
@@ -958,8 +958,8 @@
                        }
                        
                        g.ResetClip ();
-                       not_usedarea.Height = 
grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
-                       not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + 
grid.grid_drawing.rowshdrs_area.Height;
+                       not_usedarea.Height = 
grid.grid_drawing.rowhdrs_maxheight - grid.grid_drawing.rowhdrs_area.Height;
+                       not_usedarea.Y = grid.grid_drawing.rowhdrs_area.Y + 
grid.grid_drawing.rowhdrs_area.Height;
                        g.FillRectangle (ResPool.GetSolidBrush 
(grid.BackgroundColor), not_usedarea);
                }
                
@@ -1032,6 +1032,22 @@
                                        }
                                }
                        }
+
+                       if (grid.CurrentTableStyle.HasRelations) {
+                               bounds.X += bounds.Width / 2;
+                               bounds.Width /= 2;
+
+                               if (grid.IsExpanded (row)) {
+                                       g.DrawString ("-", grid.Font,
+                                                     ResPool.GetSolidBrush 
(grid.CurrentTableStyle.CurrentHeaderForeColor),
+                                                     bounds);
+                               }
+                               else {
+                                       g.DrawString ("+", grid.Font,
+                                                     ResPool.GetSolidBrush 
(grid.CurrentTableStyle.CurrentHeaderForeColor),
+                                                     bounds);
+                               }
+                       }
                }
                
                public override void DataGridPaintRows (Graphics g, Rectangle 
cells, Rectangle clip, DataGrid grid)
@@ -1050,15 +1066,16 @@
                                rowcnt++;
                        }                       
                        
-                       rect_row.Height = grid.RowHeight;
                        rect_row.Width = cells.Width;
                        for (int row = grid.FirstVisibleRow; row < rowcnt; 
row++) {                                                             
-                               rect_row.Y = cells.Y + ((row - 
grid.FirstVisibleRow) * grid.RowHeight);
+                               rect_row.Height = grid.rows[row].Height;
+                               rect_row.Y = cells.Y + 
grid.rows[row].VerticalOffset - grid.rows[grid.FirstVisibleRow].VerticalOffset;
                                if (clip.IntersectsWith (rect_row)) {
                                        DataGridPaintRow (g, row, rect_row, 
false, clip, grid);
                                }
                        }
-                       
+
+                       // XXX
                        if (grid.ShowEditRow && grid.RowsCount > 0 && 
grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
                                rect_row.Y = cells.Y + ((rowcnt - 
grid.FirstVisibleRow) * grid.RowHeight);
                                if (clip.IntersectsWith (rect_row)) {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to