]> git.sesse.net Git - vlc/blob - modules/gui/skins2/utils/var_tree.hpp
* all: don't rebuild the whole playtree when an item is updated
[vlc] / modules / gui / skins2 / utils / var_tree.hpp
1 /*****************************************************************************
2  * var_tree.hpp
3  *****************************************************************************
4  * Copyright (C) 2005 VideoLAN
5  * $Id: var_bool.hpp 9934 2005-02-15 13:55:08Z courmisch $
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifndef VAR_TREE_HPP
25 #define VAR_TREE_HPP
26
27 #include <list>
28
29 #include "variable.hpp"
30 #include "observer.hpp"
31 #include "ustring.hpp"
32 #include "var_percent.hpp"
33
34 /// Tree variable
35 class VarTree: public Variable, public Subject<VarTree>
36 {
37     public:
38         VarTree( intf_thread_t *pIntf );
39
40         VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
41                  const UStringPtr &rcString, bool selected, bool playing,
42                  bool expanded, void *pData );
43
44         virtual ~VarTree();
45
46         /// Get the variable type
47         virtual const string &getType() const { return m_type; }
48
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 );
52
53         /// Remove the selected item from the children's list
54         virtual void delSelected();
55
56         /// Remove all elements from the children's list
57         virtual void clear();
58
59         /// FIXME should be private
60         int m_id;
61         UStringPtr m_cString;
62         bool m_selected;
63         bool m_playing;
64         bool m_expanded;
65         void *m_pData;
66
67         /// Get the number of children
68         int size() const { return m_children.size(); }
69
70         /// Iterators
71         typedef list<VarTree>::iterator Iterator;
72         typedef list<VarTree>::const_iterator ConstIterator;
73
74         /// Begining of the children's list
75         Iterator begin() { return m_children.begin(); }
76         ConstIterator begin() const { return m_children.begin(); }
77
78         /// End of children's list
79         Iterator end() { return m_children.end(); }
80         ConstIterator end() const { return m_children.end(); }
81
82         /// Back of children's list
83         VarTree &back() { return m_children.back(); }
84
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;
88
89         /// Parent node
90         VarTree *parent() { return m_pParent; }
91         void VarTree::checkParents( VarTree *pParent );
92
93         Iterator uncle();
94
95         /// Get root node
96         VarTree *root()
97         {
98             VarTree *parent = this;
99             while( parent->parent() != NULL )
100                 parent = parent->parent();
101             return parent;
102         }
103
104         /// Get depth (root depth is 0)
105         int depth()
106         {
107             VarTree *parent = this;
108             int depth = 0;
109             while( ( parent = parent->parent() ) != NULL )
110                 depth++;
111             return depth;
112         }
113
114         /// Execute the action associated to this item
115         virtual void action( VarTree *pItem ) {}
116
117         /// Get a reference on the position variable
118         VarPercent &getPositionVar() const
119         { return *((VarPercent*)m_cPosition.get()); }
120
121         /// Get a counted pointer on the position variable
122         const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
123
124         /// Count the number of items that should be displayed if the playlist window wasn't limited
125         int visibleItems();
126
127         /// Return iterator to the n'th visible item
128         Iterator getVisibleItem( int n );
129
130         /// Given an iterator to a visible item, return the next visible item
131         Iterator getNextVisibleItem( Iterator it );
132
133         /// Find a children node with the given id
134         Iterator findById( int id );
135
136     private:
137         /// List of children
138         list<VarTree> m_children;
139
140         /// Pointer to parent node
141         VarTree *m_pParent;
142
143         /// Variable type
144         static const string m_type;
145
146         /// Position variable
147         VariablePtr m_cPosition;
148 };
149
150 #endif