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