* roottypes.cs: Rename from tree.cs.
[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                                 return (styles == 0 && (fontinfo == null || fontinfo.IsEmpty));
360                         }
361                 }
362
363                 protected bool IsTrackingViewState 
364                 {
365                         get 
366                         {
367                                 return tracking;
368                         }
369                 }
370
371                 [Browsable(false)]
372                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
373                 protected internal StateBag ViewState 
374                 {
375                         get 
376                         {
377                                 return viewstate;
378                         }
379                 }
380                 #endregion      // Protected Instance Properties
381
382                 #region Public Instance Methods
383                 public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer) 
384                 {
385                         AddAttributesToRender(writer, null);
386                 }
387
388                 public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
389                 {
390                         if ((styles & Styles.CssClass) != 0) 
391                         {
392                                 string s = (string)viewstate["CssClass"];
393                                 if (s != string.Empty)
394                                         writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
395                         }
396
397                         WriteStyleAttributes (writer);
398                 }
399
400                 void WriteStyleAttributes (HtmlTextWriter writer) 
401                 {
402                         string          s;
403                         Color           color;
404                         BorderStyle     bs;
405                         Unit            u;
406
407                         if ((styles & Styles.BackColor) != 0) {
408                                 color = (Color)viewstate["BackColor"];
409                                 if (!color.IsEmpty)
410                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
411                         }
412
413                         if ((styles & Styles.BorderColor) != 0) {
414                                 color = (Color)viewstate["BorderColor"];
415                                 if (!color.IsEmpty)
416                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
417                         }
418
419                         bool have_width = false;
420                         if ((styles & Styles.BorderWidth) != 0) {
421                                 u = (Unit)viewstate["BorderWidth"];
422                                 if (!u.IsEmpty) {
423                                         if (u.Value > 0)
424                                                 have_width = true;
425                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, u.ToString());
426                                 }
427                         }
428
429                         if ((styles & Styles.BorderStyle) != 0) {
430                                 bs = (BorderStyle)viewstate["BorderStyle"];
431                                 if (bs != BorderStyle.NotSet) 
432                                         writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, bs.ToString());
433                                 else {
434                                         if ((styles & Styles.BorderWidth) != 0)
435                                                 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
436                                 }
437                         } else if (have_width) {
438                                 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderStyle, "solid");
439                         }
440
441                         if ((styles & Styles.ForeColor) != 0) {
442                                 color = (Color)viewstate["ForeColor"];
443                                 if (!color.IsEmpty)
444                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
445                         }
446
447                         if ((styles & Styles.Height) != 0) {
448                                 u = (Unit)viewstate["Height"];
449                                 if (!u.IsEmpty)
450                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Height, u.ToString());
451                         }
452
453                         if ((styles & Styles.Width) != 0) {
454                                 u = (Unit)viewstate["Width"];
455                                 if (!u.IsEmpty)
456                                         writer.AddStyleAttribute (HtmlTextWriterStyle.Width, u.ToString());
457                         }
458
459                         if (fontinfo != null) {
460                                 // Fonts are a bit weird
461                                 if (fontinfo.Name != string.Empty) {
462                                         s = fontinfo.Names[0];
463                                         for (int i = 1; i < fontinfo.Names.Length; i++)
464                                                 s += "," + fontinfo.Names[i];
465                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontFamily, s);
466                                 }
467
468                                 if (fontinfo.Bold)
469                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontWeight, "bold");
470
471                                 if (fontinfo.Italic)
472                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontStyle, "italic");
473
474                                 if (!fontinfo.Size.IsEmpty)
475                                         writer.AddStyleAttribute (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
476
477                                 // These styles are munged into a attribute decoration
478                                 s = string.Empty;
479
480                                 if (fontinfo.Overline)
481                                         s += "overline ";
482
483                                 if (fontinfo.Strikeout)
484                                         s += "line-through ";
485
486                                 if (fontinfo.Underline)
487                                         s += "underline ";
488
489                                 if (s != string.Empty)
490                                         writer.AddStyleAttribute (HtmlTextWriterStyle.TextDecoration, s);
491                         }
492                 }
493
494                 void FillStyleAttributes (CssStyleCollection attributes) 
495                 {
496                         string          s;
497                         Color           color;
498                         BorderStyle     bs;
499                         Unit            u;
500
501                         if ((styles & Styles.BackColor) != 0)
502                         {
503                                 color = (Color)viewstate["BackColor"];
504                                 if (!color.IsEmpty)
505                                         attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
506                         }
507
508                         if ((styles & Styles.BorderColor) != 0) 
509                         {
510                                 color = (Color)viewstate["BorderColor"];
511                                 if (!color.IsEmpty)
512                                         attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
513                         }
514
515                         if ((styles & Styles.BorderStyle) != 0) 
516                         {
517                                 bs = (BorderStyle)viewstate["BorderStyle"];
518                                 if (bs != BorderStyle.NotSet) 
519                                         attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString());
520                         }
521
522                         if ((styles & Styles.BorderWidth) != 0) 
523                         {
524                                 u = (Unit)viewstate["BorderWidth"];
525                                 if (!u.IsEmpty)
526                                         attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString());
527                         }
528
529                         if ((styles & Styles.ForeColor) != 0) 
530                         {
531                                 color = (Color)viewstate["ForeColor"];
532                                 if (!color.IsEmpty)
533                                         attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
534                         }
535
536                         if ((styles & Styles.Height) != 0) 
537                         {
538                                 u = (Unit)viewstate["Height"];
539                                 if (!u.IsEmpty)
540                                         attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
541                         }
542
543                         if ((styles & Styles.Width) != 0) 
544                         {
545                                 u = (Unit)viewstate["Width"];
546                                 if (!u.IsEmpty)
547                                         attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
548                         }
549
550                         if (fontinfo != null) {
551                                 // Fonts are a bit weird
552                                 if (fontinfo.Name != string.Empty) 
553                                 {
554                                         s = fontinfo.Names[0];
555                                         for (int i = 1; i < fontinfo.Names.Length; i++) 
556                                         {
557                                                 s += "," + fontinfo.Names[i];
558                                         }
559                                         attributes.Add (HtmlTextWriterStyle.FontFamily, s);
560                                 }
561
562                                 if (fontinfo.Bold) 
563                                 {
564                                         attributes.Add (HtmlTextWriterStyle.FontWeight, "bold");
565                                 }
566
567                                 if (fontinfo.Italic) 
568                                 {
569                                         attributes.Add (HtmlTextWriterStyle.FontStyle, "italic");
570                                 }
571
572                                 if (!fontinfo.Size.IsEmpty) 
573                                 {
574                                         attributes.Add (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
575                                 }
576
577                                 // These styles are munged into a attribute decoration
578                                 s = string.Empty;
579
580                                 if (fontinfo.Overline) 
581                                 {
582                                         s += "overline ";
583                                 }
584
585                                 if (fontinfo.Strikeout) 
586                                 {
587                                         s += "line-through ";
588                                 }
589
590                                 if (fontinfo.Underline) 
591                                 {
592                                         s += "underline ";
593                                 }
594
595                                 if (s != string.Empty) 
596                                 {
597                                         attributes.Add (HtmlTextWriterStyle.TextDecoration, s);
598                                 }
599                         }
600                 }
601
602                 public virtual void CopyFrom(Style s) 
603                 {
604                         if ((s == null) || s.IsEmpty) 
605                         {
606                                 return;
607                         }
608
609                         if (s.fontinfo != null) 
610                         {
611                                 Font.CopyFrom(s.fontinfo);
612                         }
613
614                         if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
615                         {
616                                 this.BackColor = s.BackColor;
617                         }
618                         if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
619                         {
620                                 this.BorderColor = s.BorderColor;
621                         }
622                         if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
623                         {
624                                 this.BorderStyle = s.BorderStyle;
625                         }
626                         if (((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty))
627                         {
628                                 this.BorderWidth = s.BorderWidth;
629                         }
630                         if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
631                         {
632                                 this.CssClass = s.CssClass;
633                         }
634                         if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
635                         {
636                                 this.ForeColor = s.ForeColor;
637                         }
638                         if (((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty))
639                         {
640                                 this.Height = s.Height;
641                         }
642                         if (((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty))
643                         {
644                                 this.Width = s.Width;
645                         }
646                 }
647
648                 public virtual void MergeWith(Style s) 
649                 {
650                         if ((s == null) || (s.IsEmpty))
651                         {
652                                 return;
653                         }
654
655                         if (s.fontinfo != null) 
656                         {
657                                 Font.MergeWith(s.fontinfo);
658                         }
659
660                         if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
661                         {
662                                 this.BackColor = s.BackColor;
663                         }
664                         if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty)) 
665                         {
666                                 this.BorderColor = s.BorderColor;
667                         }
668                         if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet)) 
669                         {
670                                 this.BorderStyle = s.BorderStyle;
671                         }
672                         if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (!s.BorderWidth.IsEmpty)) 
673                         {
674                                 this.BorderWidth = s.BorderWidth;
675                         }
676                         if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty)) 
677                         {
678                                 this.CssClass = s.CssClass;
679                         }
680                         if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty)) 
681                         {
682                                 this.ForeColor = s.ForeColor;
683                         }
684                         if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (!s.Height.IsEmpty)) 
685                         {
686                                 this.Height = s.Height;
687                         }
688                         if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (!s.Width.IsEmpty)) 
689                         {
690                                 this.Width = s.Width;
691                         }
692                 }
693
694                 /*
695                 internal void Print ()
696                 {
697                         Console.WriteLine ("BackColor: {0}", BackColor);
698                         Console.WriteLine ("BorderColor: {0}", BorderColor);
699                         Console.WriteLine ("BorderStyle: {0}", BorderStyle);
700                         Console.WriteLine ("BorderWidth: {0}", BorderWidth);
701                         Console.WriteLine ("CssClass: {0}", CssClass);
702                         Console.WriteLine ("ForeColor: {0}", ForeColor);
703                         Console.WriteLine ("Height: {0}", Height);
704                         Console.WriteLine ("Width: {0}", Width);
705                 }
706                 */
707
708                 public virtual void Reset() 
709                 {
710                         viewstate.Remove("BackColor");
711                         viewstate.Remove("BorderColor");
712                         viewstate.Remove("BorderStyle");
713                         viewstate.Remove("BorderWidth");
714                         viewstate.Remove("CssClass");
715                         viewstate.Remove("ForeColor");
716                         viewstate.Remove("Height");
717                         viewstate.Remove("Width");
718                         if (fontinfo != null) 
719                         {
720                                 fontinfo.Reset();
721                         }
722                         styles = Styles.None;
723                 }
724 #if ONLY_1_1
725                 public override string ToString() 
726                 {
727                         return string.Empty;
728                 }
729 #endif
730                 #endregion      // Public Instance Methods
731
732                 #region Protected Instance Methods
733                 protected internal void LoadViewState(object state) 
734                 {
735                         viewstate.LoadViewState(state);
736
737                         // Update our style
738                         this.styles = Styles.None;
739
740                         if (viewstate["BackColor"] != null) 
741                         {
742                                 styles |= Styles.BackColor;
743                         }
744                         if (viewstate["BorderColor"] != null) 
745                         {
746                                 styles |= Styles.BorderColor;
747                         }
748                         if (viewstate["BorderStyle"] != null) 
749                         {
750                                 styles |= Styles.BorderStyle;
751                         }
752                         if (viewstate["BorderWidth"] != null) 
753                         {
754                                 styles |= Styles.BorderWidth;
755                         }
756                         if (viewstate["CssClass"] != null) 
757                         {
758                                 styles |= Styles.CssClass;
759                         }
760                         if (viewstate["ForeColor"] != null) 
761                         {
762                                 styles |= Styles.ForeColor;
763                         }
764                         if (viewstate["Height"] != null) 
765                         {
766                                 styles |= Styles.Height;
767                         }
768                         if (viewstate["Width"] != null) 
769                         {
770                                 styles |= Styles.Width;
771                         }
772                         if (fontinfo != null) {
773                                 fontinfo.LoadViewState();
774                         }
775
776                         LoadViewStateInternal();
777                 }
778
779                 internal virtual void LoadViewStateInternal()
780                 {
781                         // Override me
782                 }
783
784                 protected internal virtual object SaveViewState () 
785                 {
786                         if (styles != Styles.None) 
787                         {
788                                 return viewstate.SaveViewState();
789                         }
790                         return null;
791                 }
792
793                 [MonoTODO]
794                 protected internal virtual void SetBit( int bit ) 
795                 {
796                         throw new NotImplementedException();
797                 }
798
799                 protected internal virtual void TrackViewState() 
800                 {
801                         tracking = true;
802                         viewstate.TrackViewState();
803                 }
804                 #endregion      // Protected Instance Methods
805
806                 #region IStateManager Properties & Methods
807                 void IStateManager.LoadViewState(object state) 
808                 {
809                         LoadViewState(state);
810                 }
811
812                 object IStateManager.SaveViewState() 
813                 {
814                         return SaveViewState();
815                 }
816
817                 void IStateManager.TrackViewState() 
818                 {
819                         TrackViewState();
820                 }
821
822                 bool IStateManager.IsTrackingViewState 
823                 {
824                         get 
825                         {
826                                 return this.IsTrackingViewState;
827                         }
828                 }
829                 #endregion      // IStateManager Properties & Methods
830
831 #if NET_2_0
832                 protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
833                 {
834                         FillStyleAttributes (attributes);
835                 }
836
837                 internal void SetRegisteredCssClass (string name)
838                 {
839                         registered_class = name;
840                 }
841
842                 public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
843                 {
844                         CssStyleCollection col = new CssStyleCollection (new StateBag ());
845                         FillStyleAttributes (col, resolver);
846                         return col;
847                 }
848
849                 [MonoTODO]
850                 [EditorBrowsable(EditorBrowsableState.Advanced)]
851                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
852                 [Browsable(false)]
853                 public string RegisteredCssClass {
854                         get {
855                                 if (registered_class == null)
856                                         registered_class = String.Empty;
857                                 return registered_class;
858                         }
859                 }
860
861                 internal virtual void CopyTextStylesFrom (Style source)
862                 {
863                         // Need to ask lluis if we need fonts, too
864                         if ((styles & Styles.ForeColor) != 0) {
865                                 ForeColor = source.ForeColor;
866                         }
867                         if ((styles & Styles.BackColor) != 0) {
868                                 BackColor = source.BackColor;
869                         }
870                 }
871
872                 public void SetDirty ()
873                 {
874                         if (viewstate != null)
875                                 viewstate.SetDirty (true);
876                 }
877 #endif
878         }
879 }