Author: toshok
Date: 2006-11-07 10:21:02 -0500 (Tue, 07 Nov 2006)
New Revision: 67459

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
Log:
2006-11-07  Chris Toshok  <[EMAIL PROTECTED]>

        [ fix bug #79778 ]
        
        * CurrencyManager.cs: if the list is readonly, don't bother
        checking if IBindingList.AllowNew is true.

        * ThemeWin32Classic.cs (DataGridPaintParentRow): make this work
        for non-DataRowView datasources..  or rather, make it not crash.
        (DataGridPaintRelationRow): make sure we limit the row painting to
        the area not covered by the row header, and make our cell width at
        least large enough to cover the relation area.  This allows grids
        that have relations but no rows to render correctly.
        (DataGridPaintRowContents): same type of changes here.
        (SetDataSource): move back to always calling
        CalcAreasAndInvalidate.  this fixes a crash/drawing problem when
        navigating back through relations.
        (HitTest): handle the case where we have no cells but have
        relations.  Right now we generate a hit in cell 0 of whatever the
        row is, not sure if this is strictly correct, but it works for our
        purposes.
        
        * DataGrid.cs (EndEdit, CancelEdit): if we have no columns, don't
        bother doing anything.



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-07 14:52:52 UTC (rev 67458)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-07 15:21:02 UTC (rev 67459)
@@ -1,3 +1,28 @@
+2006-11-07  Chris Toshok  <[EMAIL PROTECTED]>
+
+       [ fix bug #79778 ]
+       
+       * CurrencyManager.cs: if the list is readonly, don't bother
+       checking if IBindingList.AllowNew is true.
+
+       * ThemeWin32Classic.cs (DataGridPaintParentRow): make this work
+       for non-DataRowView datasources..  or rather, make it not crash.
+       (DataGridPaintRelationRow): make sure we limit the row painting to
+       the area not covered by the row header, and make our cell width at
+       least large enough to cover the relation area.  This allows grids
+       that have relations but no rows to render correctly.
+       (DataGridPaintRowContents): same type of changes here.
+       (SetDataSource): move back to always calling
+       CalcAreasAndInvalidate.  this fixes a crash/drawing problem when
+       navigating back through relations.
+       (HitTest): handle the case where we have no cells but have
+       relations.  Right now we generate a hit in cell 0 of whatever the
+       row is, not sure if this is strictly correct, but it works for our
+       purposes.
+       
+       * DataGrid.cs (EndEdit, CancelEdit): if we have no columns, don't
+       bother doing anything.
+
 2006-11-07  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * StatusStrip.cs, ToolStripStatusLabel.cs: By request, an

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs   
    2006-11-07 14:52:52 UTC (rev 67458)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CurrencyManager.cs   
    2006-11-07 15:21:02 UTC (rev 67459)
@@ -175,6 +175,10 @@
                 [MonoTODO ("this needs re-addressing once 
DataViewManager.AllowNew is implemented")]
                 internal bool CanAddRows {
                        get {
+                               /* if we're readonly, don't even bother 
checking if we can add new rows */
+                               if (list.IsReadOnly)
+                                       return false;
+
                                if (list is IBindingList) {
                                        return true;
                                        //return ((IBindingList)list).AllowNew;

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-11-07 14:52:52 UTC (rev 67458)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-11-07 15:21:02 UTC (rev 67459)
@@ -77,16 +77,16 @@
        {
                public DataGrid owner;
                public CurrencyManager list_manager;
-               public DataRowView view;
+               public object view;
                public string data_member;
                public object data_source;
                public DataGridCell current;
 
-               public DataGridDataSource (DataGrid owner, CurrencyManager 
list_manager, object data_source, string data_member, DataRowView view, 
DataGridCell current)
+               public DataGridDataSource (DataGrid owner, CurrencyManager 
list_manager, object data_source, string data_member, object view_data, 
DataGridCell current)
                {
                        this.owner = owner;
                        this.list_manager = list_manager;
-                       this.view = view;
+                       this.view = view_data;
                        this.data_source = data_source;
                        this.data_member = data_member;
                        this.current = current;
@@ -936,6 +936,9 @@
 
                protected virtual void CancelEditing ()
                {
+                       if (CurrentTableStyle.GridColumnStyles.Count == 0)
+                               return;
+
                        
CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].ConcedeFocus ();
 
                        if (is_changing) {
@@ -1182,17 +1185,24 @@
                                if (y <= pos_y + rows[row].Height) {
                                        int col_pixel;
                                        int column_cnt = first_visiblecolumn + 
visiblecolumn_count;
-                                       for (int column = first_visiblecolumn; 
column < column_cnt; column++) {
-                                               if 
(CurrentTableStyle.GridColumnStyles[column].bound == false)
-                                                       continue;
-                                               col_pixel = 
GetColumnStartingPixel (column);
-                                               pos_x = cells_area.X + 
col_pixel - horiz_pixeloffset;
-                                               width = 
CurrentTableStyle.GridColumnStyles[column].Width;
+                                       if (column_cnt > 0) {
+                                               for (int column = 
first_visiblecolumn; column < column_cnt; column++) {
+                                                       if 
(CurrentTableStyle.GridColumnStyles[column].bound == false)
+                                                               continue;
+                                                       col_pixel = 
GetColumnStartingPixel (column);
+                                                       pos_x = cells_area.X + 
col_pixel - horiz_pixeloffset;
+                                                       width = 
CurrentTableStyle.GridColumnStyles[column].Width;
 
-                                               if (x <= pos_x + width) { // 
Column found
-                                                       return new HitTestInfo 
(row, column, HitTestType.Cell);
+                                                       if (x <= pos_x + width) 
{ // Column found
+                                                               return new 
HitTestInfo (row, column, HitTestType.Cell);
+                                                       }
                                                }
                                        }
+                                       else if 
(CurrentTableStyle.HasRelations) {
+                                               /* XXX this needs checking 
against MS somehow... */
+                                               if (x < 
rows[row].relation_area.X + rows[row].relation_area.Width)
+                                                       return new HitTestInfo 
(row, 0/*XXX?*/, HitTestType.Cell);
+                                       }
 
                                        break;
                                }
@@ -1233,7 +1243,7 @@
                        if (allow_navigation == false)
                                return;
 
-                       DataGridDataSource previous_source = new 
DataGridDataSource (this, list_manager, datasource, datamember, 
(DataRowView)list_manager.Current, CurrentCell);
+                       DataGridDataSource previous_source = new 
DataGridDataSource (this, list_manager, datasource, datamember, 
list_manager.Current, CurrentCell);
                        previous_source.Rows = rows;
                        previous_source.SelectedRows = selected_rows;
                        previous_source.SelectionStart = selection_start;
@@ -2226,10 +2236,10 @@
 
                                if (recreate_rows)
                                        RecreateDataGridRows (false);
-
-                               CalcAreasAndInvalidate ();
                        }
 
+                       CalcAreasAndInvalidate ();
+
                        in_setdatasource = false;
 
                        OnDataSourceChanged (EventArgs.Empty);
@@ -2357,6 +2367,9 @@
 
                private void EndEdit ()
                {
+                       if (CurrentTableStyle.GridColumnStyles.Count == 0)
+                               return;
+
                        if 
(CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].bound == false)
                                return;
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2006-11-07 14:52:52 UTC (rev 67458)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs 
    2006-11-07 15:21:02 UTC (rev 67459)
@@ -28,6 +28,7 @@
 //
 
 using System.ComponentModel;
+using System.Data;
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
@@ -1000,7 +1001,10 @@
                        text_format.LineAlignment = StringAlignment.Center;
                        text_format.Alignment = StringAlignment.Near;
 
-                       string table_name = 
((ITypedList)row.view.DataView).GetListName (null) + ": ";
+                       string table_name = "";
+                       if (row.view is DataRowView)
+                               table_name = 
((ITypedList)((DataRowView)row.view).DataView).GetListName (null) + ": ";
+                       // XXX else?
 
                        Rectangle       text_rect;
                        Size            text_size;
@@ -1082,7 +1086,7 @@
 
                        // Background
                        g.FillRectangle (ResPool.GetSolidBrush 
(grid.CurrentTableStyle.CurrentHeaderBackColor),
-                               bounds);
+                                        bounds);
 
                        // Draw arrow
                        if (is_current_row) {
@@ -1227,17 +1231,18 @@
                                //Region current_clip;
                                Rectangle rect_cell = row_rect;
 
-                               rect_cell.X = row_rect.X + 
grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
+                               rect_cell.X = nested_rect.X + 
grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
                                rect_cell.Y += nested_rect.Height;
                                rect_cell.Height = 
grid.DataGridRows[row].RelationHeight;
+
                                rect_cell.Width = 0;
-
                                int column_cnt = grid.FirstVisibleColumn + 
grid.VisibleColumnCount;
                                for (int column = grid.FirstVisibleColumn; 
column < column_cnt; column++) {
                                        if 
(grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
                                                continue;
                                        rect_cell.Width += 
grid.CurrentTableStyle.GridColumnStyles[column].Width;
                                }
+                               rect_cell.Width = Math.Max (rect_cell.Width, 
grid.DataGridRows[row].relation_area.Width);
 
                                g.FillRectangle 
(ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
                                                 rect_cell);
@@ -1281,7 +1286,7 @@
                        int col_pixel;
                        Color backcolor, forecolor;
                        Brush backBrush, foreBrush;
-                       Rectangle not_usedarea = new Rectangle ();
+                       Rectangle not_usedarea = Rectangle.Empty;
 
                        rect_cell.Y = row_rect.Y;
                        rect_cell.Height = row_rect.Height;
@@ -1306,50 +1311,56 @@
                        // PaintCells at row, column
                        int column_cnt = grid.FirstVisibleColumn + 
grid.VisibleColumnCount;
 
-                       Region prev_clip = g.Clip;
-                       Region current_clip;
+                       if (column_cnt > 0) {
+                               Region prev_clip = g.Clip;
+                               Region current_clip;
 
-                       for (int column = grid.FirstVisibleColumn; column < 
column_cnt; column++) {
-                               if 
(grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
-                                       continue;
+                               for (int column = grid.FirstVisibleColumn; 
column < column_cnt; column++) {
+                                       if 
(grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
+                                               continue;
 
-                               col_pixel = grid.GetColumnStartingPixel 
(column);
+                                       col_pixel = grid.GetColumnStartingPixel 
(column);
 
-                               rect_cell.X = row_rect.X + col_pixel - 
grid.HorizPixelOffset;
-                               rect_cell.Width = 
grid.CurrentTableStyle.GridColumnStyles[column].Width;
+                                       rect_cell.X = row_rect.X + col_pixel - 
grid.HorizPixelOffset;
+                                       rect_cell.Width = 
grid.CurrentTableStyle.GridColumnStyles[column].Width;
 
-                               if (clip.IntersectsWith (rect_cell)) {
-                                       current_clip = new Region (rect_cell);
-                                       current_clip.Intersect (row_rect);
-                                       current_clip.Intersect (prev_clip);
-                                       g.Clip = current_clip;
+                                       if (clip.IntersectsWith (rect_cell)) {
+                                               current_clip = new Region 
(rect_cell);
+                                               current_clip.Intersect 
(row_rect);
+                                               current_clip.Intersect 
(prev_clip);
+                                               g.Clip = current_clip;
 
-                                       if (is_newrow) {
-                                               
grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, 
-                                                                               
                             backBrush,
-                                                                               
                             foreBrush);
-                                       } else {
-                                               
grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, 
grid.ListManager, row,
-                                                                               
                       backBrush,
-                                                                               
                       foreBrush,
-                                                                               
                       grid.RightToLeft == RightToLeft.Yes);
+                                               if (is_newrow) {
+                                                       
grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, 
+                                                                               
                                     backBrush,
+                                                                               
                                     foreBrush);
+                                               } else {
+                                                       
grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, 
grid.ListManager, row,
+                                                                               
                               backBrush,
+                                                                               
                               foreBrush,
+                                                                               
                               grid.RightToLeft == RightToLeft.Yes);
+                                               }
+
+                                               current_clip.Dispose ();
                                        }
+                               }
 
-                                       current_clip.Dispose ();
+                               g.Clip = prev_clip;
+                       
+                               if (row_rect.X + row_rect.Width > rect_cell.X + 
rect_cell.Width) {
+                                       not_usedarea.X = rect_cell.X + 
rect_cell.Width;
+                                       not_usedarea.Width = row_rect.X + 
row_rect.Width - rect_cell.X - rect_cell.Width;
+                                       not_usedarea.Y = row_rect.Y;
+                                       not_usedarea.Height = row_rect.Height;
                                }
                        }
+                       else {
+                               not_usedarea = row_rect;
+                       }
 
-                       g.Clip = prev_clip;
-                       
-                       if (row_rect.X + row_rect.Width > rect_cell.X + 
rect_cell.Width) {
-                               not_usedarea.X = rect_cell.X + rect_cell.Width;
-                               not_usedarea.Width = row_rect.X + 
row_rect.Width - rect_cell.X - rect_cell.Width;
-                               not_usedarea.Y = row_rect.Y;
-                               not_usedarea.Height = row_rect.Height;
-                               if (clip.IntersectsWith (not_usedarea))
-                                       g.FillRectangle (ResPool.GetSolidBrush 
(grid.BackgroundColor),
-                                                        not_usedarea);
-                       }
+                       if (!not_usedarea.IsEmpty && clip.IntersectsWith 
(not_usedarea))
+                               g.FillRectangle (ResPool.GetSolidBrush 
(grid.BackgroundColor),
+                                                not_usedarea);
                }
 
                public override void DataGridPaintRow (Graphics g, int row, 
Rectangle row_rect, bool is_newrow,

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

Reply via email to