1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include "variable.hpp"
31 #include "observer.hpp"
32 #include "ustring.hpp"
33 #include "var_percent.hpp"
35 /// Description of an update to the tree
36 typedef struct tree_update
46 class VarTree: public Variable, public Subject<VarTree, tree_update>
49 VarTree( intf_thread_t *pIntf );
51 VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
52 const UStringPtr &rcString, bool selected, bool playing,
53 bool expanded,bool readonly, void *pData );
57 /// Get the variable type
58 virtual const string &getType() const { return m_type; }
60 /// Add a pointer on string in the children's list
61 virtual void add( int id, const UStringPtr &rcString, bool selected,
62 bool playing, bool expanded, bool readonly,
65 /// Remove the selected item from the children's list
66 virtual void delSelected();
68 /// Remove all elements from the children's list
71 /// \todo Use accessors for these fields ?
80 inline bool isReadonly() { return m_readonly; };
82 /// Get the number of children
83 int size() const { return m_children.size(); }
86 typedef list<VarTree>::iterator Iterator;
87 typedef list<VarTree>::const_iterator ConstIterator;
89 /// Begining of the children's list
90 Iterator begin() { return m_children.begin(); }
91 ConstIterator begin() const { return m_children.begin(); }
93 /// End of children's list
94 Iterator end() { return m_children.end(); }
95 ConstIterator end() const { return m_children.end(); }
97 /// Back of children's list
98 VarTree &back() { return m_children.back(); }
100 /// Return an iterator on the n'th element of the children's list
101 Iterator operator[]( int n );
102 ConstIterator operator[]( int n ) const;
105 VarTree *parent() { return m_pParent; }
108 Iterator getNextSibling( Iterator );
110 Iterator next_uncle();
111 Iterator prev_uncle();
114 Iterator firstLeaf();
116 void removeChild( VarTree::Iterator item )
118 m_children.erase( item );
121 /// Execute the action associated to this item
122 virtual void action( VarTree *pItem ) { }
124 /// Get a reference on the position variable
125 VarPercent &getPositionVar() const
126 { return *((VarPercent*)m_cPosition.get()); }
128 /// Get a counted pointer on the position variable
129 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
131 /// Count the number of items that should be displayed if the
132 /// playlist window wasn't limited
135 /// Count the number of leafs in the tree
138 /// Return iterator to the n'th visible item
139 Iterator getVisibleItem( int n );
141 /// Return iterator to the n'th leaf
142 Iterator getLeaf( int n );
144 /// Given an iterator to a visible item, return the next visible item
145 Iterator getNextVisibleItem( Iterator it );
147 /// Given an it to a visible item, return the previous visible item
148 Iterator getPrevVisibleItem( Iterator it );
150 /// Given an iterator to an item, return the next item
151 Iterator getNextItem( Iterator it );
153 /// Given an iterator to an item, return the previous item
154 Iterator getPrevItem( Iterator it );
156 /// Given an iterator to an item, return the next leaf
157 Iterator getNextLeaf( Iterator it );
159 /// Given an iterator to an item, return the previous leaf
160 Iterator getPrevLeaf( Iterator it );
162 /// Find a children node with the given id
163 Iterator findById( int id );
165 /// Ensure an item is expanded
166 void ensureExpanded( VarTree::Iterator );
168 /// flag a whole subtree for deletion
169 void cascadeDelete();
171 /// Get depth (root depth is 0)
174 VarTree *parent = this;
176 while( ( parent = parent->parent() ) != NULL )
187 VarTree *parent = this;
188 while( parent->parent() != NULL )
189 parent = parent->parent();
194 list<VarTree> m_children;
196 /// Pointer to parent node
202 static const string m_type;
204 /// Position variable
205 VariablePtr m_cPosition;