-
-//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-/**\r
- * Namespace: System.Web.UI.WebControls\r
- * Class: FontUnitConverter\r
- *\r
- * Author: Gaurav Vaish, Gonzalo Paniagua Javier\r
- * Maintainer: gvaish@iitk.ac.in\r
- * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>, <gonzalo@ximian.com>\r
- * Implementation: yes\r
- * Status: 95%\r
- *\r
- * (C) Gaurav Vaish (2002)\r
- * (c) 2002 Ximian, Inc. (http://www.ximian.com)\r
- */\r
-\r
-using System;\r
-using System.Globalization;\r
-using System.ComponentModel;\r
-using System.Web;\r
-using System.Web.UI;\r
-using System.Reflection;\r
-using System.ComponentModel.Design.Serialization;\r
-\r
-namespace System.Web.UI.WebControls\r
-{\r
- public class FontUnitConverter : TypeConverter\r
- {\r
- static volatile StandardValuesCollection valuesCollection;\r
- static readonly object lockobj = new object ();\r
-\r
- public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)\r
- {\r
- if(sourceType == typeof(string))\r
- return true;\r
- return base.CanConvertFrom(context, sourceType);\r
- }\r
-\r
-#if NET_2_0\r
- public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)\r
- {\r
- if (destinationType == typeof (string))\r
- return true;\r
-\r
- if (destinationType == typeof (InstanceDescriptor))\r
- return true;\r
-\r
- return base.CanConvertTo (context, destinationType);\r
- }\r
-#endif\r
-\r
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)\r
- {\r
- if(value == null)\r
- return null;\r
- if(value is string)\r
- {\r
- string val = ((string)value).Trim();\r
- if(val.Length == 0)\r
- {\r
- return FontUnit.Empty;\r
- }\r
- return FontUnit.Parse(val, CultureInfo.InvariantCulture);\r
- }\r
- return base.ConvertFrom(context, culture, value);\r
- }\r
-\r
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\r
- {\r
- if(destinationType == typeof (string) && value is FontUnit)\r
- {\r
- FontUnit val = (FontUnit)value;\r
- if(val.Type == FontSize.NotSet)\r
- {\r
- return String.Empty;\r
- }\r
- return val.ToString (culture);\r
- }\r
-#if NET_2_0\r
- if (destinationType == typeof (InstanceDescriptor)) {
- if (value is string)
- value = FontUnit.Parse ((string)value, CultureInfo.InvariantCulture);
-
- if (value is FontUnit) {\r
- FontUnit s = (FontUnit) value;
- if (s.Type == FontSize.AsUnit) {
- ConstructorInfo ci = typeof(FontUnit).GetConstructor (new Type[] { typeof (Unit) });\r
- return new InstanceDescriptor (ci, new object[] {s.Unit});\r
- } else {\r
- ConstructorInfo ci = typeof(FontUnit).GetConstructor (new Type[] { typeof (FontSize) });\r
- return new InstanceDescriptor (ci, new object[] {s.Type});
- }
- }\r
- }\r
-#endif\r
- return base.ConvertTo(context, culture, value, destinationType);\r
- }\r
-\r
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)\r
- {\r
- if (valuesCollection != null)\r
- return valuesCollection;\r
-\r
- lock (lockobj) {\r
- if (valuesCollection != null)\r
- return valuesCollection;\r
-\r
- Array values = Enum.GetValues (typeof (FontUnit));\r
- Array.Sort (values);\r
- valuesCollection = new StandardValuesCollection (values);\r
- }\r
-\r
- return valuesCollection;\r
- }\r
-\r
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)\r
- {\r
- return false;\r
- }\r
-\r
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context)\r
- {\r
- return true;\r
- }\r
- }\r
-}\r
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace System.Web.UI.WebControls
+{
+ public class FontUnitConverter : TypeConverter
+ {
+ #region Public Constructors
+ public FontUnitConverter()
+ {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Methods
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ if (sourceType == typeof(string))
+ {
+ return true;
+ }
+ return base.CanConvertFrom (context, sourceType);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ string s;
+
+ if ((value == null) || !(value is string))
+ {
+ return base.ConvertFrom (context, culture, value);
+ }
+
+
+ s = (string)value;
+
+ if (culture == null)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ if (s == "")
+ {
+ return FontUnit.Empty;
+ }
+ return FontUnit.Parse(s, culture);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
+ {
+ FontUnit fu;
+
+ if ((value == null) || !(value is FontUnit) || (destinationType != typeof(string)))
+ {
+ return base.ConvertTo (context, culture, value, destinationType);
+ }
+
+ if (culture == null)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ fu = (FontUnit)value;
+
+ return fu.ToString(culture);
+ }
+
+ public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
+ {
+ PropertyDescriptorCollection props = TypeDescriptor.GetProperties (typeof (FontUnit));
+ ArrayList vals = new ArrayList ();
+
+ for (int i = 0; i < props.Count; i++)
+ vals.Add (props [i].GetValue (null));
+ return new StandardValuesCollection (vals);
+ }
+
+ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
+ {
+ return false;
+ }
+
+ public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
+ {
+ return true;
+ }
+ #endregion // Public Instance Methods
+ }
+}