]> Creatis software - bbtk.git/blob - kernel/src/ThirdParty/wx/treemultictrl/TreeMultiItemNode.cpp
Feature #1774
[bbtk.git] / kernel / src / ThirdParty / wx / treemultictrl / TreeMultiItemNode.cpp
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 //---------------------------------------------------------------------------
29 // $RCSfile: TreeMultiItemNode.cpp,v $
30 // $Source: /cvs/creatis/bbtk/kernel/src/ThirdParty/wx/treemultictrl/TreeMultiItemNode.cpp,v $
31 // $Revision: 1.2 $
32 // $Date: 2012/11/16 08:49:16 $
33 //---------------------------------------------------------------------------
34 // Author:      Jorgen Bodde
35 // Copyright:   (c) Jorgen Bodde
36 // License:     wxWidgets License
37 //---------------------------------------------------------------------------
38
39 #ifdef __GNUG__
40     #pragma implementation "TreeMultiItemNode.cpp"
41 #endif
42
43 /* for compilers that support precompilation
44    includes "wx/wx.h" */
45
46 #include "wx/wxprec.h"
47
48 #ifdef __BORLANDC__
49     #pragma hdrstop
50 #endif
51
52 #include "wx/treemultictrl/TreeMultiItemNode.h"
53
54 #include "wx/arrimpl.cpp"
55 WX_DEFINE_OBJARRAY(TreeMultiItemBaseArray);
56
57 /** TreeMultiItemNode
58   * This class is a container holder for multiple TreeMultiItemBase classes.
59   * Since both a TreeMultiItemNode and a TreeMultiItemWindow are a descendant
60   * from a TreeMultiItemBase class, it can hold multiple of these.
61   * In the case of a directory tree structure, it can hold multiple
62   * directories, and leafs (files).
63   */
64
65 // default constructor for container composite
66 TreeMultiItemNode::TreeMultiItemNode(TreeMultiItemNode *parent, const wxString &caption, const wxString &name)
67         : TreeMultiItemBase(parent)
68         , _caption(caption)
69         , _nodeExpanded(true)
70
71 {
72         _name = name;
73         Clear();
74 }
75
76 //------------------------------------------------------------
77
78 TreeMultiItemNode::~TreeMultiItemNode()
79 {
80     // delete all items on this level
81     Clear();
82 }
83
84 //------------------------------------------------------------
85
86 void TreeMultiItemNode::AddNode(TreeMultiItemBase *node)
87 {
88         if(node)
89                 _items.Add(node);
90 }
91
92 void TreeMultiItemNode::InsertNode(TreeMultiItemBase* NodePtr, size_t Position)
93 {
94         if (NodePtr != NULL)
95                 this->_items.Insert(NodePtr,Position);
96 }
97
98 //------------------------------------------------------------
99
100 void TreeMultiItemNode::DeleteNode(TreeMultiItemBase *node)
101 {
102         // this is wrong. The RemoveAt and Remove should delete
103         // the object
104         if(node)
105         {
106                 _items.Detach(Index(node));
107                 delete node;
108         }
109
110 }
111
112 //------------------------------------------------------------
113
114 void TreeMultiItemNode::DeleteNode(int index)
115 {
116         // this is wrong. The RemoveAt and Remove should delete
117         // the object
118         if(index < (int)_items.Count() && index >= 0)
119                 _items.RemoveAt(index);
120 }
121
122 //------------------------------------------------------------
123
124 int TreeMultiItemNode::GetNodeCount() const
125 {
126         return _items.Count();
127 }
128
129 //------------------------------------------------------------
130
131 TreeMultiItemBase *TreeMultiItemNode::GetNode(int index) const
132 {
133         TreeMultiItemBase *value = 0;
134
135         if(index < (int)_items.Count() && index >= 0)
136                 value = &_items.Item(index);
137
138         return value;
139 }
140
141 //------------------------------------------------------------
142
143 TreeMultiItemBase *TreeMultiItemNode::RemoveNode(TreeMultiItemBase *node)
144 {
145         if(node)
146                 _items.Detach(_items.Index(*node));
147
148         return node;
149 }
150
151 //------------------------------------------------------------
152
153 TreeMultiItemBase * TreeMultiItemNode::RemoveNode(int index)
154 {
155         TreeMultiItemBase *value = 0;
156
157         if(index < (int)_items.Count() && index > 0)
158         {
159                 value = &_items.Item(index);
160                 _items.Detach(index);
161         }
162
163         return value;
164 }
165
166 //------------------------------------------------------------
167
168 int TreeMultiItemNode::Index(TreeMultiItemBase *node,  bool searchFromEnd) const
169 {
170         wxCHECK(node, -1);
171
172         return _items.Index(*node, searchFromEnd);
173 }
174
175 //------------------------------------------------------------
176
177 void  TreeMultiItemNode::Clear()
178 {
179         _items.Clear();
180 }
181
182 //------------------------------------------------------------
183
184 TreeMultiItemBase * TreeMultiItemNode::GetNodeNext(int &cookie) const
185 {
186         TreeMultiItemBase *value = 0;
187
188         if(cookie >= 0 && cookie < (int)_items.Count())
189         {
190                 value = &_items[cookie];
191                 cookie++;
192         }
193
194         return value;
195 }
196
197 //------------------------------------------------------------
198
199 TreeMultiItemBase* TreeMultiItemNode::First() const
200 {
201   if (this->_items.GetCount() > 0)
202     return &(this->_items[0]);
203   else
204     return NULL;
205 } /* TreeMultiItemNode::First() const */
206
207 TreeMultiItemBase* TreeMultiItemNode::Last() const
208 {
209         if(this->_items.GetCount() > 0)
210           return &(this->_items.Last());
211         else
212           return NULL;
213 } /* TreeMultiItemNode::Last() const */
214