2 // TableLayoutSettings.cs
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.ComponentModel;
32 using System.Collections.Generic;
33 using System.Windows.Forms.Layout;
34 using System.Runtime.Serialization;
36 namespace System.Windows.Forms
39 [TypeConverter (typeof (TableLayoutSettingsTypeConverter))]
40 public sealed class TableLayoutSettings : LayoutSettings, ISerializable
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;
53 #region Internal Constructor
54 internal TableLayoutSettings (TableLayoutPanel panel)
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;
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> ();
69 #region Public Properties
71 public int ColumnCount {
72 get { return this.column_count; }
75 throw new ArgumentOutOfRangeException();
81 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
82 public TableLayoutColumnStyleCollection ColumnStyles {
83 get { return this.column_styles; }
86 [DefaultValue (TableLayoutPanelGrowStyle.AddRows)]
87 public TableLayoutPanelGrowStyle GrowStyle {
88 get { return this.grow_style; }
90 if (!Enum.IsDefined (typeof(TableLayoutPanelGrowStyle), value))
91 throw new ArgumentException();
97 public override LayoutEngine LayoutEngine {
98 get { return this.panel.LayoutEngine; }
102 public int RowCount {
103 get { return this.row_count; }
106 throw new ArgumentOutOfRangeException ();
111 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
112 public TableLayoutRowStyleCollection RowStyles {
113 get { return row_styles; }
117 #region Public Methods
119 public TableLayoutPanelCellPosition GetCellPosition (Object control)
122 throw new ArgumentNullException ();
127 if (!columns.TryGetValue (control, out column))
129 if (!rows.TryGetValue (control, out row))
132 return new TableLayoutPanelCellPosition (column, row);
136 public int GetColumn (Object control)
139 throw new ArgumentNullException ();
143 if (columns.TryGetValue (control, out retval))
149 public int GetColumnSpan (Object control)
152 throw new ArgumentNullException ();
156 if (column_spans.TryGetValue (control, out retval))
163 public int GetRow (Object control)
166 throw new ArgumentNullException ();
170 if (rows.TryGetValue (control, out retval))
176 public int GetRowSpan (Object control)
179 throw new ArgumentNullException ();
183 if (row_spans.TryGetValue (control, out retval))
190 public void SetCellPosition (Object control, TableLayoutPanelCellPosition cellPosition)
193 throw new ArgumentNullException ();
195 columns[control] = cellPosition.Column;
196 rows[control] = cellPosition.Row;
199 public void SetColumn (Object control, int column)
202 throw new ArgumentNullException ();
204 throw new ArgumentException ();
206 columns[control] = column;
209 public void SetColumnSpan (Object control, int value)
212 throw new ArgumentNullException ();
214 throw new ArgumentException ();
216 column_spans[control] = value;
219 public void SetRow (Object control, int row)
222 throw new ArgumentNullException ();
224 throw new ArgumentException ();
229 public void SetRowSpan (Object control, int value)
232 throw new ArgumentNullException ();
234 throw new ArgumentException ();
236 row_spans[control] = value;
240 #region ISerializable Members
241 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
243 throw new NotImplementedException ();