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