2005-04-01 Jordi Mas i Hernandez <jordi@ximian.com>
[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.ComponentModel;
32 using System.Drawing;
33 using System.Runtime.InteropServices;
34
35 namespace System.Windows.Forms
36 {
37         public class DataGridTableStyle : Component
38         {
39                 #region Local Variables
40                 private static readonly Color           def_alternating_backcolor = SystemColors.Window;
41                 private static readonly Color           def_backcolor = SystemColors.Window;
42                 private static readonly Color           def_forecolor = SystemColors.WindowText;
43                 private static readonly Color           def_gridline_color = SystemColors.Control;
44                 private static readonly Color           def_header_backcolor = SystemColors.Control;
45                 private static readonly Font            def_header_font = null;
46                 private static readonly Color           def_header_forecolor = SystemColors.ControlText;
47                 private static readonly Color           def_link_color = SystemColors.HotTrack;
48                 private static readonly Color           def_link_hovercolor = SystemColors.HotTrack;
49                 private static readonly Color           def_selection_backcolor = SystemColors.ActiveCaption;
50                 private static readonly Color           def_selection_forecolor = SystemColors.ActiveCaptionText;
51
52                 private bool                            allow_sorting;
53                 private DataGrid                        datagrid;
54                 private Color                           header_forecolor;
55                 private string                          mapping_name;
56                 private Color                           alternating_backcolor;
57                 private bool                            columnheaders_visible;
58                 private GridColumnStylesCollection      column_styles;
59                 private Color                           gridline_color;
60                 private DataGridLineStyle               gridline_style;
61                 private Color                           header_backcolor;
62                 private Font                            header_font;
63                 private Color                           link_color;
64                 private Color                           link_hovercolor;
65                 private int                             preferredcolumn_width;
66                 private int                             preferredrow_height;
67                 private bool                            _readonly;
68                 private bool                            rowheaders_visible;
69                 private Color                           selection_backcolor;
70                 private Color                           selection_forecolor;
71                 private int                             rowheaders_width;
72                 private Color                           backcolor;
73                 private Color                           forecolor;
74                 private bool                            is_default;
75                 #endregion      // Local Variables
76
77                 #region Constructors
78                 public DataGridTableStyle ()
79                 {
80                         CommonConstructor ();
81                         is_default = false;
82                 }
83
84                 public DataGridTableStyle (bool isDefaultTableStyle)
85                 {
86                         CommonConstructor ();
87                         is_default = isDefaultTableStyle;
88                 }
89
90                 // TODO: What to do with the CurrencyManager
91                 public DataGridTableStyle (CurrencyManager listManager)
92                 {
93                         CommonConstructor ();
94                         is_default = false;
95                 }
96
97                 private void CommonConstructor ()
98                 {
99                         allow_sorting = true;
100                         datagrid = null;
101                         header_forecolor = def_header_forecolor;
102                         mapping_name = string.Empty;
103                         column_styles = new GridColumnStylesCollection (this);
104
105                         alternating_backcolor = def_alternating_backcolor;
106                         columnheaders_visible = true;
107                         gridline_color = def_gridline_color;
108                         gridline_style = DataGridLineStyle.Solid;
109                         header_backcolor = def_header_backcolor;
110                         header_font = def_header_font;
111                         link_color = def_link_color;
112                         link_hovercolor = def_link_hovercolor;
113                         preferredcolumn_width = 75;
114                         preferredrow_height = ThemeEngine.Current.DefaultFont.Height + 3;
115                         _readonly = false;
116                         rowheaders_visible = true;
117                         selection_backcolor = def_selection_backcolor;
118                         selection_forecolor = def_selection_forecolor;
119                         rowheaders_width = 35;
120                         backcolor = def_backcolor;
121                         forecolor = def_forecolor;
122                 }
123                 #endregion
124
125                 #region Public Instance Properties
126                 public bool AllowSorting {
127                         get {
128                                 return allow_sorting;
129                         }
130
131                         set {
132                                 if (allow_sorting != value) {
133                                         allow_sorting = value;
134                                         OnAllowSortingChanged (EventArgs.Empty);
135                                 }
136                         }
137                 }
138
139                 public Color AlternatingBackColor {
140                         get {
141                                 return alternating_backcolor;
142                         }
143
144                         set {
145                                 if (!alternating_backcolor.Equals (value)) {
146                                         alternating_backcolor = value;
147                                         OnAlternatingBackColorChanged (EventArgs.Empty);
148                                 }
149                         }
150                 }
151
152                 public Color BackColor {
153                         get {
154                                 return backcolor;
155                         }
156
157                         set {
158                                 if (!backcolor.Equals (value)) {
159                                         backcolor = value;
160                                         OnBackColorChanged (EventArgs.Empty);
161                                 }
162                         }
163                 }
164
165                 public bool ColumnHeadersVisible {
166                         get {
167                                 return columnheaders_visible;
168                         }
169
170                         set {
171                                 if (columnheaders_visible != value) {
172                                         columnheaders_visible = value;
173                                         OnColumnHeadersVisibleChanged (EventArgs.Empty);
174                                 }
175                         }
176                 }
177
178                 public virtual DataGrid DataGrid {
179                         get {
180                                 return datagrid;
181                         }
182
183                         set {
184                                 if (datagrid != value) {
185                                         datagrid = value;
186                                 }
187                         }
188                 }
189
190                 public Color ForeColor {
191                         get {
192                                 return forecolor;
193                         }
194
195                         set {
196                                 if (!forecolor.Equals (value)) {
197                                         forecolor = value;
198                                         OnForeColorChanged (EventArgs.Empty);
199                                 }
200                         }
201                 }
202
203                 public virtual GridColumnStylesCollection GridColumnStyles {
204                         get { return column_styles; }
205                 }
206
207                 public Color GridLineColor {
208                         get {
209                                 return gridline_color;
210                         }
211
212                         set {
213                                 if (!gridline_color.Equals (value)) {
214                                         gridline_color = value;
215                                         OnGridLineColorChanged (EventArgs.Empty);
216                                 }
217                         }
218                 }
219
220                 public DataGridLineStyle GridLineStyle {
221                         get {
222                                 return gridline_style;
223                         }
224
225                         set {
226                                 if (gridline_style != value) {
227                                         gridline_style = value;
228                                         OnGridLineStyleChanged (EventArgs.Empty);
229                                 }
230                         }
231                 }
232
233                 public Color HeaderBackColor {
234                         get {
235                                 return header_backcolor;
236                         }
237
238                         set {
239                                 if (!header_backcolor.Equals (value)) {
240                                         header_backcolor = value;
241                                         OnHeaderBackColorChanged (EventArgs.Empty);
242                                 }
243                         }
244                 }
245
246                 public Font HeaderFont {
247                         get {
248                                 if (header_font != null)
249                                         return header_font;
250
251                                 if (datagrid != null)
252                                         return datagrid.Font;
253
254                                 return ThemeEngine.Current.DefaultFont;
255                         }
256
257                         set {
258                                 if (header_font != value) {
259                                         header_font = value;
260                                         OnHeaderFontChanged (EventArgs.Empty);
261                                 }
262                         }
263                 }
264
265                 public Color HeaderForeColor {
266                         get {
267                                 return header_forecolor;
268                         }
269
270                         set {
271
272                                 if (!header_forecolor.Equals (value)) {
273                                         header_forecolor = value;
274                                         OnHeaderForeColorChanged (EventArgs.Empty);
275                                 }
276                         }
277                 }
278
279                 public Color LinkColor {
280                         get {
281                                 return link_color;
282                         }
283
284                         set {
285                                 if (!link_color.Equals (value)) {
286                                         link_color = value;
287                                         OnLinkColorChanged (EventArgs.Empty);
288                                 }
289                         }
290                 }
291
292                 [ComVisible(false)]
293                 public Color LinkHoverColor {
294                         get {
295                                 return link_hovercolor;
296                         }
297
298                         set {
299                                 if (!link_hovercolor.Equals (value)) {
300                                         link_hovercolor = value;
301                                         OnLinkHoverColorChanged (EventArgs.Empty);
302                                 }
303                         }
304                 }
305
306                 public string MappingName {
307                         get {
308                                 return mapping_name;
309                         }
310
311                         set {
312                                 if (mapping_name != value) {
313                                         mapping_name = value;
314                                         OnMappingNameChanged (EventArgs.Empty);
315                                 }
316                         }
317                 }
318
319                 public int PreferredColumnWidth {
320                         get {
321                                 return preferredcolumn_width;
322                         }
323
324                         set {
325                                 if (preferredcolumn_width != value) {
326                                         preferredcolumn_width = value;
327                                         OnPreferredColumnWidthChanged (EventArgs.Empty);
328                                 }
329                         }
330                 }
331
332                 public int PreferredRowHeight {
333                         get {
334                                 return preferredrow_height;
335                         }
336
337                         set {
338                                 if (preferredrow_height != value) {
339                                         preferredrow_height = value;
340                                         OnPreferredRowHeightChanged (EventArgs.Empty);
341                                 }
342                         }
343                 }
344
345                 public bool ReadOnly {
346                         get {
347                                 return _readonly;
348                         }
349
350                         set {
351                                 if (_readonly != value) {
352                                         _readonly = value;
353                                         OnReadOnlyChanged (EventArgs.Empty);
354                                 }
355                         }
356                 }
357
358                 public bool RowHeadersVisible {
359                         get {
360                                 return rowheaders_visible;
361                         }
362
363                         set {
364                                 if (rowheaders_visible != value) {
365                                         rowheaders_visible = value;
366                                         OnRowHeadersVisibleChanged (EventArgs.Empty);
367                                 }
368                         }
369                 }
370
371                 public int RowHeaderWidth {
372                         get {
373                                 return rowheaders_width;
374                         }
375
376                         set {
377                                 if (rowheaders_width != value) {
378                                         rowheaders_width = value;
379                                         OnRowHeaderWidthChanged (EventArgs.Empty);
380                                 }
381                         }
382                 }
383
384                 public Color SelectionBackColor {
385                         get {
386                                 return selection_backcolor;
387                         }
388
389                         set {
390                                 if (!selection_backcolor.Equals (value)) {
391                                         selection_backcolor = value;
392                                         OnSelectionBackColorChanged (EventArgs.Empty);
393                                 }
394                         }
395                 }
396
397                 public Color SelectionForeColor  {
398                         get {
399                                 return selection_forecolor;
400                         }
401
402                         set {
403                                 if (!selection_forecolor.Equals (value)) {
404                                         selection_forecolor = value;
405                                         OnSelectionForeColorChanged (EventArgs.Empty);
406                                 }
407                         }
408                 }
409
410                 #endregion      // Public Instance Properties
411
412                 #region Public Instance Methods
413
414                 [MonoTODO]
415                 public virtual bool BeginEdit (DataGridColumnStyle gridColumn,  int rowNumber)
416                 {
417                         throw new NotImplementedException ();
418                 }
419
420                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
421                 {
422                         throw new NotImplementedException ();
423                 }
424
425                 // TODO: How to specify the isDefault boolean
426                 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop,  bool isDefault)
427                 {
428                         throw new NotImplementedException ();
429
430                 }
431
432                 protected override void Dispose (bool disposing)
433                 {
434                         base.Dispose (disposing);
435                 }
436
437                 [MonoTODO]
438                 public virtual bool EndEdit ( DataGridColumnStyle gridColumn,  int rowNumber,  bool shouldAbort)
439                 {
440                         throw new NotImplementedException ();
441                 }
442
443                 protected virtual void OnAllowSortingChanged (EventArgs e)
444                 {
445                         if (AllowSortingChanged != null) {
446                                 AllowSortingChanged (this, e);
447                         }
448                 }
449
450                 protected virtual void OnAlternatingBackColorChanged (EventArgs e)
451                 {
452                         if (AlternatingBackColorChanged != null) {
453                                 AlternatingBackColorChanged (this, e);
454                         }
455                 }
456
457                 protected virtual void OnBackColorChanged (EventArgs e)
458                 {
459                         if (BackColorChanged != null) {
460                                 BackColorChanged (this, e);
461                         }
462                 }
463
464                 protected virtual void OnColumnHeadersVisibleChanged (EventArgs e)
465                 {
466                         if (ColumnHeadersVisibleChanged != null) {
467                                 ColumnHeadersVisibleChanged (this, e);
468                         }
469                 }
470
471                 protected virtual void OnForeColorChanged (EventArgs e)
472                 {
473                         if (ForeColorChanged != null) {
474                                 ForeColorChanged (this, e);
475                         }
476                 }
477
478                 protected virtual void OnGridLineColorChanged (EventArgs e)
479                 {
480                         if (GridLineColorChanged != null) {
481                                 GridLineColorChanged (this, e);
482                         }
483                 }
484
485                 protected virtual void OnGridLineStyleChanged (EventArgs e)
486                 {
487                         if (GridLineStyleChanged != null) {
488                                 GridLineStyleChanged (this, e);
489                         }
490                 }
491
492                 protected virtual void OnHeaderBackColorChanged (EventArgs e)
493                 {
494                         if (HeaderBackColorChanged != null) {
495                                 HeaderBackColorChanged (this, e);
496                         }
497                 }
498
499                 protected virtual void OnHeaderFontChanged (EventArgs e)
500                 {
501                         if (HeaderFontChanged != null) {
502                                 HeaderFontChanged (this, e);
503                         }
504                 }
505
506                 protected virtual void OnHeaderForeColorChanged (EventArgs e)
507                 {
508                         if (HeaderForeColorChanged != null) {
509                                 HeaderForeColorChanged (this, e);
510                         }
511                 }
512
513                 protected virtual void OnLinkColorChanged (EventArgs e)
514                 {
515                         if (LinkColorChanged != null) {
516                                 LinkColorChanged (this, e);
517                         }
518                 }
519
520                 protected virtual void OnLinkHoverColorChanged (EventArgs e)
521                 {
522                         if (LinkHoverColorChanged != null) {
523                                 LinkHoverColorChanged (this, e);
524                         }
525                 }
526
527                 protected virtual void OnMappingNameChanged (EventArgs e)
528                 {
529                         if (MappingNameChanged != null) {
530                                 MappingNameChanged(this, e);
531                         }
532                 }
533
534                 protected virtual void OnPreferredColumnWidthChanged (EventArgs e)
535                 {
536                         if (PreferredColumnWidthChanged != null) {
537                                 PreferredColumnWidthChanged (this, e);
538                         }
539                 }
540
541                 protected virtual void OnPreferredRowHeightChanged (EventArgs e)
542                 {
543                         if (PreferredRowHeightChanged != null) {
544                                 PreferredRowHeightChanged (this, e);
545                         }
546                 }
547
548                 protected virtual void OnReadOnlyChanged (EventArgs e)
549                 {
550                         if (ReadOnlyChanged != null) {
551                                 ReadOnlyChanged (this, e);
552                         }
553                 }
554
555                 protected virtual void OnRowHeadersVisibleChanged (EventArgs e)
556                 {
557                         if (RowHeadersVisibleChanged != null) {
558                                 RowHeadersVisibleChanged (this, e);
559                         }
560                 }
561
562                 protected virtual void OnRowHeaderWidthChanged (EventArgs e)
563                 {
564                         if (RowHeaderWidthChanged != null) {
565                                 RowHeaderWidthChanged (this, e);
566                         }
567                 }
568
569                 protected virtual void OnSelectionBackColorChanged (EventArgs e)
570                 {
571                         if (SelectionBackColorChanged != null) {
572                                 SelectionBackColorChanged (this, e);
573                         }
574                 }
575
576                 protected virtual void OnSelectionForeColorChanged (EventArgs e)
577                 {
578                         if (SelectionForeColorChanged != null) {
579                                 SelectionForeColorChanged (this, e);
580                         }
581                 }
582
583                 public void ResetAlternatingBackColor ()
584                 {
585                         AlternatingBackColor = def_alternating_backcolor;
586                 }
587
588                 public void ResetBackColor ()
589                 {
590                         BackColor = def_backcolor;
591                 }
592
593                 public void ResetForeColor ()
594                 {
595                         ForeColor = def_forecolor;
596                 }
597
598                 public void ResetGridLineColor ()
599                 {
600                         GridLineColor = def_gridline_color;
601                 }
602
603                 public void ResetHeaderBackColor ()
604                 {
605                         HeaderBackColor = def_header_backcolor;
606                 }
607
608                 public void ResetHeaderFont ()
609                 {
610                         HeaderFont = def_header_font;
611                 }
612
613                 public void ResetHeaderForeColor ()
614                 {
615                         HeaderForeColor = def_header_forecolor;
616                 }
617
618                 public void ResetLinkColor ()
619                 {
620                         LinkColor = def_link_color;
621                 }
622
623                 public void ResetLinkHoverColor ()
624                 {
625                         LinkHoverColor = def_link_hovercolor;
626                 }
627
628                 public void ResetSelectionBackColor ()
629                 {
630                         SelectionBackColor = def_selection_backcolor;
631                 }
632
633                 public void ResetSelectionForeColor ()
634                 {
635                         SelectionForeColor = def_selection_forecolor;
636                 }
637
638                 protected virtual bool ShouldSerializeAlternatingBackColor ()
639                 {
640                         return (!alternating_backcolor.Equals (def_alternating_backcolor));
641                 }
642
643                 protected bool ShouldSerializeBackColor ()
644                 {
645                         return (!backcolor.Equals (def_backcolor));
646                 }
647
648                 protected bool ShouldSerializeForeColor ()
649                 {
650                         return (!forecolor.Equals (def_forecolor));
651                 }
652
653                 protected virtual bool ShouldSerializeGridLineColor ()
654                 {
655                         return (!gridline_color.Equals (def_gridline_color));
656                 }
657
658                 protected virtual bool ShouldSerializeHeaderBackColor ()
659                 {
660                         return (!header_backcolor.Equals (def_header_backcolor));
661                 }
662
663                 protected virtual bool ShouldSerializeHeaderForeColor ()
664                 {
665                         return (!header_forecolor.Equals (def_header_forecolor));
666                 }
667
668                 protected virtual bool ShouldSerializeLinkColor ()
669                 {
670                         return (!link_color.Equals (def_link_color));
671                 }
672
673                 protected virtual bool ShouldSerializeLinkHoverColor ()
674                 {
675                         return (!link_hovercolor.Equals (def_link_hovercolor));
676                 }
677
678                 protected bool ShouldSerializePreferredRowHeight ()
679                 {
680                         return (preferredrow_height != ThemeEngine.Current.DefaultFont.Height + 3);
681                 }
682
683                 protected bool ShouldSerializeSelectionBackColor ()
684                 {
685                         return (!selection_backcolor.Equals (def_selection_backcolor));
686                 }
687
688                 protected virtual bool ShouldSerializeSelectionForeColor ()
689                 {
690                         return (!selection_forecolor.Equals (def_selection_forecolor));
691                 }
692                 #endregion      // Protected Instance Methods
693
694                 #region Events
695                 public event EventHandler AllowSortingChanged;
696                 public event EventHandler AlternatingBackColorChanged;
697                 public event EventHandler BackColorChanged;
698                 public event EventHandler ColumnHeadersVisibleChanged;
699                 public event EventHandler ForeColorChanged;
700                 public event EventHandler GridLineColorChanged;
701                 public event EventHandler GridLineStyleChanged;
702                 public event EventHandler HeaderBackColorChanged;
703                 public event EventHandler HeaderFontChanged;
704                 public event EventHandler HeaderForeColorChanged;
705                 public event EventHandler LinkColorChanged;
706                 public event EventHandler LinkHoverColorChanged;
707                 public event EventHandler MappingNameChanged;
708                 public event EventHandler PreferredColumnWidthChanged;
709                 public event EventHandler PreferredRowHeightChanged;
710                 public event EventHandler ReadOnlyChanged;
711                 public event EventHandler RowHeadersVisibleChanged;
712                 public event EventHandler RowHeaderWidthChanged;
713                 public event EventHandler SelectionBackColorChanged;
714                 public event EventHandler SelectionForeColorChanged;
715                 #endregion      // Events
716         }
717 }
718