a68a21dbdcd150140c8e03625837eb15bb5e1268
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewComboBoxCell.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using System.Collections;
30 using System.ComponentModel;
31 using System.Drawing;
32
33 namespace System.Windows.Forms {
34
35         public class DataGridViewComboBoxCell : DataGridViewCell {
36
37                 private bool autoComplete;
38                 private object dataSource;
39                 private string displayMember;
40                 private DataGridViewComboBoxDisplayStyle displayStyle;
41                 private bool displayStyleForCurrentCellOnly;
42                 private int dropDownWidth;
43                 private FlatStyle flatStyle;
44                 private ObjectCollection items;
45                 private int maxDropDownItems;
46                 private bool sorted;
47                 private string valueMember;
48
49                 public DataGridViewComboBoxCell () : base() {
50                         autoComplete = true;
51                         dataSource = null;
52                         displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
53                         displayStyleForCurrentCellOnly = false;
54                         dropDownWidth = 1;
55                         flatStyle = FlatStyle.Standard;
56                         items = new ObjectCollection(this);
57                         maxDropDownItems = 8;
58                         sorted = false;
59                 }
60
61                 public virtual bool AutoComplete {
62                         get { return autoComplete; }
63                         set { autoComplete = value; }
64                 }
65
66                 public virtual object DataSource {
67                         get { return dataSource; }
68                         set {
69                                 if (value is IList || value is IListSource || value == null) {
70                                         dataSource = value;
71                                         return;
72                                 }
73                                 throw new Exception("Value is no IList, IListSource or null.");
74                         }
75                 }
76
77                 public virtual string DisplayMember {
78                         get { return displayMember; }
79                         set { displayMember = value; }
80                 }
81
82                 public DataGridViewComboBoxDisplayStyle DisplayStyle {
83                         get { return displayStyle; }
84                         set { displayStyle = value; }
85                 }
86
87                 public bool DisplayStyleForCurrentCellOnly {
88                         get { return displayStyleForCurrentCellOnly; }
89                         set { displayStyleForCurrentCellOnly = value; }
90                 }
91
92                 public virtual int DropDownWidth {
93                         get { return dropDownWidth; }
94                         set {
95                                 if (value < 1) {
96                                         throw new ArgumentOutOfRangeException("Value is less than 1.");
97                                 }
98                                 dropDownWidth = value;
99                         }
100                 }
101
102                 public override Type EditType {
103                         get { return typeof(DataGridViewComboBoxEditingControl); }
104                 }
105
106                 public FlatStyle FlatStyle {
107                         get { return flatStyle; }
108                         set {
109                                 if (!Enum.IsDefined(typeof(FlatStyle), value)) {
110                                         throw new InvalidEnumArgumentException("Value is not valid FlatStyle.");
111                                 }
112                                 flatStyle = value;
113                         }
114                 }
115
116                 public override Type FormattedValueType {
117                         get { return typeof(string); }
118                 }
119
120                 public virtual ObjectCollection Items {
121                         get { return items; }
122                 }
123
124                 public virtual int MaxDropDownItems {
125                         get { return maxDropDownItems; }
126                         set {
127                                 if (value < 1 || value > 100) {
128                                         throw new ArgumentOutOfRangeException("Value is less than 1 or greater than 100.");
129                                 }
130                                 maxDropDownItems = value;
131                         }
132                 }
133
134                 public virtual bool Sorted {
135                         get { return sorted; }
136                         set {
137                                 /*
138                                 if () {
139                                         throw new ArgumentException("Cannot sort a cell attached to a data source.");
140                                 }
141                                 */
142                                 sorted = value;
143                         }
144                 }
145
146                 public virtual string ValueMember {
147                         get { return valueMember; }
148                         set { valueMember = value; }
149                 }
150
151                 public override Type ValueType {
152                         get { return typeof(string); }
153                 }
154
155                 public override object Clone () {
156                         DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) base.Clone();
157                         cell.autoComplete = this.autoComplete;
158                         cell.dataSource = this.dataSource;
159                         cell.displayStyle = this.displayStyle;
160                         cell.displayStyleForCurrentCellOnly = this.displayStyleForCurrentCellOnly;
161                         cell.dropDownWidth = this.dropDownWidth;
162                         cell.flatStyle = this.flatStyle;
163                         cell.items.AddRange(this.items);
164                         cell.maxDropDownItems = this.maxDropDownItems;
165                         cell.sorted = this.sorted;
166                         return cell;
167                 }
168
169                 public override void DetachEditingControl () {
170                         throw new NotImplementedException();
171                 }
172
173                 public override void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
174                         throw new NotImplementedException();
175                 }
176
177                 public override bool KeyEntersEditMode (KeyEventArgs e) {
178                         throw new NotImplementedException();
179                 }
180
181                 public override object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) {
182                         throw new NotImplementedException();
183                 }
184
185                 public override string ToString () {
186                         throw new NotImplementedException();
187                 }
188
189                 protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
190                         throw new NotImplementedException();
191                 }
192
193                 protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
194                         throw new NotImplementedException();
195                 }
196
197                 protected override object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
198                         throw new NotImplementedException();
199                 }
200
201                 protected override Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
202                         throw new NotImplementedException();
203                 }
204
205                 protected override void OnDataGridViewChanged () {
206                         throw new NotImplementedException();
207                 }
208
209                 protected override void OnEnter (int rowIndex, bool throughMouseClick) {
210                         throw new NotImplementedException();
211                 }
212
213                 protected override void OnLeave (int rowIndex, bool throughMouseClick) {
214                         throw new NotImplementedException();
215                 }
216
217                 protected override void OnMouseClick (DataGridViewCellMouseEventArgs e) {
218                         throw new NotImplementedException();
219                 }
220
221                 protected override void OnMouseEnter (int rowIndex) {
222                         throw new NotImplementedException();
223                 }
224
225                 protected override void OnMouseLeave (int rowIndex) {
226                         throw new NotImplementedException();
227                 }
228
229                 protected override void OnMouseMove (DataGridViewCellMouseEventArgs e) {
230                         throw new NotImplementedException();
231                 }
232
233                 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) {
234                         throw new NotImplementedException();
235                 }
236
237                 public class ObjectCollection : IList, ICollection, IEnumerable {
238
239                         private ArrayList list;
240
241                         private DataGridViewComboBoxCell owner;
242
243                         public ObjectCollection (DataGridViewComboBoxCell owner) {
244                                 this.owner = owner;
245                                 list = new ArrayList();
246                         }
247
248                         public virtual int Count {
249                                 get { return list.Count; }
250                         }
251
252                         public virtual bool IsFixedSize {
253                                 get { return list.IsFixedSize; }
254                         }
255
256                         public virtual bool IsReadOnly {
257                                 get { return list.IsReadOnly; }
258                         }
259
260                         public virtual bool IsSynchronized {
261                                 get { return list.IsSynchronized; }
262                         }
263
264                         public virtual object SyncRoot {
265                                 get { return list.SyncRoot; }
266                         }
267
268                         public virtual object this [int index] {
269                                 get { return list[index]; }
270                                 set { list[index] = value; }
271                         }
272
273                         public int Add (object item) {
274                                 return list.Add(item);
275                         }
276
277                         public void AddRange (ObjectCollection value) {
278                                 list.AddRange(value.list);
279                         }
280
281                         public void AddRange (object[] items) {
282                                 list.AddRange(items);
283                         }
284
285                         //public sealed void Clear () {
286                         public void Clear () {
287                                 list.Clear();
288                         }
289
290                         //public sealed bool Contains (object value) {
291                         public bool Contains (object value) {
292                                 return list.Contains(value);
293                         }
294
295                         public void CopyTo (Array destination, int arrayIndex) {
296                                 list.CopyTo(destination, arrayIndex);
297                         }
298
299                         //public sealed IEnumerator GetEnumerator () {
300                         public IEnumerator GetEnumerator () {
301                                 return list.GetEnumerator();
302                         }
303
304                         //public sealed int IndexOf (object value) {
305                         public int IndexOf (object value) {
306                                 return list.IndexOf(value);
307                         }
308
309                         //public sealed void Insert (int index, object item) {
310                         public void Insert (int index, object item) {
311                                 list.Insert(index, item);
312                         }
313
314                         //public sealed void Remove (object value) {
315                         public void Remove (object value) {
316                                 list.Remove(value);
317                         }
318
319                         //public sealed void RemoveAt (int index) {
320                         public void RemoveAt (int index) {
321                                 list.RemoveAt(index);
322                         }
323
324                 }
325
326         }
327
328 }
329
330 #endif