X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fskins2%2Futils%2Fvar_tree.hpp;h=26709e32aae19b84b377fbbefcc8c3e5f5e2a1d1;hb=98c1ff6e3d80c30af01c0c211c0ead8964d3d8a1;hp=5d561765a04629247aa11820a76116386a743f89;hpb=c7e38315469013101306e8c94f58fc6a651ba5ce;p=vlc diff --git a/modules/gui/skins2/utils/var_tree.hpp b/modules/gui/skins2/utils/var_tree.hpp index 5d561765a0..26709e32aa 100644 --- a/modules/gui/skins2/utils/var_tree.hpp +++ b/modules/gui/skins2/utils/var_tree.hpp @@ -1,10 +1,11 @@ /***************************************************************************** * var_tree.hpp ***************************************************************************** - * Copyright (C) 2005 VideoLAN - * $Id: var_bool.hpp 9934 2005-02-15 13:55:08Z courmisch $ + * Copyright (C) 2005 the VideoLAN team + * $Id$ * * Authors: Antoine Cellerier + * Clément Stenac * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,9 +17,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #ifndef VAR_TREE_HPP @@ -31,95 +32,177 @@ #include "ustring.hpp" #include "var_percent.hpp" +/// Description of an update to the tree +typedef struct tree_update +{ + int i_type; + int i_parent; + int i_id; + bool b_active_item; + bool b_visible; +} tree_update; + /// Tree variable -class VarTree: public Variable, public Subject +class VarTree: public Variable, public Subject { - public: - VarTree( intf_thread_t *pIntf, VarTree *m_pParent2 ); - virtual ~VarTree(); +public: + VarTree( intf_thread_t *pIntf ); + + VarTree( intf_thread_t *pIntf, VarTree *pParent, int id, + const UStringPtr &rcString, bool selected, bool playing, + bool expanded,bool readonly, void *pData ); + + virtual ~VarTree(); + + /// Get the variable type + virtual const string &getType() const { return m_type; } + + /// Add a pointer on string in the children's list + virtual void add( int id, const UStringPtr &rcString, bool selected, + bool playing, bool expanded, bool readonly, + void *pData ); + + /// Remove the selected item from the children's list + virtual void delSelected(); + + /// Remove all elements from the children's list + virtual void clear(); + + /// \todo Use accessors for these fields ? + int m_id; + UStringPtr m_cString; + bool m_selected; + bool m_playing; + bool m_expanded; + bool m_deleted; + void *m_pData; + + inline bool isReadonly() { return m_readonly; }; + + /// Get the number of children + int size() const { return m_children.size(); } + + /// Iterators + typedef list::iterator Iterator; + typedef list::const_iterator ConstIterator; + + /// Begining of the children's list + Iterator begin() { return m_children.begin(); } + ConstIterator begin() const { return m_children.begin(); } + + /// End of children's list + Iterator end() { return m_children.end(); } + ConstIterator end() const { return m_children.end(); } + + /// Back of children's list + VarTree &back() { return m_children.back(); } + + /// Return an iterator on the n'th element of the children's list + Iterator operator[]( int n ); + ConstIterator operator[]( int n ) const; + + /// Parent node + VarTree *parent() { return m_pParent; } + + /// Get next sibling + Iterator getNextSibling( Iterator ); + + Iterator next_uncle(); + Iterator prev_uncle(); + + /// Get first leaf + Iterator firstLeaf(); + + void removeChild( VarTree::Iterator item ) + { + m_children.erase( item ); + } - /// Get the variable type - virtual const string &getType() const { return m_type; } + /// Execute the action associated to this item + virtual void action( VarTree *pItem ) { } - /// Add a pointer on string in the children's list - virtual void add( const UStringPtr &rcString, bool selected=true, bool playing=true, bool expanded=true, void *pData=NULL ); + /// Get a reference on the position variable + VarPercent &getPositionVar() const + { return *((VarPercent*)m_cPosition.get()); } - /// Remove the selected item from the children's list - virtual void delSelected(); + /// Get a counted pointer on the position variable + const VariablePtr &getPositionVarPtr() const { return m_cPosition; } - /// Remove all elements from the children's list - virtual void clear(); + /// Count the number of items that should be displayed if the + /// playlist window wasn't limited + int visibleItems(); - UStringPtr m_cString; - bool m_selected; - bool m_playing; - bool m_expanded; - void *m_pData; + /// Count the number of leafs in the tree + int countLeafs(); - /// Get the number of children - int size() const { return m_children.size(); } + /// Return iterator to the n'th visible item + Iterator getVisibleItem( int n ); - /// Iterators - typedef list::iterator Iterator; - typedef list::const_iterator ConstIterator; + /// Return iterator to the n'th leaf + Iterator getLeaf( int n ); - /// Begining of the children's list - Iterator begin() { return m_children.begin(); } - ConstIterator begin() const { return m_children.begin(); } + /// Given an iterator to a visible item, return the next visible item + Iterator getNextVisibleItem( Iterator it ); - /// End of children's list - Iterator end() { return m_children.end(); } - ConstIterator end() const { return m_children.end(); } + /// Given an it to a visible item, return the previous visible item + Iterator getPrevVisibleItem( Iterator it ); - /// Back of children's list - VarTree &back() { return m_children.back(); } + /// Given an iterator to an item, return the next item + Iterator getNextItem( Iterator it ); - /// Return an iterator on the n'th element of the children's list - Iterator operator[]( int n ); - ConstIterator operator[]( int n ) const; + /// Given an iterator to an item, return the previous item + Iterator getPrevItem( Iterator it ); - /// Parent node - VarTree *parent() { return m_pParent; } - void VarTree::checkParents( VarTree *m_pParent2 ); + /// Given an iterator to an item, return the next leaf + Iterator getNextLeaf( Iterator it ); - Iterator uncle(); + /// Given an iterator to an item, return the previous leaf + Iterator getPrevLeaf( Iterator it ); - /// Get root node - VarTree *root() { VarTree *parent=this; while( parent->parent() != NULL ) parent = parent->parent(); return parent; } + /// Find a children node with the given id + Iterator findById( int id ); - /// Get depth (root depth is 0) - int depth() { VarTree *parent=this; int depth=0; while( ( parent = parent->parent() ) != NULL ) depth++; return depth; } + /// Ensure an item is expanded + void ensureExpanded( VarTree::Iterator ); - /// Execute the action associated to this item - virtual void action( VarTree *pItem ) {} + /// flag a whole subtree for deletion + void cascadeDelete(); - /// Get a reference on the position variable - VarPercent &getPositionVar() const - { return *((VarPercent*)m_cPosition.get()); } + /// Get depth (root depth is 0) + int depth() + { + VarTree *parent = this; + int depth = 0; + while( ( parent = parent->parent() ) != NULL ) + depth++; + return depth; + } - /// Get a counted pointer on the position variable - const VariablePtr &getPositionVarPtr() const { return m_cPosition; } - /// Count the number of items that should be displayed if the playlist window wasn't limited - int visibleItems(); +private: - /// Return iterator to the n'th visible item - Iterator visibleItem( int n ); + /// Get root node + VarTree *root() + { + VarTree *parent = this; + while( parent->parent() != NULL ) + parent = parent->parent(); + return parent; + } - private: -// intf_thread_t *pIntf; + /// List of children + list m_children; - ///list of children - list m_children; + /// Pointer to parent node + VarTree *m_pParent; - ///Pointer to parent node - VarTree *m_pParent; + bool m_readonly; - ///Variable type - static const string m_type; + /// Variable type + static const string m_type; - /// Position variable - VariablePtr m_cPosition; + /// Position variable + VariablePtr m_cPosition; }; #endif