* Application.cs: fix compilation errors when debug is enabled.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / LinkArea.cs
index 36af1e8594a121ef90e41b8bf838a91122a1798f..0417decd10797a0c417724dad863b734c2e7ffdd 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:
 //
 
 // 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;
        
@@ -55,6 +132,8 @@ namespace System.Windows.Forms
                        set { length = value; }
                }                               
                
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public bool IsEmpty {
                        get {
                                if (start == 0 && length == 0)
@@ -83,6 +162,12 @@ namespace System.Windows.Forms
                        return start << 4 | length;
                }
                
+#if NET_2_0
+               public override string ToString ()
+               {
+                       return string.Format ("{{Start={0}, Length={1}}}", this.start.ToString (), this.length.ToString ());
+               }
+#endif
                #endregion //Methods
                
        }