diff options
author | Gert Driesen <drieseng@users.sourceforge.net> | 2007-03-02 00:53:20 +0300 |
---|---|---|
committer | Gert Driesen <drieseng@users.sourceforge.net> | 2007-03-02 00:53:20 +0300 |
commit | a46f1f61071fd0ac476c51a5309361296487c5dc (patch) | |
tree | 620d7025c97a3710b5dd472c6621ec166740b31f /mcs/class/Managed.Windows.Forms/System.Windows.Forms | |
parent | 97fc5dad07b155a04299713e69e89a306f365af0 (diff) |
* ListView.cs: Add fireEvent argument to ReorderColumn since the
ColumnReordered event must not be signaled when modifying DisplayIndex
of a ColumnHeader. Added internal ReorderColumns method which takes
care of drawing, and updating the internal DisplayIndex of the
ColumnHeader. Added AddColumn method which is invoked from
ColumnHeaderCollection when adding or inserting columns, and which
ensures that reorder_columns_indices is kept in sync. Avoid redrawing
after adding each ColumnHeader in ColumnHeaderCollection.AddRange.
Recalculated dispay indices after removing a ColumnHeader.
* ColumnHeader.cs: Save DisplayIndex separately from ListView to
match MS. Allows last display index to be returned after ListView
is disposed. Update actual location of ColumnHeader when DisplayIndex
is modified.
* ListViewCollectionsTest.cs: Added ColumnHeader.Index tests.
* ColumnHeaderTest.cs: Added more DisplayIndex tests.
svn path=/trunk/mcs/; revision=73617
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/System.Windows.Forms')
3 files changed, 118 insertions, 42 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index d738f7a1237..8e0514fa5dd 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,19 @@ +2007-03-01 Gert Driesen <drieseng@users.sourceforge.net> + + * ListView.cs: Add fireEvent argument to ReorderColumn since the + ColumnReordered event must not be signaled when modifying DisplayIndex + of a ColumnHeader. Added internal ReorderColumns method which takes + care of drawing, and updating the internal DisplayIndex of the + ColumnHeader. Added AddColumn method which is invoked from + ColumnHeaderCollection when adding or inserting columns, and which + ensures that reorder_columns_indices is kept in sync. Avoid redrawing + after adding each ColumnHeader in ColumnHeaderCollection.AddRange. + Recalculated dispay indices after removing a ColumnHeader. + * ColumnHeader.cs: Save DisplayIndex separately from ListView to + match MS. Allows last display index to be returned after ListView + is disposed. Update actual location of ColumnHeader when DisplayIndex + is modified. + 2007-03-01 Everaldo Canuto <everaldo@simios.org> * LinkLabel.cs: Improve CalcTrimRectangle. diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ColumnHeader.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ColumnHeader.cs index e4970728d51..b6c3f5c9687 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ColumnHeader.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ColumnHeader.cs @@ -51,6 +51,7 @@ namespace System.Windows.Forms private string name = String.Empty; private object tag; #endif + private int display_index = -1; // internal variables Rectangle column_rect = Rectangle.Empty; @@ -132,8 +133,13 @@ namespace System.Windows.Forms get { return format; } } + internal int InternalDisplayIndex { + get { return display_index; } + set { display_index = value; } + } + internal void CalcColumnHeader () - { + { if (text_alignment == HorizontalAlignment.Center) format.Alignment = StringAlignment.Center; else if (text_alignment == HorizontalAlignment.Right) @@ -167,23 +173,26 @@ namespace System.Windows.Forms #endregion // Private Internal Methods Properties #region Public Instance Properties + #if NET_2_0 [Localizable (true)] [RefreshProperties (RefreshProperties.Repaint)] public int DisplayIndex { get { if (owner == null) - return -1; + return display_index; return owner.GetReorderedColumnIndex (this); - } + } set { - if (owner == null) + if (owner == null) { + display_index = value; return; + } if (value < 0 || value >= owner.Columns.Count) - throw new ArgumentOutOfRangeException ("value"); + throw new ArgumentOutOfRangeException ("DisplayIndex"); - owner.ReorderColumn (this, value); + owner.ReorderColumn (this, value, false); } } diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs index a4c7013ded4..c54f36d129d 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListView.cs @@ -1099,7 +1099,7 @@ namespace System.Windows.Forms return -1; } #endif - + internal ColumnHeader GetReorderedColumn (int index) { if (reordered_column_indices == null) @@ -1108,24 +1108,28 @@ namespace System.Windows.Forms return Columns [reordered_column_indices [index]]; } - internal void ReorderColumn (ColumnHeader col, int index) + internal void ReorderColumn (ColumnHeader col, int index, bool fireEvent) { #if NET_2_0 - ColumnReorderedEventHandler eh = (ColumnReorderedEventHandler) (Events [ColumnReorderedEvent]); - if (eh != null){ - ColumnReorderedEventArgs args = new ColumnReorderedEventArgs (col.Index, index, col); - - eh (this, args); - if (args.Cancel){ - header_control.Invalidate (); - item_control.Invalidate (); - return; + if (fireEvent) { + ColumnReorderedEventHandler eh = (ColumnReorderedEventHandler) (Events [ColumnReorderedEvent]); + if (eh != null){ + ColumnReorderedEventArgs args = new ColumnReorderedEventArgs (col.Index, index, col); + + eh (this, args); + if (args.Cancel) { + header_control.Invalidate (); + item_control.Invalidate (); + return; + } } } #endif + int column_count = Columns.Count; + if (reordered_column_indices == null) { - reordered_column_indices = new int [Columns.Count]; - for (int i = 0; i < Columns.Count; i++) + reordered_column_indices = new int [column_count]; + for (int i = 0; i < column_count; i++) reordered_column_indices [i] = i; } @@ -1133,10 +1137,10 @@ namespace System.Windows.Forms return; int[] curr = reordered_column_indices; - int[] result = new int [Columns.Count]; + int [] result = new int [column_count]; int curr_idx = 0; - for (int i = 0; i < Columns.Count; i++) { - if (curr_idx < Columns.Count && curr [curr_idx] == col.Index) + for (int i = 0; i < column_count; i++) { + if (curr_idx < column_count && curr [curr_idx] == col.Index) curr_idx++; if (i == index) @@ -1145,13 +1149,49 @@ namespace System.Windows.Forms result [i] = curr [curr_idx++]; } - reordered_column_indices = result; - LayoutDetails (); - header_control.Invalidate (); - item_control.Invalidate (); + ReorderColumns (result, true); + } + + internal void ReorderColumns (int [] display_indices, bool redraw) + { + reordered_column_indices = display_indices; + for (int i = 0; i < Columns.Count; i++) { + ColumnHeader col = Columns [i]; + col.InternalDisplayIndex = reordered_column_indices [i]; + } + if (redraw && view == View.Details && IsHandleCreated) { + LayoutDetails (); + header_control.Invalidate (); + item_control.Invalidate (); + } } - Size LargeIconItemSize { + internal void AddColumn (ColumnHeader newCol, int index, bool redraw) + { + int column_count = Columns.Count; + newCol.SetListView (this); + + int [] display_indices = new int [column_count]; + for (int i = 0; i < column_count; i++) { + ColumnHeader col = Columns [i]; + if (i == index) { + display_indices [i] = index; + } else { + int display_index = col.InternalDisplayIndex; + if (display_index < index) { + display_indices [i] = display_index; + } else { + display_indices [i] = (display_index + 1); + } + } + } + + ReorderColumns (display_indices, redraw); + Invalidate (); + } + + Size LargeIconItemSize + { get { int image_w = LargeImageList == null ? 12 : LargeImageList.ImageSize.Width; int image_h = LargeImageList == null ? 2 : LargeImageList.ImageSize.Height; @@ -2913,7 +2953,7 @@ namespace System.Windows.Forms if (drag_to_index > GetReorderedIndex (clicked_column)) drag_to_index--; if (owner.GetReorderedColumn (drag_to_index) != clicked_column) - owner.ReorderColumn (clicked_column, drag_to_index); + owner.ReorderColumn (clicked_column, drag_to_index, true); drag_to_index = -1; Invalidate (); } @@ -3351,12 +3391,8 @@ namespace System.Windows.Forms #region Public Methods public virtual int Add (ColumnHeader value) { - int idx; - value.SetListView (this.owner); - idx = list.Add (value); - if (owner.IsHandleCreated) { - owner.Redraw (true); - } + int idx = list.Add (value); + owner.AddColumn (value, idx, true); return idx; } @@ -3412,11 +3448,11 @@ namespace System.Windows.Forms public virtual void AddRange (ColumnHeader [] values) { foreach (ColumnHeader colHeader in values) { - colHeader.SetListView (this.owner); - Add (colHeader); + int idx = list.Add (colHeader); + owner.AddColumn (colHeader, idx, false); } - owner.Redraw (true); + owner.Redraw (true); } public virtual void Clear () @@ -3424,7 +3460,7 @@ namespace System.Windows.Forms foreach (ColumnHeader col in list) col.SetListView (null); list.Clear (); - owner.Redraw (true); + owner.ReorderColumns (new int [0], true); } public bool Contains (ColumnHeader value) @@ -3522,9 +3558,8 @@ namespace System.Windows.Forms if (index < 0 || index > list.Count) throw new ArgumentOutOfRangeException ("index"); - value.SetListView (owner); list.Insert (index, value); - owner.Redraw (true); + owner.AddColumn (value, index, true); } #if NET_2_0 @@ -3575,10 +3610,26 @@ namespace System.Windows.Forms public virtual void Remove (ColumnHeader column) { - // TODO: Update Column internal index ? + if (!Contains (column)) + return; + list.Remove (column); column.SetListView (null); - owner.Redraw (true); + + int rem_display_index = column.InternalDisplayIndex; + int [] display_indices = new int [list.Count]; + for (int i = 0; i < display_indices.Length; i++) { + ColumnHeader col = (ColumnHeader) list [i]; + int display_index = col.InternalDisplayIndex; + if (display_index < rem_display_index) { + display_indices [i] = display_index; + } else { + display_indices [i] = (display_index - 1); + } + } + + column.InternalDisplayIndex = -1; + owner.ReorderColumns (display_indices, true); } #if NET_2_0 |