X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FManaged.Windows.Forms%2FSystem.Windows.Forms%2FDataGridViewComboBoxCell.cs;h=f4b30d637e1f859f819411361283cf570404f02d;hb=92920d5c69fac562024499ec52b509cae23e2718;hp=a68a21dbdcd150140c8e03625837eb15bb5e1268;hpb=f84f760a1c8a8c0ec6ae16b7f38d14a49d329ad7;p=mono.git diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxCell.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxCell.cs index a68a21dbdcd..f4b30d637e1 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxCell.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewComboBoxCell.cs @@ -46,6 +46,8 @@ namespace System.Windows.Forms { private bool sorted; private string valueMember; + private DataGridViewComboBoxEditingControl editingControl; + public DataGridViewComboBoxCell () : base() { autoComplete = true; dataSource = null; @@ -58,6 +60,7 @@ namespace System.Windows.Forms { sorted = false; } + [DefaultValue (true)] public virtual bool AutoComplete { get { return autoComplete; } set { autoComplete = value; } @@ -74,21 +77,25 @@ namespace System.Windows.Forms { } } + [DefaultValue ("")] public virtual string DisplayMember { get { return displayMember; } set { displayMember = value; } } + [DefaultValue (DataGridViewComboBoxDisplayStyle.DropDownButton)] public DataGridViewComboBoxDisplayStyle DisplayStyle { get { return displayStyle; } set { displayStyle = value; } } + [DefaultValue (false)] public bool DisplayStyleForCurrentCellOnly { get { return displayStyleForCurrentCellOnly; } set { displayStyleForCurrentCellOnly = value; } } + [DefaultValue (1)] public virtual int DropDownWidth { get { return dropDownWidth; } set { @@ -103,6 +110,7 @@ namespace System.Windows.Forms { get { return typeof(DataGridViewComboBoxEditingControl); } } + [DefaultValue (FlatStyle.Standard)] public FlatStyle FlatStyle { get { return flatStyle; } set { @@ -117,10 +125,12 @@ namespace System.Windows.Forms { get { return typeof(string); } } + [Browsable (false)] public virtual ObjectCollection Items { get { return items; } } + [DefaultValue (8)] public virtual int MaxDropDownItems { get { return maxDropDownItems; } set { @@ -131,6 +141,7 @@ namespace System.Windows.Forms { } } + [DefaultValue (false)] public virtual bool Sorted { get { return sorted; } set { @@ -143,6 +154,7 @@ namespace System.Windows.Forms { } } + [DefaultValue ("")] public virtual string ValueMember { get { return valueMember; } set { valueMember = value; } @@ -167,11 +179,32 @@ namespace System.Windows.Forms { } public override void DetachEditingControl () { - throw new NotImplementedException(); + this.DataGridView.EditingControlInternal = null; } public override void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { - throw new NotImplementedException(); + base.InitializeEditingControl (rowIndex, initialFormattedValue, dataGridViewCellStyle); + + editingControl = DataGridView.EditingControl as DataGridViewComboBoxEditingControl; + + if (editingControl == null) + return; + + // A simple way to check if the control has + // been initialized already. + if (editingControl.Items.Count > 0) + return; + + editingControl.DropDownStyle = ComboBoxStyle.DropDownList; + editingControl.Text = initialFormattedValue == null ? string.Empty : initialFormattedValue.ToString (); + editingControl.SelectedIndexChanged += new EventHandler (editingControl_SelectedIndexChanged); + editingControl.Items.Clear (); + editingControl.Items.AddRange (this.Items); + } + + void editingControl_SelectedIndexChanged (object sender, EventArgs e) + { + Value = editingControl.SelectedItem; } public override bool KeyEntersEditMode (KeyEventArgs e) { @@ -183,15 +216,20 @@ namespace System.Windows.Forms { } public override string ToString () { - throw new NotImplementedException(); + return string.Format ("DataGridViewComboBoxCell {{ ColumnIndex={0}, RowIndex={1} }}", ColumnIndex, RowIndex); } protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) { throw new NotImplementedException(); } - protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) { - throw new NotImplementedException(); + protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) + { + if (DataGridView == null || string.IsNullOrEmpty (ErrorText)) + return Rectangle.Empty; + + Size error_icon = new Size (12, 11); + return new Rectangle (new Point (Size.Width - error_icon.Width - 23, (Size.Height - error_icon.Height) / 2), error_icon); } protected override object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) { @@ -203,65 +241,104 @@ namespace System.Windows.Forms { } protected override void OnDataGridViewChanged () { - throw new NotImplementedException(); + // Here we're supposed to do something with DataSource, etc, according to MSDN. + base.OnDataGridViewChanged (); } protected override void OnEnter (int rowIndex, bool throughMouseClick) { - throw new NotImplementedException(); + base.OnEnter (rowIndex, throughMouseClick); } protected override void OnLeave (int rowIndex, bool throughMouseClick) { - throw new NotImplementedException(); + base.OnLeave (rowIndex, throughMouseClick); } protected override void OnMouseClick (DataGridViewCellMouseEventArgs e) { - throw new NotImplementedException(); + base.OnMouseClick (e); } protected override void OnMouseEnter (int rowIndex) { - throw new NotImplementedException(); + base.OnMouseEnter (rowIndex); } protected override void OnMouseLeave (int rowIndex) { - throw new NotImplementedException(); + base.OnMouseLeave (rowIndex); } protected override void OnMouseMove (DataGridViewCellMouseEventArgs e) { - throw new NotImplementedException(); + //Console.WriteLine ("MouseMove (Location: {0}", e.Location); + base.OnMouseMove (e); + } + + protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, + int rowIndex, DataGridViewElementStates elementState, object value, + object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, + DataGridViewPaintParts paintParts) { + + + Rectangle button_area, text_area; + text_area = cellBounds; + button_area = CalculateButtonArea (cellBounds); + + graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.BackColor), cellBounds); + ThemeEngine.Current.CPDrawComboButton (graphics, button_area, ButtonState.Normal); + + string text; + if (formattedValue == null) + text = string.Empty; + else { + text = formattedValue.ToString (); + } + + graphics.DrawString (text, cellStyle.Font, ThemeEngine.Current.ResPool.GetSolidBrush (cellStyle.ForeColor), text_area, StringFormat.GenericTypographic); } - protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementeState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { - throw new NotImplementedException(); + private Rectangle CalculateButtonArea (Rectangle cellBounds) + { + Rectangle button_area, text_area; + int border = ThemeEngine.Current.Border3DSize.Width; + const int button_width = 16; + + text_area = cellBounds; + + button_area = cellBounds; + button_area.X = text_area.Right - button_width - border; + button_area.Y = text_area.Y + border; + button_area.Width = button_width; + button_area.Height = text_area.Height - 2 * border; + + return button_area; } + [ListBindable (false)] public class ObjectCollection : IList, ICollection, IEnumerable { private ArrayList list; - private DataGridViewComboBoxCell owner; + //private DataGridViewComboBoxCell owner; public ObjectCollection (DataGridViewComboBoxCell owner) { - this.owner = owner; + //this.owner = owner; list = new ArrayList(); } - public virtual int Count { + public int Count { get { return list.Count; } } - public virtual bool IsFixedSize { + bool IList.IsFixedSize { get { return list.IsFixedSize; } } - public virtual bool IsReadOnly { + public bool IsReadOnly { get { return list.IsReadOnly; } } - public virtual bool IsSynchronized { + bool ICollection.IsSynchronized { get { return list.IsSynchronized; } } - public virtual object SyncRoot { + object ICollection.SyncRoot { get { return list.SyncRoot; } } @@ -278,49 +355,54 @@ namespace System.Windows.Forms { list.AddRange(value.list); } - public void AddRange (object[] items) { + public void AddRange (params object[] items) { list.AddRange(items); } - //public sealed void Clear () { public void Clear () { list.Clear(); } - //public sealed bool Contains (object value) { public bool Contains (object value) { return list.Contains(value); } - public void CopyTo (Array destination, int arrayIndex) { - list.CopyTo(destination, arrayIndex); + void ICollection.CopyTo (Array destination, int index) + { + CopyTo ((object[]) destination, index); + } + + public void CopyTo (object[] destination, int arrayIndex) + { + list.CopyTo (destination, arrayIndex); } - //public sealed IEnumerator GetEnumerator () { public IEnumerator GetEnumerator () { return list.GetEnumerator(); } - //public sealed int IndexOf (object value) { public int IndexOf (object value) { return list.IndexOf(value); } - //public sealed void Insert (int index, object item) { public void Insert (int index, object item) { list.Insert(index, item); } - //public sealed void Remove (object value) { public void Remove (object value) { list.Remove(value); } - //public sealed void RemoveAt (int index) { public void RemoveAt (int index) { list.RemoveAt(index); } + + int IList.Add (object item) + { + return Add (item); + } + } }