var_tree.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * var_tree.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2005 the VideoLAN team
00005  * $Id: c03425e84a7648528b487599b595e2c97c1470f9 $
00006  *
00007  * Authors: Antoine Cellerier <dionoea@videolan.org>
00008  *          Clément Stenac <zorglub@videolan.org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VAR_TREE_HPP
00026 #define VAR_TREE_HPP
00027 
00028 #include <list>
00029 
00030 #include "variable.hpp"
00031 #include "observer.hpp"
00032 #include "ustring.hpp"
00033 #include "var_percent.hpp"
00034 
00035 /// Description of an update to the tree
00036 typedef struct tree_update
00037 {
00038      int i_type;
00039      int i_parent;
00040      int i_id;
00041      bool b_active_item;
00042      bool b_visible;
00043 } tree_update;
00044 
00045 /// Tree variable
00046 class VarTree: public Variable, public Subject<VarTree, tree_update>
00047 {
00048 public:
00049     VarTree( intf_thread_t *pIntf );
00050 
00051     VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
00052              const UStringPtr &rcString, bool selected, bool playing,
00053              bool expanded,bool readonly, void *pData );
00054 
00055     virtual ~VarTree();
00056 
00057     /// Get the variable type
00058     virtual const string &getType() const { return m_type; }
00059 
00060     /// Add a pointer on string in the children's list
00061     virtual void add( int id, const UStringPtr &rcString, bool selected,
00062                       bool playing, bool expanded, bool readonly,
00063                       void *pData );
00064 
00065     /// Remove the selected item from the children's list
00066     virtual void delSelected();
00067 
00068     /// Remove all elements from the children's list
00069     virtual void clear();
00070 
00071     /// \todo Use accessors for these fields ?
00072     int m_id;
00073     UStringPtr m_cString;
00074     bool m_selected;
00075     bool m_playing;
00076     bool m_expanded;
00077     bool m_deleted;
00078     void *m_pData;
00079 
00080     inline bool isReadonly() { return m_readonly; };
00081 
00082     /// Get the number of children
00083     int size() const { return m_children.size(); }
00084 
00085     /// Iterators
00086     typedef list<VarTree>::iterator Iterator;
00087     typedef list<VarTree>::const_iterator ConstIterator;
00088 
00089     /// Begining of the children's list
00090     Iterator begin() { return m_children.begin(); }
00091     ConstIterator begin() const { return m_children.begin(); }
00092 
00093     /// End of children's list
00094     Iterator end() { return m_children.end(); }
00095     ConstIterator end() const { return m_children.end(); }
00096 
00097     /// Back of children's list
00098     VarTree &back() { return m_children.back(); }
00099 
00100     /// Return an iterator on the n'th element of the children's list
00101     Iterator operator[]( int n );
00102     ConstIterator operator[]( int n ) const;
00103 
00104     /// Parent node
00105     VarTree *parent() { return m_pParent; }
00106     void checkParents( VarTree *pParent );
00107 
00108     /// Get next sibling
00109     Iterator getNextSibling( Iterator );
00110 
00111     Iterator next_uncle();
00112     Iterator prev_uncle();
00113 
00114     /// Get root node
00115     VarTree *root()
00116     {
00117         VarTree *parent = this;
00118         while( parent->parent() != NULL )
00119             parent = parent->parent();
00120         return parent;
00121     }
00122 
00123     /// Get first leaf
00124     Iterator firstLeaf();
00125 
00126     void removeChild( VarTree::Iterator item )
00127     {
00128         m_children.erase( item );
00129     }
00130 
00131     /// Execute the action associated to this item
00132     virtual void action( VarTree *pItem ) { }
00133 
00134     /// Get a reference on the position variable
00135     VarPercent &getPositionVar() const
00136     { return *((VarPercent*)m_cPosition.get()); }
00137 
00138     /// Get a counted pointer on the position variable
00139     const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
00140 
00141     /// Count the number of items that should be displayed if the
00142     /// playlist window wasn't limited
00143     int visibleItems();
00144 
00145     /// Count the number of leafs in the tree
00146     int countLeafs();
00147 
00148     /// Return iterator to the n'th visible item
00149     Iterator getVisibleItem( int n );
00150 
00151     /// Return iterator to the n'th leaf
00152     Iterator getLeaf( int n );
00153 
00154     /// Given an iterator to a visible item, return the next visible item
00155     Iterator getNextVisibleItem( Iterator it );
00156 
00157     /// Given an it to a visible item, return the previous visible item
00158     Iterator getPrevVisibleItem( Iterator it );
00159 
00160     /// Given an iterator to an item, return the next item
00161     Iterator getNextItem( Iterator it );
00162 
00163     /// Given an iterator to an item, return the previous item
00164     Iterator getPrevItem( Iterator it );
00165 
00166     /// Given an iterator to an item, return the next leaf
00167     Iterator getNextLeaf( Iterator it );
00168 
00169     /// Given an iterator to an item, return the previous leaf
00170     Iterator getPrevLeaf( Iterator it );
00171 
00172     /// Find a children node with the given id
00173     Iterator findById( int id );
00174 
00175     /// Ensure an item is expanded
00176     void ensureExpanded( VarTree::Iterator );
00177 
00178     /// Get depth (root depth is 0)
00179     int depth()
00180     {
00181         VarTree *parent = this;
00182         int depth = 0;
00183         while( ( parent = parent->parent() ) != NULL )
00184             depth++;
00185         return depth;
00186     }
00187 
00188 
00189 private:
00190     /// List of children
00191     list<VarTree> m_children;
00192 
00193     /// Pointer to parent node
00194     VarTree *m_pParent;
00195 
00196     bool m_readonly;
00197 
00198     /// Variable type
00199     static const string m_type;
00200 
00201     /// Position variable
00202     VariablePtr m_cPosition;
00203 };
00204 
00205 #endif

Generated on Tue May 25 08:04:58 2010 for VLC by  doxygen 1.5.6