2010-02-18 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / FontUnitConverter.cs
index d008dc2c33f243b7a792b858c17f3a5e96acea32..6daa7babd2b73b1790cabd10324015e9672dfd63 100644 (file)
@@ -1,5 +1,3 @@
-
-//
 // 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
-\r
-namespace System.Web.UI.WebControls\r
-{\r
-       public class FontUnitConverter : TypeConverter\r
-       {\r
-               static StandardValuesCollection valuesCollection;\r
-               static string creatingValues = "creating value collection";\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
-               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, culture);\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(value != null && 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
-                       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 (creatingValues) {\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 bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) 
+               {
+                       if (destinationType == typeof (string)) {
+                               return true;
+                       }
+
+                       return base.CanConvertTo (context, destinationType);
+               }
+
+               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
+       }
+}