]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_tree.cpp
skins2: fix playlist arrows and enter no longer functioning
[vlc] / modules / gui / skins2 / controls / ctrl_tree.cpp
index 7450b48ee5ee497f23e85f0a9f48c8e35914b863..34c29302b6867e5ae32cbb0210235acdf1d68acd 100644 (file)
@@ -138,6 +138,8 @@ int CtrlTree::maxItems()
 void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
                          tree_update *arg )
 {
+    m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+
     if( arg->i_type == 0 ) // Item update
     {
         if( arg->b_active_item )
@@ -150,7 +152,6 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
     /// \todo handle delete in a more clever way
     else if ( arg->i_type == 1 ) // Global change or deletion
     {
-        m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
         makeImage();
     }
     else if ( arg->i_type == 2 ) // Item-append
@@ -244,13 +245,11 @@ void CtrlTree::onResize()
     // Redraw the control if the position has changed
     m_firstPos = it;
     makeImage();
-    notifyLayout();
 }
 
 void CtrlTree::onPositionChange()
 {
     makeImage();
-    notifyLayout();
 }
 
 void CtrlTree::handleEvent( EvtGeneric &rEvent )
@@ -284,6 +283,10 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
             /* Select it_sel */
             it_sel->m_selected = true;
             m_pLastSelected = &*it_sel;
+
+            // Redraw the control
+            makeImage();
+            notifyLayout();
         }
         else if( key == KEY_PAGEDOWN )
         {
@@ -308,7 +311,6 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                 ensureVisible( it );
                 makeImage();
                 notifyLayout();
-                return;
             }
         }
         else if (key == KEY_PAGEUP )
@@ -329,122 +331,135 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
             ensureVisible( it );
             makeImage();
             notifyLayout();
-            return;
         }
