**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / FontInfo.cs
blob7310ee6251bdb7d5ad900c3cd09946c66a60c5d9
1 //
2 // System.Web.UI.WebControls.FontInfo.cs
3 //
4 // Authors:
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 // (C) Gaurav Vaish (2002)
11 // (C) 2003 Andreas Nahr
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System;
36 using System.Text;
37 using System.Reflection;
38 using System.Web;
39 using System.Web.UI;
40 using System.Drawing;
41 using System.ComponentModel;
43 namespace System.Web.UI.WebControls
45 [TypeConverter(typeof(ExpandableObjectConverter))]
46 public sealed class FontInfo
48 private Style infoOwner;
50 internal FontInfo(Style owner)
52 infoOwner = owner;
55 /// <summary>
56 /// Default constructor
57 /// <remarks>
58 /// The default constructor is made private to prevent any instances being made.
59 /// </remarks>
60 /// </summary>
61 private FontInfo()
65 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
66 [NotifyParentProperty (true)]
67 [WebSysDescription ("The 'bold' style of the font.")]
68 public bool Bold
70 get
72 if(infoOwner.IsSet(Style.FONT_BOLD))
73 return (bool)(infoOwner.ViewState["FontInfoBold"]);
74 return false;
76 set
78 infoOwner.ViewState["FontInfoBold"] = value;
79 infoOwner.Set(Style.FONT_BOLD);
83 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
84 [NotifyParentProperty (true)]
85 [WebSysDescription ("The 'italic' style of the font.")]
86 public bool Italic
88 get
90 if(infoOwner.IsSet(Style.FONT_ITALIC))
91 return (bool)(infoOwner.ViewState["FontInfoItalic"]);
92 return false;
94 set
96 infoOwner.ViewState["FontInfoItalic"] = value;
97 infoOwner.Set(Style.FONT_ITALIC);
101 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
102 [NotifyParentProperty (true)]
103 [WebSysDescription ("The 'overline' style of the font.")]
104 public bool Overline
108 if(infoOwner.IsSet(Style.FONT_OLINE))
109 return (bool)(infoOwner.ViewState["FontInfoOverline"]);
110 return false;
114 infoOwner.ViewState["FontInfoOverline"] = value;
115 infoOwner.Set(Style.FONT_OLINE);
119 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
120 [NotifyParentProperty (true)]
121 [WebSysDescription ("The 'strikeout' style of the font.")]
122 public bool Strikeout
126 if(infoOwner.IsSet(Style.FONT_STRIKE))
127 return (bool)(infoOwner.ViewState["FontInfoStrikeout"]);
128 return false;
132 infoOwner.ViewState["FontInfoStrikeout"] = value;
133 infoOwner.Set(Style.FONT_STRIKE);
137 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
138 [NotifyParentProperty (true)]
139 [WebSysDescription ("The 'underline' style of the font.")]
140 public bool Underline
144 if(infoOwner.IsSet(Style.FONT_ULINE))
145 return (bool)(infoOwner.ViewState["FontInfoUnderline"]);
146 return false;
150 infoOwner.ViewState["FontInfoUnderline"] = value;
151 infoOwner.Set(Style.FONT_ULINE);
155 [DefaultValue (null), Bindable (true), WebCategory ("Font")]
156 [NotifyParentProperty (true)]
157 [WebSysDescription ("The size of the font.")]
158 public FontUnit Size
162 if(infoOwner.IsSet(Style.FONT_SIZE))
163 return (FontUnit)(infoOwner.ViewState["FontInfoSize"]);
164 return FontUnit.Empty;
168 if ((value.Type == FontSize.AsUnit) && (value.Unit.Value < 0))
169 throw new ArgumentOutOfRangeException("value");
170 infoOwner.ViewState["FontInfoSize"] = value;
171 infoOwner.Set(Style.FONT_SIZE);
175 [DefaultValue (""), Bindable (true), WebCategory ("Font")]
176 [NotifyParentProperty (true), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
177 [Editor ("System.Drawing.Design.FontNameEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
178 [TypeConverter (typeof (FontConverter.FontNameConverter))]
179 [WebSysDescription ("The name of the font that this control should be rendered with.")]
180 public string Name
184 if(Names!=null && Names.Length > 0)
185 return Names[0];
186 return String.Empty;
190 if(value == null)
191 throw new ArgumentException();
192 string[] strArray = null;
193 if(value.Length > 0)
195 strArray = new string[1];
196 strArray[0] = value;
198 Names = strArray;
202 [WebCategory ("Font")]
203 [NotifyParentProperty (true)]
204 [Editor ("System.Windows.Forms.Design.StringArrayEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
205 [TypeConverter (typeof (FontNamesConverter))]
206 [WebSysDescription ("Multiple fonts that can be used to render the control.")]
207 public string[] Names
211 if(infoOwner.IsSet(Style.FONT_NAMES))
212 return (string[])(infoOwner.ViewState["FontInfoNames"]);
213 return (new string[0]);
217 if(value!=null)
219 infoOwner.ViewState["FontInfoNames"] = value;
220 infoOwner.Set(Style.FONT_NAMES);
225 internal void Reset()
227 if(infoOwner.IsSet(Style.FONT_NAMES))
228 infoOwner.ViewState.Remove("FontInfoNames");
229 if(infoOwner.IsSet(Style.FONT_BOLD))
230 infoOwner.ViewState.Remove("FontInfoBold");
231 if(infoOwner.IsSet(Style.FONT_ITALIC))
232 infoOwner.ViewState.Remove("FontInfoItalic");
233 if(infoOwner.IsSet(Style.FONT_STRIKE))
234 infoOwner.ViewState.Remove("FontInfoStrikeout");
235 if(infoOwner.IsSet(Style.FONT_OLINE))
236 infoOwner.ViewState.Remove("FontInfoOverline");
237 if(infoOwner.IsSet(Style.FONT_ULINE))
238 infoOwner.ViewState.Remove("FontInfoUnderline");
239 if(infoOwner.IsSet(Style.FONT_SIZE) && infoOwner.Font.Size != FontUnit.Empty)
240 infoOwner.ViewState.Remove("FontInfoSize");
243 internal Style Owner
247 return infoOwner;
251 public void CopyFrom(FontInfo source)
253 if(source!=null)
255 if(source.Owner.IsSet(Style.FONT_NAMES))
256 Names = source.Names;
257 if(source.Owner.IsSet(Style.FONT_BOLD)&& source.Bold)
258 Bold = source.Bold;
259 if(source.Owner.IsSet(Style.FONT_ITALIC)&& source.Italic)
260 Italic = source.Italic;
261 if(source.Owner.IsSet(Style.FONT_STRIKE)&& source.Strikeout)
262 Strikeout = source.Strikeout;
263 if(source.Owner.IsSet(Style.FONT_OLINE)&& source.Overline)
264 Overline = source.Overline;
265 if(source.Owner.IsSet(Style.FONT_ULINE)&& source.Underline)
266 Underline = source.Underline;
267 if(source.Owner.IsSet(Style.FONT_SIZE) && source.Size != FontUnit.Empty)
268 Size = source.Size;
272 public void MergeWith(FontInfo with)
274 if(with!=null)
276 if(with.Owner.IsSet(Style.FONT_NAMES) && !infoOwner.IsSet(Style.FONT_NAMES))
277 Names = with.Names;
278 if(with.Owner.IsSet(Style.FONT_BOLD) && !infoOwner.IsSet(Style.FONT_BOLD))
279 Bold = with.Bold;
280 if(with.Owner.IsSet(Style.FONT_ITALIC) && !infoOwner.IsSet(Style.FONT_ITALIC))
281 Italic = with.Italic;
282 if(with.Owner.IsSet(Style.FONT_STRIKE) && !infoOwner.IsSet(Style.FONT_STRIKE))
283 Strikeout = with.Strikeout;
284 if(with.Owner.IsSet(Style.FONT_OLINE) && !infoOwner.IsSet(Style.FONT_OLINE))
285 Overline = with.Overline;
286 if(with.Owner.IsSet(Style.FONT_ULINE) && !infoOwner.IsSet(Style.FONT_ULINE))
287 Underline = with.Underline;
288 if(with.Owner.IsSet(Style.FONT_SIZE) && with.Size != FontUnit.Empty && !infoOwner.IsSet(Style.FONT_SIZE))
289 Size = with.Size;
293 public bool ShouldSerializeNames()
295 return (Names.Length > 0);
298 public override string ToString()
300 return ( (Name.Length > 0) ? (Name.ToString() + ", " + Size.ToString()) : Size.ToString() );