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
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 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();
117 VarTree *parent = this;
118 while( parent->parent() != NULL )
119 parent = parent->parent();
124 Iterator firstLeaf();
126 void removeChild( VarTree::Iterator item )
128 m_children.erase( item );
131 /// Execute the action associated to this item
132 virtual void action( VarTree *pItem ) {}
134 /// Get a reference on the position variable
135 VarPercent &getPositionVar() const
136 { return *((VarPercent*)m_cPosition.get()); }
138 /// Get a counted pointer on the position variable
139 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
141 /// Count the number of items that should be displayed if the playlist window wasn't limited
144 /// Count the number of leafs in the tree
147 /// Return iterator to the n'th visible item
148 Iterator getVisibleItem( int n );
150 /// Return iterator to the n'th leaf
151 Iterator getLeaf( int n );
153 /// Given an iterator to a visible item, return the next visible item
154 Iterator getNextVisibleItem( Iterator it );
156 /// Given an it to a visible item, return the previous visible item
157 Iterator getPrevVisibleItem( Iterator it );
159 /// Given an iterator to an item, return the next item
160 Iterator getNextItem( Iterator it );
162 /// Given an iterator to an item, return the previous item
163 Iterator getPrevItem( Iterator it );
165 /// Given an iterator to an item, return the next leaf
166 Iterator getNextLeaf( Iterator it );
168 /// Given an iterator to an item, return the previous leaf
169 Iterator getPrevLeaf( Iterator it );
171 /// Find a children node with the given id
172 Iterator findById( int id );
174 /// Ensure an item is expanded
175 void ensureExpanded( VarTree::Iterator );
177 /// Get depth (root depth is 0)
180 VarTree *parent = this;
182 while( ( parent = parent->parent() ) != NULL )
190 list<VarTree> m_children;
192 /// Pointer to parent node
198 static const string m_type;
200 /// Position variable
201 VariablePtr m_cPosition;