090ba92ecf7adafc75b7a0bed0ff14e87293dda3
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / TableLayoutStyleCollection.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 //
21 // Author:
22 //   Miguel de Icaza (miguel@gnome.org)
23 //
24 // Copyright 2004-2006 Novell, Inc.
25 //
26
27 using System;
28 using System.ComponentModel;
29 using System.Collections;
30 using System.Windows.Forms.Layout;
31
32 namespace System.Windows.Forms {
33         [Editor ("System.Windows.Forms.Design.StyleCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
34         public abstract class TableLayoutStyleCollection : IList, ICollection, IEnumerable
35         {
36                 ArrayList al = new ArrayList ();
37                 TableLayoutPanel table;
38                 
39                 internal TableLayoutStyleCollection (TableLayoutPanel table)
40                 {
41                         if (table == null)
42                                 throw new ArgumentNullException("table");
43                         
44                         this.table = table;
45                 }
46                 
47                 public int Add (TableLayoutStyle style)
48                 {
49                         return ((IList)this).Add (style);
50                 }
51                 
52                 public void Clear ()
53                 {
54                         foreach (TableLayoutStyle style in al)
55                                 style.Owner = null;
56                         al.Clear ();
57                         table.PerformLayout ();
58                 }
59                 
60                 public int Count {
61                         get { return al.Count; }
62                 }
63                 
64                 public void RemoveAt (int index)
65                 {
66                         ((TableLayoutStyle)al[index]).Owner = null;
67                         al.RemoveAt (index);
68                         table.PerformLayout ();
69                 }
70                 
71 #region IList methods
72                 //
73                 // The IList methods will later be implemeneted, this is to get us started
74                 //
75                 int IList.Add (object style)
76                 {
77                         TableLayoutStyle layoutStyle = (TableLayoutStyle) style;
78                         if (layoutStyle.Owner != null)
79                                 throw new ArgumentException ("Style is already owned");
80
81                         layoutStyle.Owner = table;
82                         int result = al.Add (layoutStyle);
83
84                         if (table != null)
85                                 table.PerformLayout ();
86
87                         return result;
88                 }
89                 
90                 bool IList.Contains (object style)
91                 {
92                         return al.Contains ((TableLayoutStyle) style);
93                 }
94                 
95                 int IList.IndexOf (object style)
96                 {
97                         return al.IndexOf ((TableLayoutStyle) style);
98                 }
99                 
100                 void IList.Insert (int index, object style)
101                 {
102                         if (((TableLayoutStyle)style).Owner != null)
103                                 throw new ArgumentException ("Style is already owned");
104                         ((TableLayoutStyle)style).Owner = table;
105                         al.Insert (index, (TableLayoutStyle) style);
106                         table.PerformLayout ();
107                 }
108
109                 void IList.Remove (object style)
110                 {
111                         ((TableLayoutStyle)style).Owner = null;
112                         al.Remove ((TableLayoutStyle) style);
113                         table.PerformLayout ();
114                 }
115
116                 bool IList.IsFixedSize {
117                         get {
118                                 return al.IsFixedSize;
119                         }
120                 }
121
122                 bool IList.IsReadOnly {
123                         get {
124                                 return al.IsReadOnly;
125                         }
126                 }
127
128                 object IList.this [int index] {
129                         get {
130                                 return al [index];
131                         }
132                         set {
133                                 if (((TableLayoutStyle)value).Owner != null)
134                                         throw new ArgumentException ("Style is already owned");
135                                 ((TableLayoutStyle)value).Owner = table;
136                                 al [index] = value;
137                                 table.PerformLayout ();
138                         }
139                 }
140 #endregion
141
142 #region ICollection methods
143                 void ICollection.CopyTo (Array array, int startIndex)
144                 {
145                         al.CopyTo (array, startIndex);
146                 }
147
148                 object ICollection.SyncRoot {
149                         get {
150                                 return al.SyncRoot;
151                         }
152                 }
153
154                 bool ICollection.IsSynchronized {
155                         get {
156                                 return al.IsSynchronized;
157                         }
158                 }
159 #endregion
160
161 #region IEnumerable methods
162                 IEnumerator IEnumerable.GetEnumerator ()
163                 {
164                         return al.GetEnumerator ();
165                 }
166 #endregion
167                 public TableLayoutStyle this [int index] {
168                         get {
169                                 return (TableLayoutStyle) ((IList)this)[index];
170                         }
171
172                         set {
173                                 ((IList)this)[index] = value;
174                         }
175                 }
176         }
177                 
178 }