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; }
106 void checkParents( VarTree *pParent );
109 Iterator getNextSibling( Iterator );
111 Iterator next_uncle();
112 Iterator prev_uncle();
115 Iterator firstLeaf();
117 void removeChild( VarTree::Iterator item )
119 m_children.erase( item );
122 /// Execute the action associated to this item
123 virtual void action( VarTree *pItem ) { }
125 /// Get a reference on the position variable
126 VarPercent &getPositionVar() const
127 { return *((VarPercent*)m_cPosition.get()); }
129 /// Get a counted pointer on the position variable
130 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
132 /// Count the number of items that should be displayed if the
133 /// playlist window wasn't limited
136 /// Count the number of leafs in the tree
139 /// Return iterator to the n'th visible item
140 Iterator getVisibleItem( int n );
142 /// Return iterator to the n'th leaf
143 Iterator getLeaf( int n );
145 /// Given an iterator to a visible item, return the next visible item
146 Iterator getNextVisibleItem( Iterator it );
148 /// Given an it to a visible item, return the previous visible item
149 Iterator getPrevVisibleItem( Iterator it );
151 /// Given an iterator to an item, return the next item
152 Iterator getNextItem( Iterator it );
154 /// Given an iterator to an item, return the previous item
155 Iterator getPrevItem( Iterator it );
157 /// Given an iterator to an item, return the next leaf
158 Iterator getNextLeaf( Iterator it );
160 /// Given an iterator to an item, return the previous leaf
161 Iterator getPrevLeaf( Iterator it );
163 /// Find a children node with the given id
164 Iterator findById( int id );
166 /// Ensure an item is expanded
167 void ensureExpanded( VarTree::Iterator );
169 /// Get depth (root depth is 0)
172 VarTree *parent = this;
174 while( ( parent = parent->parent() ) != NULL )
185 VarTree *parent = this;
186 while( parent->parent() != NULL )
187 parent = parent->parent();
192 list<VarTree> m_children;
194 /// Pointer to parent node
200 static const string m_type;
202 /// Position variable
203 VariablePtr m_cPosition;