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) 2007 Novell, Inc. (http://www.novell.com)
23 // Chris Toshok (toshok@novell.com)
27 using System.ComponentModel;
28 using System.Windows.Converters;
29 using System.Windows.Markup;
31 namespace System.Windows {
34 [ValueSerializer (typeof (SizeValueSerializer))]
35 [TypeConverter (typeof (SizeConverter))]
36 public struct Size : IFormattable
38 public Size (double width, double height)
40 if (width < 0 || height < 0)
41 throw new ArgumentException ("Width and Height must be non-negative.");
47 public bool Equals (Size value)
49 return width == value.Width && height == value.Height;
52 public override bool Equals (object o)
57 return Equals ((Size)o);
60 public static bool Equals (Size size1, Size size2)
62 return size1.Equals (size2);
65 public override int GetHashCode ()
67 throw new NotImplementedException ();
70 public static Size Parse (string source)
72 throw new NotImplementedException ();
75 public override string ToString ()
79 return String.Format ("{0},{1}", width, height);
82 public string ToString (IFormatProvider provider)
84 throw new NotImplementedException ();
87 string IFormattable.ToString (string format, IFormatProvider provider)
89 throw new NotImplementedException ();
94 return (width == Double.NegativeInfinity &&
95 height == Double.NegativeInfinity);
99 public double Height {
100 get { return height; }
103 throw new InvalidOperationException ("Cannot modify this property on the Empty Size.");
106 throw new ArgumentException ("height must be non-negative.");
112 public double Width {
113 get { return width; }
116 throw new InvalidOperationException ("Cannot modify this property on the Empty Size.");
119 throw new ArgumentException ("width must be non-negative.");
125 public static Size Empty {
127 Size s = new Size ();
128 s.width = s.height = Double.NegativeInfinity;
134 public static explicit operator Point (Size size)
136 return new Point (size.Width, size.Height);
139 public static explicit operator Vector (Size size)
141 return new Vector (size.Width, size.Height);
144 public static bool operator ==(Size size1, Size size2)
146 return size1.Equals (size2);
149 public static bool operator !=(Size size1, Size size2)
151 return !size1.Equals (size2);