2007-03-19 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewCell.cs
blob6dcd7b9aac8e2e44626218d60eb69f10c3719fc5
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.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
22 // Author:
23 // Pedro Martínez Juliá <pedromj@gmail.com>
27 #if NET_2_0
29 using System;
30 using System.Drawing;
31 using System.ComponentModel;
32 using System.Runtime.InteropServices;
34 namespace System.Windows.Forms {
36 // XXX [TypeConverter (typeof (DataGridViewCellConverter))]
37 public abstract class DataGridViewCell : DataGridViewElement, ICloneable, IDisposable
39 private DataGridView dataGridViewOwner;
41 private AccessibleObject accessibilityObject;
42 private int columnIndex;
43 private Rectangle contentBounds;
44 private ContextMenuStrip contextMenuStrip;
45 private object defaultNewRowValue;
46 private bool displayed;
47 private object editedFormattedValue;
48 private Type editType;
49 private Rectangle errorIconBounds;
50 private string errorText;
51 private Type formattedValueType;
52 private bool frozen;
53 private DataGridViewElementStates inheritedState;
54 private bool isInEditMode;
55 private DataGridViewColumn owningColumn;
56 private DataGridViewRow owningRow;
57 private Size preferredSize;
58 private bool readOnly;
59 private bool resizable;
60 private bool selected;
61 private Size size;
62 private DataGridViewCellStyle style;
63 private object tag;
64 private string toolTipText;
65 private object valuex;
66 private Type valueType;
67 private bool visible;
69 protected DataGridViewCell ()
71 columnIndex = -1;
74 ~DataGridViewCell ()
76 Dispose(false);
79 [Browsable (false)]
80 public AccessibleObject AccessibilityObject {
81 get {
82 if (accessibilityObject == null) {
83 accessibilityObject = CreateAccessibilityInstance();
85 return accessibilityObject;
89 public int ColumnIndex {
90 get { return columnIndex; }
93 [Browsable (false)]
94 public Rectangle ContentBounds {
95 get { return contentBounds; }
98 [DefaultValue (null)]
99 public virtual ContextMenuStrip ContextMenuStrip {
100 get { return contextMenuStrip; }
101 set { contextMenuStrip = value; }
104 [Browsable (false)]
105 public virtual object DefaultNewRowValue {
106 get { return defaultNewRowValue; }
109 [Browsable (false)]
110 public virtual bool Displayed {
111 get { return displayed; }
114 [Browsable (false)]
115 [EditorBrowsable (EditorBrowsableState.Advanced)]
116 public object EditedFormattedValue {
117 get { return editedFormattedValue; }
120 [Browsable (false)]
121 [EditorBrowsable (EditorBrowsableState.Advanced)]
122 public virtual Type EditType {
123 get { return editType; }
126 [Browsable (false)]
127 [EditorBrowsable (EditorBrowsableState.Advanced)]
128 public Rectangle ErrorIconBounds {
129 get { return errorIconBounds; }
132 [Browsable (false)]
133 public string ErrorText {
134 get { return errorText; }
135 set {
136 if (errorText != value) {
137 errorText = value;
138 OnErrorTextChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
143 [Browsable (false)]
144 public object FormattedValue {
145 get {
146 DataGridViewCellStyle style = InheritedStyle;
147 if (style.Format != String.Empty && FormattedValueType == typeof(string)) {
148 return String.Format("{0:" + style.Format + "}", Value);
150 return Convert.ChangeType(Value, FormattedValueType, style.FormatProvider);
154 [Browsable (false)]
155 public virtual Type FormattedValueType {
156 get { return formattedValueType; }
159 [Browsable (false)]
160 public virtual bool Frozen {
161 get { return frozen; }
164 [Browsable (false)]
165 public bool HasStyle {
166 get { return style != null; }
169 [Browsable (false)]
170 public DataGridViewElementStates InheritedState {
171 get { return inheritedState; }
174 [Browsable (false)]
175 public DataGridViewCellStyle InheritedStyle {
176 get {
177 DataGridViewCellStyle result = new DataGridViewCellStyle();
178 if (style != null && style.Alignment != DataGridViewContentAlignment.NotSet) {
179 result.Alignment = style.Alignment;
181 else if (OwningRow != null && OwningRow.DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
182 result.Alignment = OwningRow.DefaultCellStyle.Alignment;
184 else if (DataGridView != null) {
185 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
186 result.Alignment = DataGridView.AlternatingRowsDefaultCellStyle.Alignment;
188 else if (DataGridView.RowsDefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
189 result.Alignment = DataGridView.RowsDefaultCellStyle.Alignment;
191 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Alignment != DataGridViewContentAlignment.NotSet) {
192 result.Alignment = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Alignment;
194 else {
195 result.Alignment = DataGridView.DefaultCellStyle.Alignment;
198 if (style != null && style.BackColor != Color.Empty) {
199 result.BackColor = style.BackColor;
201 else if (OwningRow != null && OwningRow.DefaultCellStyle.BackColor != Color.Empty) {
202 result.BackColor = OwningRow.DefaultCellStyle.BackColor;
204 else if (DataGridView != null) {
205 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.BackColor != Color.Empty) {
206 result.BackColor = DataGridView.AlternatingRowsDefaultCellStyle.BackColor;
208 else if (DataGridView.RowsDefaultCellStyle.BackColor != Color.Empty) {
209 result.BackColor = DataGridView.RowsDefaultCellStyle.BackColor;
211 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.BackColor != Color.Empty) {
212 result.BackColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.BackColor;
214 else {
215 result.BackColor = DataGridView.DefaultCellStyle.BackColor;
218 if (style != null && style.Font != null) {
219 result.Font = style.Font;
221 else if (OwningRow != null && OwningRow.DefaultCellStyle.Font != null) {
222 result.Font = OwningRow.DefaultCellStyle.Font;
224 else if (DataGridView != null) {
225 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Font != null) {
226 result.Font = DataGridView.AlternatingRowsDefaultCellStyle.Font;
228 else if (DataGridView.RowsDefaultCellStyle.Font != null) {
229 result.Font = DataGridView.RowsDefaultCellStyle.Font;
231 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Font != null) {
232 result.Font = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Font;
234 else {
235 result.Font = DataGridView.DefaultCellStyle.Font;
238 if (style != null && style.ForeColor != Color.Empty) {
239 result.ForeColor = style.ForeColor;
241 else if (OwningRow != null && OwningRow.DefaultCellStyle.ForeColor != Color.Empty) {
242 result.ForeColor = OwningRow.DefaultCellStyle.ForeColor;
244 else if (DataGridView != null) {
245 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.ForeColor != Color.Empty) {
246 result.ForeColor = DataGridView.AlternatingRowsDefaultCellStyle.ForeColor;
248 else if (DataGridView.RowsDefaultCellStyle.ForeColor != Color.Empty) {
249 result.ForeColor = DataGridView.RowsDefaultCellStyle.ForeColor;
251 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.ForeColor != Color.Empty) {
252 result.ForeColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.ForeColor;
254 else {
255 result.ForeColor = DataGridView.DefaultCellStyle.ForeColor;
258 if (style != null && style.Format != String.Empty) {
259 result.Format = style.Format;
261 else if (OwningRow != null && OwningRow.DefaultCellStyle.Format != String.Empty) {
262 result.Format = OwningRow.DefaultCellStyle.Format;
264 else if (DataGridView != null) {
265 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Format != String.Empty) {
266 result.Format = DataGridView.AlternatingRowsDefaultCellStyle.Format;
268 else if (DataGridView.RowsDefaultCellStyle.Format != String.Empty) {
269 result.Format = DataGridView.RowsDefaultCellStyle.Format;
271 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Format != String.Empty) {
272 result.Format = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Format;
274 else {
275 result.Format = DataGridView.DefaultCellStyle.Format;
278 if (style != null && style.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
279 result.FormatProvider = style.FormatProvider;
281 else if (OwningRow != null && OwningRow.DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
282 result.FormatProvider = OwningRow.DefaultCellStyle.FormatProvider;
284 else if (DataGridView != null) {
285 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
286 result.FormatProvider = DataGridView.AlternatingRowsDefaultCellStyle.FormatProvider;
288 else if (DataGridView.RowsDefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
289 result.FormatProvider = DataGridView.RowsDefaultCellStyle.FormatProvider;
291 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.FormatProvider != System.Globalization.CultureInfo.CurrentUICulture) {
292 result.FormatProvider = DataGridView.Columns[ColumnIndex].DefaultCellStyle.FormatProvider;
294 else {
295 result.FormatProvider = DataGridView.DefaultCellStyle.FormatProvider;
298 if (style != null && (string) style.NullValue != "(null)") {
299 result.NullValue = style.NullValue;
301 else if (OwningRow != null && (string) OwningRow.DefaultCellStyle.NullValue != "(null)") {
302 result.NullValue = OwningRow.DefaultCellStyle.NullValue;
304 else if (DataGridView != null) {
305 if ((RowIndex % 2) == 1 && (string) DataGridView.AlternatingRowsDefaultCellStyle.NullValue != "(null)") {
306 result.NullValue = DataGridView.AlternatingRowsDefaultCellStyle.NullValue;
308 else if ((string) DataGridView.RowsDefaultCellStyle.NullValue != "(null)") {
309 result.NullValue = DataGridView.RowsDefaultCellStyle.NullValue;
311 else if (ColumnIndex >= 0 && (string) DataGridView.Columns[ColumnIndex].DefaultCellStyle.NullValue != "(null)") {
312 result.NullValue = DataGridView.Columns[ColumnIndex].DefaultCellStyle.NullValue;
314 else {
315 result.NullValue = DataGridView.DefaultCellStyle.NullValue;
318 if (style != null && style.Padding != Padding.Empty) {
319 result.Padding = style.Padding;
321 else if (OwningRow != null && OwningRow.DefaultCellStyle.Padding != Padding.Empty) {
322 result.Padding = OwningRow.DefaultCellStyle.Padding;
324 else if (DataGridView != null) {
325 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Padding != Padding.Empty) {
326 result.Padding = DataGridView.AlternatingRowsDefaultCellStyle.Padding;
328 else if (DataGridView.RowsDefaultCellStyle.Padding != Padding.Empty) {
329 result.Padding = DataGridView.RowsDefaultCellStyle.Padding;
331 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Padding != Padding.Empty) {
332 result.Padding = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Padding;
334 else {
335 result.Padding = DataGridView.DefaultCellStyle.Padding;
338 if (style != null && style.SelectionBackColor != Color.Empty) {
339 result.SelectionBackColor = style.SelectionBackColor;
341 else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionBackColor != Color.Empty) {
342 result.SelectionBackColor = OwningRow.DefaultCellStyle.SelectionBackColor;
344 else if (DataGridView != null) {
345 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
346 result.SelectionBackColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionBackColor;
348 else if (DataGridView.RowsDefaultCellStyle.SelectionBackColor != Color.Empty) {
349 result.SelectionBackColor = DataGridView.RowsDefaultCellStyle.SelectionBackColor;
351 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionBackColor != Color.Empty) {
352 result.SelectionBackColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionBackColor;
354 else {
355 result.SelectionBackColor = DataGridView.DefaultCellStyle.SelectionBackColor;
358 if (style != null && style.SelectionForeColor != Color.Empty) {
359 result.SelectionForeColor = style.SelectionForeColor;
361 else if (OwningRow != null && OwningRow.DefaultCellStyle.SelectionForeColor != Color.Empty) {
362 result.SelectionForeColor = OwningRow.DefaultCellStyle.SelectionForeColor;
364 else if (DataGridView != null) {
365 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
366 result.SelectionForeColor = DataGridView.AlternatingRowsDefaultCellStyle.SelectionForeColor;
368 else if (DataGridView.RowsDefaultCellStyle.SelectionForeColor != Color.Empty) {
369 result.SelectionForeColor = DataGridView.RowsDefaultCellStyle.SelectionForeColor;
371 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionForeColor != Color.Empty) {
372 result.SelectionForeColor = DataGridView.Columns[ColumnIndex].DefaultCellStyle.SelectionForeColor;
374 else {
375 result.SelectionForeColor = DataGridView.DefaultCellStyle.SelectionForeColor;
378 if (style != null && style.Tag != null) {
379 result.Tag = style.Tag;
381 else if (OwningRow != null && OwningRow.DefaultCellStyle.Tag != null) {
382 result.Tag = OwningRow.DefaultCellStyle.Tag;
384 else if (DataGridView != null) {
385 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.Tag != null) {
386 result.Tag = DataGridView.AlternatingRowsDefaultCellStyle.Tag;
388 else if (DataGridView.RowsDefaultCellStyle.Tag != null) {
389 result.Tag = DataGridView.RowsDefaultCellStyle.Tag;
391 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.Tag != null) {
392 result.Tag = DataGridView.Columns[ColumnIndex].DefaultCellStyle.Tag;
394 else {
395 result.Tag = DataGridView.DefaultCellStyle.Tag;
398 if (style != null && style.WrapMode != DataGridViewTriState.NotSet) {
399 result.WrapMode = style.WrapMode;
401 else if (OwningRow != null && OwningRow.DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
402 result.WrapMode = OwningRow.DefaultCellStyle.WrapMode;
404 else if (DataGridView != null) {
405 if ((RowIndex % 2) == 1 && DataGridView.AlternatingRowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
406 result.WrapMode = DataGridView.AlternatingRowsDefaultCellStyle.WrapMode;
408 else if (DataGridView.RowsDefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
409 result.WrapMode = DataGridView.RowsDefaultCellStyle.WrapMode;
411 else if (ColumnIndex >= 0 && DataGridView.Columns[ColumnIndex].DefaultCellStyle.WrapMode != DataGridViewTriState.NotSet) {
412 result.WrapMode = DataGridView.Columns[ColumnIndex].DefaultCellStyle.WrapMode;
414 else {
415 result.WrapMode = DataGridView.DefaultCellStyle.WrapMode;
418 return result;
422 [Browsable (false)]
423 public bool IsInEditMode {
424 get { return isInEditMode; }
427 [Browsable (false)]
428 [EditorBrowsable (EditorBrowsableState.Advanced)]
429 public DataGridViewColumn OwningColumn {
430 get { return owningColumn; }
433 [Browsable (false)]
434 [EditorBrowsable (EditorBrowsableState.Advanced)]
435 public DataGridViewRow OwningRow {
436 get { return owningRow; }
439 [Browsable (false)]
440 public Size PreferredSize {
441 get { return preferredSize; }
444 [Browsable (false)]
445 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
446 public virtual bool ReadOnly {
447 get { return readOnly; }
448 set { readOnly = value; }
451 [Browsable (false)]
452 public virtual bool Resizable {
453 get { return resizable; }
456 [Browsable (false)]
457 public int RowIndex {
458 get {
459 if (owningRow == null) {
460 return -1;
462 return owningRow.Index;
466 [Browsable (false)]
467 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
468 public virtual bool Selected {
469 get { return selected; }
470 set {
471 if (value != ((State & DataGridViewElementStates.Selected) != 0)) {
472 SetState(State ^ DataGridViewElementStates.Selected);
474 selected = value;
478 [Browsable (false)]
479 public Size Size {
480 get { return size; }
483 [Browsable (true)]
484 public DataGridViewCellStyle Style {
485 get {
486 if (style != null) {
487 style = new DataGridViewCellStyle();
488 style.StyleChanged += OnStyleChanged;
490 return style;
492 set { style = value; }
495 [Bindable (true, BindingDirection.OneWay)]
496 [DefaultValue (null)]
497 [Localizable (false)]
498 [TypeConverter ("System.ComponentModel.StringConverter, " + Consts.AssemblySystem)]
499 public object Tag {
500 get { return tag; }
501 set { tag = value; }
504 [Browsable (false)]
505 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
506 public string ToolTipText {
507 get { return toolTipText; }
508 set { toolTipText = value; }
511 [Browsable (false)]
512 public object Value {
513 get { return valuex; }
514 set {
515 if (valuex != value) {
516 valuex = value;
517 RaiseCellValueChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
522 [Browsable (false)]
523 public virtual Type ValueType {
524 get { return valueType; }
525 set { valueType = value; }
528 [Browsable (false)]
529 public virtual bool Visible {
530 get { return visible; }
533 [EditorBrowsable (EditorBrowsableState.Advanced)]
534 public virtual DataGridViewAdvancedBorderStyle AdjustCellBorderStyle (DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
535 return dataGridViewAdvancedBorderStyleInput;
538 public virtual object Clone () {
539 return this.MemberwiseClone();
541 DataGridViewCell result = null; // = new DataGridViewCell();
542 result.accessibilityObject = this.accessibilityObject;
543 result.columnIndex = this.columnIndex;
544 result.contentBounds = this.contentBounds;
545 //result.contextMenuStrip = this.contextMenuStrip;
546 result.defaultNewRowValue = this.defaultNewRowValue;
547 result.displayed = this.displayed;
548 result.editedFormattedValue = this.editedFormattedValue;
549 result.editType = this.editType;
550 result.errorIconBounds = this.errorIconBounds;
551 result.errorText = this.errorText;
552 result.formattedValueType = this.formattedValueType;
553 result.frozen = this.frozen;
554 result.hasStyle = this.hasStyle;
555 result.inheritedState = this.inheritedState;
556 result.inheritedStyle = this.inheritedStyle;
557 result.isInEditMode = this.isInEditMode;
558 result.owningColumn = this.owningColumn;
559 result.owningRow = this.owningRow;
560 result.preferredSize = this.preferredSize;
561 result.readOnly = this.readOnly;
562 result.resizable = this.resizable;
563 result.selected = this.selected;
564 result.size = this.size;
565 result.style = this.style;
566 result.tag = this.tag;
567 result.toolTipText = this.toolTipText;
568 result.valuex = this.valuex;
569 result.valueType = this.valueType;
570 result.visible = this.visible;
571 return result;
575 [EditorBrowsable (EditorBrowsableState.Advanced)]
576 public virtual void DetachEditingControl () {
579 //public sealed void Dispose () {
580 public void Dispose () {
583 public Rectangle GetContentBounds (int rowIndex) {
584 throw new NotImplementedException();
587 public object GetEditedFormattedValue (int rowIndex, DataGridViewDataErrorContexts context) {
588 throw new NotImplementedException();
591 public virtual ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
593 throw new NotImplementedException();
596 public virtual DataGridViewElementStates GetInheritedState (int rowIndex) {
597 throw new NotImplementedException();
600 public virtual DataGridViewCellStyle GetInheritedStyle (DataGridViewCellStyle inheritedCellStyle, int rowIndex, bool includeColors) {
602 * System.InvalidOperationException :: The cell has no associated System.Windows.Forms.DataGridView, or the cell's System.Windows.Forms.DataGridViewCell.ColumnIndex is less than 0.
603 * System.ArgumentOutOfRangeException :: rowIndex is less than 0, or greater than or equal to the number of rows in the parent System.Windows.Forms.DataGridView.
604 * */
605 throw new NotImplementedException();
608 [EditorBrowsable (EditorBrowsableState.Advanced)]
609 public virtual void InitializeEditingControl (int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) {
610 if (DataGridView == null || DataGridView.EditingControl == null) {
611 throw new InvalidOperationException("No editing control defined");
615 public virtual bool KeyEntersEditMode (KeyEventArgs e) {
616 throw new NotImplementedException();
619 [EditorBrowsable (EditorBrowsableState.Advanced)]
620 public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags) {
621 if (graphics == null) {
622 throw new ArgumentNullException("Graphics argument null");
624 if (font == null) {
625 throw new ArgumentNullException("Font argument null");
627 if (maxWidth < 1) {
628 throw new ArgumentOutOfRangeException("maxWidth is less than 1.");
630 // if (flags ---> InvalidEnumArgumentException
631 throw new NotImplementedException();
634 [EditorBrowsable (EditorBrowsableState.Advanced)]
635 public static int MeasureTextHeight (Graphics graphics, string text, Font font, int maxWidth, TextFormatFlags flags, out bool widthTruncated) {
636 throw new NotImplementedException();
639 [EditorBrowsable (EditorBrowsableState.Advanced)]
640 public static Size MeasureTextPreferredSize (Graphics graphics, string text, Font font, float maxRatio, TextFormatFlags flags) {
641 if (graphics == null) {
642 throw new ArgumentNullException("Graphics argument null");
644 if (font == null) {
645 throw new ArgumentNullException("Font argument null");
647 if (maxRatio <= 0) {
648 throw new ArgumentOutOfRangeException("maxRatio is less than or equals to 0.");
650 throw new NotImplementedException();
653 [EditorBrowsable (EditorBrowsableState.Advanced)]
654 public static Size MeasureTextSize (Graphics graphics, string text, Font font, TextFormatFlags flags) {
655 /////////////////////////// ¿flags?
656 return graphics.MeasureString(text, font).ToSize();
659 [EditorBrowsable (EditorBrowsableState.Advanced)]
660 public static int MeasureTextWidth (Graphics graphics, string text, Font font, int maxHeight, TextFormatFlags flags) {
661 if (graphics == null) {
662 throw new ArgumentNullException("Graphics argument null");
664 if (font == null) {
665 throw new ArgumentNullException("Font argument null");
667 if (maxHeight < 1) {
668 throw new ArgumentOutOfRangeException("maxHeight is less than 1.");
670 throw new NotImplementedException();
673 public virtual object ParseFormattedValue (object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) {
674 if (cellStyle == null) {
675 throw new ArgumentNullException("cellStyle is null.");
677 if (formattedValueType == null) {
678 throw new FormatException("The System.Windows.Forms.DataGridViewCell.FormattedValueType property value is null.");
680 if (formattedValue == null) {
681 throw new ArgumentException("formattedValue is null.");
683 if (formattedValue.GetType() != formattedValueType) {
685 return null;
688 [EditorBrowsable (EditorBrowsableState.Advanced)]
689 public virtual void PositionEditingControl (bool setLocation, bool setSize, Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
690 throw new NotImplementedException();
693 [EditorBrowsable (EditorBrowsableState.Advanced)]
694 public virtual Rectangle PositionEditingPanel (Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {
695 throw new NotImplementedException();
698 public override string ToString () {
699 return String.Format("{0} {RowIndex = {1}, ColumnIndex = {2}}", this.GetType().FullName, RowIndex, columnIndex);
702 protected virtual Rectangle BorderWidths (DataGridViewAdvancedBorderStyle advancedBorderStyle)
704 throw new NotImplementedException();
707 protected virtual bool ClickUnsharesRow (DataGridViewCellEventArgs e)
709 throw new NotImplementedException();
712 protected virtual bool ContentClickUnsharesRow (DataGridViewCellEventArgs e)
714 throw new NotImplementedException();
717 protected virtual bool ContentDoubleClickUnsharesRow (DataGridViewCellEventArgs e)
719 throw new NotImplementedException();
722 protected virtual AccessibleObject CreateAccessibilityInstance () {
723 return new DataGridViewCellAccessibleObject(this);
726 protected virtual void Dispose (bool disposing) {
729 protected virtual bool DoubleClickUnsharesRow (DataGridViewCellEventArgs e) {
730 throw new NotImplementedException();
733 protected virtual bool EnterUnsharesRow (int rowIndex, bool throughMouseClick) {
734 throw new NotImplementedException();
737 protected virtual object GetClipboardContent (int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format) {
738 throw new NotImplementedException();
741 protected virtual Rectangle GetContentBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
742 throw new NotImplementedException();
745 protected virtual Rectangle GetErrorIconBounds (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex) {
746 throw new NotImplementedException();
749 protected internal virtual string GetErrorText (int rowIndex) {
750 throw new NotImplementedException();
753 protected virtual object GetFormattedValue (object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
755 throw new NotImplementedException();
758 protected virtual Size GetPreferredSize (Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {
759 throw new NotImplementedException();
762 protected virtual Size GetSize (int rowIndex) {
763 throw new NotImplementedException();
766 protected virtual object GetValue (int rowIndex) {
767 throw new NotImplementedException();
770 protected virtual bool KeyDownUnsharesRow (KeyEventArgs e, int rowIndex) {
771 throw new NotImplementedException();
774 protected virtual bool KeyPressUnsharesRow (KeyPressEventArgs e, int rowIndex) {
775 throw new NotImplementedException();
778 protected virtual bool KeyUpUnsharesRow (KeyEventArgs e, int rowIndex) {
779 throw new NotImplementedException();
782 protected virtual bool LeaveUnsharesRow (int rowIndex, bool throughMouseClick) {
783 throw new NotImplementedException();
786 protected virtual bool MouseClickUnsharesRow (DataGridViewCellMouseEventArgs e) {
787 throw new NotImplementedException();
790 protected virtual bool MouseDoubleClickUnsharesRow (DataGridViewCellMouseEventArgs e) {
791 throw new NotImplementedException();
794 protected virtual bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e) {
795 throw new NotImplementedException();
798 protected virtual bool MouseEnterUnsharesRow (int rowIndex) {
799 throw new NotImplementedException();
802 protected virtual bool MouseLeaveUnsharesRow (int rowIndex) {
803 throw new NotImplementedException();
806 protected virtual bool MouseMoveUnsharesRow (DataGridViewCellMouseEventArgs e) {
807 throw new NotImplementedException();
810 protected virtual bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e) {
811 throw new NotImplementedException();
814 protected virtual void OnClick (DataGridViewCellEventArgs e) {
817 protected virtual void OnContentClick (DataGridViewCellEventArgs e) {
820 protected virtual void OnContentDoubleClick (DataGridViewCellEventArgs e) {
823 protected override void OnDataGridViewChanged () {
826 protected virtual void OnDoubleClick (DataGridViewCellEventArgs e) {
829 protected virtual void OnEnter (int rowIndex, bool throughMouseClick) {
832 protected virtual void OnKeyDown (KeyEventArgs e, int rowIndex) {
835 protected virtual void OnKeyPress (KeyPressEventArgs e, int rowIndex) {
838 protected virtual void OnKeyUp (KeyEventArgs e, int rowIndex) {
841 protected virtual void OnLeave (int rowIndex, bool throughMouseClick) {
844 protected virtual void OnMouseClick (DataGridViewCellMouseEventArgs e) {
847 protected virtual void OnMouseDoubleClick (DataGridViewCellMouseEventArgs e) {
850 protected virtual void OnMouseDown (DataGridViewCellMouseEventArgs e) {
853 protected virtual void OnMouseEnter (int rowIndex) {
856 protected virtual void OnMouseLeave (int rowIndex) {
859 protected virtual void OnMouseMove (DataGridViewCellMouseEventArgs e) {
862 protected virtual void OnMouseUp (DataGridViewCellMouseEventArgs e) {
865 protected virtual void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
866 throw new NotImplementedException();
869 protected virtual void PaintBorder (Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle) {
870 Pen pen = new Pen(DataGridView.GridColor);
872 switch (advancedBorderStyle.All) {
873 case DataGridViewAdvancedCellBorderStyle.None:
874 break;
875 case DataGridViewAdvancedCellBorderStyle.Single:
876 graphics.DrawRectangle(pen, bounds);
877 break;
878 case DataGridViewAdvancedCellBorderStyle.Inset:
879 bounds.X += 1;
880 bounds.Y += 1;
881 bounds.Width -= 2;
882 bounds.Height -= 2;
883 graphics.DrawRectangle(pen, bounds);
884 break;
885 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
886 case DataGridViewAdvancedCellBorderStyle.Outset:
887 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
888 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
889 break;
890 case DataGridViewAdvancedCellBorderStyle.NotSet:
892 switch (advancedBorderStyle.Left) {
893 case DataGridViewAdvancedCellBorderStyle.None:
894 break;
895 case DataGridViewAdvancedCellBorderStyle.Single:
896 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);
897 break;
898 case DataGridViewAdvancedCellBorderStyle.Inset:
899 graphics.DrawLine(pen, bounds.X + 2, bounds.Y, bounds.X + 2, bounds.Y + bounds.Height - 1);
900 break;
901 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
902 case DataGridViewAdvancedCellBorderStyle.Outset:
903 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
904 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);
905 graphics.DrawLine(pen, bounds.X + 2, bounds.Y, bounds.X + 2, bounds.Y + bounds.Height - 1);
906 break;
907 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
908 break;
910 switch (advancedBorderStyle.Right) {
911 case DataGridViewAdvancedCellBorderStyle.None:
912 break;
913 case DataGridViewAdvancedCellBorderStyle.Single:
914 graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
915 break;
916 case DataGridViewAdvancedCellBorderStyle.Inset:
917 graphics.DrawLine(pen, bounds.X + bounds.Width + 1, bounds.Y, bounds.X + bounds.Width - 3, bounds.Y + bounds.Height - 1);
918 break;
919 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
920 case DataGridViewAdvancedCellBorderStyle.Outset:
921 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
922 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
923 break;
925 switch (advancedBorderStyle.Top) {
926 case DataGridViewAdvancedCellBorderStyle.None:
927 break;
928 case DataGridViewAdvancedCellBorderStyle.Single:
929 graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
930 break;
931 case DataGridViewAdvancedCellBorderStyle.Inset:
932 graphics.DrawLine(pen, bounds.X, bounds.Y + 2, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height + 1);
933 break;
934 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
935 case DataGridViewAdvancedCellBorderStyle.Outset:
936 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
937 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
938 break;
940 switch (advancedBorderStyle.Bottom) {
941 case DataGridViewAdvancedCellBorderStyle.None:
942 break;
943 case DataGridViewAdvancedCellBorderStyle.Single:
944 graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
945 break;
946 case DataGridViewAdvancedCellBorderStyle.Inset:
947 case DataGridViewAdvancedCellBorderStyle.InsetDouble:
948 case DataGridViewAdvancedCellBorderStyle.Outset:
949 case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
950 case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
951 break;
953 // break;
957 protected virtual void PaintErrorIcon (Graphics graphics, Rectangle clipBounds, Rectangle cellValueBounds, string errorText) {
958 throw new NotImplementedException();
961 protected virtual bool SetValue (int rowIndex, object value) {
962 throw new NotImplementedException();
965 private void OnStyleChanged (object sender, EventArgs args) {
966 if (DataGridView != null) {
967 DataGridView.RaiseCellStyleChanged(new DataGridViewCellEventArgs(ColumnIndex, RowIndex));
971 internal void InternalPaint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
972 Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
975 internal void SetOwningRow (DataGridViewRow row) {
976 owningRow = row;
979 internal void SetColumnIndex (int index) {
980 columnIndex = index;
983 internal void SetContentBounds (Rectangle bounds) {
984 contentBounds = bounds;
987 internal void SetIsInEditMode (bool isInEditMode) {
988 this.isInEditMode = isInEditMode;
991 internal void SetSize (Size size) {
992 this.size = size;
995 internal void OnErrorTextChanged (DataGridViewCellEventArgs args) {
996 if (DataGridView != null) {
997 DataGridView.OnCellErrorTextChanged(args);
1001 [ComVisibleAttribute(true)]
1002 protected class DataGridViewCellAccessibleObject : AccessibleObject {
1004 private DataGridViewCell dataGridViewCell;
1006 public DataGridViewCellAccessibleObject () {
1009 public DataGridViewCellAccessibleObject (DataGridViewCell cell) {
1010 this.dataGridViewCell = cell;
1013 public override Rectangle Bounds {
1014 get { throw new NotImplementedException(); }
1017 public override string DefaultAction {
1018 get { return "Edit"; }
1021 public override string Name {
1022 get { return dataGridViewCell.OwningColumn.HeaderText + ": " + dataGridViewCell.RowIndex.ToString(); }
1025 public DataGridViewCell Owner {
1026 get { return dataGridViewCell; }
1027 set { dataGridViewCell = value; }
1030 public override AccessibleObject Parent {
1031 get { return dataGridViewCell.OwningRow.AccessibilityObject; }
1034 public override AccessibleRole Role {
1035 get { return AccessibleRole.Cell; }
1038 public override AccessibleStates State {
1039 get {
1040 if (dataGridViewCell.Selected) {
1041 return AccessibleStates.Selected;
1043 else {
1044 return AccessibleStates.Focused;
1049 public override string Value {
1050 get {
1051 if (dataGridViewCell.FormattedValue == null) {
1052 return "(null)";
1054 return dataGridViewCell.FormattedValue.ToString();
1058 public override void DoDefaultAction () {
1059 if (dataGridViewCell.DataGridView.EditMode != DataGridViewEditMode.EditProgrammatically) {
1060 if (dataGridViewCell.IsInEditMode) {
1061 // commit edit
1063 else {
1064 // begin edit
1069 public override AccessibleObject GetChild (int index) {
1070 throw new NotImplementedException();
1073 public override int GetChildCount () {
1074 if (dataGridViewCell.IsInEditMode) {
1075 return 1;
1077 return -1;
1080 public override AccessibleObject GetFocused () {
1081 return null;
1084 public override AccessibleObject GetSelected () {
1085 return null;
1088 public override AccessibleObject Navigate (AccessibleNavigation navigationDirection) {
1089 switch (navigationDirection) {
1090 case AccessibleNavigation.Right:
1091 break;
1092 case AccessibleNavigation.Left:
1093 break;
1094 case AccessibleNavigation.Next:
1095 break;
1096 case AccessibleNavigation.Previous:
1097 break;
1098 case AccessibleNavigation.Up:
1099 break;
1100 case AccessibleNavigation.Down:
1101 break;
1102 default:
1103 return null;
1105 return null;
1108 public override void Select (AccessibleSelection flags) {
1109 switch (flags) {
1110 case AccessibleSelection.TakeFocus:
1111 dataGridViewCell.dataGridViewOwner.Focus();
1112 break;
1113 case AccessibleSelection.TakeSelection:
1114 //dataGridViewCell.Focus();
1115 break;
1116 case AccessibleSelection.AddSelection:
1117 dataGridViewCell.dataGridViewOwner.SelectedCells.InternalAdd(dataGridViewCell);
1118 break;
1119 case AccessibleSelection.RemoveSelection:
1120 dataGridViewCell.dataGridViewOwner.SelectedCells.InternalRemove(dataGridViewCell);
1121 break;
1131 #endif