]> git.sesse.net Git - vlc/commitdiff
some more mouse control on playtree display/selection
authorAntoine Cellerier <dionoea@videolan.org>
Sat, 20 Aug 2005 11:10:30 +0000 (11:10 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sat, 20 Aug 2005 11:10:30 +0000 (11:10 +0000)
modules/gui/skins2/controls/ctrl_tree.cpp
modules/gui/skins2/controls/ctrl_tree.hpp
modules/gui/skins2/vars/playtree.cpp

index ae8648150b1ad81080a994840d72e1918b8ae412..4ffe077bf2f078784d66ae5443ea759d6beca30a 100644 (file)
@@ -100,6 +100,24 @@ int CtrlTree::itemHeight()
     return itemHeight;
 }
 
+int CtrlTree::itemImageWidth()
+{
+    int bitmapWidth = 5;
+    if( m_pClosedBitmap )
+    {
+        bitmapWidth = __MAX( m_pClosedBitmap->getWidth(), bitmapWidth );
+    }
+    if( m_pOpenBitmap )
+    {
+        bitmapWidth = __MAX( m_pOpenBitmap->getWidth(), bitmapWidth );
+    }
+    if( m_pItemBitmap )
+    {
+        bitmapWidth = __MAX( m_pItemBitmap->getWidth(), bitmapWidth );
+    }
+    return bitmapWidth + 2;
+}
+
 int CtrlTree::maxItems()
 {
     const Position *pPos = getPosition();
@@ -291,11 +309,84 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
         EvtMouse &rEvtMouse = (EvtMouse&)rEvent;
         const Position *pos = getPosition();
         int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight();
+        int xPos = rEvtMouse.getXPos() - pos->getLeft();
         VarTree::Iterator it;
         int index = 0;
 
-        // TODO : add all other mouse controls
-        /**/ if( rEvent.getAsString().find( "mouse:left:down" ) !=
+        if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) !=
+            string::npos )
+        {
+            // Flag to know if the currend item must be selected
+            bool select = false;
+            index = -1;
+            for( it = m_rTree.begin(); it != m_rTree.end(); )
+            {
+                bool nextSelect = select;
+                if( it == m_lastPos ) index = 0;
+                if( index == yPos || &*it == m_pLastSelected )
+                {
+                    if( select )
+                    {
+                        nextSelect = false;
+                    }
+                    else
+                    {
+                        select = true;
+                        nextSelect = true;
+                    }
+                }
+                it->m_selected = (*it).m_selected || select;
+                select = nextSelect;
+                if( index != -1 )
+                    index++;
+                IT_DISP_LOOP_END( it );
+            }
+        }
+        else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) !=
+                 string::npos )
+        {
+            for( it = m_lastPos; it != m_rTree.end(); )
+            {
+                if( index == yPos )
+                {
+                    it->m_selected = !it->m_selected;
+                    m_pLastSelected = &*it;
+                    break;
+                }
+                index++;
+                IT_DISP_LOOP_END( it );
+            }
+        }
+        else if( rEvent.getAsString().find( "mouse:left:down:shift" ) !=
+                 string::npos )
+        {
+            // Flag to know if the currend item must be selected
+            bool select = false;
+            index = -1;
+            for( it = m_rTree.begin(); it != m_rTree.end(); )
+            {
+                bool nextSelect = select;
+                if( it == m_lastPos ) index = 0;
+                if( index == yPos || &*it == m_pLastSelected )
+                {
+                    if( select )
+                    {
+                        nextSelect = false;
+                    }
+                    else
+                    {
+                        select = true;
+                        nextSelect = true;
+                    }
+                }
+                it->m_selected = select;
+                select = nextSelect;
+                if( index != -1 )
+                    index++;
+                IT_DISP_LOOP_END( it );
+            }
+        }
+        else if( rEvent.getAsString().find( "mouse:left:down" ) !=
                  string::npos )
         {
             for( it = m_lastPos; it != m_rTree.end(); )
@@ -321,10 +412,17 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
             {
                 if( index == yPos )
                 {
-                    it->m_selected = true;
-                    m_pLastSelected = &*it;
-                    // Execute the action associated to this item
-                    m_rTree.action( &*it );
+                    if( it->size() && xPos < it->depth() * itemImageWidth() )
+                    {
+                        it->m_expanded = !it->m_expanded;
+                    }
+                    else
+                    {
+                        it->m_selected = true;
+                        m_pLastSelected = &*it;
+                        // Execute the action associated to this item
+                        m_rTree.action( &*it );
+                    }
                 }
                 else
                 {
@@ -450,20 +548,7 @@ void CtrlTree::makeImage()
     }
 //    fprintf( stderr, "done\n");
 
-    int bitmapWidth = 5;
-    if( m_pClosedBitmap )
-    {
-        bitmapWidth = __MAX( m_pClosedBitmap->getWidth(), bitmapWidth );
-    }
-    if( m_pOpenBitmap )
-    {
-        bitmapWidth = __MAX( m_pOpenBitmap->getWidth(), bitmapWidth );
-    }
-    if( m_pItemBitmap )
-    {
-        bitmapWidth = __MAX( m_pItemBitmap->getWidth(), bitmapWidth );
-    }
-    bitmapWidth += 2;
+    int bitmapWidth = itemImageWidth();
 
     // FIXME : Draw the items
     int yPos = 0;
index 50aa48e890950307e64cf38e13cf81ccd9b4bb70..6d262b607aac76dbe0227945044779624165107b 100644 (file)
@@ -116,6 +116,9 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>,
         /// Compute the item's height (depends on fonts and images used)
         int itemHeight();
 
+        /// Compute the width of an item's bitmap
+        int itemImageWidth();
+
         /// Check if the tree must be scrolled
         void autoScroll();
 
index ee845a2989df557def57ac216e2f3ffec8145abd..871e9eedc75139ec31f9e5edaac253203ee46973 100644 (file)
@@ -63,6 +63,9 @@ void Playtree::delSelected()
 
 void Playtree::action( VarTree *pItem )
 {
+    /* do we really want to call preparse here ? */
+    playlist_PreparseEnqueueItem( m_pPlaylist,
+                                  (playlist_item_t *)pItem->m_pData );
     vlc_mutex_lock( &m_pPlaylist->object_lock );
     VarTree::Iterator it;
     if( pItem->size() )