2005-06-09 Jordi Mas i Hernandez <jordi@ximian.com>
authorJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Thu, 9 Jun 2005 09:18:22 +0000 (09:18 -0000)
committerJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Thu, 9 Jun 2005 09:18:22 +0000 (09:18 -0000)
* DataGridTextBoxColumn.cs: drawing fixes
* DataGridCell.cs: fixes ToString method to match MSNet
* DataGridTableStyle.cs: fixes
* DataGridBoolColumn.cs: fixes, drawing
* DataGridDrawingLogic.cs: fixes, new methods
* DataGridTextBox.cs: Keyboard and fixes
* DataGrid.cs:
- Keyboard navigation
- Scrolling fixes
- Row selection (single, multiple, deletion, etc)
- Lots of fixes

svn path=/trunk/mcs/; revision=45682

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridBoolColumn.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridCell.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTableStyle.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTextBox.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTextBoxColumn.cs

index 5c3b6fdf7325bedaa836579d4040e28a48b51024..075e8fca3522ed2d3b04d8562d5c90efa5ca3ec8 100644 (file)
@@ -1,3 +1,17 @@
+2005-06-09  Jordi Mas i Hernandez <jordi@ximian.com>
+
+       * DataGridTextBoxColumn.cs: drawing fixes
+       * DataGridCell.cs: fixes ToString method to match MSNet
+       * DataGridTableStyle.cs: fixes
+       * DataGridBoolColumn.cs: fixes, drawing
+       * DataGridDrawingLogic.cs: fixes, new methods
+       * DataGridTextBox.cs: Keyboard and fixes
+       * DataGrid.cs:
+               - Keyboard navigation
+               - Scrolling fixes
+               - Row selection (single, multiple, deletion, etc)
+               - Lots of fixes
+       
 2005-06-07  Jackson Harper  <jackson@ximian.com>
 
        * ThemeWin32Classic.cs: Clear the background area when drawing
index 44b03d1a79c710445494efa24bf6c4829421b36e..76b6419113cc944aec6b6189f74f0b00c39ca01e 100644 (file)
@@ -123,6 +123,7 @@ namespace System.Windows.Forms
                private static readonly Color   def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
                private static readonly Color   def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
                private static readonly Color   def_link_color = ThemeEngine.Current.DataGridLinkColor;
+               internal readonly int def_preferredrow_height;
 
                private bool allow_navigation;
                private bool allow_sorting;
@@ -160,7 +161,6 @@ namespace System.Windows.Forms
                internal int visiblecolumn_count;
                internal int visiblerow_count;
                internal int first_visiblecolumn;
-               private int currentrow_index;
                private GridTableStylesCollection styles_collection;
                private DataGridParentRowsLabelStyle parentrowslabel_style;
                internal DataGridCell current_cell;
@@ -175,6 +175,9 @@ namespace System.Windows.Forms
                internal int horz_pixeloffset;
                internal bool is_editing;       // Current cell is edit mode
                internal bool is_changing;      // Indicates if current cell is been changed (in edit mode)
+               private Hashtable selected_rows;
+               private bool ctrl_pressed;
+               private bool shift_pressed;
                #endregion // Local Variables
 
                #region Public Constructors
@@ -207,8 +210,7 @@ namespace System.Windows.Forms
                        parentrowsfore_color = def_parentrowsfore_color;
                        parentrows_visible = false; // should be true (temp)
                        preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth;
-                       preferredrow_height = 16;
-                       _readonly = false ;
+                       _readonly = false;
                        rowheaders_visible = true;
                        selection_backcolor = def_selection_backcolor;
                        selection_forecolor = def_selection_forecolor;
@@ -216,7 +218,6 @@ namespace System.Windows.Forms
                        visiblecolumn_count = 0;
                        visiblerow_count = 0;
                        current_cell = new DataGridCell ();
-                       currentrow_index = -1;
                        first_visiblerow = 0;
                        first_visiblecolumn = 0;
                        horz_pixeloffset = 0;
@@ -225,6 +226,10 @@ namespace System.Windows.Forms
                        forecolor = SystemColors.WindowText;
                        parentrowslabel_style = DataGridParentRowsLabelStyle.Both;
                        backcolor = SystemColors.Window;
+                       selected_rows = new Hashtable ();
+                       ctrl_pressed = false;
+                       shift_pressed = false;
+                       preferredrow_height = def_preferredrow_height = FontHeight + 3;
 
                        default_style = new DataGridTableStyle (true);
                        styles_collection = new GridTableStylesCollection (this);
@@ -237,6 +242,8 @@ namespace System.Windows.Forms
                        vert_scrollbar = new VScrollBar ();
                        vert_scrollbar.Scroll += new ScrollEventHandler (GridVScrolled);
                        grid_drawing = new DataGridDrawing (this);
+                       KeyUp += new KeyEventHandler (OnKeyUpDG);
+                       HandleCreated += new EventHandler (OnCreateHandle);
 
                        SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
 
@@ -443,9 +450,10 @@ namespace System.Windows.Forms
 
                        set {
                                if (!current_cell.Equals (value)) {
-                                       grid_drawing.InvalidateRowHeader (current_cell.RowNumber); // old row header
+                                       CancelEditing ();
+                                       EnsureCellVisilibility (value);
                                        current_cell = value;
-                                       InvalidateCurrentRowHeader ();
+                                       OnCurrentCellChanged (EventArgs.Empty);
                                }
                        }
                }
