This should fix #76928. This fix incorporates ideas from a patch
[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         [SerializableAttribute()]
34         public struct Padding {
35
36                 private int bottom;
37                 private int left;
38                 private int right;
39                 private int top;
40
41                 public Padding (int all) {
42                         bottom = left = right = top = all;
43                 }
44
45                 public Padding (int left, int top, int right, int bottom) {
46                         this.left = left;
47                         this.top = top;
48                         this.right = right;
49                         this.bottom = bottom;
50                 }
51
52                 public static readonly Padding Empty = new Padding(0);
53
54                 public int All {
55                         get {
56                                 if (left == top && left == right && left == bottom) {
57                                         return left;
58                                 }
59                                 return -1;
60                         }
61                         set { left = top = right = bottom = value; }
62                 }
63
64                 public int Bottom {
65                         get { return bottom; }
66                         set { bottom = value; }
67                 }
68
69                 public int Horizontal {
70                         get { return left + right; }
71                 }
72
73                 public int Left {
74                         get { return left; }
75                         set { left = value; }
76                 }
77
78                 public int Right {
79                         get { return right; }
80                         set { right = value; }
81                 }
82
83                 public Size Size {
84                         get { return new Size(left + right, top + bottom); }
85                 }
86
87                 public int Top {
88                         get { return top; }
89                         set { top = value; }
90                 }
91
92                 public int Vertical {
93                         get { return top + bottom; }
94                 }
95
96                 public static Padding Add (Padding p1, Padding p2) {
97                         return op_Addition(p1, p2);
98                 }
99
100                 public override bool Equals (object other) {
101                         if (other is Padding) {
102                                 Padding other_aux = (Padding) other;
103                                 return this.left == other_aux.left &&
104                                         this.top == other_aux.top &&
105                                         this.right == other_aux.right &&
106                                         this.bottom == other_aux.bottom;
107                         }
108                         return false;
109                 }
110
111                 public override int GetHashCode () {
112                         ////////////////////////////// COMPROBAR EN Windows /////////////////////////
113                         return top ^ bottom ^ left ^ right;
114                 }
115
116                 public static Padding op_Addition (Padding p1, Padding p2) {
117                         return new Padding(p1.Left + p2.Left, p1.Top + p2.Top, p1.Right + p2.Right, p1.Bottom + p2.Bottom);
118                 }
119
120                 public static bool op_Equality (Padding p1, Padding p2) {
121                         return p1.Equals(p2);
122                 }
123
124                 public static bool op_Inequality (Padding p1, Padding p2) {
125                         return !(p1.Equals(p2));
126                 }
127
128                 public static Padding op_Subtraction (Padding p1, Padding p2) {
129                         return new Padding(p1.Left - p2.Left, p1.Top - p2.Top, p1.Right - p2.Right, p1.Bottom - p2.Bottom);
130                 }
131
132                 public static Padding Subtract (Padding p1, Padding p2) {
133                         return op_Subtraction(p1, p2);
134                 }
135
136                 public override string ToString () {
137                         return ""; ////////////////////////// Windows //////////////////////////////////
138                 }
139
140         }
141
142 }
143
144 #endif