[winforms] Style
[mono.git] / mcs / class / System.Drawing / System.Drawing / SizeFConverter.cs
index bdb97eb7674b702f618a0622dd5c1af81ca51c5c..5dcb8f6d7748f94d792372410e2c3d02f2fe1979 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005, 2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -40,13 +40,13 @@ using System.Reflection;
 
 namespace System.Drawing
 {
-       public class SizeFConverter : TypeConverter\r
-       {\r
+       public class SizeFConverter : TypeConverter
+       {
                public SizeFConverter ()
                {
 
                }
-\r
+
                public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
                {
                        if (sourceType == typeof (string))
@@ -54,7 +54,7 @@ namespace System.Drawing
 
                        return base.CanConvertFrom (context, sourceType);
                }
-\r
+
                public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
                {
                        if (destinationType == typeof (string))
@@ -65,7 +65,7 @@ namespace System.Drawing
 
                        return base.CanConvertTo (context, destinationType);
                }
-\r
+
                public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
                {
                        string s = value as string;
@@ -86,35 +86,35 @@ namespace System.Drawing
                        return new SizeF (numSubs[0], numSubs[1]);
 
                }
-\r
+
                public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                {
-                       if ((destinationType == typeof (string)) && (value is SizeF))
-                               return ((SizeF) value).Width.ToString(culture) + culture.TextInfo.ListSeparator
-                                       + " " + ((SizeF) value).Height.ToString(culture);
-
-                       if (destinationType == typeof (InstanceDescriptor) && value is SizeF) {
-                               SizeF s = (SizeF) value;
-                               ConstructorInfo ctor = typeof(SizeF).GetConstructor (new Type[] {typeof(int), typeof(int)});
-                               return new InstanceDescriptor (ctor, new object[] {s.Width, s.Height});
+                       if (value is SizeF) {
+                               SizeF size = (SizeF) value;
+                               if (destinationType == typeof (string)) {
+                                       return size.Width.ToString (culture) + culture.TextInfo.ListSeparator
+                                               + " " + size.Height.ToString (culture);
+                               } else if (destinationType == typeof (InstanceDescriptor)) {
+                                       ConstructorInfo ctor = typeof(SizeF).GetConstructor (new Type[] {typeof(float), typeof(float)});
+                                       return new InstanceDescriptor (ctor, new object[] { size.Width, size.Height});
+                               }
                        }
 
                        return base.ConvertTo (context, culture, value, destinationType);
                }
-\r
+
                public override object CreateInstance (ITypeDescriptorContext context, IDictionary propertyValues)
                {
-                       int width = (int) propertyValues ["Width"];
-                       int height = (int) propertyValues ["Height"];
-
-                       return new SizeF (width, height);
+                       float w = (float) propertyValues ["Width"];
+                       float h = (float) propertyValues ["Height"];
+                       return new SizeF (w, h);
                }
-\r
+
                public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
                {
                        return true;
                }
-\r
+
                public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
                {
                        if (value is SizeF)
@@ -122,11 +122,11 @@ namespace System.Drawing
 
                        return base.GetProperties (context, value, attributes);
                }
-\r
+
                public override bool GetPropertiesSupported (ITypeDescriptorContext context)
                {
                        return true;
-               }\r
+               }
        }
 }