@@ -454,13 +462,12 @@ namespace System.Windows.Forms
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public int CurrentRowIndex {
                        get {
-                               return currentrow_index;
+                               return current_cell.RowNumber;
                        }
 
                        set {
-                               if (currentrow_index != value) {
-                                       currentrow_index = value;
-                                       Refresh ();
+                               if (current_cell.RowNumber != value) {
+                                       CurrentCell = new DataGridCell (value, current_cell.ColumnNumber);
                                }
                        }
                }
@@ -940,11 +947,11 @@ namespace System.Windows.Forms
 
                internal int RowHeight {
                        get {
-                               if (preferredrow_height > Font.Height + 3) {
+                               if (preferredrow_height > Font.Height + 3 + 1 /* line */) {
                                        return preferredrow_height;
 
                                } else {
-                                       return Font.Height + 3;
+                                       return Font.Height + 3 + 1 /* line */;
                                }
                        }
                }
@@ -965,11 +972,7 @@ namespace System.Windows.Forms
 
 
                protected virtual void CancelEditing ()
-               {
-                       if (is_editing == false) {
-                               return;
-                       }
-
+               {                       
                        CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].Abort (current_cell.RowNumber);
                        is_editing = false;
                        is_changing = false;
@@ -1016,13 +1019,13 @@ namespace System.Windows.Forms
                        if (is_editing == false) {
                                return false;
                        }
-                       
+
                        if (shouldAbort) {
                                gridColumn.Abort (rowNumber);
                        } else {
                                gridColumn.Commit (ListManager, rowNumber);
                        }
-                       
+
                        is_editing = false;
                        is_changing = false;
                        InvalidateCurrentRowHeader ();
@@ -1066,88 +1069,20 @@ namespace System.Windows.Forms
                                return;
                        }
 
-                       Rectangle invalidate = new Rectangle ();
-                       Rectangle invalidate_column = new Rectangle ();
-
-                       if (se.NewValue > horz_pixeloffset) { // ScrollRight
-                               int pixels = se.NewValue - horz_pixeloffset;
-
-                               // Columns header
-                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X + grid_drawing.ColumnsHeadersArea.Width - pixels;
-                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
-                               invalidate_column.Width = pixels;
-                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
-                               XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, -pixels, 0, false);
-
-                               // Cells
-                               invalidate.X = grid_drawing.CellsArea.X + grid_drawing.CellsArea.Width - pixels;
-                               invalidate.Y = grid_drawing.CellsArea.Y;
-                               invalidate.Width = pixels;
-                               invalidate.Height = grid_drawing.CellsArea.Height;
-                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, -pixels, 0, false);
-
-                       } else {
-                               int pixels = horz_pixeloffset - se.NewValue;
-
-                               // Columns header
-                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X;
-                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
-                               invalidate_column.Width = pixels;
-                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
-                               XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, pixels, 0, false);
-
-                               // Cells
-                               invalidate.X =  grid_drawing.CellsArea.X;
-                               invalidate.Y =  grid_drawing.CellsArea.Y;
-                               invalidate.Width = pixels;
-                               invalidate.Height = grid_drawing.CellsArea.Height;
-                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, pixels, 0, false);
-                       }
-
-                       horz_pixeloffset = se.NewValue;
-                       grid_drawing.UpdateVisibleColumn ();
-                       Invalidate (invalidate_column);
-                       Invalidate (invalidate);
+                       ScrollToColumnInPixels (se.NewValue);
                }
 
                protected virtual void GridVScrolled (object sender, ScrollEventArgs se)
-               {                       
+               {
                        int old_first_visiblerow = first_visiblerow;
                        first_visiblerow = se.NewValue;
                        grid_drawing.UpdateVisibleRowCount ();
-                       
+
                        if (first_visiblerow == old_first_visiblerow) {
                                return;
                        }
-                       
-                       Rectangle invalidate = new Rectangle ();
-
-                       if (se.NewValue > old_first_visiblerow ) { // Scrolldown
-                               int scrolled_rows = se.NewValue - old_first_visiblerow;
-                               int pixels = scrolled_rows * RowHeight;
-
-                               invalidate.X =  grid_drawing.CellsArea.X;
-                               invalidate.Y =  grid_drawing.CellsArea.Y + grid_drawing.CellsArea.Height - pixels;
-                               invalidate.Width = grid_drawing.CellsArea.Width;
-                               invalidate.Height = pixels;
-
-                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, -pixels, false);
-
-                       } else { // ScrollUp
-                               int scrolled_rows = old_first_visiblerow - se.NewValue;
-                               int pixels = scrolled_rows * RowHeight;
-
-                               invalidate.X =  grid_drawing.CellsArea.X;
-                               invalidate.Y =  grid_drawing.CellsArea.Y;
-                               invalidate.Width = grid_drawing.CellsArea.Width;
-                               invalidate.Height = pixels;
-
-                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, pixels, false);
-                       }                       
-                       
-                       Invalidate (invalidate);
-                       Invalidate (grid_drawing.RowsHeadersArea);
 
+                       ScrollToRow (old_first_visiblerow, first_visiblerow);
                }
 
                public HitTestInfo HitTest (Point position)
@@ -1168,7 +1103,7 @@ namespace System.Windows.Forms
 
                public bool IsSelected (int row)
                {
-                       throw new NotImplementedException ();
+                       return selected_rows[row] != null;
                }
 
                public void NavigateBack ()
