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,
{
if( arg->i_type == 0 ) // Item update
{
autoScroll();
if( arg->b_active_item && arg->b_visible )
autoScroll();
makeImage();
}
/// \todo handle delete in a more clever way
......@@ -222,6 +223,52 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
{
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();
it = m_rTree.getNextVisibleItem( it ) )
{
......
......@@ -107,7 +107,7 @@ VarTree::ConstIterator VarTree::operator[]( int n ) const
/* find iterator to next ancestor
* ... which means parent++ or grandparent++ or grandgrandparent++ ... */
VarTree::Iterator VarTree::uncle()
VarTree::Iterator VarTree::next_uncle()
{
VarTree *p_parent = parent();
if( p_parent != NULL )
......@@ -139,6 +139,39 @@ VarTree::Iterator VarTree::uncle()
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 )
{
m_pParent = pParent;
......@@ -196,12 +229,37 @@ VarTree::Iterator VarTree::getNextVisibleItem( Iterator it )
// Was 'it' the last brother? If so, look for uncles
if( it_old->parent() && it_old->parent()->end() == it )
{
it = it_old->uncle();
it = it_old->next_uncle();
}
}
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 )
{
if( it->size() )
......@@ -215,7 +273,7 @@ VarTree::Iterator VarTree::getNextItem( Iterator it )
// Was 'it' the last brother? If so, look for uncles
if( it_old->parent() && it_old->parent()->end() == it )
{
it = it_old->uncle();
it = it_old->next_uncle();
}
}
return it;
......
......@@ -37,6 +37,7 @@ typedef struct tree_update
int i_type;
int i_parent;
int i_id;
bool b_active_item;
bool b_visible;
} tree_update;
......@@ -99,7 +100,8 @@ class VarTree: public Variable, public Subject<VarTree, tree_update*>
VarTree *parent() { return m_pParent; }
void checkParents( VarTree *pParent );
Iterator uncle();
Iterator next_uncle();
Iterator prev_uncle();
/// Get root node
VarTree *root()
......@@ -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
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
Iterator getNextItem( Iterator it );
......
......@@ -118,6 +118,8 @@ void Playtree::onChange()
void Playtree::onUpdateItem( int id )
{
Iterator it = findById( id );
tree_update descr;
descr.b_active_item = false;
if( it != end() )
{
// Update the item
......@@ -125,12 +127,12 @@ void Playtree::onUpdateItem( int id )
UString *pName = new UString( getIntf(), pNode->input.psz_name );
it->m_cString = UStringPtr( pName );
it->m_playing = m_pPlaylist->status.p_item == pNode;
if( it->m_playing ) descr.b_active_item = true;
}
else
{
msg_Warn(getIntf(), "Cannot find node with id %d", id );
}
tree_update descr;
descr.i_type = 0;
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