2 // System.Drawing.Margins.cs
5 // Dennis Hayes (dennish@Raytek.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 // Sebastien Pouliot <sebastien@ximian.com>
9 // (C) 2002 Ximian, Inc
10 // Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
34 namespace System.Drawing.Printing
39 [TypeConverter (typeof (MarginsConverter))]
40 public class Margins : ICloneable {
54 public Margins (int left, int right, int top, int bottom)
68 InvalidMargin ("left");
79 InvalidMargin ("right");
90 InvalidMargin ("top");
101 InvalidMargin ("bottom");
106 private void InvalidMargin (string property)
108 string msg = Locale.GetText ("All Margins must be greater than 0");
109 throw new System.ArgumentException (msg, property);
112 public object Clone ()
114 return new Margins (left, right, top, bottom);
117 public override bool Equals (object obj)
119 return Equals (obj as Margins);
122 private bool Equals (Margins m)
124 // avoid recursion with == operator
125 if ((object)m == null)
127 return ((m.Left == left) && (m.Right == right) && (m.Top == top) && (m.Bottom == bottom));
130 public override int GetHashCode ()
132 return left | (right << 8) | (right >> 24) | (top << 16) | (top >> 16) | (bottom << 24) | (bottom >> 8);
135 public override string ToString ()
137 string ret = "[Margins Left={0} Right={1} Top={2} Bottom={3}]";
138 return String.Format (ret, left, right, top, bottom);
142 public static bool operator == (Margins m1, Margins m2)
144 // avoid recursion with == operator
145 if ((object)m1 == null)
146 return ((object)m2 == null);
147 return m1.Equals (m2);
150 public static bool operator != (Margins m1, Margins m2)
152 // avoid recursion with == operator
153 if ((object)m1 == null)
154 return ((object)m2 != null);
155 return !m1.Equals (m2);