2006-03-10 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Padding.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) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using System.Drawing;
30
31 namespace System.Windows.Forms {
32
33         [Serializable]
34         public struct Padding {
35
36                 private int bottom;
37                 private int left;
38                 private int right;
39                 private int top;
40                 private bool initialized;
41
42                 public Padding (int all) {
43                         left = all;
44                         right = all;
45                         top = all;
46                         bottom = all;
47                         initialized = true;
48                 }
49
50                 public Padding (int left, int top, int right, int bottom) {
51                         this.left = left;
52                         this.right = right;
53                         this.top = top;
54                         this.bottom = bottom;
55                         initialized = true;
56                 }
57
58                 public static readonly Padding Empty = new Padding();
59
60                 public int All {
61                         get {
62                                 if (initialized && left == top && left == right && left == bottom) {
63                                         return left;
64                                 }
65                                 return -1;
66                         }
67                         set { Left = Top = Right = Bottom = value; }
68                 }
69
70                 public int Bottom {
71                         get { return bottom; }
72                         set { bottom = value; initialized = true; }
73                 }
74
75                 public int Horizontal {
76                         get { return left + right; }
77                 }
78
79                 public int Left {
80                         get { return left; }
81                         set { left = value; initialized = true; }
82                 }
83
84                 public int Right {
85                         get { return right; }
86                         set { right = value; initialized = true; }
87                 }
88
89                 public Size Size {
90                         get { return new Size(left + right, top + bottom); }
91                 }
92
93                 public int Top {
94                         get { return top; }
95                         set { top = value; initialized = true; }
96                 }
97
98                 public int Vertical {
99                         get { return top + bottom; }
100                 }
101
102                 public static Padding Add (Padding p1, Padding p2) {
103                         return p1 + p2;
104                 }
105
106                 public override bool Equals (object other) {
107                         if (other is Padding) {
108                                 Padding other_aux = (Padding) other;
109                                 return this.left == other_aux.left &&
110                                         this.top == other_aux.top &&
111                                         this.right == other_aux.right &&
112                                         this.bottom == other_aux.bottom;
113                         }
114                         return false;
115                 }
116
117                 public override int GetHashCode () {
118                         ////////////////////////////// COMPROBAR EN Windows /////////////////////////
119                         return top ^ bottom ^ left ^ right;
120                 }
121
122                 public static Padding operator+ (Padding p1, Padding p2) {
123                         return new Padding(p1.Left + p2.Left, p1.Top + p2.Top, p1.Right + p2.Right, p1.Bottom + p2.Bottom);
124                 }
125
126                 public static bool operator== (Padding p1, Padding p2) {
127                         return p1.Equals(p2);
128                 }
129
130                 public static bool operator!= (Padding p1, Padding p2) {
131                         return !(p1.Equals(p2));
132                 }
133
134                 public static Padding operator- (Padding p1, Padding p2) {
135                         return new Padding(p1.Left - p2.Left, p1.Top - p2.Top, p1.Right - p2.Right, p1.Bottom - p2.Bottom);
136                 }
137
138                 public static Padding Subtract (Padding p1, Padding p2) {
139                         return p1 - p2;
140                 }
141
142                 public override string ToString () {
143                         return "{Left=" + Left + ",Top="+ Top + ",Right=" + Right + ",Bottom=" + Bottom + "}"; 
144                 }
145         }
146
147 }
148
149 #endif