-
-
-        for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
-             it != m_rTree.end();
-             it = m_flat ? m_rTree.getNextLeaf( it )
-                         : m_rTree.getNextVisibleItem( it ) )
+        else if ( key == KEY_UP ||
+                  key == KEY_DOWN ||
+                  key == KEY_LEFT ||
+                  key == KEY_RIGHT ||
+                  key == KEY_ENTER ||
+                  key == ' ' )
         {
-            VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it )
-                                            : m_rTree.getNextVisibleItem( it );
-            if( key == KEY_UP )
+            for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+                 it != m_rTree.end();
+                 it = m_flat ? m_rTree.getNextLeaf( it )
+                             : m_rTree.getNextVisibleItem( it ) )
             {
-                // Scroll up one item
-                if( ( it->parent()
-                      && it != it->parent()->begin() )
-                    || &*it != m_pLastSelected )
+                VarTree::Iterator next = m_flat ?
+                                         m_rTree.getNextLeaf( it ) :
+                                         m_rTree.getNextVisibleItem( it );
+                if( key == KEY_UP )
                 {
-                    bool nextWasSelected = ( &*next == m_pLastSelected );
-                    it->m_selected = nextWasSelected;
-                    if( nextWasSelected )
+                    // Scroll up one item
+                    if( ( it->parent()
+                          && it != it->parent()->begin() )
+                        || &*it != m_pLastSelected )
                     {
-                        m_pLastSelected = &*it;
-                        needShow = true; toShow = it;
+                        bool nextWasSelected = ( &*next == m_pLastSelected );
+                        it->m_selected = nextWasSelected;
+                        if( nextWasSelected )
+                        {
+                            m_pLastSelected = &*it;
+                            needShow = true; toShow = it;
+                        }
                     }
                 }
-            }
-            else if( key == KEY_DOWN )
-            {
-                // Scroll down one item
-                if( ( it->parent()
-                      && next != it->parent()->end() )
-                    || &*it != m_pLastSelected )
-                {
-                    (*it).m_selected = previousWasSelected;
-                }
-                if( previousWasSelected )
+                else if( key == KEY_DOWN )
                 {
-                    m_pLastSelected = &*it;
-                    needShow = true; toShow = it;
-                    previousWasSelected = false;
-                }
-                else
-                {
-                    previousWasSelected = ( &*it == m_pLastSelected );
-                }
+                    // Scroll down one item
+                    if( ( it->parent()
+                          && next != it->parent()->end() )
+                        || &*it != m_pLastSelected )
+                    {
+                        (*it).m_selected = previousWasSelected;
+                    }
+                    if( previousWasSelected )
+                    {
+                        m_pLastSelected = &*it;
+                        needShow = true; toShow = it;
+                        previousWasSelected = false;
+                    }
+                    else
+                    {
+                        previousWasSelected = ( &*it == m_pLastSelected );
+                    }
 
-                // Fix last tree item selection
-                if( ( m_flat ? m_rTree.getNextLeaf( it )
-                    : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end()
-                 && &*it == m_pLastSelected )
-                {
-                    (*it).m_selected = true;
+                    // Fix last tree item selection
+                    if( ( m_flat ? m_rTree.getNextLeaf( it )
+                        : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end()
+                     && &*it == m_pLastSelected )
+                    {
+                        (*it).m_selected = true;
+                    }
                 }
-            }
-            else if( key == KEY_RIGHT )
-            {
-                // Go down one level (and expand node)
-                if( &*it == m_pLastSelected )
+                else if( key == KEY_RIGHT )
                 {
-                    if( it->m_expanded )
+                    // Go down one level (and expand node)
+                    if( &*it == m_pLastSelected )
                     {
-                        if( it->size() )
+                        if( it->m_expanded )
                         {
-                            it->m_selected = false;
-                            it->begin()->m_selected = true;
-                            m_pLastSelected = &*(it->begin());
+                            if( it->size() )
+                            {
+                                it->m_selected = false;
+                                it->begin()->m_selected = true;
+                                m_pLastSelected = &*(it->begin());
+                            }
+                            else
+                            {
+                                m_rTree.action( &*it );
+                            }
                         }
                         else
                         {
-                            m_rTree.action( &*it );
+                            it->m_expanded = true;
+                            bChangedPosition = true;
                         }
                     }
-                    else
-                    {
-                        it->m_expanded = true;
-                        bChangedPosition = true;
-                    }
                 }
-            }
-            else if( key == KEY_LEFT )
-            {
-                // Go up one level (and close node)
-                if( &*it == m_pLastSelected )
+                else if( key == KEY_LEFT )
                 {
-                    if( it->m_expanded && it->size() )
-                    {
-                        it->m_expanded = false;
-                        bChangedPosition = true;
-                    }
-                    else
+                    // Go up one level (and close node)
+                    if( &*it == m_pLastSelected )
                     {
-                        if( it->parent() && it->parent() != &m_rTree)
+                        if( it->m_expanded && it->size() )
                         {
-                            it->m_selected = false;
-                            m_pLastSelected = it->parent();
-                            m_pLastSelected->m_selected = true;
+                            it->m_expanded = false;
+                            bChangedPosition = true;
+                        }
+                        else
+                        {
+                            if( it->parent() && it->parent() != &m_rTree)
+                            {
+                                it->m_selected = false;
+                                m_pLastSelected = it->parent();
+                                m_pLastSelected->m_selected = true;
+                            }
                         }
                     }
                 }
-            }
-            else if( key == KEY_ENTER || key == ' ' )
-            {
-                // Go up one level (and close node)
-                if( &*it == m_pLastSelected )
+                else if( key == KEY_ENTER || key == ' ' )
                 {
-                    m_rTree.action( &*it );
+                    // Go up one level (and close node)
+                    if( &*it == m_pLastSelected )
+                    {
+                        m_rTree.action( &*it );
+                    }
                 }
             }
+            if( needShow )
+                ensureVisible( toShow );
+            // Redraw the control
+            makeImage();
+            notifyLayout();
+        }
+        else
+        {
+            // other keys to be forwarded to vlc core
+            EvtKey& rEvtKey = (EvtKey&)rEvent;
+            var_SetInteger( getIntf()->p_libvlc, "key-pressed",
+                            rEvtKey.getModKey() );
         }
-        if( needShow )
-            ensureVisible( toShow );
 
-        // Redraw the control
-        makeImage();
-        notifyLayout();
     }
 
     else if( rEvent.getAsString().find( "mouse:left" ) != string::npos )
@@ -629,10 +644,19 @@ bool CtrlTree::mouseOver( int x, int y ) const
         x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight();
 }
 
-void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest )
+void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h)
 {
-    if( m_pImage )
-        rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
+    const Position *pPos = getPosition();
+    rect region( pPos->getLeft(), pPos->getTop(),
+                 pPos->getWidth(), pPos->getHeight() );
+    rect clip( xDest, yDest, w, h );
+    rect inter;
+
+    if( rect::intersect( region, clip, &inter ) && m_pImage )
+        rImage.drawGraphics( *m_pImage,
+                      inter.x - pPos->getLeft(),
+                      inter.y - pPos->getTop(),
+                      inter.x, inter.y, inter.width, inter.height );
 }
 
 bool CtrlTree::ensureVisible( VarTree::Iterator item )