2 // System.Windows.Forms.TreeNodeCollection
5 // stubbed out by Jackson Harper (jackson@latitudegeo.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) 2002 Ximian, Inc
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
34 namespace System.Windows.Forms {
40 public class TreeNodeCollection : IList, ICollection, IEnumerable {
42 private TreeNode owner;
43 private ArrayList list;
44 private TreeView treeView;
46 internal TreeNodeCollection ( TreeNode owner )
48 list = new ArrayList();
53 get { return list.Count; }
56 public bool IsReadOnly {
57 get { return list.IsReadOnly; }
60 public virtual TreeNode this[int index] {
62 return (TreeNode) list[index];
69 public virtual TreeNode Add( string text )
71 TreeNode node = new TreeNode ( text );
77 public virtual int Add( TreeNode node )
80 throw new ArgumentNullException("value");
82 if ( node.Parent != null )
83 throw new ArgumentException("Object already has a parent.", "node");
85 node.setParent( owner );
87 int index = list.Add( node );
89 TreeView tree = owner.TreeView;
90 if ( tree != null && tree.IsHandleCreated )
91 node.makeTree ( owner.Handle, tree );
96 public virtual void AddRange( TreeNode[] nodes )
99 throw new ArgumentNullException("nodes");
101 foreach ( TreeNode node in nodes ) {
102 // it will do a check for parent and set the parent
108 public virtual void Clear()
110 foreach ( object node in list ) {
111 ( ( TreeNode )node ).Remove ( );
112 ( ( TreeNode )node ).setParent ( null );
118 public bool Contains( TreeNode node )
120 return list.Contains( node );
123 public void CopyTo(Array dest, int index)
128 public IEnumerator GetEnumerator()
130 return list.GetEnumerator();
133 public int IndexOf( TreeNode node )
135 return list.IndexOf( node );
138 public virtual void Insert( int index, TreeNode node )
141 throw new ArgumentNullException ( "node" );
143 if ( node.Parent != null)
144 throw new ArgumentException ( "Object already has a parent.", "node" );
146 if (index < 0 || index > Count )
147 throw new ArgumentOutOfRangeException( "index" );
149 list.Insert( index, node );
150 node.setParent ( owner );
154 public void Remove( TreeNode node )
157 throw new ArgumentNullException( "node" );
161 node.setParent ( null );
165 public virtual void RemoveAt( int index )
167 if (index < 0 || index > Count )
168 throw new ArgumentOutOfRangeException( "index" );
170 TreeNode node = (TreeNode) list[ index ];
171 list.RemoveAt( index );
173 node.setParent ( null );
176 /// IList Interface implmentation.
178 bool IList.IsReadOnly{
180 // We allow addition, removeal, and editing of items after creation of the list.
184 bool IList.IsFixedSize{
186 // We allow addition and removeal of items after creation of the list.
192 object IList.this[int index]{
194 throw new NotImplementedException ();
203 throw new NotImplementedException ();
207 int IList.Add( object value){
208 throw new NotImplementedException ();
212 bool IList.Contains( object value){
213 throw new NotImplementedException ();
217 int IList.IndexOf( object value){
218 throw new NotImplementedException ();
222 void IList.Insert(int index, object value){
227 void IList.Remove( object value){
232 void IList.RemoveAt( int index){
235 // End of IList interface
237 /// ICollection Interface implmentation.
239 int ICollection.Count{
241 throw new NotImplementedException ();
244 bool ICollection.IsSynchronized{
246 throw new NotImplementedException ();
249 object ICollection.SyncRoot{
251 throw new NotImplementedException ();
254 void ICollection.CopyTo(Array array, int index){
258 internal TreeView TreeView {
259 get { return treeView; }
260 set { treeView = value;}
262 // End Of ICollection