Commit cb2ad9ec authored by Olivier Teulière's avatar Olivier Teulière

* skins2 (tree playlist):

     - Fixed a selection bug in CtrlTree
     - Simplified some algorithms using helper methods
     - A few coding style fixes
parent 4ab6e7c7
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ctrl_tree.hpp * ctrl_tree.hpp
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: ctrl_list.hpp 11009 2005-05-14 14:39:05Z ipkiss $ * $Id$
* *
* Authors: Antoine Cellerier * Authors: Antoine Cellerier
* *
...@@ -124,6 +124,13 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>, ...@@ -124,6 +124,13 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>,
/// Draw the image of the control /// Draw the image of the control
void makeImage(); void makeImage();
/// Return the n'th displayed item (starting at position 0)
/**
* Return m_rTree.end() if such an item cannot be found (n < 0, or
* n too big)
*/
VarTree::Iterator findItemAtPos( int n );
}; };
#endif #endif
...@@ -23,16 +23,17 @@ ...@@ -23,16 +23,17 @@
#include "var_tree.hpp" #include "var_tree.hpp"
const string VarTree::m_type = "tree"; const string VarTree::m_type = "tree";
VarTree::VarTree( intf_thread_t *pIntf, VarTree *m_pParent2 ) VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent )
:Variable( pIntf ) : Variable( pIntf )
{ {
m_selected = false; m_selected = false;
m_playing = false; m_playing = false;
m_expanded = true; m_expanded = true;
m_pData = NULL; m_pData = NULL;
m_pParent = m_pParent2; m_pParent = pParent;
// Create the position variable // Create the position variable
m_cPosition = VariablePtr( new VarPercent( pIntf ) ); m_cPosition = VariablePtr( new VarPercent( pIntf ) );
...@@ -44,7 +45,11 @@ VarTree::~VarTree() ...@@ -44,7 +45,11 @@ VarTree::~VarTree()
// TODO : check that children are deleted // TODO : check that children are deleted
} }
void VarTree::add( const UStringPtr &rcString, bool selected, bool playing, bool expanded, void *pData ) void VarTree::add( const UStringPtr &rcString,
bool selected,
bool playing,
bool expanded,
void *pData )
{ {
m_children.push_back( VarTree( getIntf(), this ) ); m_children.push_back( VarTree( getIntf(), this ) );
back().m_cString = rcString; back().m_cString = rcString;
...@@ -107,7 +112,6 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const ...@@ -107,7 +112,6 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const
* ... which means parent++ or grandparent++ or grandgrandparent++ ... */ * ... which means parent++ or grandparent++ or grandgrandparent++ ... */
VarTree::Iterator VarTree::uncle() VarTree::Iterator VarTree::uncle()
{ {
// fprintf( stderr, "trying to find uncle\n");
VarTree *p_parent = parent(); VarTree *p_parent = parent();
if( p_parent != NULL ) if( p_parent != NULL )
{ {
...@@ -115,7 +119,7 @@ VarTree::Iterator VarTree::uncle() ...@@ -115,7 +119,7 @@ VarTree::Iterator VarTree::uncle()
while( p_grandparent != NULL ) while( p_grandparent != NULL )
{ {
Iterator it = p_grandparent->begin(); Iterator it = p_grandparent->begin();
while( !(it == p_grandparent->end()) && &(*it) != p_parent ) it++; while( it != p_grandparent->end() && &(*it) != p_parent ) it++;
if( it != p_grandparent->end() ) if( it != p_grandparent->end() )
{ {
it++; it++;
...@@ -138,11 +142,11 @@ VarTree::Iterator VarTree::uncle() ...@@ -138,11 +142,11 @@ VarTree::Iterator VarTree::uncle()
return root()->end(); return root()->end();
} }
void VarTree::checkParents( VarTree *m_pParent2 ) void VarTree::checkParents( VarTree *pParent )
{ {
m_pParent = m_pParent2; m_pParent = pParent;
Iterator it = begin(); Iterator it = begin();
while( it!=end() ) while( it != end() )
{ {
it->checkParents( this ); it->checkParents( this );
it++; it++;
...@@ -164,7 +168,7 @@ int VarTree::visibleItems() ...@@ -164,7 +168,7 @@ int VarTree::visibleItems()
return i_count; return i_count;
} }
VarTree::Iterator VarTree::visibleItem( int n ) VarTree::Iterator VarTree::getVisibleItem( int n )
{ {
Iterator it = begin(); Iterator it = begin();
while( it != end() ) while( it != end() )
...@@ -174,10 +178,30 @@ VarTree::Iterator VarTree::visibleItem( int n ) ...@@ -174,10 +178,30 @@ VarTree::Iterator VarTree::visibleItem( int n )
if( it->m_expanded ) if( it->m_expanded )
{ {
int i = n - it->visibleItems(); int i = n - it->visibleItems();
if( i <= 0 ) return it->visibleItem( n ); if( i <= 0 ) return it->getVisibleItem( n );
n = i; n = i;
} }
it++; it++;
} }
return end(); return end();
} }
VarTree::Iterator VarTree::getNextVisibleItem( Iterator it )
{
if( it->m_expanded && it->size() )
{
it = it->begin();
}
else
{
VarTree::Iterator it_old = it;
it++;
// Was 'it' the last brother? If so, look for uncles
if( it_old->parent() && it_old->parent()->end() == it )
{
it = it_old->uncle();
}
}
return it;
}
...@@ -35,14 +35,18 @@ ...@@ -35,14 +35,18 @@
class VarTree: public Variable, public Subject<VarTree> class VarTree: public Variable, public Subject<VarTree>
{ {
public: public:
VarTree( intf_thread_t *pIntf, VarTree *m_pParent2 ); VarTree( intf_thread_t *pIntf, VarTree *pParent );
virtual ~VarTree(); virtual ~VarTree();
/// Get the variable type /// Get the variable type
virtual const string &getType() const { return m_type; } virtual const string &getType() const { return m_type; }
/// Add a pointer on string in the children's list /// 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 ); virtual void add( const UStringPtr &rcString,
bool selected = true,
bool playing = true,
bool expanded = true,
void *pData = NULL );
/// Remove the selected item from the children's list /// Remove the selected item from the children's list
virtual void delSelected(); virtual void delSelected();
...@@ -80,15 +84,28 @@ class VarTree: public Variable, public Subject<VarTree> ...@@ -80,15 +84,28 @@ class VarTree: public Variable, public Subject<VarTree>
/// Parent node /// Parent node
VarTree *parent() { return m_pParent; } VarTree *parent() { return m_pParent; }
void VarTree::checkParents( VarTree *m_pParent2 ); void VarTree::checkParents( VarTree *pParent );
Iterator uncle(); Iterator uncle();
/// Get root node /// Get root node
VarTree *root() { VarTree *parent=this; while( parent->parent() != NULL ) parent = parent->parent(); return parent; } VarTree *root()
{
VarTree *parent = this;
while( parent->parent() != NULL )
parent = parent->parent();
return parent;
}
/// Get depth (root depth is 0) /// Get depth (root depth is 0)
int depth() { VarTree *parent=this; int depth=0; while( ( parent = parent->parent() ) != NULL ) depth++; return depth; } int depth()
{
VarTree *parent = this;
int depth = 0;
while( ( parent = parent->parent() ) != NULL )
depth++;
return depth;
}
/// Execute the action associated to this item /// Execute the action associated to this item
virtual void action( VarTree *pItem ) {} virtual void action( VarTree *pItem ) {}
...@@ -104,18 +121,21 @@ class VarTree: public Variable, public Subject<VarTree> ...@@ -104,18 +121,21 @@ class VarTree: public Variable, public Subject<VarTree>
int visibleItems(); int visibleItems();
/// Return iterator to the n'th visible item /// Return iterator to the n'th visible item
Iterator visibleItem( int n ); Iterator getVisibleItem( int n );
/// Given an iterator to a visible item, return the next visible item
Iterator getNextVisibleItem( Iterator it );
private: private:
// intf_thread_t *pIntf; // intf_thread_t *pIntf;
///list of children /// List of children
list<VarTree> m_children; list<VarTree> m_children;
///Pointer to parent node /// Pointer to parent node
VarTree *m_pParent; VarTree *m_pParent;
///Variable type /// Variable type
static const string m_type; static const string m_type;
/// Position variable /// Position variable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment