[jit] Enable partial generic sharing when not using AOT as an experiment.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / LinkArea.cs
index c817501ca8777a4592a0f925f21fd3e0f59cf7cd..d6241a2cf8e47853b46a221a37deded0f8f17da8 100644 (file)
@@ -17,7 +17,7 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // Authors:
 //
 //     Andreas Nahr, ClassDevelopment@A-SoftTech.com
 //     Jordi Mas i Hernandez, jordi@ximian.com
 //
-// $Revision: 1.2 $
-// $Modtime: $
-// $Log: LinkArea.cs,v $
-// Revision 1.2  2004/08/11 22:20:59  pbartok
-// - Signature fixes
-//
-// Revision 1.1  2004/07/21 16:19:17  jordi
-// LinkLabel control implementation
-//
-//
+
 
 // COMPLETE
 
+using System.ComponentModel;
+using System.Globalization;
+
 namespace System.Windows.Forms
 {
        [Serializable]
+       [TypeConverter(typeof(LinkArea.LinkAreaConverter))]
        public struct LinkArea
        {
+               #region LinkAreaConverter Class
+               public class LinkAreaConverter : TypeConverter {
+                       public LinkAreaConverter() {
+                       }
+
+                       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[]        parts;
+                               int             start;
+                               int             length;
+
+                               if ((value == null) || !(value is String)) {
+                                       return base.ConvertFrom (context, culture, value);
+                               }
+
+                               if (culture == null) {
+                                       culture = CultureInfo.CurrentCulture;
+                               }
+
+                               parts = ((string)value).Split(culture.TextInfo.ListSeparator.ToCharArray());
+                               start = int.Parse(parts[0].Trim());
+                               length = int.Parse(parts[1].Trim());
+                               return new LinkArea(start, length);
+                       }
+
+                       public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
+                               LinkArea        l;
+
+                               if ((value == null) || !(value is LinkArea) || (destinationType != typeof(string))) {
+                                       return base.ConvertTo (context, culture, value, destinationType);
+                               }
+
+                               if (culture == null) {
+                                       culture = CultureInfo.CurrentCulture;
+                               }
+
+                               l = (LinkArea)value;
+
+
+                               return l.Start.ToString() + culture.TextInfo.ListSeparator + l.Length.ToString();
+                       }
+
+                       public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) {
+                               return new LinkArea((int)propertyValues["Start"], (int)propertyValues["Length"]);
+                       }
+
+                       public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) {
+                               return true;
+                       }
+
+                       public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
+                               return TypeDescriptor.GetProperties(typeof(LinkArea), attributes);
+                       }
+
+                       public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
+                               return true;
+                       }
+               }               
+               #endregion      // LinkAreaConverter Class
+
                private int start;
                private int length;
        
@@ -64,6 +132,8 @@ namespace System.Windows.Forms
                        set { length = value; }
                }                               
                
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool IsEmpty {
                        get {
                                if (start == 0 && length == 0)
@@ -92,6 +162,20 @@ namespace System.Windows.Forms
                        return start << 4 | length;
                }
                
+               public override string ToString ()
+               {
+                       return string.Format ("{{Start={0}, Length={1}}}", this.start.ToString (), this.length.ToString ());
+               }
+               
+               public static bool operator == (LinkArea linkArea1, LinkArea linkArea2)
+               {
+                       return (linkArea1.Length == linkArea2.Length) && (linkArea1.Start == linkArea2.Start);
+               }
+
+               public static bool operator != (LinkArea linkArea1, LinkArea linkArea2)
+               {
+                       return !(linkArea1 == linkArea2);
+               }
                #endregion //Methods
                
        }