New test.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewCheckBoxCell.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;
30 using System.ComponentModel;
31 using System.Drawing;
32
33 namespace System.Windows.Forms {
34
35         public class DataGridViewCheckBoxCell : DataGridViewCell, IDataGridViewEditingCell {
36
37                 private object editingCellFormattedValue;
38                 private bool editingCellValueChanged;
39                 private object falseValue;
40                 private FlatStyle flatStyle;
41                 private object indeterminateValue;
42                 private bool threeState;
43                 private object trueValue;
44                 private Type valueType;
45
46                 public DataGridViewCheckBoxCell () {
47                         editingCellValueChanged = false;
48                         falseValue = null;
49                         flatStyle = FlatStyle.Standard;
50                         indeterminateValue = null;
51                         threeState = false;
52                         trueValue = null;
53                         valueType = null;
54                 }
55
56                 public DataGridViewCheckBoxCell (bool threeState) : this() {
57                 }
58
59                 public virtual object EditingCellFormattedValue {
60                         get { return editingCellFormattedValue; }
61                         set {
62                                 if (FormattedValueType == null || value == null || value.GetType() != FormattedValueType || !(value is Boolean) || !(value is CheckState)) {
63                                         throw new ArgumentException("Cannot set this property.");
64                                 }
65                                 editingCellFormattedValue = value;
66                         }
67                 }
68
69                 public virtual bool EditingCellValueChanged {
70                         get { return editingCellValueChanged; }
71                         set { editingCellValueChanged = value; }
72                 }
73
74                 public override Type EditType {
75                         get { return null; }
76                 }
77
78                 public object FalseValue {
79                         get { return falseValue; }
80                         set { falseValue = value; }
81                 }
82
83                 public FlatStyle FlatStyle {
84                         get { return flatStyle; }
85                         set {
86                                 if (!Enum.IsDefined(typeof(FlatStyle), value)) {
87                                         throw new InvalidEnumArgumentException("Value is not valid FlatStyle.");
88                                 }
89                                 if (value == FlatStyle.Popup) {
90                                         throw new Exception("FlatStyle cannot be set to Popup in this control.");
91                                 }
92                         }
93                 }
94
95                 public override Type FormattedValueType {
96                         get {
97                                 if (ThreeState) {
98                                         return typeof(CheckState);
99                                 }
100                                 return typeof(Boolean);
101                         }
102                 }
103
104                 public object IndeterminateValue {
105                         get { return indeterminateValue; }
106                         set { indeterminateValue = value; }
107                 }
108
109                 public bool ThreeState {
110                         get { return threeState; }
111                         set { threeState = value; }
112                 }
113
114                 public object TrueValue {
115                         get { return trueValue; }
116                         set { trueValue = value; }
117                 }
118
119                 public override Type ValueType {
120                         get {
121                                 if (valueType == null) {
122                                         if (OwningColumn != null) {
123                                                 return OwningColumn.ValueType;
124                                         }
125                                         if (ThreeState) {
126                                                 return typeof(CheckState);
127                                         }
128                                         return typeof(Boolean);
129                                 }
130                                 return valueType;
131                         }
132                         set { valueType = value; }
133                 }
134
135                 public override object Clone () {
136                         DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell) base.Clone();
137                         cell.editingCellValueChanged = this.editingCellValueChanged;
138                         cell.falseValue = this.falseValue;
139                         cell.flatStyle = this.flatStyle;
140                         cell.indeterminateValue = this.indeterminateValue;
141                         cell.threeState = this.threeState;
142                         cell.trueValue = this.trueValue;
143                         cell.valueType = this.valueType;
144                         return cell;
145                 }
146
147                 public virtual object GetEditingCellFormattedValue (DataGridViewDataErrorContexts context) {
148                         if (FormattedValueType == null) {
149                                 throw new InvalidOperationException("FormattedValueType is null.");
150                         }
151                         if ((context & DataGridViewDataErrorContexts.ClipboardContent) != 0) {
152                                 return Convert.ToString(Value);
153                         }
154                         if (ThreeState) {
155                                 return (CheckState) Value;
156                         }
157                         return (Boolean) Value;
158                 }
159
160                 public override object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) {
161                         if (cellStyle == null) {
162                                 throw new ArgumentNullException("CellStyle is null");
163                         }
164                         if (FormattedValueType == null) {
165                                 throw new FormatException("FormattedValueType is null.");
166                         }
167                         if (formattedValue == null || formattedValue.GetType() != FormattedValueType) {
168                                 throw new ArgumentException("FormattedValue is null or is not instance of FormattedValueType.");
169                         }
170                         throw new NotImplementedException();
171                 }
172
173                 public virtual void PrepareEditingCellForEdit (bool selectAll) {
174                 }
175
176                 public override string ToString () {
177                         return GetType().Name + ": RowIndex: " + RowIndex.ToString() + "; ColumnIndex: " + ColumnIndex.ToString() + ";";
178                 }
179
180                 protected override bool ContentClickUnsharesRow (DataGridViewCellEventArgs e) {
181                         return this.IsInEditMode;
182                 }
183
184                 //protected override bool ContentDoubleClickUnsaresRow (DataGridViewCellEventArgs e) {
185                 protected bool ContentDoubleClickUnsaresRow (DataGridViewCellEventArgs e) {
186                         return this.IsInEditMode;
187                 }
188
189                 protected override AccessibleObject CreateAccessibilityInstance () {
190                         return new DataGridViewCheckBoxCellAccessibleObject(this);
191                 }
192
193                 protected override Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
194                         throw new NotImplementedException();
195                 }
196
197                 protected override Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
198                         throw new NotImplementedException();
199                 }
200
201                 //protected override object GetFormttedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
202                 protected object GetFormttedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) {
203                         if (DataGridView == null) {
204                                 return null;
205                         }
206                         throw new NotImplementedException();
207                 }
208
209                 protected override Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
210                         throw new NotImplementedException();
211                 }
212
213                 protected override object GetValue (int rowIndex) {
214                         throw new NotImplementedException();
215                 }
216
217                 protected override bool KeyDownUnsharesRow (KeyEventArgs e, int rowIndex) {
218                         // true if the user pressed the SPACE key without modifier keys; otherwise, false
219                         throw new NotImplementedException();
220                 }
221
222                 protected override bool KeyUpUnsharesRow (KeyEventArgs e, int rowIndex) {
223                         // true if the user released the SPACE key; otherwise false
224                         throw new NotImplementedException();
225
226                 }
227
228                 protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e) {
229                         return (e.Button == MouseButtons.Left);
230                 }
231
232                 protected override bool MouseEnterUnsharesRow (int rowIndex) {
233                         // true if the cell was the last cell receiving a mouse click; otherwise, false.
234                         throw new NotImplementedException();
235                 }
236
237                 protected override bool MouseLeaveUnsharesRow (int rowIndex) {
238                         // true if the button displayed by the cell is in the pressed state; otherwise, false.
239                         throw new NotImplementedException();
240                 }
241
242                 protected override bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e) {
243                         // true if the mouse up was caused by the release of the left mouse button; otherwise false.
244                         throw new NotImplementedException();
245                 }
246
247                 protected override void OnContentClick (DataGridViewCellEventArgs e) {
248                         throw new NotImplementedException();
249                 }
250
251                 protected override void OnContentDoubleClick (DataGridViewCellEventArgs e) {
252                         throw new NotImplementedException();
253                 }
254
255                 protected override void OnKeyDown (KeyEventArgs e, int rowIndex) {
256                         // when activated by the SPACE key, this method updates the cell's user interface
257                         throw new NotImplementedException();
258                 }
259
260                 protected override void OnKeyUp (KeyEventArgs e, int rowIndex) {
261                         // when activated by the SPACE key, this method updates the cell's user interface
262                         throw new NotImplementedException();
263                 }
264
265                 protected override void OnLeave (int rowIndex, bool throughMouseClick) {
266                         throw new NotImplementedException();
267                 }
268
269                 protected override void OnMouseDown (DataGridViewCellMouseEventArgs e) {
270                         // if activated by depresing the left mouse button, this method updates the cell's user interface
271                         throw new NotImplementedException();
272                 }
273
274                 protected override void OnMouseEnter (int rowIndex) {
275                         throw new NotImplementedException();
276                 }
277
278                 protected override void OnMouseLeave (int rowIndex) {
279                         // if the cell's button is not in its normal state, this method causes the cell's user interface to be updated.
280                         throw new NotImplementedException();
281                 }
282
283                 protected override void OnMouseUp (DataGridViewCellMouseEventArgs e) {
284                         // if activated by the left mouse button, this method updates the cell's user interface
285                         throw new NotImplementedException();
286                 }
287
288                 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
289                         throw new NotImplementedException();
290                 }
291
292                 protected class DataGridViewCheckBoxCellAccessibleObject : DataGridViewCellAccessibleObject {
293
294                         public DataGridViewCheckBoxCellAccessibleObject (DataGridViewCell owner) : base(owner) {
295                         }
296
297                         public override string DefaultAction {
298                                 get {
299                                         if (Owner.ReadOnly) {
300                                                 return "";
301                                         }
302                                         // return "Press to check" if the check box is not selected
303                                         // and "Press to uncheck" if the check box is selected
304                                         throw new NotImplementedException();
305                                 }
306                         }
307
308                         public override void DoDefaultAction () {
309                                 // change the state of the check box
310                         }
311
312                         public override int GetChildCount () {
313                                 return -1;
314                         }
315
316                 }
317
318         }
319
320 }
321
322 #endif