- Implement 2.0 image key feature.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridTableStyle.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) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //
24 //      Peter Bartok <pbartok@novell.com>
25 //      Jordi Mas i Hernandez <jordi@ximian.com>
26 //
27 //
28 // NOT COMPLETE
29 //
30
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Drawing;
34 using System.Runtime.InteropServices;
35 using System.Data;
36 using System.Xml;
37 using System.Runtime.Serialization;
38
39 namespace System.Windows.Forms
40 {
41         [DesignTimeVisible(false)]
42         [ToolboxItem(false)]
43         public class DataGridTableStyle : Component, IDataGridEditingService
44         {
45 #if NET_2_0
46                 readonly
47 #endif
48                 public static DataGridTableStyle DefaultTableStyle = new DataGridTableStyle (true);
49
50                 #region Local Variables
51                 private static readonly Color           def_alternating_backcolor = ThemeEngine.Current.DataGridAlternatingBackColor;
52                 private static readonly Color           def_backcolor = ThemeEngine.Current.DataGridBackColor;
53                 private static readonly Color           def_forecolor = SystemColors.WindowText;
54                 private static readonly Color           def_gridline_color = ThemeEngine.Current.DataGridGridLineColor;
55                 private static readonly Color           def_header_backcolor = ThemeEngine.Current.DataGridHeaderBackColor;
56                 private static readonly Font            def_header_font = ThemeEngine.Current.DefaultFont;
57                 private static readonly Color           def_header_forecolor = ThemeEngine.Current.DataGridHeaderForeColor;
58                 private static readonly Color           def_link_color = ThemeEngine.Current.DataGridLinkColor;
59                 private static readonly Color           def_link_hovercolor = ThemeEngine.Current.DataGridLinkHoverColor;
60                 private static readonly Color           def_selection_backcolor = ThemeEngine.Current.DataGridSelectionBackColor;
61                 private static readonly Color           def_selection_forecolor = ThemeEngine.Current.DataGridSelectionForeColor;
62                 private static readonly int             def_preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
63
64                 private bool                            allow_sorting;
65                 private DataGrid                        datagrid;
66                 private Color                           header_forecolor;
67                 private string                          mapping_name;
68                 private Color                           alternating_backcolor;
69                 private bool                            columnheaders_visible;
70                 private GridColumnStylesCollection      column_styles;
71                 private Color                           gridline_color;
72                 private DataGridLineStyle               gridline_style;
73                 private Color                           header_backcolor;
74                 private Font                            header_font;
75                 private Color                           link_color;
76                 private Color                           link_hovercolor;
77                 private int                             preferredcolumn_width;
78                 private int                             preferredrow_height;
79                 private bool                            _readonly;
80                 private bool                            rowheaders_visible;
81                 private Color                           selection_backcolor;
82                 private Color                           selection_forecolor;
83                 private int                             rowheaders_width;
84                 private Color                           backcolor;
85                 private Color                           forecolor;
86                 private bool                            is_default;
87                 internal ArrayList                      table_relations;
88                 CurrencyManager                         manager;
89                 #endregion      // Local Variables
90
91                 #region Constructors
92                 public DataGridTableStyle ()
93                         : this (false)
94                 {
95                 }
96
97                 public DataGridTableStyle (bool isDefaultTableStyle)
98                 {
99                         is_default = isDefaultTableStyle;
100                         allow_sorting = true;
101                         datagrid = null;
102                         header_forecolor = def_header_forecolor;
103                         mapping_name = string.Empty;
104                         table_relations = new ArrayList ();
105                         column_styles = new GridColumnStylesCollection (this);
106
107                         alternating_backcolor = def_alternating_backcolor;
108                         columnheaders_visible = true;
109                         gridline_color = def_gridline_color;
110                         gridline_style = DataGridLineStyle.Solid;
111                         header_backcolor = def_header_backcolor;
112                         header_font = def_header_font;
113                         link_color = def_link_color;
114                         link_hovercolor = def_link_hovercolor;
115                         preferredcolumn_width = ThemeEngine.Current.DataGridPreferredColumnWidth;
116                         preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
117                         _readonly = false;
118                         rowheaders_visible = true;
119                         selection_backcolor = def_selection_backcolor;
120                         selection_forecolor = def_selection_forecolor;
121                         rowheaders_width = 35;
122                         backcolor = def_backcolor;
123                         forecolor = def_forecolor;
124                 }
125
126                 public DataGridTableStyle (CurrencyManager listManager)
127                         : this (false)
128                 {
129                         manager = listManager;
130                 }
131                 #endregion
132
133                 #region Public Instance Properties
134                 [DefaultValue(true)]
135                 public bool AllowSorting {
136                         get { return allow_sorting; }
137                         set {
138                                 if (is_default)
139                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
140
141                                 if (allow_sorting != value) {
142                                         allow_sorting = value;
143                                         OnAllowSortingChanged (EventArgs.Empty);
144                                 }
145                         }
146                 }
147
148                 public Color AlternatingBackColor {
149                         get { return alternating_backcolor; }
150                         set {
151                                 if (is_default)
152                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
153
154                                 if (alternating_backcolor != value) {
155                                         alternating_backcolor = value;
156                                         OnAlternatingBackColorChanged (EventArgs.Empty);
157                                 }
158                         }
159                 }
160
161                 public Color BackColor {
162                         get { return backcolor; }
163                         set {
164                                 if (is_default)
165                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
166
167                                 if (backcolor != value) {
168                                         backcolor = value;
169                                         // XXX This should be OnBackColorChanged, MS made a c&p error, I think
170                                         OnForeColorChanged (EventArgs.Empty);
171                                 }
172                         }
173                 }
174
175                 [DefaultValue(true)]
176                 public bool ColumnHeadersVisible {
177                         get {
178                                 return columnheaders_visible;
179                         }
180
181                         set {
182                                 if (columnheaders_visible != value) {
183                                         columnheaders_visible = value;
184                                         OnColumnHeadersVisibleChanged (EventArgs.Empty);
185                                 }
186                         }
187                 }
188
189                 [Browsable(false)]
190                 public virtual DataGrid DataGrid {
191                         get { return datagrid; }
192                         set {
193                                 if (datagrid != value) {
194                                         datagrid = value;
195
196                                         /* now set the value on all our column styles */
197                                         for (int i = 0; i < column_styles.Count; i ++) {
198                                                 column_styles[i].SetDataGridInternal (datagrid);
199                                         }
200                                 }
201                         }
202                 }
203
204                 public Color ForeColor {
205                         get { return forecolor; }
206                         set {
207                                 if (is_default)
208                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
209
210                                 if (forecolor != value) {
211                                         forecolor = value;
212                                         // XXX This should be OnForeColorChanged, MS made a c&p error, I think
213                                         OnBackColorChanged (EventArgs.Empty);
214                                 }
215                         }
216                 }
217
218                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
219                 [Localizable(true)]
220                 public virtual GridColumnStylesCollection GridColumnStyles {
221                         get { return column_styles; }
222                 }
223
224                 public Color GridLineColor {
225                         get { return gridline_color; }
226                         set {
227                                 if (is_default)
228                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
229
230                                 if (gridline_color != value) {
231                                         gridline_color = value;
232                                         OnGridLineColorChanged (EventArgs.Empty);
233                                 }
234                         }
235                 }
236
237                 [DefaultValue(DataGridLineStyle.Solid)]
238                 public DataGridLineStyle GridLineStyle {
239                         get { return gridline_style; }
240                         set {
241                                 if (is_default)
242                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
243
244                                 if (gridline_style != value) {
245                                         gridline_style = value;
246                                         OnGridLineStyleChanged (EventArgs.Empty);
247                                 }
248                         }
249                 }
250
251                 public Color HeaderBackColor {
252                         get { return header_backcolor; }
253                         set {
254                                 if (is_default)
255                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
256
257                                 if (value == Color.Empty) {
258                                         throw new ArgumentNullException ("Color.Empty value is invalid.");
259                                 }
260
261                                 if (header_backcolor != value) {
262                                         header_backcolor = value;
263                                         OnHeaderBackColorChanged (EventArgs.Empty);
264                                 }
265                         }
266                 }
267
268                 [AmbientValue(null)]
269                 [Localizable(true)]
270                 public Font HeaderFont {
271                         get { return header_font; }
272                         set {
273                                 if (is_default)
274                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
275
276                                 if (value == null)
277                                         value = def_header_font;
278
279                                 if (header_font != value) {
280                                         header_font = value;
281                                         OnHeaderFontChanged (EventArgs.Empty);
282                                 }
283                         }
284                 }
285
286                 public Color HeaderForeColor {
287                         get { return header_forecolor; }
288                         set {
289                                 if (is_default)
290                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
291
292                                 if (header_forecolor != value) {
293                                         header_forecolor = value;
294                                         OnHeaderForeColorChanged (EventArgs.Empty);
295                                 }
296                         }
297                 }
298
299                 public Color LinkColor {
300                         get { return link_color; }
301                         set {
302                                 if (is_default)
303                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
304
305                                 if (link_color != value) {
306                                         link_color = value;
307                                         OnLinkColorChanged (EventArgs.Empty);
308                                 }
309                         }
310                 }
311
312 #if !NET_2_0
313                 [ComVisible(false)]
314 #endif
315                 [EditorBrowsable(EditorBrowsableState.Never)]
316                 [Browsable(false)]
317                 public Color LinkHoverColor {
318                         get { return link_hovercolor; }
319                         set {
320                                 if (link_hovercolor != value) {
321                                         link_hovercolor = value;
322                                         // XXX MS doesn't emit this event (even though they should...)
323                                         // OnLinkHoverColorChanged (EventArgs.Empty);
324                                 }
325                         }
326                 }
327
328                 [Editor("System.Windows.Forms.Design.DataGridTableStyleMappingNameEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
329 #if NET_2_0
330                 [DefaultValue ("")]
331 #endif
332                 public string MappingName {
333                         get { return mapping_name; }
334                         set {
335                                 if (value == null)
336                                         value = "";
337
338                                 if (mapping_name != value) {
339                                         mapping_name = value;
340                                         OnMappingNameChanged (EventArgs.Empty);
341                                 }
342                         }
343                 }
344
345                 [DefaultValue(75)]
346                 [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
347                 [Localizable(true)]
348                 public int PreferredColumnWidth {
349                         get { return preferredcolumn_width; }
350                         set {
351                                 if (is_default)
352                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
353
354                                 if (value < 0) {
355                                         throw new ArgumentException ("PreferredColumnWidth is less than 0");
356                                 }
357
358                                 if (preferredcolumn_width != value) {
359                                         preferredcolumn_width = value;
360                                         OnPreferredColumnWidthChanged (EventArgs.Empty);
361                                 }
362                         }
363                 }
364
365                 [Localizable(true)]
366                 public int PreferredRowHeight {
367                         get { return preferredrow_height; }
368                         set {
369                                 if (is_default)
370                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
371
372                                 if (preferredrow_height != value) {
373                                         preferredrow_height = value;
374                                         OnPreferredRowHeightChanged (EventArgs.Empty);
375                                 }
376                         }
377                 }
378
379                 [DefaultValue(false)]
380                 public virtual bool ReadOnly {
381                         get { return _readonly; }
382                         set {
383                                 if (_readonly != value) {
384                                         _readonly = value;
385                                         OnReadOnlyChanged (EventArgs.Empty);
386                                 }
387                         }
388                 }
389
390                 [DefaultValue(true)]
391                 public bool RowHeadersVisible {
392                         get { return rowheaders_visible; }
393                         set {
394                                 if (rowheaders_visible != value) {
395                                         rowheaders_visible = value;
396                                         OnRowHeadersVisibleChanged (EventArgs.Empty);
397                                 }
398                         }
399                 }
400
401                 [DefaultValue(35)]
402                 [Localizable(true)]
403                 public int RowHeaderWidth {
404                         get { return rowheaders_width; }
405                         set {
406                                 if (rowheaders_width != value) {
407                                         rowheaders_width = value;
408                                         OnRowHeaderWidthChanged (EventArgs.Empty);
409                                 }
410                         }
411                 }
412
413                 public Color SelectionBackColor {
414                         get { return selection_backcolor; }
415                         set {
416                                 if (is_default)
417                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
418
419                                 if (selection_backcolor != value) {
420                                         selection_backcolor = value;
421                                         OnSelectionBackColorChanged (EventArgs.Empty);
422                                 }
423                         }
424                 }
425
426                 [Description("The foreground color for the current data grid row")]
427                 public Color SelectionForeColor  {
428                         get { return selection_forecolor; }
429                         set {
430                                 if (is_default)
431                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
432
433                                 if (selection_forecolor != value) {
434                                         selection_forecolor = value;
435                                         OnSelectionForeColorChanged (EventArgs.Empty);
436                                 }
437                         }
438                 }
439
440                 #endregion      // Public Instance Properties
441
442                 #region Private Instance Properties
443                 internal DataGridLineStyle CurrentGridLineStyle {
444                         get {
445                                 if (is_default && datagrid != null) {
446                                         return datagrid.GridLineStyle;
447                                 }
448
449                                 return gridline_style;
450                         }
451                 }
452
453                 internal Color CurrentGridLineColor {
454                         get {
455                                 if (is_default && datagrid != null) {
456                                         return datagrid.GridLineColor;
457                                 }
458
459                                 return gridline_color;
460                         }
461                 }
462
463                 internal Color CurrentHeaderBackColor {
464                         get {
465                                 if (is_default && datagrid != null) {
466                                         return datagrid.HeaderBackColor;
467                                 }
468
469                                 return header_backcolor;
470                         }
471                 }
472
473                 internal Color CurrentHeaderForeColor {
474                         get {
475                                 if (is_default && datagrid != null) {
476                                         return datagrid.HeaderForeColor;
477                                 }
478
479                                 return header_forecolor;
480                         }
481                 }
482
483                 internal int CurrentPreferredColumnWidth {
484                         get {
485                                 if (is_default && datagrid != null) {
486                                         return datagrid.PreferredColumnWidth;
487                                 }
488
489                                 return preferredcolumn_width;
490                         }
491                 }
492
493                 internal int CurrentPreferredRowHeight {
494                         get {
495                                 if (is_default && datagrid != null) {
496                                         return datagrid.PreferredRowHeight;
497                                 }
498
499                                 return preferredrow_height;
500                         }
501                 }
502                 
503                 internal bool CurrentRowHeadersVisible {
504                         get {
505                                 if (is_default && datagrid != null) {
506                                         return datagrid.RowHeadersVisible;
507                                 }
508
509                                 return rowheaders_visible;
510                         }
511                 }
512
513                 internal bool HasRelations {
514                         get { return table_relations.Count > 0; }
515                 }
516
517                 internal string[] Relations {
518                         get {
519                                 string[] rel = new string[table_relations.Count];
520                                 table_relations.CopyTo (rel, 0);
521                                 return rel;
522                         }
523                 }
524
525                 #endregion Private Instance Properties
526
527                 #region Public Instance Methods
528
529                 [MonoTODO]
530                 public bool BeginEdit (DataGridColumnStyle gridColumn,  int rowNumber)
531                 {
532                         throw new NotImplementedException ();
533                 }
534
535                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
536                 {
537                         return CreateGridColumn (prop,  false);
538                 }
539
540                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop,  bool isDefault)
541                 {
542                         if (prop.PropertyType == typeof (bool))
543                                 return new DataGridBoolColumn (prop, isDefault);
544                         else {
545                                 // At least to special cases with formats
546                                 if (prop.PropertyType.Equals (typeof (DateTime))) {
547                                         return new DataGridTextBoxColumn (prop, "d", isDefault);
548                                 }
549
550                                 if (prop.PropertyType.Equals (typeof (Int32)) ||
551                                         prop.PropertyType.Equals (typeof (Int16))) {
552                                         return new DataGridTextBoxColumn (prop, "G", isDefault);
553                                 }
554
555                                 return new DataGridTextBoxColumn (prop, isDefault);
556                         }
557                 }
558
559                 protected override void Dispose (bool disposing)
560                 {
561                         base.Dispose (disposing);
562                 }
563
564                 [MonoTODO]
565                 public bool EndEdit ( DataGridColumnStyle gridColumn,  int rowNumber,  bool shouldAbort)
566                 {
567                         throw new NotImplementedException ();
568                 }
569
570                 protected virtual void OnAllowSortingChanged (EventArgs e)
571                 {
572                         EventHandler eh = (EventHandler)(Events [AllowSortingChangedEvent]);
573                         if (eh != null)
574                                 eh (this, e);
575                 }
576
577                 protected virtual void OnAlternatingBackColorChanged (EventArgs e)
578                 {
579                         EventHandler eh = (EventHandler)(Events [AlternatingBackColorChangedEvent]);
580                         if (eh != null)
581                                 eh (this, e);
582                 }
583
584                 protected virtual void OnBackColorChanged (EventArgs e)
585                 {
586                         EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
587                         if (eh != null)
588                                 eh (this, e);
589                 }
590
591                 protected virtual void OnColumnHeadersVisibleChanged (EventArgs e)
592                 {
593                         EventHandler eh = (EventHandler)(Events [ColumnHeadersVisibleChangedEvent]);
594                         if (eh != null)
595                                 eh (this, e);
596                 }
597
598                 protected virtual void OnForeColorChanged (EventArgs e)
599                 {
600                         EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
601                         if (eh != null)
602                                 eh (this, e);
603                 }
604
605                 protected virtual void OnGridLineColorChanged (EventArgs e)
606                 {
607                         EventHandler eh = (EventHandler)(Events [GridLineColorChangedEvent]);
608                         if (eh != null)
609                                 eh (this, e);
610                 }
611
612                 protected virtual void OnGridLineStyleChanged (EventArgs e)
613                 {
614                         EventHandler eh = (EventHandler)(Events [GridLineStyleChangedEvent]);
615                         if (eh != null)
616                                 eh (this, e);
617                 }
618
619                 protected virtual void OnHeaderBackColorChanged (EventArgs e)
620                 {
621                         EventHandler eh = (EventHandler)(Events [HeaderBackColorChangedEvent]);
622                         if (eh != null)
623                                 eh (this, e);
624                 }
625
626                 protected virtual void OnHeaderFontChanged (EventArgs e)
627                 {
628                         EventHandler eh = (EventHandler)(Events [HeaderFontChangedEvent]);
629                         if (eh != null)
630                                 eh (this, e);
631                 }
632
633                 protected virtual void OnHeaderForeColorChanged (EventArgs e)
634                 {
635                         EventHandler eh = (EventHandler)(Events [HeaderForeColorChangedEvent]);
636                         if (eh != null)
637                                 eh (this, e);
638                 }
639
640                 protected virtual void OnLinkColorChanged (EventArgs e)
641                 {
642                         EventHandler eh = (EventHandler)(Events [LinkColorChangedEvent]);
643                         if (eh != null)
644                                 eh (this, e);
645                 }
646
647                 protected virtual void OnLinkHoverColorChanged (EventArgs e)
648                 {
649                         EventHandler eh = (EventHandler)(Events [LinkHoverColorChangedEvent]);
650                         if (eh != null)
651                                 eh (this, e);
652                 }
653
654                 protected virtual void OnMappingNameChanged (EventArgs e)
655                 {
656                         EventHandler eh = (EventHandler)(Events [MappingNameChangedEvent]);
657                         if (eh != null)
658                                 eh (this, e);
659                 }
660
661                 protected virtual void OnPreferredColumnWidthChanged (EventArgs e)
662                 {
663                         EventHandler eh = (EventHandler)(Events [PreferredColumnWidthChangedEvent]);
664                         if (eh != null)
665                                 eh (this, e);
666                 }
667
668                 protected virtual void OnPreferredRowHeightChanged (EventArgs e)
669                 {
670                         EventHandler eh = (EventHandler)(Events [PreferredRowHeightChangedEvent]);
671                         if (eh != null)
672                                 eh (this, e);
673                 }
674
675                 protected virtual void OnReadOnlyChanged (EventArgs e)
676                 {
677                         EventHandler eh = (EventHandler)(Events [ReadOnlyChangedEvent]);
678                         if (eh != null)
679                                 eh (this, e);
680                 }
681
682                 protected virtual void OnRowHeadersVisibleChanged (EventArgs e)
683                 {
684                         EventHandler eh = (EventHandler)(Events [RowHeadersVisibleChangedEvent]);
685                         if (eh != null)
686                                 eh (this, e);
687                 }
688
689                 protected virtual void OnRowHeaderWidthChanged (EventArgs e)
690                 {
691                         EventHandler eh = (EventHandler)(Events [RowHeaderWidthChangedEvent]);
692                         if (eh != null)
693                                 eh (this, e);
694                 }
695
696                 protected virtual void OnSelectionBackColorChanged (EventArgs e)
697                 {
698                         EventHandler eh = (EventHandler)(Events [SelectionBackColorChangedEvent]);
699                         if (eh != null)
700                                 eh (this, e);
701                 }
702
703                 protected virtual void OnSelectionForeColorChanged (EventArgs e)
704                 {
705                         EventHandler eh = (EventHandler)(Events [SelectionForeColorChangedEvent]);
706                         if (eh != null)
707                                 eh (this, e);
708                 }
709
710                 public void ResetAlternatingBackColor ()
711                 {
712                         AlternatingBackColor = def_alternating_backcolor;
713                 }
714
715                 public void ResetBackColor ()
716                 {
717                         BackColor = def_backcolor;
718                 }
719
720                 public void ResetForeColor ()
721                 {
722                         ForeColor = def_forecolor;
723                 }
724
725                 public void ResetGridLineColor ()
726                 {
727                         GridLineColor = def_gridline_color;
728                 }
729
730                 public void ResetHeaderBackColor ()
731                 {
732                         HeaderBackColor = def_header_backcolor;
733                 }
734
735                 public void ResetHeaderFont ()
736                 {
737                         HeaderFont = def_header_font;
738                 }
739
740                 public void ResetHeaderForeColor ()
741                 {
742                         HeaderForeColor = def_header_forecolor;
743                 }
744
745                 public void ResetLinkColor ()
746                 {
747                         LinkColor = def_link_color;
748                 }
749
750                 public void ResetLinkHoverColor ()
751                 {
752                         LinkHoverColor = def_link_hovercolor;
753                 }
754
755                 public void ResetSelectionBackColor ()
756                 {
757                         SelectionBackColor = def_selection_backcolor;
758                 }
759
760                 public void ResetSelectionForeColor ()
761                 {
762                         SelectionForeColor = def_selection_forecolor;
763                 }
764
765                 protected virtual bool ShouldSerializeAlternatingBackColor ()
766                 {
767                         return (alternating_backcolor != def_alternating_backcolor);
768                 }
769
770                 protected bool ShouldSerializeBackColor ()
771                 {
772                         return (backcolor != def_backcolor);
773                 }
774
775                 protected bool ShouldSerializeForeColor ()
776                 {
777                         return (forecolor != def_forecolor);
778                 }
779
780                 protected virtual bool ShouldSerializeGridLineColor ()
781                 {
782                         return (gridline_color != def_gridline_color);
783                 }
784
785                 protected virtual bool ShouldSerializeHeaderBackColor ()
786                 {
787                         return (header_backcolor != def_header_backcolor);
788                 }
789
790                 protected virtual bool ShouldSerializeHeaderForeColor ()
791                 {
792                         return (header_forecolor != def_header_forecolor);
793                 }
794
795                 protected virtual bool ShouldSerializeLinkColor ()
796                 {
797                         return (link_color != def_link_color);
798                 }
799
800                 protected virtual bool ShouldSerializeLinkHoverColor ()
801                 {
802                         return (link_hovercolor != def_link_hovercolor);
803                 }
804
805                 protected bool ShouldSerializePreferredRowHeight ()
806                 {
807                         return (preferredrow_height != def_preferredrow_height);
808                 }
809
810                 protected bool ShouldSerializeSelectionBackColor ()
811                 {
812                         return (selection_backcolor != def_selection_backcolor);
813                 }
814
815                 protected virtual bool ShouldSerializeSelectionForeColor ()
816                 {
817                         return (selection_forecolor != def_selection_forecolor);
818                 }
819                 #endregion      // Protected Instance Methods
820
821                 #region Private Instance Properties
822                 // Create column styles for this TableStyle
823                 internal void CreateColumnsForTable (bool onlyBind)
824                 {
825                         CurrencyManager mgr = manager;
826                         DataGridColumnStyle st;
827
828                         if (mgr == null) {
829                                 mgr = datagrid.ListManager;
830
831                                 if (mgr == null)
832                                         return;
833                         }
834
835                         for (int i = 0; i < column_styles.Count; i ++)
836                                 column_styles[i].bound = false;
837
838                         table_relations.Clear ();
839                         PropertyDescriptorCollection propcol = mgr.GetItemProperties ();
840
841                         for (int i = 0; i < propcol.Count; i++)
842                         {
843                                 // The column style is already provided by the user
844                                 st = column_styles[propcol[i].Name];
845                                 if (st != null) {
846                                         if (st.Width == -1)
847                                                 st.Width = CurrentPreferredColumnWidth;
848
849                                         st.PropertyDescriptor = propcol[i];
850                                         st.bound = true;
851                                         continue;
852                                 }
853
854                                 if (onlyBind == true)
855                                         continue;
856
857                                 if (typeof (IBindingList).IsAssignableFrom (propcol[i].PropertyType)) {
858                                         table_relations.Add (propcol[i].Name);
859                                 } else {
860                                         st = CreateGridColumn (propcol[i],  true);
861                                         st.bound = true;
862                                         st.grid = datagrid;
863                                         st.MappingName = propcol[i].Name;
864                                         st.HeaderText = propcol[i].Name;
865                                         st.Width = CurrentPreferredColumnWidth;
866                                         column_styles.Add (st);
867                                 }
868                         }
869
870                 }
871
872                 #endregion Private Instance Properties
873
874                 #region Events
875                 static object AllowSortingChangedEvent = new object ();
876                 static object AlternatingBackColorChangedEvent = new object ();
877                 static object BackColorChangedEvent = new object ();
878                 static object ColumnHeadersVisibleChangedEvent = new object ();
879                 static object ForeColorChangedEvent = new object ();
880                 static object GridLineColorChangedEvent = new object ();
881                 static object GridLineStyleChangedEvent = new object ();
882                 static object HeaderBackColorChangedEvent = new object ();
883                 static object HeaderFontChangedEvent = new object ();
884                 static object HeaderForeColorChangedEvent = new object ();
885                 static object LinkColorChangedEvent = new object ();
886                 static object LinkHoverColorChangedEvent = new object ();
887                 static object MappingNameChangedEvent = new object ();
888                 static object PreferredColumnWidthChangedEvent = new object ();
889                 static object PreferredRowHeightChangedEvent = new object ();
890                 static object ReadOnlyChangedEvent = new object ();
891                 static object RowHeadersVisibleChangedEvent = new object ();
892                 static object RowHeaderWidthChangedEvent = new object ();
893                 static object SelectionBackColorChangedEvent = new object ();
894                 static object SelectionForeColorChangedEvent = new object ();
895
896                 public event EventHandler AllowSortingChanged {
897                         add { Events.AddHandler (AllowSortingChangedEvent, value); }
898                         remove { Events.RemoveHandler (AllowSortingChangedEvent, value); }
899                 }
900
901                 public event EventHandler AlternatingBackColorChanged {
902                         add { Events.AddHandler (AlternatingBackColorChangedEvent, value); }
903                         remove { Events.RemoveHandler (AlternatingBackColorChangedEvent, value); }
904                 }
905
906                 public event EventHandler BackColorChanged {
907                         add { Events.AddHandler (BackColorChangedEvent, value); }
908                         remove { Events.RemoveHandler (BackColorChangedEvent, value); }
909                 }
910
911                 public event EventHandler ColumnHeadersVisibleChanged {
912                         add { Events.AddHandler (ColumnHeadersVisibleChangedEvent, value); }
913                         remove { Events.RemoveHandler (ColumnHeadersVisibleChangedEvent, value); }
914                 }
915
916                 public event EventHandler ForeColorChanged {
917                         add { Events.AddHandler (ForeColorChangedEvent, value); }
918                         remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
919                 }
920
921                 public event EventHandler GridLineColorChanged {
922                         add { Events.AddHandler (GridLineColorChangedEvent, value); }
923                         remove { Events.RemoveHandler (GridLineColorChangedEvent, value); }
924                 }
925
926                 public event EventHandler GridLineStyleChanged {
927                         add { Events.AddHandler (GridLineStyleChangedEvent, value); }
928                         remove { Events.RemoveHandler (GridLineStyleChangedEvent, value); }
929                 }
930
931                 public event EventHandler HeaderBackColorChanged {
932                         add { Events.AddHandler (HeaderBackColorChangedEvent, value); }
933                         remove { Events.RemoveHandler (HeaderBackColorChangedEvent, value); }
934                 }
935
936                 public event EventHandler HeaderFontChanged {
937                         add { Events.AddHandler (HeaderFontChangedEvent, value); }
938                         remove { Events.RemoveHandler (HeaderFontChangedEvent, value); }
939                 }
940
941                 public event EventHandler HeaderForeColorChanged {
942                         add { Events.AddHandler (HeaderForeColorChangedEvent, value); }
943                         remove { Events.RemoveHandler (HeaderForeColorChangedEvent, value); }
944                 }
945
946                 public event EventHandler LinkColorChanged {
947                         add { Events.AddHandler (LinkColorChangedEvent, value); }
948                         remove { Events.RemoveHandler (LinkColorChangedEvent, value); }
949                 }
950
951                 public event EventHandler LinkHoverColorChanged {
952                         add { Events.AddHandler (LinkHoverColorChangedEvent, value); }
953                         remove { Events.RemoveHandler (LinkHoverColorChangedEvent, value); }
954                 }
955
956                 public event EventHandler MappingNameChanged {
957                         add { Events.AddHandler (MappingNameChangedEvent, value); }
958                         remove { Events.RemoveHandler (MappingNameChangedEvent, value); }
959                 }
960
961                 public event EventHandler PreferredColumnWidthChanged {
962                         add { Events.AddHandler (PreferredColumnWidthChangedEvent, value); }
963                         remove { Events.RemoveHandler (PreferredColumnWidthChangedEvent, value); }
964                 }
965
966                 public event EventHandler PreferredRowHeightChanged {
967                         add { Events.AddHandler (PreferredRowHeightChangedEvent, value); }
968                         remove { Events.RemoveHandler (PreferredRowHeightChangedEvent, value); }
969                 }
970
971                 public event EventHandler ReadOnlyChanged {
972                         add { Events.AddHandler (ReadOnlyChangedEvent, value); }
973                         remove { Events.RemoveHandler (ReadOnlyChangedEvent, value); }
974                 }
975
976                 public event EventHandler RowHeadersVisibleChanged {
977                         add { Events.AddHandler (RowHeadersVisibleChangedEvent, value); }
978                         remove { Events.RemoveHandler (RowHeadersVisibleChangedEvent, value); }
979                 }
980
981                 public event EventHandler RowHeaderWidthChanged {
982                         add { Events.AddHandler (RowHeaderWidthChangedEvent, value); }
983                         remove { Events.RemoveHandler (RowHeaderWidthChangedEvent, value); }
984                 }
985
986                 public event EventHandler SelectionBackColorChanged {
987                         add { Events.AddHandler (SelectionBackColorChangedEvent, value); }
988                         remove { Events.RemoveHandler (SelectionBackColorChangedEvent, value); }
989                 }
990
991                 public event EventHandler SelectionForeColorChanged {
992                         add { Events.AddHandler (SelectionForeColorChangedEvent, value); }
993                         remove { Events.RemoveHandler (SelectionForeColorChangedEvent, value); }
994                 }
995                 #endregion      // Events
996         }
997 }
998