@@ -1277,12 +1212,17 @@ namespace System.Windows.Forms
                protected override void OnKeyDown (KeyEventArgs ke)
                {
                        base.OnKeyDown (ke);
-                       CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].OnKeyDown 
+
+                       if (KeyboardNavigation (ke.KeyCode) == true) {
+                               ke.Handled = true;
+                       }
+
+                       CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].OnKeyDown
                                (ke, current_cell.RowNumber, current_cell.ColumnNumber);
                }
 
                protected override void OnKeyPress (KeyPressEventArgs kpe)
-               {
+               {\r
                        base.OnKeyPress (kpe);
                }
 
@@ -1303,21 +1243,41 @@ namespace System.Windows.Forms
                        HitTestInfo testinfo;
                        testinfo = grid_drawing.HitTest (e.X, e.Y);
 
-                       if (testinfo.type == HitTestType.Cell) {
-                               
+                       switch (testinfo.type) {
+                       case HitTestType.Cell:
+                       {
                                DataGridCell new_cell = new DataGridCell (testinfo.Row, testinfo.Column);
-                               
+
                                if (new_cell.Equals (current_cell) == false) {
                                        CancelEditing ();
                                        CurrentCell = new_cell;
-                                       is_editing = true;
-                                       is_changing = false;
-                                       CurrentTableStyle.GridColumnStyles[testinfo.Column].Edit (ListManager,
-                                               testinfo.Row, GetCellBounds (testinfo.Row, testinfo.Column),
-                                               _readonly, string.Empty, true);
-                               } else {                                        
+                                       EditCell (current_cell);
+
+                               } else {
                                        CurrentTableStyle.GridColumnStyles[testinfo.Column].OnMouseDown (e, testinfo.Row, testinfo.Column);
                                }
+
+                               break;
+                       }
+                       case HitTestType.RowHeader:
+                       {
+                               if (ctrl_pressed == false && shift_pressed == false) {
+                                       ResetSelection (); // Invalidates selected rows
+                               }
+
+                               if (shift_pressed == true) {
+                                       ShiftSelection (testinfo.Row);
+                               } else { // ctrl_pressed or single item
+                                       Select (testinfo.Row);
+                               }
+
+                               CancelEditing ();
+                               CurrentCell = new DataGridCell (testinfo.Row, current_cell.ColumnNumber);
+                               OnRowHeaderClick (EventArgs.Empty);
+                               break;
+                       }
+                       default:
+                               break;
                        }
                }
 
@@ -1339,6 +1299,17 @@ namespace System.Windows.Forms
                protected override void OnMouseWheel (MouseEventArgs e)
                {
                        base.OnMouseWheel (e);
+
+                       if (e.Delta > 0) {
+                               if (current_cell.RowNumber > 0) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber - 1, current_cell.ColumnNumber);
+                               }
+                       }
+                       else {
+                               if (current_cell.RowNumber < RowsCount - 1) {
+                                       CurrentCell = new DataGridCell (current_cell.RowNumber + 1, current_cell.ColumnNumber);                                 
+                               }
+                       }
                }
 
                protected void OnNavigate (NavigateEventArgs e)
@@ -1415,8 +1386,14 @@ namespace System.Windows.Forms
                        throw new NotImplementedException ();
                }
 
+               // Called from DataGridTextBox
                protected override bool ProcessKeyPreview (ref Message m)
                {
+                       Keys key = (Keys) m.WParam.ToInt32 ();
+                       if (KeyboardNavigation (key) == true) {
+                               return true;
+                       }
+
                        return base.ProcessKeyPreview (ref m);
                }
 
@@ -1472,7 +1449,13 @@ namespace System.Windows.Forms
 
                protected void ResetSelection ()
                {
+                       ICollection keys = selected_rows.Keys;
+                       foreach (int row in selected_rows.Keys) {
+                               grid_drawing.InvalidateRow (row);
+                               grid_drawing.InvalidateRowHeader (row);
+                       }
 
+                       selected_rows.Clear ();
                }
 
                public void ResetSelectionBackColor ()
@@ -1487,7 +1470,13 @@ namespace System.Windows.Forms
 
                public void Select (int row)
                {
+                       if (selected_rows[row] == null) {
+                               selected_rows.Add (row, true);
+                       } else {
+                               selected_rows[row] = true;
+                       }
 
+                       grid_drawing.InvalidateRow (row);
                }
 
                public void SetDataBinding (object dataSource, string dataMember)
@@ -1556,7 +1545,7 @@ namespace System.Windows.Forms
 
                protected bool ShouldSerializePreferredRowHeight ()
                {
-                       return (parentrowsfore_color != def_parentrowsfore_color);
+                       return (preferredrow_height != def_preferredrow_height);
                }
 
                protected bool ShouldSerializeSelectionBackColor ()
@@ -1576,6 +1565,8 @@ namespace System.Windows.Forms
 
                public void UnSelect (int row)
                {
+                       selected_rows.Remove (row);
+                       grid_drawing.InvalidateRow (row);
 
                }
                #endregion      // Public Instance Methods
@@ -1588,13 +1579,150 @@ namespace System.Windows.Forms
                        Invalidate ();
                }
 
