Grasshopper project system now uses csproj extension
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TableLayoutSettings.cs
1 //
2 // TableLayoutSettings.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2006 Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28
29 #if NET_2_0
30 using System;
31 using System.ComponentModel;
32 using System.Collections.Generic;
33 using System.Windows.Forms.Layout;
34 using System.Runtime.Serialization;
35
36 namespace System.Windows.Forms 
37 {
38         [Serializable]
39         [TypeConverter (typeof (TableLayoutSettingsTypeConverter))]
40         public sealed class TableLayoutSettings : LayoutSettings, ISerializable 
41         {
42                 private TableLayoutColumnStyleCollection column_styles;
43                 private TableLayoutRowStyleCollection row_styles;
44                 private TableLayoutPanelGrowStyle grow_style;
45                 private int column_count;
46                 private int row_count;
47                 private Dictionary<Object, int> columns;
48                 private Dictionary<Object, int> column_spans;
49                 private Dictionary<Object, int> rows;
50                 private Dictionary<Object, int> row_spans;
51                 private TableLayoutPanel panel;
52
53                 #region Internal Constructor
54                 internal TableLayoutSettings (TableLayoutPanel panel)
55                 {
56                         this.column_styles = new TableLayoutColumnStyleCollection (panel);
57                         this.row_styles = new TableLayoutRowStyleCollection (panel);
58                         this.grow_style = TableLayoutPanelGrowStyle.AddRows;
59                         this.column_count = 0;
60                         this.row_count = 0;
61                         this.columns = new Dictionary<object, int> ();
62                         this.column_spans = new Dictionary<object, int> ();
63                         this.rows = new Dictionary<object, int> ();
64                         this.row_spans = new Dictionary<object, int> ();
65                         this.panel = panel;
66                 }
67                 #endregion              
68
69                 #region Public Properties
70                 [DefaultValue (0)]
71                 public int ColumnCount {
72                         get { return this.column_count; }
73                         set {
74                                 if (value < 0)
75                                         throw new ArgumentOutOfRangeException();
76                                         
77                                 column_count = value;
78                         }
79                 }
80
81                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
82                 public TableLayoutColumnStyleCollection ColumnStyles {
83                         get { return this.column_styles; }
84                 }
85
86                 [DefaultValue (TableLayoutPanelGrowStyle.AddRows)]
87                 public TableLayoutPanelGrowStyle GrowStyle {
88                         get { return this.grow_style; }
89                         set {
90                                 if (!Enum.IsDefined (typeof(TableLayoutPanelGrowStyle), value))
91                                         throw new ArgumentException();
92                                         
93                                 grow_style = value;
94                         }
95                 }
96                 
97                 public override LayoutEngine LayoutEngine {
98                         get { return this.panel.LayoutEngine; }
99                 }
100                 
101                 [DefaultValue (0)]
102                 public int RowCount {
103                         get { return this.row_count; }
104                         set {
105                                 if (value < 0)
106                                         throw new ArgumentOutOfRangeException ();
107                                 row_count = value;
108                         }
109                 }
110
111                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
112                 public TableLayoutRowStyleCollection RowStyles {
113                         get { return row_styles; }
114                 }
115                 #endregion
116
117                 #region Public Methods
118                 [DefaultValue (-1)]
119                 public TableLayoutPanelCellPosition GetCellPosition (Object control)
120                 {
121                         if (control == null)
122                                 throw new ArgumentNullException ();
123
124                         int column;
125                         int row;
126
127                         if (!columns.TryGetValue (control, out column))
128                                 column = -1;
129                         if (!rows.TryGetValue (control, out row))
130                                 row = -1;
131
132                         return new TableLayoutPanelCellPosition (column, row);
133                 }
134
135                 [DefaultValue (-1)]
136                 public int GetColumn (Object control)
137                 {
138                         if (control == null)
139                                 throw new ArgumentNullException ();
140
141                         int retval;
142
143                         if (columns.TryGetValue (control, out retval))
144                                 return retval;
145
146                         return -1;
147                 }
148
149                 public int GetColumnSpan (Object control)
150                 {
151                         if (control == null)
152                                 throw new ArgumentNullException ();
153
154                         int retval;
155
156                         if (column_spans.TryGetValue (control, out retval))
157                                 return retval;
158
159                         return 1;
160                 }
161
162                 [DefaultValue (-1)]
163                 public int GetRow (Object control)
164                 {
165                         if (control == null)
166                                 throw new ArgumentNullException ();
167
168                         int retval;
169
170                         if (rows.TryGetValue (control, out retval))
171                                 return retval;
172
173                         return -1;
174                 }
175
176                 public int GetRowSpan (Object control)
177                 {
178                         if (control == null)
179                                 throw new ArgumentNullException ();
180
181                         int retval;
182
183                         if (row_spans.TryGetValue (control, out retval))
184                                 return retval;
185
186                         return 1;
187                 }
188
189                 [DefaultValue (-1)]
190                 public void SetCellPosition (Object control, TableLayoutPanelCellPosition cellPosition)
191                 {
192                         if (control == null)
193                                 throw new ArgumentNullException ();
194
195                         columns[control] = cellPosition.Column;
196                         rows[control] = cellPosition.Row;
197                 }
198
199                 public void SetColumn (Object control, int column)
200                 {
201                         if (control == null)
202                                 throw new ArgumentNullException ();
203                         if (column < -1)
204                                 throw new ArgumentException ();
205                                 
206                         columns[control] = column;
207                 }
208
209                 public void SetColumnSpan (Object control, int value)
210                 {
211                         if (control == null)
212                                 throw new ArgumentNullException ();
213                         if (value < -1)
214                                 throw new ArgumentException ();
215
216                         column_spans[control] = value;
217                 }
218
219                 public void SetRow (Object control, int row)
220                 {
221                         if (control == null)
222                                 throw new ArgumentNullException ();
223                         if (row < -1)
224                                 throw new ArgumentException ();
225
226                         rows[control] = row;
227                 }
228
229                 public void SetRowSpan (Object control, int value)
230                 {
231                         if (control == null)
232                                 throw new ArgumentNullException ();
233                         if (value < -1)
234                                 throw new ArgumentException ();
235
236                         row_spans[control] = value;
237                 }
238                 #endregion
239
240                 #region ISerializable Members
241                 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
242                 {
243                         throw new NotImplementedException ();
244                 }
245                 #endregion
246         }
247 }
248 #endif