X11: improve handling of WS_EX_TOPMOST
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / LinkArea.cs
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //
24 //      Dennis Hayes, dennish@raytek.com
25 //      Andreas Nahr, ClassDevelopment@A-SoftTech.com
26 //      Jordi Mas i Hernandez, jordi@ximian.com
27 //
28
29
30 // COMPLETE
31
32 using System.ComponentModel;
33 using System.Globalization;
34
35 namespace System.Windows.Forms
36 {
37         [Serializable]
38         [TypeConverter(typeof(LinkArea.LinkAreaConverter))]
39         public struct LinkArea
40         {
41                 #region LinkAreaConverter Class
42                 public class LinkAreaConverter : TypeConverter {
43                         public LinkAreaConverter() {
44                         }
45
46                         public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
47                                 if (sourceType == typeof(string)) {
48                                         return true;
49                                 }
50                                 return base.CanConvertFrom(context, sourceType);
51                         }
52
53                         public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
54                                 if (destinationType == typeof(string)) {
55                                         return true;
56                                 }
57                                 return base.CanConvertTo(context, destinationType);
58                         }
59
60                         public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
61                                 string[]        parts;
62                                 int             start;
63                                 int             length;
64
65                                 if ((value == null) || !(value is String)) {
66                                         return base.ConvertFrom (context, culture, value);
67                                 }
68
69                                 if (culture == null) {
70                                         culture = CultureInfo.CurrentCulture;
71                                 }
72
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);
77                         }
78
79                         public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
80                                 LinkArea        l;
81
82                                 if ((value == null) || !(value is LinkArea) || (destinationType != typeof(string))) {
83                                         return base.ConvertTo (context, culture, value, destinationType);
84                                 }
85
86                                 if (culture == null) {
87                                         culture = CultureInfo.CurrentCulture;
88                                 }
89
90                                 l = (LinkArea)value;
91
92
93                                 return l.Start.ToString() + culture.TextInfo.ListSeparator + l.Length.ToString();
94                         }
95
96                         public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues) {
97                                 return new LinkArea((int)propertyValues["Start"], (int)propertyValues["Length"]);
98                         }
99
100                         public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) {
101                                 return true;
102                         }
103
104                         public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
105                                 return TypeDescriptor.GetProperties(typeof(LinkArea), attributes);
106                         }
107
108                         public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
109                                 return true;
110                         }
111                 }               
112                 #endregion      // LinkAreaConverter Class
113
114                 private int start;
115                 private int length;
116         
117                 public LinkArea (int start, int length)
118                 {
119                         this.start = start;
120                         this.length = length;
121                 }
122                 
123                 #region Public Properties
124                 
125                 public int Start {
126                         get { return start; }
127                         set { start = value; }
128                 }
129
130                 public int Length {
131                         get { return length; }
132                         set { length = value; }
133                 }                               
134                 
135                 [Browsable (false)]
136                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
137                 public bool IsEmpty {
138                         get {
139                                 if (start == 0 && length == 0)
140                                         return true;
141                                 else
142                                         return false;                   
143                                 
144                         }
145                 }
146                 
147                 #endregion //Public Properties
148                 
149                 #region Methods
150
151                 public override bool Equals (object o)
152                 {
153                         if (!(o is LinkArea)) 
154                                 return false;                   
155
156                         LinkArea comp = (LinkArea) o;
157                         return (comp.Start == start && comp.Length == length);
158                 }
159
160                 public override int GetHashCode ()
161                 {
162                         return start << 4 | length;
163                 }
164                 
165                 public override string ToString ()
166                 {
167                         return string.Format ("{{Start={0}, Length={1}}}", this.start.ToString (), this.length.ToString ());
168                 }
169                 
170                 public static bool operator == (LinkArea linkArea1, LinkArea linkArea2)
171                 {
172                         return (linkArea1.Length == linkArea2.Length) && (linkArea1.Start == linkArea2.Start);
173                 }
174
175                 public static bool operator != (LinkArea linkArea1, LinkArea linkArea2)
176                 {
177                         return !(linkArea1 == linkArea2);
178                 }
179                 #endregion //Methods
180                 
181         }
182 }