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