[corlib] Tweak the fix for the reference sources' inability to support sub-minute...
[mono.git] / mcs / class / WindowsBase / System.Windows / Size.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) 2007 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Chris Toshok (toshok@novell.com)
24 //
25
26 using System;
27 using System.ComponentModel;
28 using System.Windows.Converters;
29 using System.Windows.Markup;
30
31 namespace System.Windows {
32
33         [Serializable]
34         [ValueSerializer (typeof (SizeValueSerializer))]
35         [TypeConverter (typeof (SizeConverter))]
36         public struct Size : IFormattable
37         {
38                 public Size (double width, double height)
39                 {
40                         if (width < 0 || height < 0)
41                                 throw new ArgumentException ("Width and Height must be non-negative.");
42
43                         this.width = width;
44                         this.height = height;
45                 }
46
47                 public bool Equals (Size value)
48                 {
49                         return width == value.Width && height == value.Height;
50                 }
51                 
52                 public override bool Equals (object o)
53                 {
54                         if (!(o is Size))
55                                 return false;
56
57                         return Equals ((Size)o);
58                 }
59
60                 public static bool Equals (Size size1, Size size2)
61                 {
62                         return size1.Equals (size2);
63                 }
64
65                 public override int GetHashCode ()
66                 {
67                         throw new NotImplementedException ();
68                 }
69
70                 public static Size Parse (string source)
71                 {
72                         throw new NotImplementedException ();
73                 }
74
75                 public override string ToString ()
76                 {
77                         if (IsEmpty)
78                                 return "Empty";
79                         return String.Format ("{0},{1}", width, height);
80                 }
81
82                 public string ToString (IFormatProvider provider)
83                 {
84                         throw new NotImplementedException ();
85                 }
86
87                 string IFormattable.ToString (string format, IFormatProvider provider)
88                 {
89                         throw new NotImplementedException ();
90                 }
91
92                 public bool IsEmpty {
93                         get {
94                                 return (width == Double.NegativeInfinity &&
95                                         height == Double.NegativeInfinity);
96                         }
97                 }
98
99                 public double Height {
100                         get { return height; }
101                         set {
102                                 if (IsEmpty)
103                                         throw new InvalidOperationException ("Cannot modify this property on the Empty Size.");
104
105                                 if (value < 0)
106                                         throw new ArgumentException ("height must be non-negative.");
107
108                                 height = value;
109                         }
110                 }
111
112                 public double Width {
113                         get { return width; }
114                         set {
115                                 if (IsEmpty)
116                                         throw new InvalidOperationException ("Cannot modify this property on the Empty Size.");
117
118                                 if (value < 0)
119                                         throw new ArgumentException ("width must be non-negative.");
120
121                                 width = value;
122                         }
123                 }
124
125                 public static Size Empty {
126                         get {
127                                 Size s = new Size ();
128                                 s.width = s.height = Double.NegativeInfinity;
129                                 return s;
130                         }
131                 }
132
133                 /* operators */
134                 public static explicit operator Point (Size size)
135                 {
136                         return new Point (size.Width, size.Height);
137                 }
138
139                 public static explicit operator Vector (Size size)
140                 {
141                         return new Vector (size.Width, size.Height);
142                 }
143
144                 public static bool operator ==(Size size1, Size size2)
145                 {
146                         return size1.Equals (size2);
147                 }
148
149                 public static bool operator !=(Size size1, Size size2)
150                 {
151                         return !size1.Equals (size2);
152                 }
153
154                 double width;
155                 double height;
156         }
157 }