Add licensing info
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / TreeNodeCollection.cs
1 //
2 // System.Windows.Forms.TreeNodeCollection
3 //
4 // Author:
5 //   stubbed out by Jackson Harper (jackson@latitudegeo.com)
6 //   Dennis Hayes (dennish@Raytek.com)
7 //   Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 //
9 // (C) 2002 Ximian, Inc
10 //
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 using System.Collections;
33
34 namespace System.Windows.Forms {
35
36         // <summary>
37         //
38         // </summary>
39
40     public class TreeNodeCollection : IList, ICollection, IEnumerable {
41
42                 private TreeNode  owner;
43                 private ArrayList list;
44                 private TreeView  treeView;
45
46                 internal TreeNodeCollection ( TreeNode owner )
47                 {
48                         list = new ArrayList();
49                         this.owner = owner;
50                 }
51                 
52                 public int Count {
53                         get { return list.Count; }
54                 }
55
56                 public bool IsReadOnly {
57                         get { return list.IsReadOnly; }
58                 }
59                 [MonoTODO]
60                 public virtual TreeNode this[int index] {
61                         get {
62                                 return (TreeNode) list[index];
63                         }
64                         set {
65                                 list[index] = value;
66                         }
67                 }
68                 
69                 public virtual TreeNode Add( string text ) 
70                 {
71                         TreeNode node =  new TreeNode ( text );
72                         Add ( node );
73                         return node;
74                 }
75
76                 [MonoTODO]
77                 public virtual int Add( TreeNode node ) 
78                 {
79                         if ( node == null )
80                                 throw new ArgumentNullException("value");
81
82                         if ( node.Parent != null )
83                                 throw new ArgumentException("Object already has a parent.", "node");
84
85                         node.setParent( owner );
86
87                         int index = list.Add( node );
88
89                         TreeView tree = owner.TreeView;
90                         if ( tree != null && tree.IsHandleCreated )
91                                 node.makeTree ( owner.Handle, tree );
92
93                         return  index;          
94                 }
95
96                 public virtual void AddRange( TreeNode[] nodes ) 
97                 {
98                         if ( nodes == null )
99                                 throw new ArgumentNullException("nodes");
100
101                         foreach ( TreeNode node in nodes ) {
102                                 // it will do a check for parent and set the parent
103                                 Add ( node );
104                         }
105                 }
106
107                 [MonoTODO]
108                 public virtual void Clear() 
109                 {
110                         foreach ( object node in list ) {
111                                 ( ( TreeNode )node ).Remove ( );
112                                 ( ( TreeNode )node ).setParent ( null );
113                         }
114
115                         list.Clear();
116                 }
117
118                 public bool Contains( TreeNode node ) 
119                 {
120                         return list.Contains( node );
121                 }
122                 [MonoTODO]
123                 public void CopyTo(Array dest, int index) 
124                 {
125                         //FIXME:
126                 }
127
128                 public IEnumerator GetEnumerator() 
129                 {
130                         return list.GetEnumerator();
131                 }
132
133                 public int IndexOf( TreeNode node ) 
134                 {
135                         return list.IndexOf( node );
136                 }
137                 [MonoTODO]
138                 public virtual void Insert( int index, TreeNode node ) 
139                 {
140                         if ( node == null )
141                                 throw new ArgumentNullException ( "node" );
142
143                         if ( node.Parent != null)
144                                 throw new ArgumentException ( "Object already has a parent.", "node" );
145
146                         if (index < 0 || index > Count )
147                                 throw new ArgumentOutOfRangeException( "index" );
148
149                         list.Insert( index, node );
150                         node.setParent ( owner ); 
151                 }
152
153                 [MonoTODO]
154                 public void Remove( TreeNode node ) 
155                 {
156                         if ( node == null )
157                                 throw new ArgumentNullException( "node" );
158
159                         list.Remove( node );
160                         node.Remove( );
161                         node.setParent ( null );
162                 }
163
164                 [MonoTODO]
165                 public virtual void RemoveAt( int index ) 
166                 {
167                         if (index < 0 || index > Count )
168                                 throw new ArgumentOutOfRangeException( "index" );
169
170                         TreeNode node = (TreeNode) list[ index ];
171                         list.RemoveAt( index );
172                         node.Remove( );
173                         node.setParent ( null );
174                 }
175                 /// <summary>
176                 /// IList Interface implmentation.
177                 /// </summary>
178                 bool IList.IsReadOnly{
179                         get{
180                                 // We allow addition, removeal, and editing of items after creation of the list.
181                                 return false;
182                         }
183                 }
184                 bool IList.IsFixedSize{
185                         get{
186                                 // We allow addition and removeal of items after creation of the list.
187                                 return false;
188                         }
189                 }
190
191                 //[MonoTODO]
192                 object IList.this[int index]{
193                         get{
194                                 throw new NotImplementedException ();
195                         }
196                         set{
197                                 //FIXME:
198                         }
199                 }
200                 
201                 [MonoTODO]
202                 void IList.Clear(){
203                         throw new NotImplementedException ();
204                 }
205                 
206                 [MonoTODO]
207                 int IList.Add( object value){
208                         throw new NotImplementedException ();
209                 }
210
211                 [MonoTODO]
212                 bool IList.Contains( object value){
213                         throw new NotImplementedException ();
214                 }
215
216                 [MonoTODO]
217                 int IList.IndexOf( object value){
218                         throw new NotImplementedException ();
219                 }
220
221                 [MonoTODO]
222                 void IList.Insert(int index, object value){
223                         //FIXME:
224                 }
225
226                 [MonoTODO]
227                 void IList.Remove( object value){
228                         //FIXME:
229                 }
230
231                 [MonoTODO]
232                 void IList.RemoveAt( int index){
233                         //FIXME:
234                 }
235                 // End of IList interface
236                 /// <summary>
237                 /// ICollection Interface implmentation.
238                 /// </summary>
239                 int ICollection.Count{
240                         get{
241                                 throw new NotImplementedException ();
242                         }
243                 }
244                 bool ICollection.IsSynchronized{
245                         get{
246                                 throw new NotImplementedException ();
247                         }
248                 }
249                 object ICollection.SyncRoot{
250                         get{
251                                 throw new NotImplementedException ();
252                         }
253                 }
254                 void ICollection.CopyTo(Array array, int index){
255                         //FIXME:
256                 }
257
258                 internal TreeView TreeView {
259                         get { return treeView; }
260                         set { treeView = value;}
261                 }
262                 // End Of ICollection
263         }
264 }