Author: toshok
Date: 2006-05-31 15:30:58 -0400 (Wed, 31 May 2006)
New Revision: 61350

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
Log:
2006-05-31  Chris Toshok  <[EMAIL PROTECTED]>

        * DataGridDrawingLogic.cs (FromPixelToColumn): modify this to also
        return (via an out parameter) the starting X of the column.
        (UpdateVisibleColumn): track change to FromPixelToColumn.
        (HitTest): add a ColumnResize case here.
        (DrawResizeLine): new function, probably poorly named.

        * DataGrid.cs (.ctor): get rid of cached_currencymgr_events.  We
        only need to keep one reference.
        (set_ListManager): same.
        (OnMouseDown): call HitTest instead of grid_drawing.HitTest.
        Also, add support for HitTestType.ColumnResize.
        (OnMouseMove): add column resize behavior here, and change the
        cursor to the correct one as we move around the datagrid.
        (OnMouseUp): terminate the column resize if we're resizing.
        (ProcessGridKey): from the MS docs, Alt-0 enters the null value
        for the current cell.
        (ConnectListManagerEvents): use cached_currencymgr.
        (DisconnectListManagerEvents): fill this in, using
        cached_currencymgr.
        (SetCurrentCell): remove cached_currencymgr_events handling.
        (SetDataMember): only call DisconnectListManagerEvents if
        cached_currencymgr is != null.
        (SetDataSource): same.
        (OnListManagerCurrentChanged): cached_currencymgr_events ->
        cached_currencymgr.



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-05-31 19:19:20 UTC (rev 61349)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-05-31 19:30:58 UTC (rev 61350)
@@ -1,3 +1,31 @@
+2006-05-31  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * DataGridDrawingLogic.cs (FromPixelToColumn): modify this to also
+       return (via an out parameter) the starting X of the column.
+       (UpdateVisibleColumn): track change to FromPixelToColumn.
+       (HitTest): add a ColumnResize case here.
+       (DrawResizeLine): new function, probably poorly named.
+
+       * DataGrid.cs (.ctor): get rid of cached_currencymgr_events.  We
+       only need to keep one reference.
+       (set_ListManager): same.
+       (OnMouseDown): call HitTest instead of grid_drawing.HitTest.
+       Also, add support for HitTestType.ColumnResize.
+       (OnMouseMove): add column resize behavior here, and change the
+       cursor to the correct one as we move around the datagrid.
+       (OnMouseUp): terminate the column resize if we're resizing.
+       (ProcessGridKey): from the MS docs, Alt-0 enters the null value
+       for the current cell.
+       (ConnectListManagerEvents): use cached_currencymgr.
+       (DisconnectListManagerEvents): fill this in, using
+       cached_currencymgr.
+       (SetCurrentCell): remove cached_currencymgr_events handling.
+       (SetDataMember): only call DisconnectListManagerEvents if
+       cached_currencymgr is != null.
+       (SetDataSource): same.
+       (OnListManagerCurrentChanged): cached_currencymgr_events ->
+       cached_currencymgr.
+
 2006-05-31  Jackson Harper  <[EMAIL PROTECTED]>
 
        * BindingManagerBase.cs: Remove somedebug code that creeped into

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-05-31 19:19:20 UTC (rev 61349)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs      
2006-05-31 19:30:58 UTC (rev 61350)
@@ -178,8 +178,13 @@
                private int selection_start; // used for range selection
                private bool begininit;
                private CurrencyManager cached_currencymgr;
-               private CurrencyManager cached_currencymgr_events;
                private bool accept_listmgrevents;
+
+               bool column_resize_active;
+               int resize_column_x;
+               int resize_column_width_delta;
+               int resize_column;
+               
                #endregion // Local Variables
 
                #region Public Constructors
@@ -233,7 +238,7 @@
                        selected_rows = new Hashtable ();
                        selection_start = -1;
                        preferredrow_height = def_preferredrow_height = 
FontHeight + 3;
-                       cached_currencymgr_events = cached_currencymgr = null;
+                       cached_currencymgr = null;
                        accept_listmgrevents = true;
 
                        default_style = new DataGridTableStyle (true);
@@ -700,7 +705,6 @@
                                // If we bind real_datasource object we do not 
get the events from ListManger
                                // since the object is not the datasource and 
does not match
                                cached_currencymgr = (CurrencyManager) 
BindingContext [real_datasource, DataMember];
-                               cached_currencymgr_events = (CurrencyManager) 
BindingContext [real_datasource, DataMember];
                                ConnectListManagerEvents ();
                                return cached_currencymgr;
                        }
