(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.UI / CssStyleCollection.cs
blobb49b5778fe6b3f6b62329e34879ed4b5c940a4fc
1 //
2 // System.Web.UI.CssStyleCollection.cs
3 //
4 // Authors:
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua (gonzalo@ximian.com)
7 //
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Collections;
34 using System.Text;
36 namespace System.Web.UI {
38 public sealed class CssStyleCollection
40 private StateBag bag;
41 private StateBag style;
43 internal CssStyleCollection (StateBag bag)
45 this.bag = bag;
46 style = new StateBag ();
47 string st_string = bag ["style"] as string;
48 if (st_string != null)
49 FillStyle (st_string);
52 internal void FillStyle (string s)
54 int mark = s.IndexOf (':');
55 if (mark == -1)
56 return;
57 string key = s.Substring (0, mark). Trim ();
58 if (mark + 1 > s.Length)
59 return;
61 string fullValue = s.Substring (mark + 1);
62 if (fullValue == "")
63 return;
65 mark = fullValue.IndexOf (';');
66 string value;
67 if (mark == -1)
68 value = fullValue.Trim ();
69 else
70 value = fullValue.Substring (0, mark).Trim ();
72 style.Add (key, value);
73 if (mark + 1 > fullValue.Length)
74 return;
75 FillStyle (fullValue.Substring (mark + 1));
78 private string BagToString ()
80 StringBuilder sb = new StringBuilder ();
81 foreach (string k in style.Keys)
82 sb.AppendFormat ("{0}: {1}; ", k, style [k]);
83 return sb.ToString ();
86 public int Count
88 get { return style.Count; }
91 public string this [string key]
93 get {
94 return style [key] as string;
97 set {
98 Add (key, value);
102 public ICollection Keys {
103 get { return style.Keys; }
106 public void Add (string key, string value)
108 style [key] = value;
109 bag ["style"] = BagToString ();
112 public void Clear ()
114 bag.Remove ("style");
115 style.Clear ();
118 public void Remove (string key)
120 if (style [key] != null) {
121 style.Remove (key);
122 bag ["style"] = BagToString ();