diff options
author | Jordi Mas i Hernandez <jordi@mono-cvs.ximian.com> | 2005-02-02 16:11:01 +0300 |
---|---|---|
committer | Jordi Mas i Hernandez <jordi@mono-cvs.ximian.com> | 2005-02-02 16:11:01 +0300 |
commit | 6d7400b70d5c80f27c95e785f0a726bc6fcd5511 (patch) | |
tree | 82c16b9615eb412b712b29da10e9a6fd63745bd7 /mcs | |
parent | ec14f8ebee27db9665ed52ee57964c80f0b4fe77 (diff) |
more ComboBox and ListBox enhanments
svn path=/trunk/mcs/; revision=39984
Diffstat (limited to 'mcs')
5 files changed, 185 insertions, 57 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index 07802664f36..e1a19205f5f 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,18 @@ +2005-02-02 Jordi Mas i Hernandez <jordi@ximian.com> + + * Combobox.cs: + - Fixes default size and PreferredHeight + - Missing events + - ObjectCollection.Insert implementation + + * ListControl.cs + - Fixes signature + * ListBox.cs: + - Several fixes + - ObjectCollection.Insert implementation + - No selection after clean + - Small fixes + 2005-01-31 John BouAntoun <jba-mono@optusnet.com.au> * ThemeWin32Classic.cs: quick fix to comboboxbutton pushed painting diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CheckedListBox.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CheckedListBox.cs index 8601e0e7774..4afc715cd6b 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CheckedListBox.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CheckedListBox.cs @@ -357,9 +357,9 @@ namespace System.Windows.Forms base.OnMouseDownLB (sender, e); } - internal override void UpdateItemInfo (bool adding, int first, int last) + internal override void UpdateItemInfo (UpdateOperation operation, int first, int last) { - base.UpdateItemInfo (adding, first, last); + base.UpdateItemInfo (operation, first, last); CheckedItems.ReCreate (); CheckedIndices.ReCreate (); } diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs index ae341516f7c..1f2c84bc753 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs @@ -40,7 +40,7 @@ namespace System.Windows.Forms private DrawMode draw_mode; private ComboBoxStyle dropdown_style; private int dropdown_width; - private int preferred_height; + private const int preferred_height = 20; private int selected_index; private object selected_item; internal ObjectCollection items = null; @@ -87,7 +87,7 @@ namespace System.Windows.Forms { Index = index; ItemHeight = -1; - } + } } public ComboBox () @@ -95,14 +95,14 @@ namespace System.Windows.Forms items = new ObjectCollection (this); listbox_ctrl = null; textbox_ctrl = null; - combobox_info = new ComboBoxInfo (); + combobox_info = new ComboBoxInfo (); + combobox_info.item_height = FontHeight + 2; DropDownStyle = ComboBoxStyle.DropDown; BackColor = ThemeEngine.Current.ColorWindow; draw_mode = DrawMode.Normal; selected_index = -1; selected_item = null; maxdrop_items = 8; - combobox_info.item_height = FontHeight + 2; suspend_ctrlupdate = false; clicked = false; dropdown_width = -1; @@ -110,8 +110,7 @@ namespace System.Windows.Forms integral_height = true; process_textchanged_event = true; - string_format = new StringFormat (); - + string_format = new StringFormat (); /* Events */ MouseDown += new MouseEventHandler (OnMouseDownCB); @@ -203,8 +202,7 @@ namespace System.Windows.Forms textbox_ctrl.Dispose (); textbox_ctrl = null; } - } - + } dropdown_style = value; @@ -312,7 +310,6 @@ namespace System.Windows.Forms } } - public ComboBox.ObjectCollection Items { get { return items; } } @@ -530,7 +527,7 @@ namespace System.Windows.Forms public void EndUpdate () { suspend_ctrlupdate = false; - Refresh (); + UpdatedItems (); } public int FindString (string s) @@ -717,7 +714,8 @@ namespace System.Windows.Forms protected virtual void OnSelectedItemChanged (EventArgs e) { - + if (SelectedIndexChanged != null) + SelectedIndexChanged (this, e); } protected override void OnSelectedValueChanged (EventArgs e) @@ -727,7 +725,8 @@ namespace System.Windows.Forms protected virtual void OnSelectionChangeCommitted (EventArgs e) { - + if (SelectionChangeCommitted != null) + SelectionChangeCommitted (this, e); } protected override void RefreshItem (int index) @@ -999,7 +998,6 @@ namespace System.Windows.Forms listbox_ctrl.SetTopItem (item); listbox_ctrl.SetHighLightedItem (item); - } internal void SetControlText (string s) @@ -1030,14 +1028,13 @@ namespace System.Windows.Forms private ComboBox owner; internal ArrayList object_items = new ArrayList (); - internal ArrayList listbox_items = new ArrayList (); + internal ArrayList combobox_items = new ArrayList (); public ObjectCollection (ComboBox owner) { this.owner = owner; } - #region Public Properties public virtual int Count { get { return object_items.Count; } @@ -1075,6 +1072,22 @@ namespace System.Windows.Forms } #endregion Public Properties + + #region Private Properties + internal ArrayList ObjectItems { + get { return object_items;} + set { + object_items = value; + } + } + + internal ArrayList ListBoxItems { + get { return combobox_items;} + set { + combobox_items = value; + } + } + #endregion Private Properties #region Public Methods public int Add (object item) @@ -1097,10 +1110,11 @@ namespace System.Windows.Forms public virtual void Clear () { object_items.Clear (); - listbox_items.Clear (); + combobox_items.Clear (); owner.UpdatedItems (); - + owner.selected_index = -1; } + public virtual bool Contains (object obj) { return object_items.Contains (obj); @@ -1133,7 +1147,34 @@ namespace System.Windows.Forms public virtual void Insert (int index, object item) { - throw new NotImplementedException (); + if (index < 0 || index >= Count) + throw new ArgumentOutOfRangeException ("Index of out range"); + + ObjectCollection new_items = new ObjectCollection (owner); + object sel_item = owner.SelectedItem; + + owner.BeginUpdate (); + + for (int i = 0; i < index; i++) { + new_items.AddItem (ObjectItems[i]); + } + + new_items.AddItem (item); + + for (int i = index; i < Count; i++){ + new_items.AddItem (ObjectItems[i]); + } + + ObjectItems = new_items.ObjectItems; + ListBoxItems = new_items.ListBoxItems; + + if (sel_item != null) { + int idx = IndexOf (sel_item); + owner.selected_index = idx; + owner.listbox_ctrl.SetHighLightedItem (idx); + } + + owner.EndUpdate (); // Calls UpdateItemInfo } public virtual void Remove (object value) @@ -1147,7 +1188,7 @@ namespace System.Windows.Forms throw new ArgumentOutOfRangeException ("Index of out range"); object_items.RemoveAt (index); - listbox_items.RemoveAt (index); + combobox_items.RemoveAt (index); owner.UpdatedItems (); } #endregion Public Methods @@ -1157,7 +1198,7 @@ namespace System.Windows.Forms { int cnt = object_items.Count; object_items.Add (item); - listbox_items.Add (new ComboBox.ComboBoxItem (cnt)); + combobox_items.Add (new ComboBox.ComboBoxItem (cnt)); return cnt; } @@ -1166,7 +1207,7 @@ namespace System.Windows.Forms if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException ("Index of out range"); - return (ComboBox.ComboBoxItem) listbox_items[index]; + return (ComboBox.ComboBoxItem) combobox_items[index]; } internal void SetComboBoxItem (ComboBox.ComboBoxItem item, int index) @@ -1174,7 +1215,7 @@ namespace System.Windows.Forms if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException ("Index of out range"); - listbox_items[index] = item; + combobox_items[index] = item; } #endregion Private Methods @@ -1514,6 +1555,8 @@ namespace System.Windows.Forms if (item != -1) { SetHighLightedItem (item); + owner.OnSelectionChangeCommitted (new EventArgs ()); + if (owner.DropDownStyle == ComboBoxStyle.Simple) { owner.SetControlText (owner.Items[item].ToString ()); } @@ -1563,8 +1606,8 @@ namespace System.Windows.Forms /* Current item */ invalidate = GetItemDisplayRectangle (highlighted_item, top_item); if (ClientRectangle.Contains (invalidate)) - Invalidate (invalidate); - + Invalidate (invalidate); + } public void SetTopItem (int item) @@ -1585,6 +1628,7 @@ namespace System.Windows.Forms if (index != -1) { owner.SelectedIndex = index; SetHighLightedItem (index); + owner.OnSelectionChangeCommitted (new EventArgs ()); HideWindow (); return; } @@ -1661,8 +1705,7 @@ namespace System.Windows.Forms vscrollbar_ctrl.FireMouseUp (new MouseEventArgs (e.Button, e.Clicks, pnt_client.X, pnt_client.Y, e.Delta)); - } - + } } private void OnPaintPUW (Object o, PaintEventArgs pevent) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs index bed47c80619..a28776f5619 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs @@ -79,6 +79,13 @@ namespace System.Windows.Forms ItemHeight = -1; State = CheckState.Unchecked; } + + public void CopyState (ListBoxItem src) + { + Selected = src.Selected; + ItemHeight = src.ItemHeight; + State = src.State; + } } internal enum ItemNavigation @@ -92,6 +99,13 @@ namespace System.Windows.Forms PreviousColumn, NextColumn } + + internal enum UpdateOperation + { + AddItems, + DeleteItems, + AllItems + } private BorderStyle border_style; private int column_width; @@ -350,7 +364,7 @@ namespace System.Windows.Forms if (IsHandleCreated) { RellocateScrollBars (); CalcClientArea (); - UpdateItemInfo (false, -1, -1); + UpdateItemInfo (UpdateOperation.AllItems, 0, 0); } } } @@ -442,9 +456,27 @@ namespace System.Windows.Forms if (selection_mode == value) return; - - selection_mode = value; - base.Refresh (); + + selection_mode = value; + + if (SelectedItems.Count > 0) { + switch (selection_mode) { + case SelectionMode.None: + ClearSelected (); + break; + case SelectionMode.One: { + if (SelectedItems.Count > 1) { // All except one + int cnt = selected_indices.Count - 1; + for (int i = 0; i < cnt; i++) { + UnSelectItem (i, true); + } + } + } + break; + default: + break; + } + } } } @@ -556,7 +588,7 @@ namespace System.Windows.Forms public void EndUpdate () { suspend_ctrlupdate = false; - UpdateItemInfo (false, -1, -1); + UpdateItemInfo (UpdateOperation.AllItems, 0, 0); base.Refresh (); } @@ -630,8 +662,7 @@ namespace System.Windows.Forms } } else { rect.Y = ItemHeight * index; - } - + } } else { int which_page; @@ -722,7 +753,7 @@ namespace System.Windows.Forms RellocateScrollBars (); CalcClientArea (); - UpdateItemInfo (false, -1, -1); + UpdateItemInfo (UpdateOperation.AllItems, 0, 0); } protected override void OnHandleCreated (EventArgs e) @@ -732,7 +763,7 @@ namespace System.Windows.Forms UpdateInternalClientRect (ClientRectangle); Controls.Add (vscrollbar_ctrl); Controls.Add (hscrollbar_ctrl); - UpdateItemInfo (false, -1, -1); + UpdateItemInfo (UpdateOperation.AllItems, 0, 0); } protected override void OnHandleDestroyed (EventArgs e) @@ -1499,7 +1530,6 @@ namespace System.Windows.Forms selected_items.RemoveObject (Items[index]); } - if (ClientRectangle.Contains (invalidate)) Invalidate (invalidate); } @@ -1516,7 +1546,7 @@ namespace System.Windows.Forms } // Updates the scrollbar's position with the new items and inside area - internal virtual void UpdateItemInfo (bool adding, int first, int last) + internal virtual void UpdateItemInfo (UpdateOperation operation, int first, int last) { if (!IsHandleCreated || suspend_ctrlupdate == true) return; @@ -1538,7 +1568,7 @@ namespace System.Windows.Forms if (MultiColumn == false) { /* Calc the longest items for non multicolumn listboxes */ - if ((first == -1 && last == -1) || (adding == false)) { + if (operation == UpdateOperation.AllItems || operation == UpdateOperation.DeleteItems) { SizeF size; for (int i = 0; i < Items.Count; i++) { @@ -1549,7 +1579,7 @@ namespace System.Windows.Forms } } else { - if (adding) { + if (operation == UpdateOperation.AddItems) { SizeF size; for (int i = first; i < last + 1; i++) { @@ -1563,9 +1593,10 @@ namespace System.Windows.Forms } if (sorted) - Sort (); - - if (adding == false) { + Sort (); + + if (Items.Count == 0) { + SelectedIndex = -1; focused_item = -1; } @@ -1582,7 +1613,7 @@ namespace System.Windows.Forms UpdateShowHorizontalScrollBar (); UpdateShowVerticalScrollBar (); RellocateScrollBars (); - UpdateItemInfo (false, -1, -1); + UpdateItemInfo (UpdateOperation.AllItems, 0, 0); } /* Determines if the horizontal scrollbar has to be displyed */ @@ -1780,6 +1811,22 @@ namespace System.Windows.Forms } #endregion Public Properties + + #region Private Properties + internal ArrayList ObjectItems { + get { return object_items;} + set { + object_items = value; + } + } + + internal ArrayList ListBoxItems { + get { return listbox_items;} + set { + listbox_items = value; + } + } + #endregion Private Properties #region Public Methods public int Add (object item) @@ -1787,7 +1834,7 @@ namespace System.Windows.Forms int idx; idx = AddItem (item); - owner.UpdateItemInfo (true, idx, idx); + owner.UpdateItemInfo (UpdateOperation.AddItems, idx, idx); return idx; } @@ -1798,7 +1845,7 @@ namespace System.Windows.Forms foreach (object mi in items) AddItem (mi); - owner.UpdateItemInfo (true, cnt, Count); + owner.UpdateItemInfo (UpdateOperation.AddItems, cnt, Count); } public void AddRange (ObjectCollection col) @@ -1808,14 +1855,14 @@ namespace System.Windows.Forms foreach (object mi in col) AddItem (mi); - owner.UpdateItemInfo (true, cnt, Count); + owner.UpdateItemInfo (UpdateOperation.AddItems, cnt, Count); } public virtual void Clear () { object_items.Clear (); listbox_items.Clear (); - owner.UpdateItemInfo (false, -1, -1); + owner.UpdateItemInfo (UpdateOperation.AllItems, 0, 0); } public virtual bool Contains (object obj) { @@ -1849,13 +1896,35 @@ namespace System.Windows.Forms public virtual void Insert (int index, object item) { - throw new NotImplementedException (); + if (index < 0 || index >= Count) + throw new ArgumentOutOfRangeException ("Index of out range"); + + int idx; + ObjectCollection new_items = new ObjectCollection (owner); + + owner.BeginUpdate (); + + for (int i = 0; i < index; i++) { + idx = new_items.AddItem (ObjectItems[i]); + (new_items.GetListBoxItem (idx)).CopyState (GetListBoxItem (i)); + } + + new_items.AddItem (item); + + for (int i = index; i < Count; i++){ + idx = new_items.AddItem (ObjectItems[i]); + (new_items.GetListBoxItem (idx)).CopyState (GetListBoxItem (i)); + } + + ObjectItems = new_items.ObjectItems; + ListBoxItems = new_items.ListBoxItems; + + owner.EndUpdate (); // Calls UpdateItemInfo } public virtual void Remove (object value) - { - RemoveAt (IndexOf (value)); - owner.UpdateItemInfo (false, -1, -1); + { + RemoveAt (IndexOf (value)); } public virtual void RemoveAt (int index) @@ -1864,13 +1933,13 @@ namespace System.Windows.Forms throw new ArgumentOutOfRangeException ("Index of out range"); object_items.RemoveAt (index); - listbox_items.RemoveAt (index); - owner.UpdateItemInfo (false, -1, -1); + listbox_items.RemoveAt (index); + owner.UpdateItemInfo (UpdateOperation.DeleteItems, index, index); } #endregion Public Methods #region Private Methods - private int AddItem (object item) + internal int AddItem (object item) { int cnt = object_items.Count; object_items.Add (item); diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs index 00a2dc99800..50b636c5237 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListControl.cs @@ -59,7 +59,8 @@ namespace System.Windows.Forms get {throw new NotImplementedException (); } set {throw new NotImplementedException (); } } - string DisplayMember { + + public string DisplayMember { get { return display_member; } set { display_member = value; } } |