+               internal bool KeyboardNavigation (Keys key)
+               {
+                       if (RowsCount == 0) {
+                               return false;
+                       }
+
+                       switch (key) {
+                               case Keys.ControlKey:
+                                       ctrl_pressed = true;
+                                       break;
+                               case Keys.ShiftKey:
+                                       shift_pressed = true;
+                                       break;
+                               case Keys.Up:
+                               {
+                                       if (current_cell.RowNumber > 0) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber - 1, current_cell.ColumnNumber);
+                                               EditCell (current_cell);
+                                       }
+                                       break;
+                               }
+                               case Keys.Down:
+                               {
+                                       if (current_cell.RowNumber < RowsCount - 1) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber + 1, current_cell.ColumnNumber);
+                                               EditCell (current_cell);
+                                       }
+                                       break;
+                               }
+                               case Keys.Right:
+                               {
+                                       if (current_cell.ColumnNumber + 1 < CurrentTableStyle.GridColumnStyles.Count) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber + 1);
+                                               EditCell (current_cell);
+                                       }
+                                       break;
+                               }
+                               case Keys.Left:
+                               {
+                                       if (current_cell.ColumnNumber > 0) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber, current_cell.ColumnNumber - 1);
+                                               EditCell (current_cell);
+                                       }
+                                       break;
+                               }
+                               case Keys.PageUp:
+                               {
+                                       if (current_cell.RowNumber > grid_drawing.VLargeChange) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber - grid_drawing.VLargeChange, current_cell.ColumnNumber);
+                                       } else {
+                                               CurrentCell = new DataGridCell (0, current_cell.ColumnNumber);
+                                       }
+
+                                       EditCell (current_cell);
+                                       break;
+                               }
+                               case Keys.PageDown:
+                               {
+                                       if (current_cell.RowNumber + grid_drawing.VLargeChange < RowsCount) {
+                                               CurrentCell = new DataGridCell (current_cell.RowNumber + grid_drawing.VLargeChange, current_cell.ColumnNumber);
+                                       } else {
+                                               CurrentCell = new DataGridCell (RowsCount - 1, current_cell.ColumnNumber);
+                                       }
+
+                                       EditCell (current_cell);
+                                       break;
+                               }
+                               case Keys.Home:
+                               {
+                                       CurrentCell = new DataGridCell (0, current_cell.ColumnNumber);
+                                       EditCell (current_cell);
+                                       break;
+                               }
+                               case Keys.End:
+                               {
+                                       CurrentCell = new DataGridCell (RowsCount - 1, current_cell.ColumnNumber);
+                                       EditCell (current_cell);
+                                       break;
+                               }
+                               case Keys.Delete:
+                               {
+                                       ICollection keys = selected_rows.Keys;
+                                       foreach (int row in selected_rows.Keys) {
+                                               ListManager.RemoveAt (row);                                             
+                                       }
+                                       selected_rows.Clear ();
+                                       CalcAreasAndInvalidate ();
+                                       break;                                  
+                               }
+                               default:
+                                       return false; // message not processed
+                               }
+
+                               return true; // message processed
+                       }
+
                // EndEdit current editing operation
                public virtual bool EndEdit (bool shouldAbort)
-               {                       
-                       return EndEdit (CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber], 
+               {
+                       return EndEdit (CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber],
                                current_cell.RowNumber, shouldAbort);
                }
 
+               private void EnsureCellVisilibility (DataGridCell cell)
+               {
+                       if (current_cell.RowNumber != cell.RowNumber) {
+                               grid_drawing.InvalidateRowHeader (current_cell.RowNumber);
+                               grid_drawing.InvalidateRowHeader (cell.RowNumber);
+                       }
+
+                       if (cell.ColumnNumber < first_visiblecolumn ||
+                               cell.ColumnNumber >= first_visiblecolumn + visiblecolumn_count) {
+
+                               int col, pixel;
+
+                               if (cell.ColumnNumber + 1 >= first_visiblecolumn + visiblecolumn_count) {
+                                       col = 1 + cell.ColumnNumber - visiblecolumn_count;
+                               }else {
+                                       col = cell.RowNumber;
+                               }
+
+                               pixel = grid_drawing.GetColumnStartingPixel (col);
+                               ScrollToColumnInPixels (pixel);
+                       }
+
+                       if (cell.RowNumber < first_visiblerow ||
+                               cell.RowNumber + 1 >= first_visiblerow + visiblerow_count) {
+
+                               if (cell.RowNumber + 1 >= first_visiblerow + visiblerow_count) {
+                                       int old_first_visiblerow = first_visiblerow;
+                                       first_visiblerow = 1 + cell.RowNumber - visiblerow_count;
+                                       grid_drawing.UpdateVisibleRowCount ();
+                                       ScrollToRow (old_first_visiblerow, first_visiblerow);
+                               }else {
+                                       int old_first_visiblerow = first_visiblerow;
+                                       first_visiblerow = cell.RowNumber;
+                                       grid_drawing.UpdateVisibleRowCount ();
+                                       ScrollToRow (old_first_visiblerow, first_visiblerow);
+                               }
+
+                               vert_scrollbar.Value = first_visiblerow;
+                       }
+               }
+
                internal void InvalidateCurrentRowHeader ()
                {
                        grid_drawing.InvalidateRowHeader (current_cell.RowNumber);
@@ -1628,7 +1756,7 @@ namespace System.Windows.Forms
                                datamember = "";
                                real_datasource = source;
                        }
-                       
+
                        OnDataSourceChanged (EventArgs.Empty);
                        return true;
                }
@@ -1645,6 +1773,25 @@ namespace System.Windows.Forms
                        grid_drawing.CalcGridAreas ();
                }
 
