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 @@
* ctrl_tree.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: ctrl_list.hpp 11009 2005-05-14 14:39:05Z ipkiss $
* $Id$
*
* Authors: Antoine Cellerier
*
......@@ -124,6 +124,13 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>,
/// Draw the image of the control
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
......@@ -23,16 +23,17 @@
#include "var_tree.hpp"
const string VarTree::m_type = "tree";
VarTree::VarTree( intf_thread_t *pIntf, VarTree *m_pParent2 )
:Variable( pIntf )
VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent )
: Variable( pIntf )
{
m_selected = false;
m_playing = false;
m_expanded = true;
m_pData = NULL;
m_pParent = m_pParent2;
m_pParent = pParent;
// Create the position variable
m_cPosition = VariablePtr( new VarPercent( pIntf ) );
......@@ -44,7 +45,11 @@ VarTree::~VarTree()
// 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 ) );
back().m_cString = rcString;
......@@ -107,7 +112,6 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const
* ... which means parent++ or grandparent++ or grandgrandparent++ ... */
VarTree::Iterator VarTree::uncle()
{
// fprintf( stderr, "trying to find uncle\n");
VarTree *p_parent = parent();
if( p_parent != NULL )
{
......@@ -115,7 +119,7 @@ VarTree::Iterator VarTree::uncle()
while( p_grandparent != NULL )
{
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() )
{
it++;
......@@ -138,11 +142,11 @@ VarTree::Iterator VarTree::uncle()
return root()->end();
}
void VarTree::checkParents( VarTree *m_pParent2 )
void VarTree::checkParents( VarTree *pParent )
{
m_pParent = m_pParent2;
m_pParent = pParent;
Iterator it = begin();
while( it!=end() )
while( it != end() )
{
it->checkParents( this );
it++;
......@@ -164,7 +168,7 @@ int VarTree::visibleItems()
return i_count;
}
VarTree::Iterator VarTree::visibleItem( int n )
VarTree::Iterator VarTree::getVisibleItem( int n )
{
Iterator it = begin();
while( it != end() )
......@@ -174,10 +178,30 @@ VarTree::Iterator VarTree::visibleItem( int n )
if( it->m_expanded )
{
int i = n - it->visibleItems();
if( i <= 0 ) return it->visibleItem( n );
if( i <= 0 ) return it->getVisibleItem( n );
n = i;
}
it++;
}
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 @@
class VarTree: public Variable, public Subject<VarTree>
{
public:
VarTree( intf_thread_t *pIntf, VarTree *m_pParent2 );
VarTree( intf_thread_t *pIntf, VarTree *pParent );
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( 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
virtual void delSelected();
......@@ -80,22 +84,35 @@ class VarTree: public Variable, public Subject<VarTree>
/// Parent node
VarTree *parent() { return m_pParent; }
void VarTree::checkParents( VarTree *m_pParent2 );
void VarTree::checkParents( VarTree *pParent );
Iterator uncle();
/// 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)
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
virtual void action( VarTree *pItem ) {}
/// Get a reference on the position variable
VarPercent &getPositionVar() const
{ return *((VarPercent*)m_cPosition.get()); }
{ return *((VarPercent*)m_cPosition.get()); }
/// Get a counted pointer on the position variable
const VariablePtr &getPositionVarPtr() const { return m_cPosition; }
......@@ -104,18 +121,21 @@ class VarTree: public Variable, public Subject<VarTree>
int visibleItems();
/// 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:
// intf_thread_t *pIntf;
///list of children
/// List of children
list<VarTree> m_children;
///Pointer to parent node
/// Pointer to parent node
VarTree *m_pParent;
///Variable type
/// Variable type
static const string m_type;
/// 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