* TabControl.cs: Show the tooltip depending on the value
[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 = null;
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 {
272                                 if (header_font != null)
273                                         return header_font;
274
275                                 if (DataGrid != null)
276                                         return DataGrid.Font;
277
278                                 return def_header_font;
279                         }
280                         set {
281                                 if (is_default)
282                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
283
284                                 if (header_font != value) {
285                                         header_font = value;
286                                         OnHeaderFontChanged (EventArgs.Empty);
287                                 }
288                         }
289                 }
290
291                 public Color HeaderForeColor {
292                         get { return header_forecolor; }
293                         set {
294                                 if (is_default)
295                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
296
297                                 if (header_forecolor != value) {
298                                         header_forecolor = value;
299                                         OnHeaderForeColorChanged (EventArgs.Empty);
300                                 }
301                         }
302                 }
303
304                 public Color LinkColor {
305                         get { return link_color; }
306                         set {
307                                 if (is_default)
308                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
309
310                                 if (link_color != value) {
311                                         link_color = value;
312                                         OnLinkColorChanged (EventArgs.Empty);
313                                 }
314                         }
315                 }
316
317 #if !NET_2_0
318                 [ComVisible(false)]
319 #endif
320                 [EditorBrowsable(EditorBrowsableState.Never)]
321                 [Browsable(false)]
322                 public Color LinkHoverColor {
323                         get { return link_hovercolor; }
324                         set {
325                                 if (link_hovercolor != value) {
326                                         link_hovercolor = value;
327                                         // XXX MS doesn't emit this event (even though they should...)
328                                         // OnLinkHoverColorChanged (EventArgs.Empty);
329                                 }
330                         }
331                 }
332
333                 [Editor("System.Windows.Forms.Design.DataGridTableStyleMappingNameEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
334 #if NET_2_0
335                 [DefaultValue ("")]
336 #endif
337                 public string MappingName {
338                         get { return mapping_name; }
339                         set {
340                                 if (value == null)
341                                         value = "";
342
343                                 if (mapping_name != value) {
344                                         mapping_name = value;
345                                         OnMappingNameChanged (EventArgs.Empty);
346                                 }
347                         }
348                 }
349
350                 [DefaultValue(75)]
351                 [TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter))]
352                 [Localizable(true)]
353                 public int PreferredColumnWidth {
354                         get { return preferredcolumn_width; }
355                         set {
356                                 if (is_default)
357                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
358
359                                 if (value < 0) {
360                                         throw new ArgumentException ("PreferredColumnWidth is less than 0");
361                                 }
362
363                                 if (preferredcolumn_width != value) {
364                                         preferredcolumn_width = value;
365                                         OnPreferredColumnWidthChanged (EventArgs.Empty);
366                                 }
367                         }
368                 }
369
370                 [Localizable(true)]
371                 public int PreferredRowHeight {
372                         get { return preferredrow_height; }
373                         set {
374                                 if (is_default)
375                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
376
377                                 if (preferredrow_height != value) {
378                                         preferredrow_height = value;
379                                         OnPreferredRowHeightChanged (EventArgs.Empty);
380                                 }
381                         }
382                 }
383
384                 [DefaultValue(false)]
385                 public virtual bool ReadOnly {
386                         get { return _readonly; }
387                         set {
388                                 if (_readonly != value) {
389                                         _readonly = value;
390                                         OnReadOnlyChanged (EventArgs.Empty);
391                                 }
392                         }
393                 }
394
395                 [DefaultValue(true)]
396                 public bool RowHeadersVisible {
397                         get { return rowheaders_visible; }
398                         set {
399                                 if (rowheaders_visible != value) {
400                                         rowheaders_visible = value;
401                                         OnRowHeadersVisibleChanged (EventArgs.Empty);
402                                 }
403                         }
404                 }
405
406                 [DefaultValue(35)]
407                 [Localizable(true)]
408                 public int RowHeaderWidth {
409                         get { return rowheaders_width; }
410                         set {
411                                 if (rowheaders_width != value) {
412                                         rowheaders_width = value;
413                                         OnRowHeaderWidthChanged (EventArgs.Empty);
414                                 }
415                         }
416                 }
417
418                 public Color SelectionBackColor {
419                         get { return selection_backcolor; }
420                         set {
421                                 if (is_default)
422                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
423
424                                 if (selection_backcolor != value) {
425                                         selection_backcolor = value;
426                                         OnSelectionBackColorChanged (EventArgs.Empty);
427                                 }
428                         }
429                 }
430
431                 [Description("The foreground color for the current data grid row")]
432                 public Color SelectionForeColor  {
433                         get { return selection_forecolor; }
434                         set {
435                                 if (is_default)
436                                         throw new ArgumentException ("Cannot change the value of this property on the default DataGridTableStyle.");
437
438                                 if (selection_forecolor != value) {
439                                         selection_forecolor = value;
440                                         OnSelectionForeColorChanged (EventArgs.Empty);
441                                 }
442                         }
443                 }
444
445                 #endregion      // Public Instance Properties
446
447                 #region Private Instance Properties
448                 internal DataGridLineStyle CurrentGridLineStyle {
449                         get {
450                                 if (is_default && datagrid != null) {
451                                         return datagrid.GridLineStyle;
452                                 }
453
454                                 return gridline_style;
455                         }
456                 }
457
458                 internal Color CurrentGridLineColor {
459                         get {
460                                 if (is_default && datagrid != null) {
461                                         return datagrid.GridLineColor;
462                                 }
463
464                                 return gridline_color;
465                         }
466                 }
467
468                 internal Color CurrentHeaderBackColor {
469                         get {
470                                 if (is_default && datagrid != null) {
471                                         return datagrid.HeaderBackColor;
472                                 }
473
474                                 return header_backcolor;
475                         }
476                 }
477
478                 internal Color CurrentHeaderForeColor {
479                         get {
480                                 if (is_default && datagrid != null) {
481                                         return datagrid.HeaderForeColor;
482                                 }
483
484                                 return header_forecolor;
485                         }
486                 }
487
488                 internal int CurrentPreferredColumnWidth {
489                         get {
490                                 if (is_default && datagrid != null) {
491                                         return datagrid.PreferredColumnWidth;
492                                 }
493
494                                 return preferredcolumn_width;
495                         }
496                 }
497
498                 internal int CurrentPreferredRowHeight {
499                         get {
500                                 if (is_default && datagrid != null) {
501                                         return datagrid.PreferredRowHeight;
502                                 }
503
504                                 return preferredrow_height;
505                         }
506                 }
507                 
508                 internal bool CurrentRowHeadersVisible {
509                         get {
510                                 if (is_default && datagrid != null) {
511                                         return datagrid.RowHeadersVisible;
512                                 }
513
514                                 return rowheaders_visible;
515                         }
516                 }
517
518                 internal bool HasRelations {
519                         get { return table_relations.Count > 0; }
520                 }
521
522                 internal string[] Relations {
523                         get {
524                                 string[] rel = new string[table_relations.Count];
525                                 table_relations.CopyTo (rel, 0);
526                                 return rel;
527                         }
528                 }
529
530                 #endregion Private Instance Properties
531
532                 #region Public Instance Methods
533
534                 [MonoTODO ("Not implemented, will throw NotImplementedException")]
535                 public bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
536                 {
537                         throw new NotImplementedException ();
538                 }
539
540                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
541                 {
542                         return CreateGridColumn (prop,  false);
543                 }
544
545                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop,  bool isDefault)
546                 {
547                         if (prop.PropertyType == typeof (bool))
548                                 return new DataGridBoolColumn (prop, isDefault);
549                         else {
550                                 // At least to special cases with formats
551                                 if (prop.PropertyType.Equals (typeof (DateTime))) {
552                                         return new DataGridTextBoxColumn (prop, "d", isDefault);
553                                 }
554
555                                 if (prop.PropertyType.Equals (typeof (Int32)) ||
556                                         prop.PropertyType.Equals (typeof (Int16))) {
557                                         return new DataGridTextBoxColumn (prop, "G", isDefault);
558                                 }
559
560                                 return new DataGridTextBoxColumn (prop, isDefault);
561                         }
562                 }
563
564                 protected override void Dispose (bool disposing)
565                 {
566                         base.Dispose (disposing);
567                 }
568
569                 [MonoTODO ("Not implemented, will throw NotImplementedException")]
570                 public bool EndEdit (DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
571                 {
572                         throw new NotImplementedException ();
573                 }
574
575                 protected virtual void OnAllowSortingChanged (EventArgs e)
576                 {
577                         EventHandler eh = (EventHandler)(Events [AllowSortingChangedEvent]);
578                         if (eh != null)
579                                 eh (this, e);
580                 }
581
582                 protected virtual void OnAlternatingBackColorChanged (EventArgs e)
583                 {
584                         EventHandler eh = (EventHandler)(Events [AlternatingBackColorChangedEvent]);
585                         if (eh != null)
586                                 eh (this, e);
587                 }
588
589                 protected virtual void OnBackColorChanged (EventArgs e)
590                 {
591                         EventHandler eh = (EventHandler)(Events [BackColorChangedEvent]);
592                         if (eh != null)
593                                 eh (this, e);
594                 }
595
596                 protected virtual void OnColumnHeadersVisibleChanged (EventArgs e)
597                 {
598                         EventHandler eh = (EventHandler)(Events [ColumnHeadersVisibleChangedEvent]);
599                         if (eh != null)
600                                 eh (this, e);
601                 }
602
603                 protected virtual void OnForeColorChanged (EventArgs e)
604                 {
605                         EventHandler eh = (EventHandler)(Events [ForeColorChangedEvent]);
606                         if (eh != null)
607                                 eh (this, e);
608                 }
609
610                 protected virtual void OnGridLineColorChanged (EventArgs e)
611                 {
612                         EventHandler eh = (EventHandler)(Events [GridLineColorChangedEvent]);
613                         if (eh != null)
614                                 eh (this, e);
615                 }
616
617                 protected virtual void OnGridLineStyleChanged (EventArgs e)
618                 {
619                         EventHandler eh = (EventHandler)(Events [GridLineStyleChangedEvent]);
620                         if (eh != null)
621                                 eh (this, e);
622                 }
623
624                 protected virtual void OnHeaderBackColorChanged (EventArgs e)
625                 {
626                         EventHandler eh = (EventHandler)(Events [HeaderBackColorChangedEvent]);
627                         if (eh != null)
628                                 eh (this, e);
629                 }
630
631                 protected virtual void OnHeaderFontChanged (EventArgs e)
632                 {
633                         EventHandler eh = (EventHandler)(Events [HeaderFontChangedEvent]);
634                         if (eh != null)
635                                 eh (this, e);
636                 }
637
638                 protected virtual void OnHeaderForeColorChanged (EventArgs e)
639                 {
640                         EventHandler eh = (EventHandler)(Events [HeaderForeColorChangedEvent]);
641                         if (eh != null)
642                                 eh (this, e);
643                 }
644
645                 protected virtual void OnLinkColorChanged (EventArgs e)
646                 {
647                         EventHandler eh = (EventHandler)(Events [LinkColorChangedEvent]);
648                         if (eh != null)
649                                 eh (this, e);
650                 }
651
652                 protected virtual void OnLinkHoverColorChanged (EventArgs e)
653                 {
654                         EventHandler eh = (EventHandler)(Events [LinkHoverColorChangedEvent]);
655                         if (eh != null)
656                                 eh (this, e);
657                 }
658
659                 protected virtual void OnMappingNameChanged (EventArgs e)
660                 {
661                         EventHandler eh = (EventHandler)(Events [MappingNameChangedEvent]);
662                         if (eh != null)
663                                 eh (this, e);
664                 }
665
666                 protected virtual void OnPreferredColumnWidthChanged (EventArgs e)
667                 {
668                         EventHandler eh = (EventHandler)(Events [PreferredColumnWidthChangedEvent]);
669                         if (eh != null)
670                                 eh (this, e);
671                 }
672
673                 protected virtual void OnPreferredRowHeightChanged (EventArgs e)
674                 {
675                         EventHandler eh = (EventHandler)(Events [PreferredRowHeightChangedEvent]);
676                         if (eh != null)
677                                 eh (this, e);
678                 }
679
680                 protected virtual void OnReadOnlyChanged (EventArgs e)
681                 {
682                         EventHandler eh = (EventHandler)(Events [ReadOnlyChangedEvent]);
683                         if (eh != null)
684                                 eh (this, e);
685                 }
686
687                 protected virtual void OnRowHeadersVisibleChanged (EventArgs e)
688                 {
689                         EventHandler eh = (EventHandler)(Events [RowHeadersVisibleChangedEvent]);
690                         if (eh != null)
691                                 eh (this, e);
692                 }
693
694                 protected virtual void OnRowHeaderWidthChanged (EventArgs e)
695                 {
696                         EventHandler eh = (EventHandler)(Events [RowHeaderWidthChangedEvent]);
697                         if (eh != null)
698                                 eh (this, e);
699                 }
700
701                 protected virtual void OnSelectionBackColorChanged (EventArgs e)
702                 {
703                         EventHandler eh = (EventHandler)(Events [SelectionBackColorChangedEvent]);
704                         if (eh != null)
705                                 eh (this, e);
706                 }
707
708                 protected virtual void OnSelectionForeColorChanged (EventArgs e)
709                 {
710                         EventHandler eh = (EventHandler)(Events [SelectionForeColorChangedEvent]);
711                         if (eh != null)
712                                 eh (this, e);
713                 }
714
715                 public void ResetAlternatingBackColor ()
716                 {
717                         AlternatingBackColor = def_alternating_backcolor;
718                 }
719
720                 public void ResetBackColor ()
721                 {
722                         BackColor = def_backcolor;
723                 }
724
725                 public void ResetForeColor ()
726                 {
727                         ForeColor = def_forecolor;
728                 }
729
730                 public void ResetGridLineColor ()
731                 {
732                         GridLineColor = def_gridline_color;
733                 }
734
735                 public void ResetHeaderBackColor ()
736                 {
737                         HeaderBackColor = def_header_backcolor;
738                 }
739
740                 public void ResetHeaderFont ()
741                 {
742                         HeaderFont = def_header_font;
743                 }
744
745                 public void ResetHeaderForeColor ()
746                 {
747                         HeaderForeColor = def_header_forecolor;
748                 }
749
750                 public void ResetLinkColor ()
751                 {
752                         LinkColor = def_link_color;
753                 }
754
755                 public void ResetLinkHoverColor ()
756                 {
757                         LinkHoverColor = def_link_hovercolor;
758                 }
759
760                 public void ResetSelectionBackColor ()
761                 {
762                         SelectionBackColor = def_selection_backcolor;
763                 }
764
765                 public void ResetSelectionForeColor ()
766                 {
767                         SelectionForeColor = def_selection_forecolor;
768                 }
769
770                 protected virtual bool ShouldSerializeAlternatingBackColor ()
771                 {
772                         return (alternating_backcolor != def_alternating_backcolor);
773                 }
774
775                 protected bool ShouldSerializeBackColor ()
776                 {
777                         return (backcolor != def_backcolor);
778                 }
779
780                 protected bool ShouldSerializeForeColor ()
781                 {
782                         return (forecolor != def_forecolor);
783                 }
784
785                 protected virtual bool ShouldSerializeGridLineColor ()
786                 {
787                         return (gridline_color != def_gridline_color);
788                 }
789
790                 protected virtual bool ShouldSerializeHeaderBackColor ()
791                 {
792                         return (header_backcolor != def_header_backcolor);
793                 }
794
795                 protected virtual bool ShouldSerializeHeaderForeColor ()
796                 {
797                         return (header_forecolor != def_header_forecolor);
798                 }
799
800                 protected virtual bool ShouldSerializeLinkColor ()
801                 {
802                         return (link_color != def_link_color);
803                 }
804
805                 protected virtual bool ShouldSerializeLinkHoverColor ()
806                 {
807                         return (link_hovercolor != def_link_hovercolor);
808                 }
809
810                 protected bool ShouldSerializePreferredRowHeight ()
811                 {
812                         return (preferredrow_height != def_preferredrow_height);
813                 }
814
815                 protected bool ShouldSerializeSelectionBackColor ()
816                 {
817                         return (selection_backcolor != def_selection_backcolor);
818                 }
819
820                 protected virtual bool ShouldSerializeSelectionForeColor ()
821                 {
822                         return (selection_forecolor != def_selection_forecolor);
823                 }
824                 #endregion      // Protected Instance Methods
825
826                 #region Private Instance Properties
827                 // Create column styles for this TableStyle
828                 internal void CreateColumnsForTable (bool onlyBind)
829                 {
830                         CurrencyManager mgr = manager;
831                         DataGridColumnStyle st;
832
833                         if (mgr == null) {
834                                 mgr = datagrid.ListManager;
835
836                                 if (mgr == null)
837                                         return;
838                         }
839
840                         for (int i = 0; i < column_styles.Count; i ++)
841                                 column_styles[i].bound = false;
842
843                         table_relations.Clear ();
844                         PropertyDescriptorCollection propcol = mgr.GetItemProperties ();
845
846                         for (int i = 0; i < propcol.Count; i++)
847                         {
848                                 // The column style is already provided by the user
849                                 st = column_styles[propcol[i].Name];
850                                 if (st != null) {
851                                         if (st.Width == -1)
852                                                 st.Width = CurrentPreferredColumnWidth;
853
854                                         st.PropertyDescriptor = propcol[i];
855                                         st.bound = true;
856                                         continue;
857                                 }
858
859                                 if (onlyBind == true)
860                                         continue;
861
862                                 if (typeof (IBindingList).IsAssignableFrom (propcol[i].PropertyType)) {
863                                         table_relations.Add (propcol[i].Name);
864                                 } else {
865                                         st = CreateGridColumn (propcol[i],  true);
866                                         st.bound = true;
867                                         st.grid = datagrid;
868                                         st.MappingName = propcol[i].Name;
869                                         st.HeaderText = propcol[i].Name;
870                                         st.Width = CurrentPreferredColumnWidth;
871                                         column_styles.Add (st);
872                                 }
873                         }
874
875                 }
876
877                 #endregion Private Instance Properties
878
879                 #region Events
880                 static object AllowSortingChangedEvent = new object ();
881                 static object AlternatingBackColorChangedEvent = new object ();
882                 static object BackColorChangedEvent = new object ();
883                 static object ColumnHeadersVisibleChangedEvent = new object ();
884                 static object ForeColorChangedEvent = new object ();
885                 static object GridLineColorChangedEvent = new object ();
886                 static object GridLineStyleChangedEvent = new object ();
887                 static object HeaderBackColorChangedEvent = new object ();
888                 static object HeaderFontChangedEvent = new object ();
889                 static object HeaderForeColorChangedEvent = new object ();
890                 static object LinkColorChangedEvent = new object ();
891                 static object LinkHoverColorChangedEvent = new object ();
892                 static object MappingNameChangedEvent = new object ();
893                 static object PreferredColumnWidthChangedEvent = new object ();
894                 static object PreferredRowHeightChangedEvent = new object ();
895                 static object ReadOnlyChangedEvent = new object ();
896                 static object RowHeadersVisibleChangedEvent = new object ();
897                 static object RowHeaderWidthChangedEvent = new object ();
898                 static object SelectionBackColorChangedEvent = new object ();
899                 static object SelectionForeColorChangedEvent = new object ();
900
901                 public event EventHandler AllowSortingChanged {
902                         add { Events.AddHandler (AllowSortingChangedEvent, value); }
903                         remove { Events.RemoveHandler (AllowSortingChangedEvent, value); }
904                 }
905
906                 public event EventHandler AlternatingBackColorChanged {
907                         add { Events.AddHandler (AlternatingBackColorChangedEvent, value); }
908                         remove { Events.RemoveHandler (AlternatingBackColorChangedEvent, value); }
909                 }
910
911                 public event EventHandler BackColorChanged {
912                         add { Events.AddHandler (BackColorChangedEvent, value); }
913                         remove { Events.RemoveHandler (BackColorChangedEvent, value); }
914                 }
915
916                 public event EventHandler ColumnHeadersVisibleChanged {
917                         add { Events.AddHandler (ColumnHeadersVisibleChangedEvent, value); }
918                         remove { Events.RemoveHandler (ColumnHeadersVisibleChangedEvent, value); }
919                 }
920
921                 public event EventHandler ForeColorChanged {
922                         add { Events.AddHandler (ForeColorChangedEvent, value); }
923                         remove { Events.RemoveHandler (ForeColorChangedEvent, value); }
924                 }
925
926                 public event EventHandler GridLineColorChanged {
927                         add { Events.AddHandler (GridLineColorChangedEvent, value); }
928                         remove { Events.RemoveHandler (GridLineColorChangedEvent, value); }
929                 }
930
931                 public event EventHandler GridLineStyleChanged {
932                         add { Events.AddHandler (GridLineStyleChangedEvent, value); }
933                         remove { Events.RemoveHandler (GridLineStyleChangedEvent, value); }
934                 }
935
936                 public event EventHandler HeaderBackColorChanged {
937                         add { Events.AddHandler (HeaderBackColorChangedEvent, value); }
938                         remove { Events.RemoveHandler (HeaderBackColorChangedEvent, value); }
939                 }
940
941                 public event EventHandler HeaderFontChanged {
942                         add { Events.AddHandler (HeaderFontChangedEvent, value); }
943                         remove { Events.RemoveHandler (HeaderFontChangedEvent, value); }
944                 }
945
946                 public event EventHandler HeaderForeColorChanged {
947                         add { Events.AddHandler (HeaderForeColorChangedEvent, value); }
948                         remove { Events.RemoveHandler (HeaderForeColorChangedEvent, value); }
949                 }
950
951                 public event EventHandler LinkColorChanged {
952                         add { Events.AddHandler (LinkColorChangedEvent, value); }
953                         remove { Events.RemoveHandler (LinkColorChangedEvent, value); }
954                 }
955
956                 public event EventHandler LinkHoverColorChanged {
957                         add { Events.AddHandler (LinkHoverColorChangedEvent, value); }
958                         remove { Events.RemoveHandler (LinkHoverColorChangedEvent, value); }
959                 }
960
961                 public event EventHandler MappingNameChanged {
962                         add { Events.AddHandler (MappingNameChangedEvent, value); }
963                         remove { Events.RemoveHandler (MappingNameChangedEvent, value); }
964                 }
965
966                 public event EventHandler PreferredColumnWidthChanged {
967                         add { Events.AddHandler (PreferredColumnWidthChangedEvent, value); }
968                         remove { Events.RemoveHandler (PreferredColumnWidthChangedEvent, value); }
969                 }
970
971                 public event EventHandler PreferredRowHeightChanged {
972                         add { Events.AddHandler (PreferredRowHeightChangedEvent, value); }
973                         remove { Events.RemoveHandler (PreferredRowHeightChangedEvent, value); }
974                 }
975
976                 public event EventHandler ReadOnlyChanged {
977                         add { Events.AddHandler (ReadOnlyChangedEvent, value); }
978                         remove { Events.RemoveHandler (ReadOnlyChangedEvent, value); }
979                 }
980
981                 public event EventHandler RowHeadersVisibleChanged {
982                         add { Events.AddHandler (RowHeadersVisibleChangedEvent, value); }
983                         remove { Events.RemoveHandler (RowHeadersVisibleChangedEvent, value); }
984                 }
985
986                 public event EventHandler RowHeaderWidthChanged {
987                         add { Events.AddHandler (RowHeaderWidthChangedEvent, value); }
988                         remove { Events.RemoveHandler (RowHeaderWidthChangedEvent, value); }
989                 }
990
991                 public event EventHandler SelectionBackColorChanged {
992                         add { Events.AddHandler (SelectionBackColorChangedEvent, value); }
993                         remove { Events.RemoveHandler (SelectionBackColorChangedEvent, value); }
994                 }
995
996                 public event EventHandler SelectionForeColorChanged {
997                         add { Events.AddHandler (SelectionForeColorChangedEvent, value); }
998                         remove { Events.RemoveHandler (SelectionForeColorChangedEvent, value); }
999                 }
1000                 #endregion      // Events
1001         }
1002 }