// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2005,2006 Novell, Inc. (http://www.novell.com)
//
// Author:
// Pedro MartÃnez Juliá <pedromj@gmail.com>
+// Daniel Nauck (dna(at)mono-project(dot)de)
//
-
#if NET_2_0
+using System;
+using System.ComponentModel;
using System.Drawing;
namespace System.Windows.Forms {
- [SerializableAttribute()]
+ [Serializable]
+ //FIXME: implement [TypeConverter(typeof(PaddingConverter))]
public struct Padding {
- private int bottom;
- private int left;
- private int right;
- private int top;
+ //NOTE: "_var" field name is required by serialization.
+ private int _bottom;
+ private int _left;
+ private int _right;
+ private int _top;
+ private bool _all;
public Padding (int all) {
- bottom = left = right = top = all;
+ _left = all;
+ _right = all;
+ _top = all;
+ _bottom = all;
+ _all = true;
}
public Padding (int left, int top, int right, int bottom) {
- this.left = left;
- this.top = top;
- this.right = right;
- this.bottom = bottom;
+ _left = left;
+ _right = right;
+ _top = top;
+ _bottom = bottom;
+ _all = (_left == _top) && (_left == _right) && (_left == _bottom);
}
public static readonly Padding Empty = new Padding(0);
+ [RefreshProperties(RefreshProperties.All)]
public int All {
- get {
- if (left == top && left == right && left == bottom) {
- return left;
- }
- return -1;
+ get {
+ if(!_all)
+ return -1;
+ else
+ return _top;
+ }
+ set {
+ _all = true;
+ _left = _top = _right = _bottom = value;
}
- set { left = top = right = bottom = value; }
}
+ [RefreshProperties(RefreshProperties.All)]
public int Bottom {
- get { return bottom; }
- set { bottom = value; }
+ get { return _bottom; }
+ set {
+ _bottom = value;
+ _all = false;
+ }
}
+ [Browsable(false)]
public int Horizontal {
- get { return left + right; }
+ get { return _left + _right; }
}
+ [RefreshProperties(RefreshProperties.All)]
public int Left {
- get { return left; }
- set { left = value; }
+ get { return _left; }
+ set {
+ _left = value;
+ _all = false;
+ }
}
+ [RefreshProperties(RefreshProperties.All)]
public int Right {
- get { return right; }
- set { right = value; }
+ get { return _right; }
+ set {
+ _right = value;
+ _all = false;
+ }
}
+ [Browsable(false)]
public Size Size {
- get { return new Size(left + right, top + bottom); }
+ get { return new Size(Horizontal, Vertical); }
}
+ [RefreshProperties(RefreshProperties.All)]
public int Top {
- get { return top; }
- set { top = value; }
+ get { return _top; }
+ set {
+ _top = value;
+ _all = false;
+ }
}
+ [Browsable(false)]
public int Vertical {
- get { return top + bottom; }
+ get { return _top + _bottom; }
}
public static Padding Add (Padding p1, Padding p2) {
- return op_Addition(p1, p2);
+ return p1 + p2;
}
public override bool Equals (object other) {
if (other is Padding) {
Padding other_aux = (Padding) other;
- return this.left == other_aux.left &&
- this.top == other_aux.top &&
- this.right == other_aux.right &&
- this.bottom == other_aux.bottom;
+ return _left == other_aux.Left &&
+ _top == other_aux.Top &&
+ _right == other_aux.Right &&
+ _bottom == other_aux.Bottom;
}
return false;
}
public override int GetHashCode () {
- ////////////////////////////// COMPROBAR EN Windows /////////////////////////
- return top ^ bottom ^ left ^ right;
+ return _top ^ _bottom ^ _left ^ _right;
}
- public static Padding op_Addition (Padding p1, Padding p2) {
+ public static Padding operator+ (Padding p1, Padding p2) {
return new Padding(p1.Left + p2.Left, p1.Top + p2.Top, p1.Right + p2.Right, p1.Bottom + p2.Bottom);
}
- public static bool op_Equality (Padding p1, Padding p2) {
+ public static bool operator== (Padding p1, Padding p2) {
return p1.Equals(p2);
}
- public static bool op_Inequality (Padding p1, Padding p2) {
+ public static bool operator!= (Padding p1, Padding p2) {
return !(p1.Equals(p2));
}
- public static Padding op_Subtraction (Padding p1, Padding p2) {
+ public static Padding operator- (Padding p1, Padding p2) {
return new Padding(p1.Left - p2.Left, p1.Top - p2.Top, p1.Right - p2.Right, p1.Bottom - p2.Bottom);
}
public static Padding Subtract (Padding p1, Padding p2) {
- return op_Subtraction(p1, p2);
+ return p1 - p2;
}
public override string ToString () {
- return ""; ////////////////////////// Windows //////////////////////////////////
+ return "{Left=" + Left + ",Top="+ Top + ",Right=" + Right + ",Bottom=" + Bottom + "}";
}
-
}
-
}
-
#endif