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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
30 using System.ComponentModel;
32 namespace System.Windows.Forms {
34 public class DataGridViewCellStyle : ICloneable {
36 private DataGridViewContentAlignment alignment;
37 private Color backColor;
38 private object dataSourceNullValue;
40 private Color foreColor;
41 private string format;
42 private IFormatProvider formatProvider;
43 private object nullValue;
44 private Padding padding;
45 private Color selectionBackColor;
46 private Color selectionForeColor;
48 private DataGridViewTriState wrapMode;
50 public DataGridViewCellStyle () {
51 alignment = DataGridViewContentAlignment.NotSet;
52 backColor = Color.Empty;
54 foreColor = Color.Empty;
55 format = String.Empty;
56 formatProvider = System.Globalization.CultureInfo.CurrentUICulture;
58 padding = Padding.Empty;
59 selectionBackColor = Color.Empty;
60 selectionForeColor = Color.Empty;
62 wrapMode = DataGridViewTriState.NotSet;
65 public DataGridViewCellStyle (DataGridViewCellStyle dataGridViewCellStyle) {
66 ApplyStyle(dataGridViewCellStyle);
69 public DataGridViewContentAlignment Alignment {
70 get { return alignment; }
72 if (!Enum.IsDefined(typeof(DataGridViewContentAlignment), value)) {
73 throw new InvalidEnumArgumentException("Value is not valid DataGridViewContentAlignment.");
75 if (alignment != value) {
82 public Color BackColor {
83 get { return backColor; }
85 if (backColor != value) {
92 public object DataSourceNullValue {
93 get { return dataSourceNullValue; }
95 if (dataSourceNullValue != value) {
96 dataSourceNullValue = value;
112 public Color ForeColor {
113 get { return foreColor; }
115 if (foreColor != value) {
122 public string Format {
123 get { return format; }
125 if (format != value) {
132 public IFormatProvider FormatProvider {
133 get { return formatProvider; }
135 if (formatProvider != value) {
136 formatProvider = value;
142 public bool IsDataSourceNullValueDefault {
143 get { return dataSourceNullValue != null; }
146 public bool IsFormatProviderDefault {
147 get { return formatProvider == System.Globalization.CultureInfo.CurrentUICulture; }
150 public bool IsNullValueDefault {
152 if (nullValue is string) {
153 return (string) nullValue == "(null)";
159 public object NullValue {
160 get { return nullValue; }
162 if (nullValue != value) {
169 public Padding Padding {
170 get { return padding; }
172 if (padding != value) {
179 public Color SelectionBackColor {
180 get { return selectionBackColor; }
182 if (value != Color.Empty && (int) value.A != 255) {
183 throw new ArgumentException("BackColor can't have alpha transparency component.");
185 if (selectionBackColor != value) {
186 selectionBackColor = value;
192 public Color SelectionForeColor {
193 get { return selectionForeColor; }
195 if (selectionForeColor != value) {
196 selectionForeColor = value;
212 public DataGridViewTriState WrapMode {
213 get { return wrapMode; }
215 if (!Enum.IsDefined(typeof(DataGridViewTriState), value)) {
216 throw new InvalidEnumArgumentException("Value is not valid DataGridViewTriState.");
218 if (wrapMode != value) {
225 public virtual void ApplyStyle (DataGridViewCellStyle dataGridViewCellStyle) {
226 this.alignment = dataGridViewCellStyle.alignment;
227 this.backColor = dataGridViewCellStyle.backColor;
228 this.dataSourceNullValue = dataGridViewCellStyle.dataSourceNullValue;
229 this.font = dataGridViewCellStyle.font;
230 this.foreColor = dataGridViewCellStyle.foreColor;
231 this.format = dataGridViewCellStyle.format;
232 this.formatProvider = dataGridViewCellStyle.formatProvider;
233 this.nullValue = dataGridViewCellStyle.nullValue;
234 this.padding = dataGridViewCellStyle.padding;
235 this.selectionBackColor = dataGridViewCellStyle.selectionBackColor;
236 this.selectionForeColor = dataGridViewCellStyle.selectionForeColor;
237 this.tag = dataGridViewCellStyle.tag;
238 this.wrapMode = dataGridViewCellStyle.wrapMode;
241 public virtual object Clone () {
242 return new DataGridViewCellStyle(this);
245 public override bool Equals (object o) {
246 if (o is DataGridViewCellStyle) {
247 DataGridViewCellStyle o_aux = (DataGridViewCellStyle) o;
248 return this.alignment == o_aux.alignment &&
249 this.backColor == o_aux.backColor &&
250 this.dataSourceNullValue == o_aux.dataSourceNullValue &&
251 this.font == o_aux.font &&
252 this.foreColor == o_aux.foreColor &&
253 this.format == o_aux.format &&
254 this.formatProvider == o_aux.formatProvider &&
255 this.nullValue == o_aux.nullValue &&
256 this.padding == o_aux.padding &&
257 this.selectionBackColor == o_aux.selectionBackColor &&
258 this.selectionForeColor == o_aux.selectionForeColor &&
259 this.tag == o_aux.tag &&
260 this.wrapMode == o_aux.wrapMode;
265 public override int GetHashCode () {
266 return base.GetHashCode();
269 public override string ToString () {
270 /////////////////////////////////////// COMPROBAR EN Windows ////////////////////////////////
274 internal event EventHandler StyleChanged;
276 internal void OnStyleChanged () {
277 if (StyleChanged != null) {
278 StyleChanged(this, EventArgs.Empty);