+               private void OnKeyUpDG (object sender, KeyEventArgs e)
+               {
+                       switch (e.KeyCode) {
+                       case Keys.ControlKey:
+                               ctrl_pressed = false;
+                               break;
+                       case Keys.ShiftKey:
+                               shift_pressed = false;
+                               break;
+                       default:
+                               break;
+                       }
+               }
+
+               private void OnCreateHandle (object sender, EventArgs e)
+               {
+                       Console.WriteLine ("OnCreateHandle");
+               }
+
                private void OnTableStylesCollectionChanged (object sender, CollectionChangeEventArgs e)
                {
                        Console.WriteLine ("Datagrid.TableStyles Collection Changed {0}, null {1}", e.Action,
@@ -1671,6 +1818,132 @@ namespace System.Windows.Forms
                        }
 
                }
+
+               private void EditCell (DataGridCell cell)
+               {
+                       ResetSelection (); // Invalidates selected rows
+                       is_editing = false;
+                       is_changing = false;
+                       CurrentTableStyle.GridColumnStyles[cell.ColumnNumber].Edit (ListManager,
+                               cell.RowNumber, GetCellBounds (cell.RowNumber, cell.ColumnNumber),
+                               _readonly, string.Empty, true);
+               }
+
+               private void ShiftSelection (int index)
+               {
+                       int shorter_item = -1, dist = RowsCount + 1, cur_dist;
+                       ICollection keys = selected_rows.Keys;
+
+                       foreach (int row in selected_rows.Keys) {
+
+                               if (row > index) {
+                                       cur_dist = row - index;
+                               }
+                               else {
+                                       cur_dist = index - row;
+                               }
+
+                               if (cur_dist < dist) {
+                                       dist = cur_dist;
+                                       shorter_item = row;
+                               }
+                       }
+
+                       if (shorter_item != -1) {
+                               int start, end;
+
+                               if (shorter_item > index) {
+                                       start = index;
+                                       end = shorter_item;
+                               } else {
+                                       start = shorter_item;
+                                       end = index;
+                               }
+
+                               ResetSelection ();
+                               for (int idx = start; idx <= end; idx++) {
+                                       Select (idx);
+                               }
+                       }
+               }
+
+               private void ScrollToColumnInPixels (int pixel)
+               {
+                       Rectangle invalidate = new Rectangle ();
+                       Rectangle invalidate_column = new Rectangle ();
+
+                       if (pixel > horz_pixeloffset) { // ScrollRight
+                               int pixels = pixel - horz_pixeloffset;
+
+                               // Columns header
+                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X + grid_drawing.ColumnsHeadersArea.Width - pixels;
+                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
+                               invalidate_column.Width = pixels;
+                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, -pixels, 0, false);
+
+                               // Cells
+                               invalidate.X = grid_drawing.CellsArea.X + grid_drawing.CellsArea.Width - pixels;
+                               invalidate.Y = grid_drawing.CellsArea.Y;
+                               invalidate.Width = pixels;
+                               invalidate.Height = grid_drawing.CellsArea.Height;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, -pixels, 0, false);
+
+                       } else {
+                               int pixels = horz_pixeloffset - pixel;
+
+                               // Columns header
+                               invalidate_column.X = grid_drawing.ColumnsHeadersArea.X;
+                               invalidate_column.Y = grid_drawing.ColumnsHeadersArea.Y;
+                               invalidate_column.Width = pixels;
+                               invalidate_column.Height = grid_drawing.ColumnsHeadersArea.Height;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.ColumnsHeadersArea, pixels, 0, false);
+
+                               // Cells
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y;
+                               invalidate.Width = pixels;
+                               invalidate.Height = grid_drawing.CellsArea.Height;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, pixels, 0, false);
+                       }
+
+                       horz_pixeloffset = horiz_scrollbar.Value = pixel;
+                       grid_drawing.UpdateVisibleColumn ();
+                       Invalidate (invalidate_column);
+                       Invalidate (invalidate);
+               }
+
+               private void ScrollToRow (int old_row, int new_row)
+               {
+                       Rectangle invalidate = new Rectangle ();
+
+                       if (new_row > old_row) { // Scrolldown
+                               int scrolled_rows = new_row - old_row;
+                               int pixels = scrolled_rows * RowHeight;
+
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y + grid_drawing.CellsArea.Height - pixels;
+                               invalidate.Width = grid_drawing.CellsArea.Width;
+                               invalidate.Height = pixels;
+
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, -pixels, false);
+
+                       } else { // ScrollUp
+                               int scrolled_rows = old_row - new_row;
+                               int pixels = scrolled_rows * RowHeight;
+
+                               invalidate.X =  grid_drawing.CellsArea.X;
+                               invalidate.Y =  grid_drawing.CellsArea.Y;
+                               invalidate.Width = grid_drawing.CellsArea.Width;
+                               invalidate.Height = pixels;
+                               XplatUI.ScrollWindow (Handle, grid_drawing.CellsArea, 0, pixels, false);                                
+                       }
+
+                       // Right now we use ScrollWindow Invalidate, let's leave remarked it here for X11 if need it
+                       //Invalidate ();
+                       Invalidate (grid_drawing.RowsHeadersArea);
+               }
+
                #endregion Private Instance Methods
 
 
index f2bcea753317128c50c27d428b28dfc22f2cb53f..29ef819aa5c1639eb274a4d4ed01b2cfa4163de2 100644 (file)
@@ -145,15 +145,15 @@ namespace System.Windows.Forms
                #region Public Instance Methods
                protected internal override void Abort (int rowNum)
                {
-                       SetState (rowNum, GetState (null, rowNum) & ~CheckState.Selected);
-                       Invalidate ();
+                       SetState (rowNum, GetState (null, rowNum) & ~CheckState.Selected);                      
+                       grid.Invalidate (grid.GetCurrentCellBounds ());
                }
 
                protected internal override bool Commit (CurrencyManager source, int rowNum)
                {
                        SetColumnValueAtRow (source, rowNum, FromStateToValue (GetState (source, rowNum)));
                        SetState (rowNum, GetState (source, rowNum) & ~CheckState.Selected);
-                       Invalidate ();
+                       grid.Invalidate (grid.GetCurrentCellBounds ());
                        return true;
                }
 
