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