]> git.sesse.net Git - vlc/commitdiff
Handle Page up / Page down (Refs:#477)
authorClément Stenac <zorglub@videolan.org>
Sat, 11 Feb 2006 14:08:44 +0000 (14:08 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 11 Feb 2006 14:08:44 +0000 (14:08 +0000)
modules/gui/skins2/controls/ctrl_tree.cpp
modules/gui/skins2/utils/var_tree.cpp
modules/gui/skins2/utils/var_tree.hpp
modules/gui/skins2/vars/playtree.cpp

index 0d49e511d3e095cba6eec179d0103a8b4957346b..3b48965fd5051b74897250dc672921014655751c 100644 (file)
@@ -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 ) )
         {
index f76c89dceeeea30b7fa01f4ccb6094be046425b4..e6d8c1159f49faa922f65fa33a0700ab69f5ce70 100644 (file)
@@ -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;
index 31add63bd5c74274f642efe1da37a48219b13d5f..96cd19bf12ea9ae123de7bd58592023091b51032 100644 (file)
@@ -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 );
 
index 43e46b572fcfa57ad0aa14605acf2d67cb8844e3..2ba159e7d4a6401b0fa9f254c43d340b79e01184 100644 (file)
@@ -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 );
 }