flush
[mcs.git] / class / System.Drawing / System.Drawing.Printing / Margins.cs
blob6a4f959d9cfe614cac78a1caa5f9d34b7130993d
1 //
2 // System.Drawing.Margins.cs
3 //
4 // Authors:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 // Sebastien Pouliot <sebastien@ximian.com>
8 //
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:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
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
36 #if NET_2_0
37 [Serializable]
38 #endif
39 [TypeConverter (typeof (MarginsConverter))]
40 public class Margins : ICloneable {
41 int left;
42 int right;
43 int top;
44 int bottom;
46 public Margins ()
48 left = 100;
49 right = 100;
50 top = 100;
51 bottom = 100;
54 public Margins (int left, int right, int top, int bottom)
56 Left = left;
57 Right = right;
58 Top = top;
59 Bottom = bottom;
62 public int Left {
63 get {
64 return left;
66 set {
67 if (value < 0)
68 InvalidMargin ("left");
69 left = value;
73 public int Right {
74 get {
75 return right;
77 set {
78 if (value < 0)
79 InvalidMargin ("right");
80 right = value;
84 public int Top {
85 get {
86 return top;
88 set {
89 if (value < 0)
90 InvalidMargin ("top");
91 top = value;
95 public int Bottom {
96 get {
97 return bottom;
99 set {
100 if (value < 0)
101 InvalidMargin ("bottom");
102 bottom = value;
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)
126 return false;
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);
141 #if NET_2_0
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);
157 #endif