@@ -1331,7 +1335,7 @@
                        bool shift_pressed = ((Control.ModifierKeys & 
Keys.Shift) != 0);
 
                        HitTestInfo testinfo;
-                       testinfo = grid_drawing.HitTest (e.X, e.Y);
+                       testinfo = HitTest (e.X, e.Y);
 
                        switch (testinfo.type) {
                        case HitTestType.Cell:
@@ -1400,7 +1404,17 @@
                                Refresh ();
                                break;
                        }
-                       
+
+                       case HitTestType.ColumnResize:
+                       {
+                               resize_column = testinfo.Column;
+                               column_resize_active = true;
+                               resize_column_x = e.X;
+                               resize_column_width_delta = 0;
+                               grid_drawing.DrawResizeLine (resize_column_x);
+                               break;
+                       }
+
                        default:
                                break;
                        }
@@ -1414,11 +1428,47 @@
                protected override void OnMouseMove (MouseEventArgs e)
                {
                        base.OnMouseMove (e);
+
+                       if (column_resize_active) {
+                               /* erase the old line */
+                               grid_drawing.DrawResizeLine (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);
+                               return;
+                       }
+                       else {
+                               HitTestInfo testinfo;
+                               testinfo = HitTest (e.X, e.Y);
+
+                               switch (testinfo.type) {
+                               case HitTestType.ColumnResize:
+                                       Cursor = Cursors.VSplit;
+                                       break;
+                               case HitTestType.RowResize:
+                                       Cursor = Cursors.HSplit;
+                                       break;
+                               default:
+                                       Cursor = Cursors.Default;
+                                       break;
+                               }
+                       }
                }
 
                protected override void OnMouseUp (MouseEventArgs e)
                {
                        base.OnMouseUp (e);
+
+                       if (column_resize_active) {
+                               column_resize_active = false;
+                               int new_width = 
CurrentTableStyle.GridColumnStyles[resize_column].Width + 
resize_column_width_delta;
+                               if (new_width < 0)
+                                       new_width = 0;
+                               
CurrentTableStyle.GridColumnStyles[resize_column].Width = new_width;
+                               Invalidate ();
+                       }
                }
 
                protected override void OnMouseWheel (MouseEventArgs e)
