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