@@ -166,7 +166,7 @@ namespace System.Windows.Forms
                protected internal override void Edit (CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText,  bool cellIsVisible)
                {
                        SetState (rowNum, GetState (source, rowNum) | CheckState.Selected);
-                       Invalidate ();
+                       grid.Invalidate (grid.GetCurrentCellBounds ());
                }
 
                [MonoTODO]
@@ -219,20 +219,22 @@ namespace System.Windows.Forms
                protected internal override void Paint (Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
                {
                        Size chkbox_size = GetPreferredSize (g, null);
-                       Rectangle rect = new Rectangle ();
-                       Rectangle rect_selected = bounds;
+                       Rectangle rect = new Rectangle ();                      
                        ButtonState state;
                        chkbox_size.Width -= 2;
                        chkbox_size.Height -= 2;
                        rect.X = bounds.X + ((bounds.Width - chkbox_size.Width) / 2);
                        rect.Y = bounds.Y + ((bounds.Height - chkbox_size.Height) / 2);
                        rect.Width = chkbox_size.Width;
-                       rect.Height = chkbox_size.Height;
-                       rect_selected.Inflate (-1, -1);         
-
-                       g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (
-                               ((GetState (source, rowNum) & CheckState.Selected) == CheckState.Selected) ? grid.SelectionBackColor: grid.BackColor),
-                               rect_selected);
+                       rect.Height = chkbox_size.Height;                       
+                       
+                       // If the cell is selected
+                       if ((GetState (source, rowNum) & CheckState.Selected) == CheckState.Selected) { 
+                               backBrush = ThemeEngine.Current.ResPool.GetSolidBrush (grid.SelectionBackColor);
+                       }
+                                               
+                       g.FillRectangle (backBrush, bounds);
+                       g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow), bounds);
 
                        switch (GetState (source, rowNum) & ~CheckState.Selected) {
                        case CheckState.Checked:
@@ -360,12 +362,10 @@ namespace System.Windows.Forms
                        grid.InvalidateCurrentRowHeader ();                     
                        SetState (row, state);
                        grid.Invalidate (grid.GetCellBounds (row, column));
-
                }
 
                private void SetState (int row, CheckState state)
-               {
-                       Console.WriteLine ("Set state {0}, {1}, {2}", row, state, Environment.StackTrace);
+               {                       
                        if (checkboxes_state[row] == null) {
                                checkboxes_state.Add (row, state);
                        } else {
index 9cbc43f24f0c4b6840aa198e353c0aeb4677bbad..5249b6e574391ae27bf3a155f1a57697bf61b44e 100644 (file)
@@ -76,7 +76,7 @@ namespace System.Windows.Forms
 
                public override string ToString ()
                {
-                       return base.ToString () + "{RowNumber = " + row +", ColumnNumber = " + column + "}";
+                       return "DataGridCell {RowNumber = " + row +", ColumnNumber = " + column + "}";
                }
 
                #endregion      // Public Instance Methods
index 32193ced3db65ed0830eb688b5bbab26a0e699f7..d0609b770c8a81a4c776d9ed17e35f24b796977c 100644 (file)
@@ -46,6 +46,7 @@ namespace System.Windows.Forms
                private Rectangle rowshdrs_area;        // Used Headers rows area
                private int rowshdrs_maxheight;         // Total height for rows (max height)
                private Rectangle cells_area;
+               private bool partial_row;
 
                #endregion // Local Variables
 
@@ -114,6 +115,8 @@ namespace System.Windows.Forms
                        client_area.Width -= BorderStyleSize * 2;
                        client_area.Height -= BorderStyleSize * 2;
 
+                       Console.WriteLine ("CalcClientArea");
+
                        //Console.WriteLine ("CalcClientArea ClientRectangle {0}, ClientArea {1}, BorderStyleSize {2}",
                        //       grid.ClientRectangle, client_area, BorderStyleSize);
                }
@@ -131,6 +134,7 @@ namespace System.Windows.Forms
                        CalcColumnsHeader ();
                        CalcCellsArea ();
 
+                       UpdateVisibleRowCount (); // need it to be able to calcultate the need of horz scrollbar
                        if (SetUpVerticalScrollBar ()) { // We need a Vertical ScrollBar
                                if (grid.caption_visible) {
                                        caption_area.Width -= grid.vert_scrollbar.Width;
@@ -167,6 +171,7 @@ namespace System.Windows.Forms
                        }
 
                        UpdateVisibleColumn ();
+                       UpdateVisibleRowCount ();
 
                        //Console.WriteLine ("DataGridDrawing.CalcGridAreas cells:{0}", cells_area);
                }
@@ -281,8 +286,6 @@ namespace System.Windows.Forms
                                return;
                        }
 
-                       UpdateVisibleRowCount ();
-
                        if (grid.caption_visible) {
                                rowshdrs_area.Y = caption_area.Y + caption_area.Height;
                        } else {
@@ -324,30 +327,36 @@ namespace System.Windows.Forms
 
                public void UpdateVisibleRowCount ()
                {
-                       int max_height = client_area.Height - caption_area.Height -
-                               parent_rows.Height - columnshdrs_area.Height;
+                       int max_height = cells_area.Height;
 
                        int rows_height = (grid.RowsCount - grid.first_visiblerow) * grid.RowHeight;
                        int max_rows = max_height / grid.RowHeight;
-                       
+
+                       //Console.WriteLine ("UpdateVisibleRowCount {0} {1}/{2} (row h) {3}",
+                       //      max_rows, max_height, grid.RowHeight, cells_area.Height);
+
                        if (max_rows > grid.RowsCount) {
                                max_rows = grid.RowsCount;
                        }
 
                        if (rows_height > cells_area.Height) {
-                               grid.visiblerow_count = max_height / grid.RowHeight;
+                               grid.visiblerow_count = max_rows;
                        } else {
                                grid.visiblerow_count = grid.RowsCount;
                        }
 
                        if (grid.visiblerow_count + grid.first_visiblerow > grid.RowsCount)
                                grid.visiblerow_count = grid.RowsCount - grid.first_visiblerow;
-                               
+
                        if (grid.visiblerow_count < max_rows) {
                                grid.visiblerow_count = max_rows;
                                grid.first_visiblerow = grid.RowsCount - max_rows;
                                grid.Invalidate ();
                        }
+
+                       // TODO: Partial visible rows? May be only paint them and not take then into account for any
+                       // anything else
+                       //grid.visiblerow_count++;
                }
 
                // From Point to Cell
@@ -363,6 +372,15 @@ namespace System.Windows.Forms
 
                        if (rowshdrs_area.Contains (x, y)) {
                                hit.type = DataGrid.HitTestType.RowHeader;
+                               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
+                                               hit.row = r;
+                                               break;
+                                       }
+                               }
                                return hit;
                        }
 
