m_rTree.addObserver( this );
m_rTree.getPositionVar().addObserver( this );
- m_lastPos = m_rTree.begin();
+ m_firstPos = m_rTree.begin();
makeImage();
}
}
-void CtrlTree::onUpdate( Subject<VarTree> &rTree )
+void CtrlTree::onUpdate( Subject<VarTree, tree_update*> &rTree,
+ tree_update *arg )
{
- // Invalidate the position when the tree is updated
- m_lastPos = m_rTree.begin();
-
- autoScroll();
+ if( arg->i_type == 0 ) // Item update
+ {
+ autoScroll();
+ makeImage();
+ }
+ else if ( arg->i_type == 1 ) // Global change or deletion
+ {
+ makeImage();
+ }
+ else if ( arg->i_type == 2 ) // Item-append
+ {
+ /* TODO: Check if the item should be visible. If it is, makeImage
+ * Else, do nothing
+ */
+ makeImage();
+ }
+ notifyLayout();
m_pLastSelected = NULL;
}
-void CtrlTree::onUpdate( Subject<VarPercent> &rPercent )
+void CtrlTree::onUpdate( Subject<VarPercent, void*> &rPercent, void* arg)
{
// Determine what is the first item to display
VarTree::Iterator it = m_rTree.begin();
#endif
it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
}
- if( m_lastPos != it )
+ if( m_firstPos != it )
{
// Redraw the control if the position has changed
- m_lastPos = it;
+ m_firstPos = it;
makeImage();
notifyLayout();
}
void CtrlTree::onResize()
{
-// FIXME : shouldn't be the same as the onUpdate function ... but i'm lazy
+ // FIXME : shouldn't be the same as the onUpdate function ... but i'm lazy
// Determine what is the first item to display
VarTree::Iterator it = m_rTree.begin();
it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
}
// Redraw the control if the position has changed
- m_lastPos = it;
+ m_firstPos = it;
makeImage();
notifyLayout();
-#if 0
- // Determine what is the first item to display
- VarTree::Iterator it = m_rTree.begin();
-
- int excessItems = m_rTree.visibleItems() - maxItems();
-
- if( excessItems > 0)
- {
- /* FIXME VarPercent &rVarPos = m_rTree.getPositionVar();
- double newVal = 1.0 - (double)m_lastPos / excessItems;
- if( newVal >= 0 )
- {
- // Change the position to keep the same first displayed item
- rVarPos.set( 1.0 - (double)m_lastPos / excessItems );
- }
- else
- {
- // We cannot keep the current first item
- m_lastPos = excessItems;
- }*/
- it = m_rTree.getVisibleItem( excessItems );
- }
- makeImage();
- notifyLayout();
-#endif
}
void CtrlTree::onPositionChange()
m_pLastSelected = &*it;
}
}
+ //ensureVisible( it );
}
else if( key == KEY_DOWN )
{
{
previousWasSelected = ( &*it == m_pLastSelected );
}
+ //ensureVisible( it );
}
else if( key == KEY_RIGHT )
{
else if( rEvent.getAsString().find( "mouse:left:down" ) !=
string::npos )
{
- // Unselect any previously selected item
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ it = findItemAtPos(yPos);
+ if( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
+ && xPos < it->depth() * itemImageWidth() )
{
- it->m_selected = false;
+ // Fold/unfold the item
+ it->m_expanded = !it->m_expanded;
}
- // Select the new item
- it = findItemAtPos(yPos);
- if( it != m_rTree.end() )
+ else
{
- it->m_selected = true;
- m_pLastSelected = &*it;
+ // Unselect any previously selected item
+ VarTree::Iterator it2;
+ for( it2 = m_rTree.begin(); it2 != m_rTree.end();
+ it2 = m_rTree.getNextVisibleItem( it2 ) )
+ {
+ it2->m_selected = false;
+ }
+ // Select the new item
+ if( it != m_rTree.end() )
+ {
+ it->m_selected = true;
+ m_pLastSelected = &*it;
+ }
}
}
it = findItemAtPos(yPos);
if( it != m_rTree.end() )
{
- if( it->size() && xPos < it->depth() * itemImageWidth() )
- {
- it->m_expanded = !it->m_expanded;
- }
- else
- {
- // Execute the action associated to this item
- m_rTree.action( &*it );
- }
+ // Execute the action associated to this item
+ m_rTree.action( &*it );
}
}
-
// Redraw the control
makeImage();
notifyLayout();
}
}
-void CtrlTree::autoScroll()
+bool CtrlTree::ensureVisible( VarTree::Iterator item )
{
- // Find the current playing stream
- int playIndex = 0;
+ // Find the item to focus
+ int focusItemIndex = 0;
VarTree::Iterator it;
for( it = m_rTree.begin(); it != m_rTree.end();
it = m_rTree.getNextVisibleItem( it ) )
{
if( it->m_playing ) break;
- playIndex++;
+ focusItemIndex++;
}
+ return ensureVisible( focusItemIndex );
+}
- if( it == m_rTree.end() ) return;
-
- // Find m_lastPos
- int lastPosIndex = 0;
+bool CtrlTree::ensureVisible( int focusItemIndex )
+{
+ // Find m_firstPos
+ VarTree::Iterator it;
+ int firstPosIndex = 0;
for( it = m_rTree.begin(); it != m_rTree.end();
it = m_rTree.getNextVisibleItem( it ) )
{
- if( it == m_lastPos ) break;
- lastPosIndex++;
+ if( it == m_firstPos ) break;
+ firstPosIndex++;
}
- if( it == m_rTree.end() ) return;
+ if( it == m_rTree.end() ) return false;
if( it != m_rTree.end()
- && ( playIndex < lastPosIndex
- || playIndex > lastPosIndex + maxItems() ) )
+ && ( focusItemIndex < firstPosIndex
+ || focusItemIndex > firstPosIndex + maxItems() ) )
{
// Scroll to have the playing stream visible
VarPercent &rVarPos = m_rTree.getPositionVar();
- rVarPos.set( 1.0 - (double)playIndex / (double)m_rTree.visibleItems() );
+ rVarPos.set( 1.0 - (double)focusItemIndex /
+ (double)m_rTree.visibleItems() );
+ return true;
}
- else
+ return false;
+}
+
+void CtrlTree::autoScroll()
+{
+ // Find the current playing stream
+ int playIndex = 0;
+ VarTree::Iterator it;
+ for( it = m_rTree.begin(); it != m_rTree.end();
+ it = m_rTree.getNextVisibleItem( it ) )
{
- makeImage();
- notifyLayout();
+ if( it->m_playing ) break;
+ playIndex++;
}
+
+ if( it == m_rTree.end() ) return;
+
+ ensureVisible( playIndex );
}
+
void CtrlTree::makeImage()
{
if( m_pImage )
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
m_pImage = pOsFactory->createOSGraphics( width, height );
- VarTree::Iterator it = m_lastPos;
+ VarTree::Iterator it = m_firstPos;
if( m_pBgBitmap )
{
bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
}
}
-// fprintf( stderr, "done\n");
int bitmapWidth = itemImageWidth();
int yPos = 0;
- it = m_lastPos;
+ it = m_firstPos;
while( it != m_rTree.end() && yPos < height )
{
const GenericBitmap *m_pCurBitmap;
}
it = m_rTree.getNextVisibleItem( it );
}
+ /* TODO: Reposition percentage var to accomodate if it's not suitable anymore
+ * (if we expanded a node)
+ */
}
VarTree::Iterator CtrlTree::findItemAtPos( int pos )
{
- // The first item is m_lastPos.
+ // The first item is m_firstPos.
// We decrement pos as we try the other items, until pos == 0.
VarTree::Iterator it;
- for( it = m_lastPos; it != m_rTree.end() && pos != 0;
+ for( it = m_firstPos; it != m_rTree.end() && pos != 0;
it = m_rTree.getNextVisibleItem( it ) )
{
pos--;
return it;
}
-