From 1e5a527b9da4f0a6df76b29f10dd5da34789036d Mon Sep 17 00:00:00 2001
From: Fabio Ritrovato <exsephiroth87@gmail.com>
Date: Wed, 3 Sep 2008 13:52:46 +0200
Subject: [PATCH] Skins2: add functions to retrieve te selected root item

---
 modules/gui/skins2/controls/ctrl_tree.cpp |    7 +++++++
 modules/gui/skins2/utils/var_tree.cpp     |    2 ++
 modules/gui/skins2/utils/var_tree.hpp     |   10 ++++++++++
 3 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/modules/gui/skins2/controls/ctrl_tree.cpp b/modules/gui/skins2/controls/ctrl_tree.cpp
index 0c27d34..12de2d1 100644
--- a/modules/gui/skins2/controls/ctrl_tree.cpp
+++ b/modules/gui/skins2/controls/ctrl_tree.cpp
@@ -290,6 +290,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
             /* Select it_sel */
             it_sel->m_selected = true;
             m_pLastSelected = &*it_sel;
+            m_rTree.setLastSelected( m_pLastSelected );
         }
         else if( key == KEY_PAGEDOWN )
         {
@@ -358,6 +359,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                     if( nextWasSelected )
                     {
                         m_pLastSelected = &*it;
+                        m_rTree.setLastSelected( m_pLastSelected );
                         needShow = true; toShow = it;
                     }
                 }
@@ -374,6 +376,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                 if( previousWasSelected )
                 {
                     m_pLastSelected = &*it;
+                    m_rTree.setLastSelected( m_pLastSelected );
                     needShow = true; toShow = it;
                     previousWasSelected = false;
                 }
@@ -402,6 +405,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                             it->m_selected = false;
                             it->begin()->m_selected = true;
                             m_pLastSelected = &*(it->begin());
+                            m_rTree.setLastSelected( m_pLastSelected );
                         }
                         else
                         {
@@ -431,6 +435,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                         {
                             it->m_selected = false;
                             m_pLastSelected = it->parent();
+                            m_rTree.setLastSelected( m_pLastSelected );
                             m_pLastSelected->m_selected = true;
                         }
                     }
@@ -498,6 +503,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
             {
                 it->m_selected = !it->m_selected;
                 m_pLastSelected = &*it;
+                m_rTree.setLastSelected( m_pLastSelected );
             }
         }
         else if( rEvent.getAsString().find( "mouse:left:down:shift" ) !=
@@ -558,6 +564,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
                     {
                         it->m_selected = true;
                         m_pLastSelected = &*it;
+                        m_rTree.setLastSelected( m_pLastSelected );
                     }
                 }
             }
diff --git a/modules/gui/skins2/utils/var_tree.cpp b/modules/gui/skins2/utils/var_tree.cpp
index a7454e5..1b5438f 100644
--- a/modules/gui/skins2/utils/var_tree.cpp
+++ b/modules/gui/skins2/utils/var_tree.cpp
@@ -35,6 +35,7 @@ VarTree::VarTree( intf_thread_t *pIntf )
     // Create the position variable
     m_cPosition = VariablePtr( new VarPercent( pIntf ) );
     getPositionVar().set( 1.0 );
+    m_pLastSelected = NULL;
 }
 
 VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
@@ -49,6 +50,7 @@ VarTree::VarTree( intf_thread_t *pIntf, VarTree *pParent, int id,
     // Create the position variable
     m_cPosition = VariablePtr( new VarPercent( pIntf ) );
     getPositionVar().set( 1.0 );
+    m_pLastSelected = NULL;
 }
 
 VarTree::~VarTree()
diff --git a/modules/gui/skins2/utils/var_tree.hpp b/modules/gui/skins2/utils/var_tree.hpp
index ad269bb..a076425 100644
--- a/modules/gui/skins2/utils/var_tree.hpp
+++ b/modules/gui/skins2/utils/var_tree.hpp
@@ -184,6 +184,13 @@ class VarTree: public Variable, public Subject<VarTree, tree_update>
             return depth;
         }
 
+        /// Set the last selected item
+        void setLastSelected( VarTree *it ) { m_pLastSelected = it; }
+
+        /// Get the last selected item
+        VarTree *getLastSelected( void ) { return m_pLastSelected; }
+
+
 
     private:
         /// List of children
@@ -199,6 +206,9 @@ class VarTree: public Variable, public Subject<VarTree, tree_update>
 
         /// Position variable
         VariablePtr m_cPosition;
+
+        /// Pointer on the last selected item in the tree
+        VarTree *m_pLastSelected;
 };
 
 #endif
-- 
1.5.4.3