@@ -429,6 +447,7 @@ namespace System.Windows.Forms
 
                public void OnPaint (PaintEventArgs pe)
                {
+                       Console.WriteLine ("OnPaint {0}", pe.ClipRectangle);
                        ThemeEngine.Current.CPDrawBorderStyle (pe.Graphics, grid.ClientRectangle, grid.border_style);
 
                        if (pe.ClipRectangle.IntersectsWith (parent_rows)) {
@@ -542,6 +561,11 @@ namespace System.Windows.Forms
                        not_usedarea.Intersect (rowshdrs_area_complete);
 
                        int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
+
+                       if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
+                               rowcnt++;
+                       }
+
                        for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
 
                                rect_row.Width = rowshdrs_area.Width;
@@ -561,6 +585,21 @@ namespace System.Windows.Forms
                        not_usedarea.Dispose ();
                }
 
+               public void InvalidateRow (int row)
+               {
+                       if (row < grid.FirstVisibleRow || row > grid.FirstVisibleRow + grid.VisibleRowCount) {
+                               return;
+                       }
+
+                       Rectangle rect_row = new Rectangle ();
+
+                       rect_row.X = cells_area.X;
+                       rect_row.Width = cells_area.Width;
+                       rect_row.Height = grid.RowHeight;
+                       rect_row.Y = cells_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
+                       grid.Invalidate (rect_row);
+               }
+
                public void InvalidateRowHeader (int row)
                {
                        Rectangle rect_rowhdr = new Rectangle ();
@@ -641,6 +680,11 @@ namespace System.Windows.Forms
                        not_usedarea.Intersect (cells_area);
 
                        int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
+
+                       if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
+                               rowcnt++;
+                       }
+
                        for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
                                // Get cell's width for column style
                                rect_row.Width = cells.Width;
@@ -661,11 +705,12 @@ namespace System.Windows.Forms
 
                public void PaintRow (Graphics g, int row, Rectangle row_rect)
                {
-                       //Console.WriteLine ("PaintRow row: {0}, rect {1}", row, row_rect);
+                       Console.WriteLine ("PaintRow row: {0}, rect {1}", row, row_rect);
 
                        Rectangle rect_cell = new Rectangle ();
                        int cnt = grid.CurrentTableStyle.GridColumnStyles.Count;
                        int col_pixel;
+                       Color backcolor, forecolor;
                        Region prev_clip = g.Clip;
                        Region current_clip;
                        Region not_usedarea = new Region (row_rect);
@@ -685,11 +730,20 @@ namespace System.Windows.Forms
                                current_clip = new Region (row_rect);
                                g.Clip = current_clip;
 
-                               g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.BackgroundColor), rect_cell);
-                               g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow), rect_cell);
+                               if (grid.IsSelected (row)) {
+                                       backcolor =  grid.SelectionBackColor;
+                                       forecolor =  grid.SelectionForeColor;
+                               } else {
+                                       backcolor =  grid.BackgroundColor;
+                                       forecolor =  grid.ForeColor;
+                               }
 
                                not_usedarea.Exclude (rect_cell);
-                               grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row);
+
+                               grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
+                                       ThemeEngine.Current.ResPool.GetSolidBrush (backcolor),
+                                       ThemeEngine.Current.ResPool.GetSolidBrush (forecolor),
+                                       grid.RightToLeft == RightToLeft.Yes);
 
                                g.Clip = prev_clip;
                                current_clip.Dispose ();
@@ -719,8 +773,8 @@ namespace System.Windows.Forms
                        grid.horiz_scrollbar.Size = new Size (client_area.Width,
                                grid.horiz_scrollbar.Height);
 
