1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
24 // Dennis Hayes, dennish@raytek.com
25 // Andreas Nahr, ClassDevelopment@A-SoftTech.com
26 // Jordi Mas i Hernandez, jordi@ximian.com
32 using System.ComponentModel;
33 using System.Globalization;
35 namespace System.Windows.Forms
38 [TypeConverter(typeof(LinkArea.LinkAreaConverter))]
39 public struct LinkArea
41 #region LinkAreaConverter Class
42 public class LinkAreaConverter : TypeConverter {
43 public LinkAreaConverter() {
46 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
47 if (sourceType == typeof(string)) {
50 return base.CanConvertFrom(context, sourceType);
53 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
54 if (destinationType == typeof(string)) {
57 return base.CanConvertTo(context, destinationType);
60 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
65 if ((value == null) || !(value is String)) {
66 return base.ConvertFrom (context, culture, value);
69 if (culture == null) {
70 culture = CultureInfo.CurrentCulture;
73 parts = ((string)value).Split(culture.TextInfo.ListSeparator.ToCharArray());
74 start = int.Parse(parts[0].Trim());
75 length = int.Parse(parts[1].Trim());
76 return new LinkArea(start, length);
79 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
82 if ((value == null) || !(value is LinkArea) || (destinationType != typeof(string))) {
83 return base.ConvertTo (context, culture, value, destinationType);
86 if (culture == null) {
87 culture = CultureInfo.CurrentCulture;
93 return l.Start.ToString() + culture.TextInfo.ListSeparator + l.Length.ToString();
96 public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) {
97 return new LinkArea((int)propertyValues["Start"], (int)propertyValues["Length"]);
100 public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) {
104 public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
105 return TypeDescriptor.GetProperties(typeof(LinkArea), attributes);
108 public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
112 #endregion // LinkAreaConverter Class
117 public LinkArea (int start, int length)
120 this.length = length;
123 #region Public Properties
126 get { return start; }
127 set { start = value; }
131 get { return length; }
132 set { length = value; }
136 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
137 public bool IsEmpty {
139 if (start == 0 && length == 0)
147 #endregion //Public Properties
151 public override bool Equals (object o)
153 if (!(o is LinkArea))
156 LinkArea comp = (LinkArea) o;
157 return (comp.Start == start && comp.Length == length);
160 public override int GetHashCode ()
162 return start << 4 | length;
166 public override string ToString ()
168 return string.Format ("{{Start={0}, Length={1}}}", this.start.ToString (), this.length.ToString ());
171 public static bool operator == (LinkArea linkArea1, LinkArea linkArea2)
173 return (linkArea1.Length == linkArea2.Length) && (linkArea1.Start == linkArea2.Start);
176 public static bool operator != (LinkArea linkArea1, LinkArea linkArea2)
178 return !(linkArea1 == linkArea2);