1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
24 // Peter Bartok <pbartok@novell.com>
25 // Jordi Mas i Hernandez <jordi@ximian.com>
31 using System.ComponentModel;
33 using System.Runtime.InteropServices;
35 namespace System.Windows.Forms
37 public class DataGridTableStyle : Component
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;
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
78 public DataGridTableStyle ()
84 public DataGridTableStyle (bool isDefaultTableStyle)
87 is_default = isDefaultTableStyle;
90 // TODO: What to do with the CurrencyManager
91 public DataGridTableStyle (CurrencyManager listManager)
97 private void CommonConstructor ()
101 header_forecolor = def_header_forecolor;
102 mapping_name = string.Empty;
103 column_styles = new GridColumnStylesCollection (this);
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;
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;
125 #region Public Instance Properties
126 public bool AllowSorting {
128 return allow_sorting;
132 if (allow_sorting != value) {
133 allow_sorting = value;
134 OnAllowSortingChanged (EventArgs.Empty);
139 public Color AlternatingBackColor {
141 return alternating_backcolor;
145 if (!alternating_backcolor.Equals (value)) {
146 alternating_backcolor = value;
147 OnAlternatingBackColorChanged (EventArgs.Empty);
152 public Color BackColor {
158 if (!backcolor.Equals (value)) {
160 OnBackColorChanged (EventArgs.Empty);
165 public bool ColumnHeadersVisible {
167 return columnheaders_visible;
171 if (columnheaders_visible != value) {
172 columnheaders_visible = value;
173 OnColumnHeadersVisibleChanged (EventArgs.Empty);
178 public virtual DataGrid DataGrid {
184 if (datagrid != value) {
190 public Color ForeColor {
196 if (!forecolor.Equals (value)) {
198 OnForeColorChanged (EventArgs.Empty);
203 public virtual GridColumnStylesCollection GridColumnStyles {
204 get { return column_styles; }
207 public Color GridLineColor {
209 return gridline_color;
213 if (!gridline_color.Equals (value)) {
214 gridline_color = value;
215 OnGridLineColorChanged (EventArgs.Empty);
220 public DataGridLineStyle GridLineStyle {
222 return gridline_style;
226 if (gridline_style != value) {
227 gridline_style = value;
228 OnGridLineStyleChanged (EventArgs.Empty);
233 public Color HeaderBackColor {
235 return header_backcolor;
239 if (!header_backcolor.Equals (value)) {
240 header_backcolor = value;
241 OnHeaderBackColorChanged (EventArgs.Empty);
246 public Font HeaderFont {
248 if (header_font != null)
251 if (datagrid != null)
252 return datagrid.Font;
254 return ThemeEngine.Current.DefaultFont;
258 if (header_font != value) {
260 OnHeaderFontChanged (EventArgs.Empty);
265 public Color HeaderForeColor {
267 return header_forecolor;
272 if (!header_forecolor.Equals (value)) {
273 header_forecolor = value;
274 OnHeaderForeColorChanged (EventArgs.Empty);
279 public Color LinkColor {
285 if (!link_color.Equals (value)) {
287 OnLinkColorChanged (EventArgs.Empty);
293 public Color LinkHoverColor {
295 return link_hovercolor;
299 if (!link_hovercolor.Equals (value)) {
300 link_hovercolor = value;
301 OnLinkHoverColorChanged (EventArgs.Empty);
306 public string MappingName {
312 if (mapping_name != value) {
313 mapping_name = value;
314 OnMappingNameChanged (EventArgs.Empty);
319 public int PreferredColumnWidth {
321 return preferredcolumn_width;
325 if (preferredcolumn_width != value) {
326 preferredcolumn_width = value;
327 OnPreferredColumnWidthChanged (EventArgs.Empty);
332 public int PreferredRowHeight {
334 return preferredrow_height;
338 if (preferredrow_height != value) {
339 preferredrow_height = value;
340 OnPreferredRowHeightChanged (EventArgs.Empty);
345 public bool ReadOnly {
351 if (_readonly != value) {
353 OnReadOnlyChanged (EventArgs.Empty);
358 public bool RowHeadersVisible {
360 return rowheaders_visible;
364 if (rowheaders_visible != value) {
365 rowheaders_visible = value;
366 OnRowHeadersVisibleChanged (EventArgs.Empty);
371 public int RowHeaderWidth {
373 return rowheaders_width;
377 if (rowheaders_width != value) {
378 rowheaders_width = value;
379 OnRowHeaderWidthChanged (EventArgs.Empty);
384 public Color SelectionBackColor {
386 return selection_backcolor;
390 if (!selection_backcolor.Equals (value)) {
391 selection_backcolor = value;
392 OnSelectionBackColorChanged (EventArgs.Empty);
397 public Color SelectionForeColor {
399 return selection_forecolor;
403 if (!selection_forecolor.Equals (value)) {
404 selection_forecolor = value;
405 OnSelectionForeColorChanged (EventArgs.Empty);
410 #endregion // Public Instance Properties
412 #region Public Instance Methods
415 public virtual bool BeginEdit (DataGridColumnStyle gridColumn, int rowNumber)
417 throw new NotImplementedException ();
420 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop)
422 throw new NotImplementedException ();
425 // TODO: How to specify the isDefault boolean
426 protected internal virtual DataGridColumnStyle CreateGridColumn (PropertyDescriptor prop, bool isDefault)
428 throw new NotImplementedException ();
432 protected override void Dispose (bool disposing)
434 base.Dispose (disposing);
438 public virtual bool EndEdit ( DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort)
440 throw new NotImplementedException ();
443 protected virtual void OnAllowSortingChanged (EventArgs e)
445 if (AllowSortingChanged != null) {
446 AllowSortingChanged (this, e);
450 protected virtual void OnAlternatingBackColorChanged (EventArgs e)
452 if (AlternatingBackColorChanged != null) {
453 AlternatingBackColorChanged (this, e);
457 protected virtual void OnBackColorChanged (EventArgs e)
459 if (BackColorChanged != null) {
460 BackColorChanged (this, e);
464 protected virtual void OnColumnHeadersVisibleChanged (EventArgs e)
466 if (ColumnHeadersVisibleChanged != null) {
467 ColumnHeadersVisibleChanged (this, e);
471 protected virtual void OnForeColorChanged (EventArgs e)
473 if (ForeColorChanged != null) {
474 ForeColorChanged (this, e);
478 protected virtual void OnGridLineColorChanged (EventArgs e)
480 if (GridLineColorChanged != null) {
481 GridLineColorChanged (this, e);
485 protected virtual void OnGridLineStyleChanged (EventArgs e)
487 if (GridLineStyleChanged != null) {
488 GridLineStyleChanged (this, e);
492 protected virtual void OnHeaderBackColorChanged (EventArgs e)
494 if (HeaderBackColorChanged != null) {
495 HeaderBackColorChanged (this, e);
499 protected virtual void OnHeaderFontChanged (EventArgs e)
501 if (HeaderFontChanged != null) {
502 HeaderFontChanged (this, e);
506 protected virtual void OnHeaderForeColorChanged (EventArgs e)
508 if (HeaderForeColorChanged != null) {
509 HeaderForeColorChanged (this, e);
513 protected virtual void OnLinkColorChanged (EventArgs e)
515 if (LinkColorChanged != null) {
516 LinkColorChanged (this, e);
520 protected virtual void OnLinkHoverColorChanged (EventArgs e)
522 if (LinkHoverColorChanged != null) {
523 LinkHoverColorChanged (this, e);
527 protected virtual void OnMappingNameChanged (EventArgs e)
529 if (MappingNameChanged != null) {
530 MappingNameChanged(this, e);
534 protected virtual void OnPreferredColumnWidthChanged (EventArgs e)
536 if (PreferredColumnWidthChanged != null) {
537 PreferredColumnWidthChanged (this, e);
541 protected virtual void OnPreferredRowHeightChanged (EventArgs e)
543 if (PreferredRowHeightChanged != null) {
544 PreferredRowHeightChanged (this, e);
548 protected virtual void OnReadOnlyChanged (EventArgs e)
550 if (ReadOnlyChanged != null) {
551 ReadOnlyChanged (this, e);
555 protected virtual void OnRowHeadersVisibleChanged (EventArgs e)
557 if (RowHeadersVisibleChanged != null) {
558 RowHeadersVisibleChanged (this, e);
562 protected virtual void OnRowHeaderWidthChanged (EventArgs e)
564 if (RowHeaderWidthChanged != null) {
565 RowHeaderWidthChanged (this, e);
569 protected virtual void OnSelectionBackColorChanged (EventArgs e)
571 if (SelectionBackColorChanged != null) {
572 SelectionBackColorChanged (this, e);
576 protected virtual void OnSelectionForeColorChanged (EventArgs e)
578 if (SelectionForeColorChanged != null) {
579 SelectionForeColorChanged (this, e);
583 public void ResetAlternatingBackColor ()
585 AlternatingBackColor = def_alternating_backcolor;
588 public void ResetBackColor ()
590 BackColor = def_backcolor;
593 public void ResetForeColor ()
595 ForeColor = def_forecolor;
598 public void ResetGridLineColor ()
600 GridLineColor = def_gridline_color;
603 public void ResetHeaderBackColor ()
605 HeaderBackColor = def_header_backcolor;
608 public void ResetHeaderFont ()
610 HeaderFont = def_header_font;
613 public void ResetHeaderForeColor ()
615 HeaderForeColor = def_header_forecolor;
618 public void ResetLinkColor ()
620 LinkColor = def_link_color;
623 public void ResetLinkHoverColor ()
625 LinkHoverColor = def_link_hovercolor;
628 public void ResetSelectionBackColor ()
630 SelectionBackColor = def_selection_backcolor;
633 public void ResetSelectionForeColor ()
635 SelectionForeColor = def_selection_forecolor;
638 protected virtual bool ShouldSerializeAlternatingBackColor ()
640 return (!alternating_backcolor.Equals (def_alternating_backcolor));
643 protected bool ShouldSerializeBackColor ()
645 return (!backcolor.Equals (def_backcolor));
648 protected bool ShouldSerializeForeColor ()
650 return (!forecolor.Equals (def_forecolor));
653 protected virtual bool ShouldSerializeGridLineColor ()
655 return (!gridline_color.Equals (def_gridline_color));
658 protected virtual bool ShouldSerializeHeaderBackColor ()
660 return (!header_backcolor.Equals (def_header_backcolor));
663 protected virtual bool ShouldSerializeHeaderForeColor ()
665 return (!header_forecolor.Equals (def_header_forecolor));
668 protected virtual bool ShouldSerializeLinkColor ()
670 return (!link_color.Equals (def_link_color));
673 protected virtual bool ShouldSerializeLinkHoverColor ()
675 return (!link_hovercolor.Equals (def_link_hovercolor));
678 protected bool ShouldSerializePreferredRowHeight ()
680 return (preferredrow_height != ThemeEngine.Current.DefaultFont.Height + 3);
683 protected bool ShouldSerializeSelectionBackColor ()
685 return (!selection_backcolor.Equals (def_selection_backcolor));
688 protected virtual bool ShouldSerializeSelectionForeColor ()
690 return (!selection_forecolor.Equals (def_selection_forecolor));
692 #endregion // Protected Instance Methods
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;