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