-                       //grid.horiz_scrollbar.Maximum = width_all - cells_area.Width;
-                       //grid.horiz_scrollbar.LargeChange = cells_area.Width;
+                       grid.horiz_scrollbar.Maximum = width_all - cells_area.Width;
+                       grid.horiz_scrollbar.LargeChange = cells_area.Width;
                        grid.Controls.Add (grid.horiz_scrollbar);
                        grid.horiz_scrollbar.Visible = true;
                        return true;
@@ -742,7 +796,7 @@ namespace System.Windows.Forms
                                client_area.Height);
 
                        grid.vert_scrollbar.Maximum = grid.RowsCount;
-                       grid.vert_scrollbar.LargeChange = cells_area.Height / grid.RowHeight;
+                       grid.vert_scrollbar.LargeChange = VLargeChange;
 
                        grid.Controls.Add (grid.vert_scrollbar);
                        grid.vert_scrollbar.Visible = true;
@@ -799,6 +853,12 @@ namespace System.Windows.Forms
                        }
                }
 
+               public int VLargeChange {
+                       get {
+                               return cells_area.Height / grid.RowHeight;
+                       }
+               }
+
                #endregion Instance Properties
        }
 }
index ca0c1ed160151206ee3839b2e79828a9ca0fb8fe..9d379b42227e4119726feb4f8dff6254d2ad6159 100644 (file)
@@ -727,7 +727,7 @@ namespace System.Windows.Forms
 
                protected bool ShouldSerializePreferredRowHeight ()
                {
-                       return (preferredrow_height != ThemeEngine.Current.DefaultFont.Height + 3);
+                       return (preferredrow_height != datagrid.def_preferredrow_height);
                }
 
                protected bool ShouldSerializeSelectionBackColor ()
@@ -750,16 +750,16 @@ namespace System.Windows.Forms
                        
                        if (mgr == null) {
                                return;
-                       }
+                       }                       
                        
-                       //column_styles.Clear ();
                        PropertyDescriptorCollection propcol = mgr.GetItemProperties ();
                        
                        for (int i = 0; i < propcol.Count; i++)
                        {
                                string s = propcol[i].Name;
                                DataGridColumnStyle colstyle = column_styles[propcol[i].Name];
-
+                               
+                               // The column style is already provided by the user
                                if (column_styles[propcol[i].Name] != null &&
                                        column_styles[propcol[i].Name].IsDefault == false) {
                                        column_styles[propcol[i].Name].table_style = this;
@@ -773,8 +773,7 @@ namespace System.Windows.Forms
                                        
                                } else {
                                        DataGridColumnStyle st = CreateGridColumn (propcol[i],  true);
-                                       st.grid = datagrid;
-                                       //st.TableStyle = this;
+                                       st.grid = datagrid;                                     
                                        st.MappingName = propcol[i].Name;
                                        st.HeaderText = propcol[i].Name;
                                        st.Width = PreferredColumnWidth;                                        
index 30b639d4315551ec659db73ac4204969a30525f0..15249e2ee767c1350732caa5d0e40f16ad79d1ad 100644 (file)
@@ -81,18 +81,32 @@ namespace System.Windows.Forms
 
                protected internal override bool ProcessKeyMessage (ref Message m)
                {
-                       int code = m.WParam.ToInt32 ();
+                       Keys key = (Keys) m.WParam.ToInt32 ();
                        
-                       if (code == 13) {                               
+                       switch (key) {
+                       case Keys.Return:
                                grid.EndEdit (false);
                                return true;
-                       }
                        
-                       if (code == 27) {
+                       case Keys.Escape:
                                grid.EndEdit (true);
                                return true;
-                       }
+                               
+                       case Keys.Right:
+                       case Keys.Up:
+                       case Keys.Down:
+                       case Keys.PageUp:
+                       case Keys.PageDown:
+                       case Keys.Home:
+                       case Keys.End:
+                               grid.EndEdit (false);
+                               break;
+                       
+                       default:
+                               break;
+                       }                       
                        
+                       isedit = false;
                        return base.ProcessKeyMessage (ref m);
                }
 
index 8547e61d491b942f39de996d7970105238ec36fc..ed90a0ed21a355e9ab24b1e0656b1d2c740cdbd9 100644 (file)
@@ -113,8 +113,7 @@ namespace System.Windows.Forms
                                base.ReadOnly = value;
                        }
                }
-
-               [MonoTODO]
+               
                [Browsable(false)]
                public virtual TextBox TextBox {
                        get {
@@ -128,13 +127,13 @@ namespace System.Windows.Forms
 
                protected internal override void Abort (int rowNum)
                {
-                       EndEdit ();
+                       EndEdit ();                     
                }
                
                protected internal override bool Commit (CurrencyManager dataSource, int rowNum)
                {
                        SetColumnValueAtRow (dataSource, rowNum, textbox.Text);
-                       EndEdit ();
+                       EndEdit ();                     
                        return true;
                }
 
@@ -166,7 +165,7 @@ namespace System.Windows.Forms
                protected void EndEdit ()
                {
                        ReleaseHostedControl ();
-                       Invalidate ();
+                       grid.Invalidate (grid.GetCurrentCellBounds ());
                }
 
                protected internal override void EnterNullValue ()
@@ -231,7 +230,10 @@ namespace System.Windows.Forms
                        } else {
                                string_format.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
                        }
-
+                       
+                       g.FillRectangle (backBrush, textBounds);
+                       g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow), textBounds);
+                       
                        string_format.FormatFlags |= StringFormatFlags.NoWrap;
                        g.DrawString (text, DataGridTableStyle.DataGrid.Font, foreBrush, textBounds, string_format);
                }