Commit 6adad42a authored by Clément Stenac's avatar Clément Stenac

Handle Page up / Page down (Refs:#477)

parent d02fbdb8
...@@ -135,7 +135,8 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update*> &rTree, ...@@ -135,7 +135,8 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update*> &rTree,
{ {
if( arg->i_type == 0 ) // Item update if( arg->i_type == 0 ) // Item update
{ {
autoScroll(); if( arg->b_active_item && arg->b_visible )
autoScroll();
makeImage(); makeImage();
} }
/// \todo handle delete in a more clever way /// \todo handle delete in a more clever way
...@@ -222,6 +223,52 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -222,6 +223,52 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
{ {
m_rTree.delSelected(); m_rTree.delSelected();
} }
else if( key == KEY_PAGEDOWN )
{
it = m_firstPos;
int i = maxItems()*1.5;
while( i >= 0 )
{
VarTree::Iterator it_old = it;
it = m_rTree.getNextVisibleItem( it );
/* End is already visible, dont' scroll */
if( it == m_rTree.end() )
{
it = it_old;
break;
}
needShow = true;
i--;
}
if( needShow )
{
ensureVisible( it );
makeImage();
notifyLayout();
return;
}
}
else if (key == KEY_PAGEUP )
{
it = m_firstPos;
int i = maxItems();
while( i >= maxItems()/2 )
{
it = m_rTree.getPrevVisibleItem( it );
/* End is already visible, dont' scroll */
if( it == m_rTree.begin() )
{
break;
}
i--;
}
ensureVisible( it );
makeImage();
notifyLayout();
return;
}
for( it = m_rTree.begin(); it != m_rTree.end(); for( it = m_rTree.begin(); it != m_rTree.end();
it = m_rTree.getNextVisibleItem( it ) ) it = m_rTree.getNextVisibleItem( it ) )
{ {
......
...@@ -107,7 +107,7 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const ...@@ -107,7 +107,7 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const
/* find iterator to next ancestor /* find iterator to next ancestor
* ... which means parent++ or grandparent++ or grandgrandparent++ ... */ * ... which means parent++ or grandparent++ or grandgrandparent++ ... */
VarTree::Iterator VarTree::uncle() VarTree::Iterator VarTree::next_uncle()
{ {
VarTree *p_parent = parent(); VarTree *p_parent = parent();
if( p_parent != NULL ) if( p_parent != NULL )
...@@ -139,6 +139,39 @@ VarTree::Iterator VarTree::uncle() ...@@ -139,6 +139,39 @@ VarTree::Iterator VarTree::uncle()
return root()->end(); return root()->end();
} }
VarTree::Iterator VarTree::prev_uncle()
{
VarTree *p_parent = parent();
if( p_parent != NULL )
{
VarTree *p_grandparent = p_parent->parent();
while( p_grandparent != NULL )
{
Iterator it = p_grandparent->end();
while( it != p_grandparent->begin() && &(*it) != p_parent ) it--;
if( it != p_grandparent->begin() )
{
it--;
if( it != p_grandparent->begin() )
{
return it;
}
}
if( p_grandparent->parent() )
{
p_parent = p_grandparent;
p_grandparent = p_parent->parent();
}
else
p_grandparent = NULL;
}
}
/* if we didn't return before, it means that we've reached the end */
return root()->begin();
}
void VarTree::checkParents( VarTree *pParent ) void VarTree::checkParents( VarTree *pParent )
{ {
m_pParent = pParent; m_pParent = pParent;
...@@ -196,12 +229,37 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it ) ...@@ -196,12 +229,37 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it )
// Was 'it' the last brother? If so, look for uncles // Was 'it' the last brother? If so, look for uncles
if( it_old->parent() && it_old->parent()->end() == it ) if( it_old->parent() && it_old->parent()->end() == it )
{ {
it = it_old->uncle(); it = it_old->next_uncle();
} }
} }
return it; return it;
} }
VarTree::Iterator VarTree::getPrevVisibleItem( Iterator it )
{
VarTree::Iterator it_old = it;
if( it == root()->begin() || it == ++(root()->begin()) ) return it;
if( it->parent() )
{
}
/* Was it the first child of its parent ? */
if( it->parent() && it == it->parent()->begin() )
{
/* Yes, get previous uncle */
it = it_old->prev_uncle();
}
else
it--;
/* We have found an expanded uncle, take its last child */
while( it != root()->begin() && it->size() && it->m_expanded )
{
it = it->end();
it--;
}
return it;
}
VarTree::Iterator VarTree::getNextItem( Iterator it ) VarTree::Iterator VarTree::getNextItem( Iterator it )
{ {
if( it->size() ) if( it->size() )
...@@ -215,7 +273,7 @@ VarTree::Iterator VarTree::getNextItem( Iterator it ) ...@@ -215,7 +273,7 @@ VarTree::Iterator VarTree::getNextItem( Iterator it )
// Was 'it' the last brother? If so, look for uncles // Was 'it' the last brother? If so, look for uncles
if( it_old->parent() && it_old->parent()->end() == it ) if( it_old->parent() && it_old->parent()->end() == it )
{ {
it = it_old->uncle(); it = it_old->next_uncle();
} }
} }
return it; return it;
......
...@@ -37,6 +37,7 @@ typedef struct tree_update ...@@ -37,6 +37,7 @@ typedef struct tree_update
int i_type; int i_type;
int i_parent; int i_parent;
int i_id; int i_id;
bool b_active_item;
bool b_visible; bool b_visible;
} tree_update; } tree_update;
...@@ -99,7 +100,8 @@ class VarTree: public Variable, public Subject<VarTree, tree_update*> ...@@ -99,7 +100,8 @@ class VarTree: public Variable, public Subject<VarTree, tree_update*>
VarTree *parent() { return m_pParent; } VarTree *parent() { return m_pParent; }
void checkParents( VarTree *pParent ); void checkParents( VarTree *pParent );
Iterator uncle(); Iterator next_uncle();
Iterator prev_uncle();
/// Get root node /// Get root node
VarTree *root() VarTree *root()
...@@ -139,6 +141,9 @@ class VarTree: public Variable, public Subject<VarTree, tree_update*> ...@@ -139,6 +141,9 @@ class VarTree: public Variable, public Subject<VarTree, tree_update*>
/// Given an iterator to a visible item, return the next visible item /// Given an iterator to a visible item, return the next visible item
Iterator getNextVisibleItem( Iterator it ); Iterator getNextVisibleItem( Iterator it );
/// Given an it to a visible item, return the previous visible item
Iterator getPrevVisibleItem( Iterator it );
/// Given an iterator to an item, return the next item /// Given an iterator to an item, return the next item
Iterator getNextItem( Iterator it ); Iterator getNextItem( Iterator it );
......
...@@ -118,6 +118,8 @@ void Playtree::onChange() ...@@ -118,6 +118,8 @@ void Playtree::onChange()
void Playtree::onUpdateItem( int id ) void Playtree::onUpdateItem( int id )
{ {
Iterator it = findById( id ); Iterator it = findById( id );
tree_update descr;
descr.b_active_item = false;
if( it != end() ) if( it != end() )
{ {
// Update the item // Update the item
...@@ -125,12 +127,12 @@ void Playtree::onUpdateItem( int id ) ...@@ -125,12 +127,12 @@ void Playtree::onUpdateItem( int id )
UString *pName = new UString( getIntf(), pNode->input.psz_name ); UString *pName = new UString( getIntf(), pNode->input.psz_name );
it->m_cString = UStringPtr( pName ); it->m_cString = UStringPtr( pName );
it->m_playing = m_pPlaylist->status.p_item == pNode; it->m_playing = m_pPlaylist->status.p_item == pNode;
if( it->m_playing ) descr.b_active_item = true;
} }
else else
{ {
msg_Warn(getIntf(), "Cannot find node with id %d", id ); msg_Warn(getIntf(), "Cannot find node with id %d", id );
} }
tree_update descr;
descr.i_type = 0; descr.i_type = 0;
notify( &descr ); notify( &descr );
} }
......
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