Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewAdvancedBorderStyle.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 using System;
28 using System.ComponentModel;
29
30 namespace System.Windows.Forms {
31
32         public sealed class DataGridViewAdvancedBorderStyle : ICloneable {
33
34                 private DataGridViewAdvancedCellBorderStyle bottom;
35                 private DataGridViewAdvancedCellBorderStyle left;
36                 private DataGridViewAdvancedCellBorderStyle right;
37                 private DataGridViewAdvancedCellBorderStyle top;
38
39                 public DataGridViewAdvancedBorderStyle ()
40                 {
41                         All = DataGridViewAdvancedCellBorderStyle.None;
42                 }
43
44                 public DataGridViewAdvancedCellBorderStyle All {
45                         get {
46                                 if (bottom == left && left == right && right == top) {
47                                         return bottom;
48                                 }
49                                 return DataGridViewAdvancedCellBorderStyle.NotSet;
50                         }
51                         set {
52                                 if (!Enum.IsDefined(typeof(DataGridViewAdvancedCellBorderStyle), value)) {
53                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAdvancedCellBorderStyle.");
54                                 }
55                                 bottom = left = right = top = value;
56                         }
57                 }
58
59                 public DataGridViewAdvancedCellBorderStyle Bottom {
60                         get { return bottom; }
61                         set {
62                                 if (!Enum.IsDefined(typeof(DataGridViewAdvancedCellBorderStyle), value)) {
63                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAdvancedCellBorderStyle.");
64                                 }
65                                 if (value == DataGridViewAdvancedCellBorderStyle.NotSet) {
66                                         throw new ArgumentException("Invlid Bottom value.");
67                                 }
68                                 bottom = value;
69                         }
70                 }
71
72                 public DataGridViewAdvancedCellBorderStyle Left {
73                         get { return left; }
74                         set {
75                                 if (!Enum.IsDefined(typeof(DataGridViewAdvancedCellBorderStyle), value)) {
76                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAdvancedCellBorderStyle.");
77                                 }
78                                 if (value == DataGridViewAdvancedCellBorderStyle.NotSet) {
79                                         throw new ArgumentException("Invlid Left value.");
80                                 }
81                                 /*
82                                 if (Control.RightToLeft == true && (value == DataGridViewAdvancedCellBorderStyle.InsetDouble || value == DataGridViewAdvancedCellBorderStyle.OutsetDouble)) {
83                                         throw new ArgumentException("Invlid Left value.");
84                                 }
85                                 */
86                                 left = value;
87                         }
88                 }
89
90                 public DataGridViewAdvancedCellBorderStyle Right {
91                         get { return right; }
92                         set {
93                                 if (!Enum.IsDefined(typeof(DataGridViewAdvancedCellBorderStyle), value)) {
94                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAdvancedCellBorderStyle.");
95                                 }
96                                 if (value == DataGridViewAdvancedCellBorderStyle.NotSet) {
97                                         throw new ArgumentException("Invlid Right value.");
98                                 }
99                                 /*
100                                 if (Control.RightToLeft == false && (value == DataGridViewAdvancedCellBorderStyle.InsetDouble || value == DataGridViewAdvancedCellBorderStyle.OutsetDouble)) {
101                                         throw new ArgumentException("Invlid Right value.");
102                                 }
103                                 */
104                                 right = value;
105                         }
106                 }
107
108                 public DataGridViewAdvancedCellBorderStyle Top {
109                         get { return top; }
110                         set {
111                                 if (!Enum.IsDefined(typeof(DataGridViewAdvancedCellBorderStyle), value)) {
112                                         throw new InvalidEnumArgumentException("Value is not valid DataGridViewAdvancedCellBorderStyle.");
113                                 }
114                                 if (value == DataGridViewAdvancedCellBorderStyle.NotSet) {
115                                         throw new ArgumentException("Invlid Top value.");
116                                 }
117                                 top = value;
118                         }
119                 }
120
121                 public override bool Equals (object other)
122                 {
123                         if (other is DataGridViewAdvancedBorderStyle) {
124                                 DataGridViewAdvancedBorderStyle otherAux = (DataGridViewAdvancedBorderStyle) other;
125                                 return bottom == otherAux.bottom &&
126                                         left == otherAux.left &&
127                                         right == otherAux.right &&
128                                         top == otherAux.top;
129                         }
130                         return false;
131                 }
132
133                 public override int GetHashCode ()
134                 {
135                         return base.GetHashCode();
136                 }
137
138                 public override string ToString ()
139                 {
140                         return String.Format("DataGridViewAdvancedBorderStyle { All={0}, Left={1}, Right={2}, Top={3}, Bottom={4} }", All, Left, Right, Top, Bottom);
141                 }
142
143                 object ICloneable.Clone ()
144                 {
145                         DataGridViewAdvancedBorderStyle result = new DataGridViewAdvancedBorderStyle();
146                         result.bottom = this.bottom;
147                         result.left = this.left;
148                         result.right = this.right;
149                         result.top = this.top;
150                         return result;
151                 }
152
153         }
154
155 }