@@ -1534,8 +1584,18 @@
                        }
 
                        bool ctrl_pressed = ((Control.ModifierKeys & 
Keys.Control) != 0);
+                       bool alt_pressed = ((Control.ModifierKeys & Keys.Alt) 
!= 0);
 
                        switch (ke.KeyCode) {
+                       case Keys.D0:
+                       {
+                               if (alt_pressed) {
+                                       if (is_editing) {
+                                               
CurrentTableStyle.GridColumnStyles[current_cell.ColumnNumber].EnterNullValue ();
+                                       }
+                               }
+                               break;
+                       }
                        case Keys.Up:
                        {
                                if (ctrl_pressed) {
@@ -1902,13 +1962,14 @@
                
                private void ConnectListManagerEvents ()
                {
-                       cached_currencymgr_events.CurrentChanged += new 
EventHandler (OnListManagerCurrentChanged);                     
-                       cached_currencymgr_events.ItemChanged += new 
ItemChangedEventHandler (OnListManagerItemChanged);
+                       cached_currencymgr.CurrentChanged += new EventHandler 
(OnListManagerCurrentChanged);                    
+                       cached_currencymgr.ItemChanged += new 
ItemChangedEventHandler (OnListManagerItemChanged);
                }
                
                private void DisconnectListManagerEvents ()
                {
-                       
+                       cached_currencymgr.CurrentChanged -= new EventHandler 
(OnListManagerCurrentChanged);                    
+                       cached_currencymgr.ItemChanged -= new 
ItemChangedEventHandler (OnListManagerItemChanged);
                }
 
                // EndEdit current editing operation
@@ -2023,8 +2084,8 @@
                        
                        accept_listmgrevents = false;
 
-                       if (cached_currencymgr_events !=  null) {
-                               cached_currencymgr_events.Position = 
current_cell.RowNumber;
+                       if (cached_currencymgr !=  null) {
+                               cached_currencymgr.Position = 
current_cell.RowNumber;
                        }
                        accept_listmgrevents = true;
 
@@ -2042,8 +2103,10 @@
 
                        datamember = member;
                        real_datasource = GetDataSource (datasource, member);
-                       DisconnectListManagerEvents ();
-                       cached_currencymgr = cached_currencymgr_events = null;
+                       if (cached_currencymgr != null) {
+                               DisconnectListManagerEvents ();
+                               cached_currencymgr = null;
+                       }
                        return true;
                }
 
@@ -2057,8 +2120,10 @@
 
                        current_cell = new DataGridCell ();
                        datasource = source;
-                       DisconnectListManagerEvents ();
-                       cached_currencymgr = cached_currencymgr_events = null;
+                       if (cached_currencymgr != null) {
+                               DisconnectListManagerEvents ();
+                               cached_currencymgr = null;
+                       }
                        try {
                                real_datasource = GetDataSource (datasource, 
DataMember);
                        }catch (Exception) {                            
@@ -2093,11 +2158,11 @@
                                return;
                        }
                        
-                       CurrentCell = new DataGridCell 
(cached_currencymgr_events.Position, current_cell.RowNumber);
+                       CurrentCell = new DataGridCell 
(cached_currencymgr.Position, current_cell.RowNumber);
                }
                
                private void OnListManagerItemChanged (object sender, 
ItemChangedEventArgs e)
-               {                               
+               {
                        if (accept_listmgrevents == false) {
                                return;
                        }                       

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
  2006-05-31 19:19:20 UTC (rev 61349)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridDrawingLogic.cs
  2006-05-31 19:30:58 UTC (rev 61350)
@@ -71,22 +71,27 @@
                }
 
                // Gets a column from a pixel
-               private int FromPixelToColumn (int pixel)
+               private int FromPixelToColumn (int pixel, out int column_x)
                {
                        int width = 0;
                        int cnt = grid.CurrentTableStyle.GridColumnStyles.Count;
+                       column_x = 0;
 
                        if (cnt == 0)
                                return 0;
                                
-                       if (grid.CurrentTableStyle.CurrentRowHeadersVisible)
+                       if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
                                width += rowshdrs_area.X + rowshdrs_area.Width;
+                               column_x += rowshdrs_area.X + 
rowshdrs_area.Width;
+                       }
 
                        for (int col = 0; col < cnt; col++) {
                                width += 
grid.CurrentTableStyle.GridColumnStyles[col].Width;
 
                                if (pixel < width)
                                        return col;
+
+                               column_x += 
grid.CurrentTableStyle.GridColumnStyles[col].Width;
                        }
 
                        return cnt - 1;
@@ -411,9 +416,11 @@
                        
                        int col;
                        int max_pixel = grid.horz_pixeloffset + 
cells_area.Width;
-                       grid.first_visiblecolumn = FromPixelToColumn 
(grid.horz_pixeloffset);
+                       int unused;
 
-                       col = FromPixelToColumn (max_pixel);
+                       grid.first_visiblecolumn = FromPixelToColumn 
(grid.horz_pixeloffset, out unused);
+
+                       col = FromPixelToColumn (max_pixel, out unused);
                        
                        grid.visiblecolumn_count = 1 + col - 
grid.first_visiblecolumn;
                        
@@ -449,18 +456,31 @@
                        
                }
 
+               const int RESIZE_AREA_SIZE = 5;
+
                // From Point to Cell
                public DataGrid.HitTestInfo HitTest (int x, int y)
                {
                        DataGrid.HitTestInfo hit = new DataGrid.HitTestInfo ();
 
-                       // TODO: Add missing ColumnResize and RowResize checks
                        if (columnshdrs_area.Contains (x, y)) {
-                               hit.type = DataGrid.HitTestType.ColumnHeader;
-                               hit.column = FromPixelToColumn (x + 
grid.horz_pixeloffset);
+                               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)
+                                   && column_under_mouse < 
grid.CurrentTableStyle.GridColumnStyles.Count) {
+                                       hit.type = 
DataGrid.HitTestType.ColumnResize;
+                                       hit.column = column_under_mouse;
+                               }
+                               else {
+                                       hit.type = 
DataGrid.HitTestType.ColumnHeader;
+                                       hit.column = column_under_mouse;
+                               }
                                return hit;
                        }
 
+                       // TODO: Add missing RowResize checks
                        if (rowshdrs_area.Contains (x, y)) {
                                hit.type = DataGrid.HitTestType.RowHeader;
                                int posy;
@@ -591,6 +611,13 @@
                        grid.Invalidate (rect_col);
                }
 
+               public void DrawResizeLine (int x)
+               {
+                       XplatUI.DrawReversibleRectangle (grid.Handle,
+                                                        new Rectangle (x, 
CellsArea.Y, 1, CellsArea.Height),
+                                                        3);
+               }
+
                void SetUpHorizontalScrollBar (out int maximum)
                {
                        maximum = CalcAllColumnsWidth ();

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

Reply via email to