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) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
31 namespace System.Windows.Forms {
33 [SerializableAttribute()]
34 public struct Padding {
40 private bool initialized;
42 public Padding (int all) {
43 Bottom = Left = Right = Top = all;
46 public Padding (int left, int top, int right, int bottom) {
53 public static readonly Padding Empty = new Padding();
57 if (initialized && left == top && left == right && left == bottom) {
62 set { Left = Top = Right = Bottom = value; }
66 get { return bottom; }
67 set { bottom = value; initialized = true; }
70 public int Horizontal {
71 get { return left + right; }
76 set { left = value; initialized = true; }
81 set { right = value; initialized = true; }
85 get { return new Size(left + right, top + bottom); }
90 set { top = value; initialized = true; }
94 get { return top + bottom; }
97 public static Padding Add (Padding p1, Padding p2) {
98 return op_Addition(p1, p2);
101 public override bool Equals (object other) {
102 if (other is Padding) {
103 Padding other_aux = (Padding) other;
104 return this.left == other_aux.left &&
105 this.top == other_aux.top &&
106 this.right == other_aux.right &&
107 this.bottom == other_aux.bottom;
112 public override int GetHashCode () {
113 ////////////////////////////// COMPROBAR EN Windows /////////////////////////
114 return top ^ bottom ^ left ^ right;
117 public static Padding op_Addition (Padding p1, Padding p2) {
118 return new Padding(p1.Left + p2.Left, p1.Top + p2.Top, p1.Right + p2.Right, p1.Bottom + p2.Bottom);
121 public static bool op_Equality (Padding p1, Padding p2) {
122 return p1.Equals(p2);
125 public static bool op_Inequality (Padding p1, Padding p2) {
126 return !(p1.Equals(p2));
129 public static Padding op_Subtraction (Padding p1, Padding p2) {
130 return new Padding(p1.Left - p2.Left, p1.Top - p2.Top, p1.Right - p2.Right, p1.Bottom - p2.Bottom);
133 public static Padding Subtract (Padding p1, Padding p2) {
134 return op_Subtraction(p1, p2);
137 public override string ToString () {
138 return "{Left=" + Left + ",Top="+ Top + ",Right=" + Right + ",Bottom=" + Bottom + "}";