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$
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
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 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 playlist window wasn't limited
00142         int visibleItems();
00143 
00144         /// Count the number of leafs in the tree
00145         int countLeafs();
00146 
00147         /// Return iterator to the n'th visible item
00148         Iterator getVisibleItem( int n );
00149 
00150         /// Return iterator to the n'th leaf
00151         Iterator getLeaf( int n );
00152 
00153         /// Given an iterator to a visible item, return the next visible item
00154         Iterator getNextVisibleItem( Iterator it );
00155 
00156         /// Given an it to a visible item, return the previous visible item
00157         Iterator getPrevVisibleItem( Iterator it );
00158 
00159         /// Given an iterator to an item, return the next item
00160         Iterator getNextItem( Iterator it );
00161 
00162         /// Given an iterator to an item, return the previous item
00163         Iterator getPrevItem( Iterator it );
00164 
00165         /// Given an iterator to an item, return the next leaf
00166         Iterator getNextLeaf( Iterator it );
00167 
00168         /// Given an iterator to an item, return the previous leaf
00169         Iterator getPrevLeaf( Iterator it );
00170 
00171         /// Find a children node with the given id
00172         Iterator findById( int id );
00173 
00174         /// Ensure an item is expanded
00175         void ensureExpanded( VarTree::Iterator );
00176 
00177         /// Get depth (root depth is 0)
00178         int depth()
00179         {
00180             VarTree *parent = this;
00181             int depth = 0;
00182             while( ( parent = parent->parent() ) != NULL )
00183                 depth++;
00184             return depth;
00185         }
00186 
00187 
00188     private:
00189         /// List of children
00190         list<VarTree> m_children;
00191 
00192         /// Pointer to parent node
00193         VarTree *m_pParent;
00194 
00195         bool m_readonly;
00196 
00197         /// Variable type
00198         static const string m_type;
00199 
00200         /// Position variable
00201         VariablePtr m_cPosition;
00202 };
00203 
00204 #endif

Generated on Wed Aug 13 08:02:38 2008 for VLC by  doxygen 1.5.1