/*****************************************************************************
* var_tree.hpp
*****************************************************************************
- * Copyright (C) 2005 VideoLAN
+ * Copyright (C) 2005 the VideoLAN team
* $Id$
*
* Authors: Antoine Cellerier <dionoea@videolan.org>
+ * Clément Stenac <zorglub@videolan.org>
*
* 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
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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
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<VarTree, tree_update*>
+class VarTree: public Variable, public Subject<VarTree, tree_update>
{
- public:
- VarTree( intf_thread_t *pIntf );
+public:
+ VarTree( intf_thread_t *pIntf );
- VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
- const UStringPtr &rcString, bool selected, bool playing,
- bool expanded, void *pData );
+ VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
+ const UStringPtr &rcString, bool selected, bool playing,
+ bool expanded,bool readonly, void *pData );
- virtual ~VarTree();
+ virtual ~VarTree();
- /// Get the variable type
- virtual const string &getType() const { return m_type; }
+ /// 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, void *pData );
+ /// 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 the selected item from the children's list
+ virtual void delSelected();
- /// Remove all elements from the children's list
- virtual void clear();
+ /// 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;
- void *m_pData;
+ /// \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;
- /// Get the number of children
- int size() const { return m_children.size(); }
+ inline bool isReadonly() { return m_readonly; };
- /// Iterators
- typedef list<VarTree>::iterator Iterator;
- typedef list<VarTree>::const_iterator ConstIterator;
+ /// Get the number of children
+ int size() const { return m_children.size(); }
- /// Begining of the children's list
- Iterator begin() { return m_children.begin(); }
- ConstIterator begin() const { return m_children.begin(); }
+ /// Iterators
+ typedef list<VarTree>::iterator Iterator;
+ typedef list<VarTree>::const_iterator ConstIterator;
- /// End of children's list
- Iterator end() { return m_children.end(); }
- ConstIterator end() const { return m_children.end(); }
+ /// Begining of the children's list
+ Iterator begin() { return m_children.begin(); }
+ ConstIterator begin() const { return m_children.begin(); }
- /// Back of children's list
- VarTree &back() { return m_children.back(); }
+ /// End of children's list
+ Iterator end() { return m_children.end(); }
+ ConstIterator end() const { return m_children.end(); }
- /// Return an iterator on the n'th element of the children's list
- Iterator operator[]( int n );
- ConstIterator operator[]( int n ) const;
+ /// Back of children's list
+ VarTree &back() { return m_children.back(); }
- /// Parent node
- VarTree *parent() { return m_pParent; }
- void checkParents( VarTree *pParent );
+ /// Return an iterator on the n'th element of the children's list
+ Iterator operator[]( int n );
+ ConstIterator operator[]( int n ) const;
- Iterator uncle();
+ /// Parent node
+ VarTree *parent() { return m_pParent; }
- /// Get root node
- VarTree *root()
- {
- VarTree *parent = this;
- while( parent->parent() != NULL )
- parent = parent->parent();
- return parent;
- }
+ /// Get next sibling
+ Iterator getNextSibling( Iterator );
- /// Get depth (root depth is 0)
- int depth()
- {
- VarTree *parent = this;
- int depth = 0;
- while( ( parent = parent->parent() ) != NULL )
- depth++;
- return depth;
- }
+ Iterator next_uncle();
+ Iterator prev_uncle();
- /// Execute the action associated to this item
- virtual void action( VarTree *pItem ) {}
+ /// Get first leaf
+ Iterator firstLeaf();
- /// Get a reference on the position variable
- VarPercent &getPositionVar() const
- { return *((VarPercent*)m_cPosition.get()); }
+ void removeChild( VarTree::Iterator item )
+ {
+ m_children.erase( item );
+ }
- /// Get a counted pointer on the position variable
- const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
+ /// Execute the action associated to this item
+ virtual void action( VarTree *pItem ) { }
- /// Count the number of items that should be displayed if the playlist window wasn't limited
- int visibleItems();
+ /// Get a reference on the position variable
+ VarPercent &getPositionVar() const
+ { return *((VarPercent*)m_cPosition.get()); }
- /// Return iterator to the n'th visible item
- Iterator getVisibleItem( int n );
+ /// Get a counted pointer on the position variable
+ const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
- /// Given an iterator to a visible item, return the next visible item
- Iterator getNextVisibleItem( Iterator it );
+ /// Count the number of items that should be displayed if the
+ /// playlist window wasn't limited
+ int visibleItems();
- /// Given an iterator to an item, return the next item
- Iterator getNextItem( Iterator it );
+ /// Count the number of leafs in the tree
+ int countLeafs();
- /// Find a children node with the given id
- Iterator findById( int id );
+ /// Return iterator to the n'th visible item
+ Iterator getVisibleItem( int n );
- /// Ensure an item is expanded
- void ensureExpanded( VarTree::Iterator );
+ /// Return iterator to the n'th leaf
+ Iterator getLeaf( int n );
- private:
- /// List of children
- list<VarTree> m_children;
+ /// Given an iterator to a visible item, return the next visible item
+ Iterator getNextVisibleItem( Iterator it );
- /// Pointer to parent node
- VarTree *m_pParent;
+ /// Given an it to a visible item, return the previous visible item
+ Iterator getPrevVisibleItem( Iterator it );
- /// Variable type
- static const string m_type;
+ /// Given an iterator to an item, return the next item
+ Iterator getNextItem( Iterator it );
- /// Position variable
- VariablePtr m_cPosition;
+ /// Given an iterator to an item, return the previous item
+ Iterator getPrevItem( Iterator it );
+
+ /// Given an iterator to an item, return the next leaf
+ Iterator getNextLeaf( Iterator it );
+
+ /// Given an iterator to an item, return the previous leaf
+ Iterator getPrevLeaf( Iterator it );
+
+ /// Find a children node with the given id
+ Iterator findById( int id );
+
+ /// Ensure an item is expanded
+ void ensureExpanded( VarTree::Iterator );
+
+ /// flag a whole subtree for deletion
+ void cascadeDelete();
+
+ /// Get depth (root depth is 0)
+ int depth()
+ {
+ VarTree *parent = this;
+ int depth = 0;
+ while( ( parent = parent->parent() ) != NULL )
+ depth++;
+ return depth;
+ }
+
+
+private:
+
+ /// Get root node
+ VarTree *root()
+ {
+ VarTree *parent = this;
+ while( parent->parent() != NULL )
+ parent = parent->parent();
+ return parent;
+ }
+
+ /// List of children
+ list<VarTree> m_children;
+
+ /// Pointer to parent node
+ VarTree *m_pParent;
+
+ bool m_readonly;
+
+ /// Variable type
+ static const string m_type;
+
+ /// Position variable
+ VariablePtr m_cPosition;
};
#endif