refactoring
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Style.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) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Dennis Bartok     (pbartok@novell.com)
24 //
25 //
26
27 using System.ComponentModel;
28 using System.Drawing;
29 using System.Security.Permissions;
30
31 namespace System.Web.UI.WebControls {
32
33         // CAS
34         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
35         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36         // attributes
37 #if NET_2_0
38 // Not until we actually have StyleConverter
39 //      [TypeConverter(typeof(System.Web.UI.WebControls.StyleConverter))]
40 #else
41         [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
42 #endif
43         [ToolboxItem("")]
44         public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager 
45         {
46                 [Flags]
47                 internal enum Styles 
48                 {
49                         None            = 0,
50                         BackColor       = 0x00000001,
51                         BorderColor     = 0x00000002,
52                         BorderStyle     = 0x00000004,
53                         BorderWidth     = 0x00000008,
54                         CssClass        = 0x00000010,
55                         Font            = 0x00000020,
56                         ForeColor       = 0x00000040,
57                         Height          = 0x00000080,
58                         Width           = 0x00000100,
59
60                         // from TableStyle (which doesn't override IsEmpty)
61                         BackImageUrl    = 0x00000200,
62                         CellPadding     = 0x00000400,
63                         CellSpacing     = 0x00000800,
64                         GridLines       = 0x00001000,
65                         HorizontalAlign = 0x00002000,
66
67                         // from TableItemStyle (which doesn't override IsEmpty neither)
68                         VerticalAlign   = 0x00004000,
69                         Wrap            = 0x00008000,
70
71                         // from DataGridPagerStyle (and, once again, no IsEmpty override)
72                         Mode            = 0x00010000,
73                         NextPageText    = 0x00020000,
74                         PageButtonCount = 0x00040000,
75                         Position        = 0x00080000,
76                         PrevPageText    = 0x00100000,
77                         Visible         = 0x00200000
78                         
79                 }
80
81                 #region Fields
82                 internal Styles         styles;
83                 internal StateBag       viewstate;
84                 private FontInfo        fontinfo;
85                 private bool            tracking;
86 #if NET_2_0
87                 private string          registered_class;
88 #endif
89                 #endregion      // Fields
90
91                 #region Public Constructors
92                 public Style() : this(new StateBag()) 
93                 {
94                 }
95
96                 public Style(System.Web.UI.StateBag bag) 
97                 {
98                         if (bag != null) {
99                                 viewstate = bag;
100                         } else {
101                                 viewstate = new StateBag();
102                         }
103                         tracking = false;
104                 }
105                 #endregion      // Public Constructors
106
107                 #region Public Instance Properties
108 #if !NET_2_0
109                 [Bindable(true)]
110 #endif
111                 [DefaultValue(typeof (Color), "")]
112                 [NotifyParentProperty(true)]
113                 [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
114                 [WebSysDescription ("")]
115                 [WebCategory ("Appearance")]
116                 public Color BackColor 
117                 {
118                         get 
119                         {
120                                 if ((styles & Styles.BackColor) == 0) 
121                                 {
122                                         return Color.Empty;
123                                 }
124
125                                 return (Color)viewstate["BackColor"];
126                         }
127
128                         set 
129                         {
130                                 viewstate["BackColor"] = value;
131                                 styles |= Styles.BackColor;
132                         }
133                 }
134
135 #if !NET_2_0
136                 [Bindable(true)]
137 #endif
138                 [DefaultValue(typeof (Color), "")]
139                 [NotifyParentProperty(true)]
140                 [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
141                 [WebSysDescription ("")]
142                 [WebCategory ("Appearance")]
143                 public Color BorderColor 
144                 {
145                         get 
146                         {
147                                 if ((styles & Styles.BorderColor) == 0) 
148                                 {
149                                         return Color.Empty;
150                                 }
151
152                                 return (Color)viewstate["BorderColor"];
153                         }
154
155                         set 
156                         {
157                                 viewstate["BorderColor"] = value;
158                                 styles |= Styles.BorderColor;
159                         }
160                 }
161
162 #if !NET_2_0
163                 [Bindable(true)]
164 #endif
165                 [DefaultValue(BorderStyle.NotSet)]
166                 [NotifyParentProperty(true)]
167                 [WebSysDescription ("")]
168                 [WebCategory ("Appearance")]
169                 public BorderStyle BorderStyle 
170                 {
171                         get 
172                         {
173                                 if ((styles & Styles.BorderStyle) == 0) 
174                                 {
175                                         return BorderStyle.NotSet;
176                                 }
177
178                                 return (BorderStyle)viewstate["BorderStyle"];
179                         }
180
181                         set 
182                         {
183                                 viewstate["BorderStyle"] = value;
184                                 styles |= Styles.BorderStyle;
185                         }
186                 }
187
188 #if !NET_2_0
189                 [Bindable(true)]
190 #endif
191                 [DefaultValue(typeof (Unit), "")]
192                 [NotifyParentProperty(true)]
193                 [WebSysDescription ("")]
194                 [WebCategory ("Appearance")]
195                 public Unit BorderWidth 
196                 {
197                         get 
198                         {
199                                 if ((styles & Styles.BorderWidth) == 0) 
200                                 {
201                                         return Unit.Empty;
202                                 }
203
204                                 return (Unit)viewstate["BorderWidth"];
205                         }
206
207                         set 
208                         {
209                                 if (value.Value < 0) 
210                                 {
211                                         throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
212                                 }
213
214                                 viewstate["BorderWidth"] = value;
215                                 styles |= Styles.BorderWidth;
216                         }
217                 }
218
219                 [DefaultValue("")]
220                 [NotifyParentProperty(true)]
221                 [WebSysDescription ("")]
222                 [WebCategory ("Appearance")]
223                 public string CssClass 
224                 {
225                         get 
226                         {
227                                 if ((styles & Styles.CssClass) == 0) 
228                                 {
229                                         return string.Empty;
230                                 }
231
232                                 return (string)viewstate["CssClass"];
233                         }
234
235                         set 
236                         {
237                                 viewstate["CssClass"] = value;
238                                 styles |= Styles.CssClass;
239                         }
240                 }
241
242                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
243                 [NotifyParentProperty(true)]
244                 [WebSysDescription ("")]
245                 [WebCategory ("Appearance")]
246                 public FontInfo Font 
247                 {
248                         get 
249                         {
250                                 if (fontinfo == null) 
251                                 {
252                                         fontinfo = new FontInfo(this);
253                                 }
254                                 return fontinfo;
255                         }
256                 }
257
258 #if !NET_2_0
259                 [Bindable(true)]
260 #endif
261                 [DefaultValue(typeof (Color), "")]
262                 [NotifyParentProperty(true)]
263                 [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
264                 [WebSysDescription ("")]
265                 [WebCategory ("Appearance")]
266                 public Color ForeColor 
267                 {
268                         get 
269                         {
270                                 if ((styles & Styles.ForeColor) == 0) 
271                                 {
272                                         return Color.Empty;
273                                 }
274
275                                 return (Color)viewstate["ForeColor"];
276                         }
277
278                         set 
279                         {
280                                 viewstate["ForeColor"] = value;
281                                 styles |= Styles.ForeColor;
282                         }
283                 }
284
285 #if !NET_2_0
286                 [Bindable(true)]
287 #endif
288                 [DefaultValue(typeof (Unit), "")]
289                 [NotifyParentProperty(true)]
290                 [WebSysDescription ("")]
291                 [WebCategory ("Appearance")]
292                 public Unit Height 
293                 {
294                         get 
295                         {
296                                 if ((styles & Styles.Height) == 0) 
297                                 {
298                                         return Unit.Empty;
299                                 }
300
301                                 return (Unit)viewstate["Height"];
302                         }
303
304                         set 
305                         {
306                                 if (value.Value < 0) 
307                                 {
308                                         throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
309                                 }
310
311                                 viewstate["Height"] = value;
312                                 styles |= Styles.Height;
313                         }
314                 }
315
316 #if !NET_2_0
317                 [Bindable(true)]
318 #endif
319                 [DefaultValue(typeof (Unit), "")]
320                 [NotifyParentProperty(true)]
321                 [WebSysDescription ("")]
322                 [WebCategory ("Appearance")]
323                 public Unit Width 
324                 {
325                         get 
326                         {
327                                 if ((styles & Styles.Width) == 0) 
328                                 {
329                                         return Unit.Empty;
330                                 }
331
332                                 return (Unit)viewstate["Width"];
333                         }
334
335                         set 
336                         {
337                                 if (value.Value < 0) 
338                                 {
339                                         throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
340                                 }
341
342                                 viewstate["Width"] = value;
343                                 styles |= Styles.Width;
344                         }
345                 }
346                 #endregion      // Public Instance Properties
347
348                 #region Protected Instance Properties
349 #if NET_2_0
350                 [Browsable (false)]
351                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
352                 public virtual bool IsEmpty 
353 #else
354                 protected internal virtual bool IsEmpty 
355 #endif
356                 {
357                         get 
358                         {
359 #if NET_2_0
360                                 return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty) && RegisteredCssClass.Length == 0);
361 #else
362                                 return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
363 #endif
364                         }
365                 }
366
367                 protected bool IsTrackingViewState 
368                 {
369                         get 
370                         {
371                                 return tracking;
372                         }
373                 }
374
375                 [Browsable(false)]
376                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
377                 protected internal StateBag ViewState 
378                 {
379                         get 
380                         {
381                                 return viewstate;
382                         }
383                 }
384                 #endregion      // Protected Instance Properties
385
386                 #region Internal Instance Properties
387                 internal bool AlwaysRenderTextDecoration
388                 {
389                         get
390                         {
391                                 if (viewstate["AlwaysRenderTextDecoration"] == null)
392                                         return false;
393                                 return (bool)viewstate["AlwaysRenderTextDecoration"];
394                         }
395                     
396                         set
397                         {
398                                 viewstate["AlwaysRenderTextDecoration"] = value;
399                         }
400                 }
401                 #endregion      // Internal Instance Properties
402                 
403                 #region Public Instance Methods
404                 public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
405                 {
406                         AddAttributesToRender(writer, null);
407                 }
408
409                 public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
410                 {
411 #if NET_2_0
412                         if (RegisteredCssClass.Length > 0) {
413                                 if (CssClass.Length > 0)
414                                         writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass + " " + RegisteredCssClass);
415                                 else
416                                         writer.AddAttribute (HtmlTextWriterAttribute.Class, RegisteredCssClass);
417                         }
418                         else 
419 #endif
420                         {
421                                 if (CssClass.Length > 0)
422                                         writer.AddAttribute (HtmlTextWriterAttribute.Class, CssClass);
423                                 WriteStyleAttributes (writer);
424                         }
425                 }
426
427                 void WriteStyleAttributes (HtmlTextWriter writer) 
428                 {
429 #if NET_2_0
430                         CssStyleCollection col = new CssStyleCollection (new StateBag ());
431                         FillStyleAttributes (col, null);
432                         foreach (string key in col.Keys) {
433                                 writer.AddStyleAttribute (key, col [key]);
434                         }
435 #else
436                         string s;
437                         Color           color;
438                         BorderStyle     bs;
439                         Unit            u;
440
441                         if ((styles & Styles.BackColor) != 0) {
442                                 color = (Color)viewstate["BackColor"];
443                                 if (!color.IsEmpty)
444                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
445                         }
446
447                         if ((styles & Styles.BorderColor) != 0) {
448                                 color = (Color)viewstate["BorderColor"];
449                                 if (!color.IsEmpty)
450                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
451                         }
452
453                         bool have_width = false;
454                         if ((styles & Styles.BorderWidth) != 0) {
455                                 u = (Unit)viewstate["BorderWidth"];
456                                 if (!u.IsEmpty) {
457                                         if (u.Value > 0)
458                                                 have_width = true;
459                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
460                                 }
461                         }
462
463                         if ((styles & Styles.BorderStyle) != 0) {
464                                 bs = (BorderStyle)viewstate["BorderStyle"];
465                                 if (bs != BorderStyle.NotSet) 
466                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
467                                 else {
468                                         if ((styles & Styles.BorderWidth) != 0)
469                                                 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
470                                 }
471                         } else if (have_width) {
472                                 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
473                         }
474
475                         if ((styles & Styles.ForeColor) != 0) {
476                                 color = (Color)viewstate["ForeColor"];
477                                 if (!color.IsEmpty)
478                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
479                         }
480
481                         if ((styles & Styles.Height) != 0) {
482                                 u = (Unit)viewstate["Height"];
483                                 if (!u.IsEmpty)
484                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
485                         }
486
487                         if ((styles & Styles.Width) != 0) {
488                                 u = (Unit)viewstate["Width"];
489                                 if (!u.IsEmpty)
490                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
491                         }
492
493                         if (!Font.IsEmpty) {
494                                 // Fonts are a bit weird
495                                 if (fontinfo.Name != string.Empty) {
496                                         s = fontinfo.Names[0];
497                                         for (int i = 1; i < fontinfo.Names.Length; i++)
498                                                 s += "," + fontinfo.Names[i];
499                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
500                                 }
501
502                                 if (fontinfo.Bold)
503                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
504
505                                 if (fontinfo.Italic)
506                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
507
508                                 if (!fontinfo.Size.IsEmpty)
509                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
510
511                                 // These styles are munged into a attribute decoration
512                                 s = string.Empty;
513
514                                 if (fontinfo.Overline)
515                                         s += "overline ";
516
517                                 if (fontinfo.Strikeout)
518                                         s += "line-through ";
519
520                                 if (fontinfo.Underline)
521                                         s += "underline ";
522
523                                 s = (s != "") ? s : AlwaysRenderTextDecoration ? "none" : "";
524                                 if (s != "")
525                                         writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
526                         }
527 #endif
528                 }
529
530 #if NET_2_0
531                 void FillStyleAttributes (CssStyleCollection attributes) 
532                 {
533                         Color           color;
534                         BorderStyle     bs;
535                         Unit            u;
536
537                         if ((styles & Styles.BackColor) != 0)
538                         {
539                                 color = (Color)viewstate["BackColor"];
540                                 if (!color.IsEmpty)
541                                         attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
542                         }
543
544                         if ((styles & Styles.BorderColor) != 0) 
545                         {
546                                 color = (Color)viewstate["BorderColor"];
547                                 if (!color.IsEmpty)
548                                         attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
549                         }
550
551                         bool have_width = false;
552                         if ((styles & Styles.BorderWidth) != 0) {
553                                 u = (Unit) viewstate ["BorderWidth"];
554                                 if (!u.IsEmpty) {
555                                         if (u.Value > 0)
556                                                 have_width = true;
557                                         attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
558                                 }
559                         }
560
561                         if ((styles & Styles.BorderStyle) != 0) {
562                                 bs = (BorderStyle) viewstate ["BorderStyle"];
563                                 if (bs != BorderStyle.NotSet)
564                                         attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
565                                 else if (have_width)
566                                                 attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
567                         }
568                         else if (have_width) {
569                                 attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
570                         }
571
572                         if ((styles & Styles.ForeColor) != 0) 
573                         {
574                                 color = (Color)viewstate["ForeColor"];
575                                 if (!color.IsEmpty)
576                                         attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
577                         }
578
579                         if ((styles & Styles.Height) != 0) 
580                         {
581                                 u = (Unit)viewstate["Height"];
582                                 if (!u.IsEmpty)
583                                         attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
584                         }
585
586                         if ((styles & Styles.Width) != 0) 
587                         {
588                                 u = (Unit)viewstate["Width"];
589                                 if (!u.IsEmpty)
590                                         attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
591                         }
592
593                         Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
594                 }
595 #endif
596
597                 public virtual void CopyFrom(Style s) 
598                 {
599                         if ((s == null) || s.IsEmpty) 
600                         {
601                                 return;
602                         }
603
604                         if (s.fontinfo != null) 
605                         {
606                                 Font.CopyFrom(s.fontinfo);
607                         }
608
609                         if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
610                         {
611                                 this.BackColor = s.BackColor;
612                         }
613                         if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
614                         {
615                                 this.BorderColor = s.BorderColor;
616                         }
617                         if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
618                         {
619                                 this.BorderStyle = s.BorderStyle;
620                         }
621                         if (((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
622                         {
623                                 this.BorderWidth = s.BorderWidth;
624                         }
625                         if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
626                         {
627                                 this.CssClass = s.CssClass;
628                         }
629                         if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
630                         {
631                                 this.ForeColor = s.ForeColor;
632                         }
633                         if (((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
634                         {
635                                 this.Height = s.Height;
636                         }
637                         if (((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
638                         {
639                                 this.Width = s.Width;
640                         }
641                 }
642
643                 public virtual void MergeWith(Style s) 
644                 {
645                         if ((s == null) || (s.IsEmpty))
646                         {
647                                 return;
648                         }
649
650                         if (s.fontinfo != null) 
651                         {
652                                 Font.MergeWith(s.fontinfo);
653                         }
654
655                         if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
656                         {
657                                 this.BackColor = s.BackColor;
658                         }
659                         if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty)) 
660                         {
661                                 this.BorderColor = s.BorderColor;
662                         }
663                         if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet)) 
664                         {
665                                 this.BorderStyle = s.BorderStyle;
666                         }
667                         if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty)) 
668                         {
669                                 this.BorderWidth = s.BorderWidth;
670                         }
671                         if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty)) 
672                         {
673                                 this.CssClass = s.CssClass;
674                         }
675                         if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty)) 
676                         {
677                                 this.ForeColor = s.ForeColor;
678                         }
679                         if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty)) 
680                         {
681                                 this.Height = s.Height;
682                         }
683                         if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty)) 
684                         {
685                                 this.Width = s.Width;
686                         }
687                 }
688
689                 /*
690                 internal void Print ()
691                 {
692                         Console.WriteLine ("BackColor: {0}", BackColor);
693                         Console.WriteLine ("BorderColor: {0}", BorderColor);
694                         Console.WriteLine ("BorderStyle: {0}", BorderStyle);
695                         Console.WriteLine ("BorderWidth: {0}", BorderWidth);
696                         Console.WriteLine ("CssClass: {0}", CssClass);
697                         Console.WriteLine ("ForeColor: {0}", ForeColor);
698                         Console.WriteLine ("Height: {0}", Height);
699                         Console.WriteLine ("Width: {0}", Width);
700                 }
701                 */
702
703                 public virtual void Reset() 
704                 {
705                         viewstate.Remove("BackColor");
706                         viewstate.Remove("BorderColor");
707                         viewstate.Remove("BorderStyle");
708                         viewstate.Remove("BorderWidth");
709                         viewstate.Remove("CssClass");
710                         viewstate.Remove("ForeColor");
711                         viewstate.Remove("Height");
712                         viewstate.Remove("Width");
713                         if (fontinfo != null) 
714                         {
715                                 fontinfo.Reset();
716                         }
717                         styles = Styles.None;
718                 }
719 #if ONLY_1_1
720                 public override string ToString() 
721                 {
722                         return string.Empty;
723                 }
724 #endif
725                 #endregion      // Public Instance Methods
726
727                 #region Protected Instance Methods
728                 protected internal void LoadViewState(object state) 
729                 {
730                         viewstate.LoadViewState(state);
731
732                         // Update our style
733                         this.styles = Styles.None;
734
735                         if (viewstate["BackColor"] != null) 
736                         {
737                                 styles |= Styles.BackColor;
738                         }
739                         if (viewstate["BorderColor"] != null) 
740                         {
741                                 styles |= Styles.BorderColor;
742                         }
743                         if (viewstate["BorderStyle"] != null) 
744                         {
745                                 styles |= Styles.BorderStyle;
746                         }
747                         if (viewstate["BorderWidth"] != null) 
748                         {
749                                 styles |= Styles.BorderWidth;
750                         }
751                         if (viewstate["CssClass"] != null) 
752                         {
753                                 styles |= Styles.CssClass;
754                         }
755                         if (viewstate["ForeColor"] != null) 
756                         {
757                                 styles |= Styles.ForeColor;
758                         }
759                         if (viewstate["Height"] != null) 
760                         {
761                                 styles |= Styles.Height;
762                         }
763                         if (viewstate["Width"] != null) 
764                         {
765                                 styles |= Styles.Width;
766                         }
767                         Font.LoadViewState();
768
769                         LoadViewStateInternal();
770                 }
771
772                 internal virtual void LoadViewStateInternal()
773                 {
774                         // Override me
775                 }
776
777                 protected internal virtual object SaveViewState () 
778                 {
779                         if (styles != Styles.None || !Font.IsEmpty) 
780                         {
781                                 return viewstate.SaveViewState();
782                         }
783                         return null;
784                 }
785
786                 [MonoTODO]
787                 protected internal virtual void SetBit( int bit ) 
788                 {
789                         throw new NotImplementedException();
790                 }
791
792                 protected internal virtual void TrackViewState() 
793                 {
794                         tracking = true;
795                         viewstate.TrackViewState();
796                 }
797                 #endregion      // Protected Instance Methods
798
799                 #region IStateManager Properties & Methods
800                 void IStateManager.LoadViewState(object state) 
801                 {
802                         LoadViewState(state);
803                 }
804
805                 object IStateManager.SaveViewState() 
806                 {
807                         return SaveViewState();
808                 }
809
810                 void IStateManager.TrackViewState() 
811                 {
812                         TrackViewState();
813                 }
814
815                 bool IStateManager.IsTrackingViewState 
816                 {
817                         get 
818                         {
819                                 return this.IsTrackingViewState;
820                         }
821                 }
822                 #endregion      // IStateManager Properties & Methods
823
824 #if NET_2_0
825                 protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
826                 {
827                         FillStyleAttributes (attributes);
828                 }
829
830                 internal void SetRegisteredCssClass (string name)
831                 {
832                         registered_class = name;
833                 }
834
835                 public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
836                 {
837                         CssStyleCollection col = new CssStyleCollection (new StateBag ());
838                         FillStyleAttributes (col, resolver);
839                         return col;
840                 }
841
842                 [MonoTODO]
843                 [EditorBrowsable(EditorBrowsableState.Advanced)]
844                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
845                 [Browsable(false)]
846                 public string RegisteredCssClass {
847                         get {
848                                 if (registered_class == null)
849                                         registered_class = String.Empty;
850                                 return registered_class;
851                         }
852                 }
853
854                 internal void CopyTextStylesFrom (Style source) {
855                         // Used primary for TreeView and Menu
856                         if ((source.styles & Styles.ForeColor) != 0) {
857                                 ForeColor = source.ForeColor;
858                         }
859                         if (!source.Font.IsEmpty) {
860                                 Font.CopyFrom (source.Font);
861                         }
862                 }
863
864                 internal void AddCssClass (string cssClass) {
865                         if (String.IsNullOrEmpty (cssClass))
866                                 return;
867
868                         if (CssClass.Length > 0)
869                                 CssClass += " ";
870                         CssClass += cssClass;
871                 }
872
873                 public void SetDirty ()
874                 {
875                         if (viewstate != null)
876                                 viewstate.SetDirty (true);
877                 }
878 #endif
879         }
880 }