Merge pull request #5573 from lateralusX/lateralusX/windows-invalid-socket-error
[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                         this.table = table;
42                 }
43                 
44                 public int Add (TableLayoutStyle style)
45                 {
46                         return ((IList)this).Add (style);
47                 }
48                 
49                 public void Clear ()
50                 {
51                         foreach (TableLayoutStyle style in al)
52                                 style.Owner = null;
53                         al.Clear ();
54                         if (table != null)
55                                 table.PerformLayout ();
56                 }
57                 
58                 public int Count {
59                         get { return al.Count; }
60                 }
61                 
62                 public void RemoveAt (int index)
63                 {
64                         ((TableLayoutStyle)al[index]).Owner = null;
65                         al.RemoveAt (index);
66                         if (table != null)
67                                 table.PerformLayout ();
68                 }
69                 
70 #region IList methods
71                 //
72                 // The IList methods will later be implemeneted, this is to get us started
73                 //
74                 int IList.Add (object style)
75                 {
76                         TableLayoutStyle layoutStyle = (TableLayoutStyle) style;
77                         if (layoutStyle.Owner != null)
78                                 throw new ArgumentException ("Style is already owned");
79
80                         layoutStyle.Owner = table;
81                         int result = al.Add (layoutStyle);
82
83                         if (table != null)
84                                 table.PerformLayout ();
85
86                         return result;
87                 }
88                 
89                 bool IList.Contains (object style)
90                 {
91                         return al.Contains ((TableLayoutStyle) style);
92                 }
93                 
94                 int IList.IndexOf (object style)
95                 {
96                         return al.IndexOf ((TableLayoutStyle) style);
97                 }
98                 
99                 void IList.Insert (int index, object style)
100                 {
101                         if (((TableLayoutStyle)style).Owner != null)
102                                 throw new ArgumentException ("Style is already owned");
103                         ((TableLayoutStyle)style).Owner = table;
104                         al.Insert (index, (TableLayoutStyle) style);
105                         if (table != null)
106                                 table.PerformLayout ();
107                 }
108
109                 void IList.Remove (object style)
110                 {
111                         ((TableLayoutStyle)style).Owner = null;
112                         al.Remove ((TableLayoutStyle) style);
113                         if (table != null)
114                                 table.PerformLayout ();
115                 }
116
117                 bool IList.IsFixedSize {
118                         get {
119                                 return al.IsFixedSize;
120                         }
121                 }
122
123                 bool IList.IsReadOnly {
124                         get {
125                                 return al.IsReadOnly;
126                         }
127                 }
128
129                 object IList.this [int index] {
130                         get {
131                                 return al [index];
132                         }
133                         set {
134                                 if (((TableLayoutStyle)value).Owner != null)
135                                         throw new ArgumentException ("Style is already owned");
136                                 ((TableLayoutStyle)value).Owner = table;
137                                 al [index] = value;
138                                 if (table != null)
139                                         table.PerformLayout ();
140                         }
141                 }
142 #endregion
143
144 #region ICollection methods
145                 void ICollection.CopyTo (Array array, int startIndex)
146                 {
147                         al.CopyTo (array, startIndex);
148                 }
149
150                 object ICollection.SyncRoot {
151                         get {
152                                 return al.SyncRoot;
153                         }
154                 }
155
156                 bool ICollection.IsSynchronized {
157                         get {
158                                 return al.IsSynchronized;
159                         }
160                 }
161 #endregion
162
163 #region IEnumerable methods
164                 IEnumerator IEnumerable.GetEnumerator ()
165                 {
166                         return al.GetEnumerator ();
167                 }
168 #endregion
169                 public TableLayoutStyle this [int index] {
170                         get {
171                                 return (TableLayoutStyle) ((IList)this)[index];
172                         }
173
174                         set {
175                                 ((IList)this)[index] = value;
176                         }
177                 }
178         }
179                 
180 }