1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
5 * $Id: var_bool.hpp 9934 2005-02-15 13:55:08Z courmisch $
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
29 #include "variable.hpp"
30 #include "observer.hpp"
31 #include "ustring.hpp"
32 #include "var_percent.hpp"
35 class VarTree: public Variable, public Subject<VarTree>
38 VarTree( intf_thread_t *pIntf );
40 VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
41 const UStringPtr &rcString, bool selected, bool playing,
42 bool expanded, void *pData );
46 /// Get the variable type
47 virtual const string &getType() const { return m_type; }
49 /// Add a pointer on string in the children's list
50 virtual void add( int id, const UStringPtr &rcString, bool selected,
51 bool playing, bool expanded, void *pData );
53 /// Remove the selected item from the children's list
54 virtual void delSelected();
56 /// Remove all elements from the children's list
59 /// FIXME should be private
67 /// Get the number of children
68 int size() const { return m_children.size(); }
71 typedef list<VarTree>::iterator Iterator;
72 typedef list<VarTree>::const_iterator ConstIterator;
74 /// Begining of the children's list
75 Iterator begin() { return m_children.begin(); }
76 ConstIterator begin() const { return m_children.begin(); }
78 /// End of children's list
79 Iterator end() { return m_children.end(); }
80 ConstIterator end() const { return m_children.end(); }
82 /// Back of children's list
83 VarTree &back() { return m_children.back(); }
85 /// Return an iterator on the n'th element of the children's list
86 Iterator operator[]( int n );
87 ConstIterator operator[]( int n ) const;
90 VarTree *parent() { return m_pParent; }
91 void VarTree::checkParents( VarTree *pParent );
98 VarTree *parent = this;
99 while( parent->parent() != NULL )
100 parent = parent->parent();
104 /// Get depth (root depth is 0)
107 VarTree *parent = this;
109 while( ( parent = parent->parent() ) != NULL )
114 /// Execute the action associated to this item
115 virtual void action( VarTree *pItem ) {}
117 /// Get a reference on the position variable
118 VarPercent &getPositionVar() const
119 { return *((VarPercent*)m_cPosition.get()); }
121 /// Get a counted pointer on the position variable
122 const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
124 /// Count the number of items that should be displayed if the playlist window wasn't limited
127 /// Return iterator to the n'th visible item
128 Iterator getVisibleItem( int n );
130 /// Given an iterator to a visible item, return the next visible item
131 Iterator getNextVisibleItem( Iterator it );
133 /// Find a children node with the given id
134 Iterator findById( int id );
138 list<VarTree> m_children;
140 /// Pointer to parent node
144 static const string m_type;
146 /// Position variable
147 VariablePtr m_cPosition;