2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridColumnCollection.cs
1 //
2 // System.Web.UI.WebControls.DataGridColumnCollection
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@novell.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.Collections;
30 using System.ComponentModel;
31
32 namespace System.Web.UI.WebControls {
33         public sealed class DataGridColumnCollection : ICollection, IStateManager {
34                 public DataGridColumnCollection (DataGrid owner, ArrayList columns)
35                 {
36                         this.owner = owner;
37                         this.columns = columns;
38                 }
39         
40         
41                 public void Add (DataGridColumn column)
42                 {
43                         columns.Add (column);
44                         column.Set_Owner (owner);
45                         if (track)
46                                 ((IStateManager) column).TrackViewState ();
47                 }
48         
49                 public void AddAt (int index, DataGridColumn column)
50                 {
51                         columns.Insert (index, column);
52                         column.Set_Owner (owner);
53                         if (track)
54                                 ((IStateManager) column).TrackViewState ();
55                 }
56         
57                 public void Clear ()
58                 {
59                         columns.Clear ();
60                 }
61         
62                 public void CopyTo (Array array, int index)
63                 {
64                         columns.CopyTo (array, index);
65                 }
66         
67                 public IEnumerator GetEnumerator ()
68                 {
69                         return columns.GetEnumerator ();
70                 }
71         
72                 public int IndexOf (DataGridColumn column)
73                 {
74                         return columns.IndexOf (column);
75                 }
76
77                 [Obsolete ("figure out what you need with me")]
78                 internal void OnColumnsChanged ()
79                 {
80                         // Do something
81                 }
82         
83                 public void Remove (DataGridColumn column)
84                 {
85                         columns.Remove (column);
86                 }
87         
88                 public void RemoveAt (int index)
89                 {
90                         columns.RemoveAt (index);
91                 }
92         
93                 void System.Web.UI.IStateManager.LoadViewState (object savedState)
94                 {
95                         object [] o = (object []) savedState;
96                         if (o == null)
97                                 return;
98
99                         int i = 0;
100                         foreach (IStateManager ism in this)
101                                 ism.LoadViewState (o [i++]);
102                 }
103         
104                 object System.Web.UI.IStateManager.SaveViewState ()
105                 {
106                         object [] o = new object [Count];
107
108                         int i = 0;
109                         foreach (IStateManager ism in this)
110                                 o [i++] = ism.SaveViewState ();
111
112                         foreach (object a in o)
113                                 if (a != null)
114                                         return o;
115                         return null;
116                 }
117         
118                 void System.Web.UI.IStateManager.TrackViewState ()
119                 {
120                         track = true;
121                         foreach (IStateManager ism in this)
122                                 ism.TrackViewState ();
123                 }
124
125                 [Browsable(false)]
126                 public int Count {
127                         get { return columns.Count; }
128                 }
129         
130                 bool IStateManager.IsTrackingViewState {
131                         get { return track; }
132                 }
133         
134                 [Browsable(false)]
135                 public bool IsReadOnly {
136                         get { return columns.IsReadOnly; }
137                 }
138         
139                 [Browsable(false)]
140                 public bool IsSynchronized {
141                         get { return columns.IsSynchronized; }  
142                 }
143
144                 [Browsable(false)]
145                 public DataGridColumn this [int index] {
146                         get { return (DataGridColumn) columns [index]; }
147                 }
148
149                 [Browsable(false)]
150                 public object SyncRoot {
151                         get { return columns.SyncRoot; }
152                 }
153         
154                 DataGrid owner;
155                 ArrayList columns;
156                 bool track;
157         }
158 }