from head
[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                 public virtual void Reset() 
656                 {
657                         viewstate.Remove("BackColor");
658                         viewstate.Remove("BorderColor");
659                         viewstate.Remove("BorderStyle");
660                         viewstate.Remove("BorderWidth");
661                         viewstate.Remove("CssClass");
662                         viewstate.Remove("ForeColor");
663                         viewstate.Remove("Height");
664                         viewstate.Remove("Width");
665                         if (fontinfo != null) 
666                         {
667                                 fontinfo.Reset();
668                         }
669                         styles = Styles.None;
670                 }
671
672                 public override string ToString() 
673                 {
674                         return string.Empty;
675                 }
676                 #endregion      // Public Instance Methods
677
678                 #region Protected Instance Methods
679                 protected internal void LoadViewState(object state) 
680                 {
681                         viewstate.LoadViewState(state);
682
683                         // Update our style
684                         this.styles = Styles.None;
685
686                         if (viewstate["BackColor"] != null) 
687                         {
688                                 styles |= Styles.BackColor;
689                         }
690                         if (viewstate["BorderColor"] != null) 
691                         {
692                                 styles |= Styles.BorderColor;
693                         }
694                         if (viewstate["BorderStyle"] != null) 
695                         {
696                                 styles |= Styles.BorderStyle;
697                         }
698                         if (viewstate["BorderWidth"] != null) 
699                         {
700                                 styles |= Styles.BorderWidth;
701                         }
702                         if (viewstate["CssClass"] != null) 
703                         {
704                                 styles |= Styles.CssClass;
705                         }
706                         if (viewstate["ForeColor"] != null) 
707                         {
708                                 styles |= Styles.ForeColor;
709                         }
710                         if (viewstate["Height"] != null) 
711                         {
712                                 styles |= Styles.Height;
713                         }
714                         if (viewstate["Width"] != null) 
715                         {
716                                 styles |= Styles.Width;
717                         }
718                         if (fontinfo != null) {
719                                 fontinfo.LoadViewState();
720                         }
721
722                         LoadViewStateInternal();
723                 }
724
725                 internal virtual void LoadViewStateInternal()
726                 {
727                         // Override me
728                 }
729
730                 protected internal virtual object SaveViewState () 
731                 {
732                         if (styles != Styles.None) 
733                         {
734                                 return viewstate.SaveViewState();
735                         }
736                         return null;
737                 }
738
739                 [MonoTODO]
740                 protected internal virtual void SetBit( int bit ) 
741                 {
742                         throw new NotImplementedException();
743                 }
744
745                 protected internal virtual void TrackViewState() 
746                 {
747                         tracking = true;
748                         viewstate.TrackViewState();
749                 }
750                 #endregion      // Protected Instance Methods
751
752                 #region IStateManager Properties & Methods
753                 void IStateManager.LoadViewState(object state) 
754                 {
755                         LoadViewState(state);
756                 }
757
758                 object IStateManager.SaveViewState() 
759                 {
760                         return SaveViewState();
761                 }
762
763                 void IStateManager.TrackViewState() 
764                 {
765                         TrackViewState();
766                 }
767
768                 bool IStateManager.IsTrackingViewState 
769                 {
770                         get 
771                         {
772                                 return this.IsTrackingViewState;
773                         }
774                 }
775                 #endregion      // IStateManager Properties & Methods
776
777 #if NET_2_0
778                 protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
779                 {
780                         FillStyleAttributes (attributes);
781                 }
782
783                 internal void SetRegisteredCssClass (string name)
784                 {
785                         registered_class = name;
786                 }
787
788                 public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
789                 {
790                         CssStyleCollection col = new CssStyleCollection ();
791                         FillStyleAttributes (col, resolver);
792                         return col;
793                 }
794
795                 [MonoTODO]
796                 public string RegisteredCssClass {
797                         get {
798                                 return registered_class;
799                         }
800                 }
801
802                 internal virtual void CopyTextStylesFrom (Style source)
803                 {
804                         // Need to ask lluis if we need fonts, too
805                         if ((styles & Styles.ForeColor) != 0) {
806                                 ForeColor = source.ForeColor;
807                         }
808                         if ((styles & Styles.BackColor) != 0) {
809                                 BackColor = source.BackColor;
810                         }
811                 }
812
813                 public void SetDirty ()
814                 {
815                         if (viewstate != null)
816                                 viewstate.SetDirty ();
817                 }
818
819                 public static bool IsStyleEmpty (Style s)
820                 {
821                         if (s == null)
822                                 return true;
823                         return s.IsEmpty;
824                 }
825
826 #endif
827         }
828 }