*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <math.h>
m_pOpenBitmap( pOpenBitmap ), m_pClosedBitmap( pClosedBitmap ),
m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ),
m_bgColor2( bgColor2 ), m_selColor( selColor ),
- m_pLastSelected( NULL ), m_pImage( NULL )
+ m_pLastSelected( NULL ), m_pImage( NULL ), m_dontMove( false )
{
// Observe the tree and position variables
m_rTree.addObserver( this );
{
if( arg->i_type == 0 ) // Item update
{
- autoScroll();
- makeImage();
+ if( arg->b_active_item )
+ {
+ autoScroll();
+ ///\todo We should make image if we are visible in the view
+ makeImage();
+ }
}
+ /// \todo handle delete in a more clever way
else if ( arg->i_type == 1 ) // Global change or deletion
{
+ m_firstPos = m_rTree.begin();
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();
+ /// \todo Check if the item is really visible in the view
+ // (we only check if it in the document)
+ if( arg->b_visible == true )
+ {
+ makeImage();
+ }
+ }
+ else if( arg->i_type == 3 ) // item-del
+ {
+ /* Make sure firstPos and lastSelected are still valid */
+ while( m_firstPos->m_deleted && m_firstPos != m_rTree.root()->begin() )
+ {
+ m_firstPos = m_rTree.getPrevVisibleItem( m_firstPos );
+ }
+ if( m_firstPos->m_deleted ) m_firstPos = m_rTree.root()->begin();
+
+ if( arg->b_visible == true )
+ {
+ makeImage();
+ }
}
notifyLayout();
- m_pLastSelected = NULL;
}
void CtrlTree::onUpdate( Subject<VarPercent, void*> &rPercent, void* arg)
// Determine what is the first item to display
VarTree::Iterator it = m_rTree.begin();
+ if( m_dontMove ) return;
+
int excessItems = m_rTree.visibleItems() - maxItems();
if( excessItems > 0)
void CtrlTree::onResize()
{
- // 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();
void CtrlTree::handleEvent( EvtGeneric &rEvent )
{
+ bool bChangedPosition = false;
+ VarTree::Iterator toShow; bool needShow = false;
if( rEvent.getAsString().find( "key:down" ) != string::npos )
{
int key = ((EvtKey&)rEvent).getKey();
VarTree::Iterator it;
bool previousWasSelected = false;
+
+ /* Delete the selection */
+ if( key == KEY_DELETE )
+ {
+ /* Find first non selected item before m_pLastSelected */
+ VarTree::Iterator it_sel = m_rTree.begin();
+ for( it = m_rTree.begin(); it != m_rTree.end();
+ it = m_rTree.getNextVisibleItem( it ) )
+ {
+ if( &*it == m_pLastSelected ) break;
+ if( !it->m_selected ) it_sel = it;
+ }
+
+ /* Delete selected stuff */
+ m_rTree.delSelected();
+
+ /* Select it_sel */
+ it_sel->m_selected = true;
+ m_pLastSelected = &*it_sel;
+ }
+ else if( key == KEY_PAGEDOWN )
+ {
+ it = m_firstPos;
+ int i = (int)(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 ) )
{
if( nextWasSelected )
{
m_pLastSelected = &*it;
+ needShow = true; toShow = it;
}
}
- //ensureVisible( it );
}
else if( key == KEY_DOWN )
{
if( previousWasSelected )
{
m_pLastSelected = &*it;
+ needShow = true; toShow = it;
previousWasSelected = false;
}
else
{
previousWasSelected = ( &*it == m_pLastSelected );
}
- //ensureVisible( it );
+
+ // Fix last tree item selection
+ if( m_rTree.getNextVisibleItem( it ) == m_rTree.end()
+ && &*it == m_pLastSelected )
+ {
+ (*it).m_selected = true;
+ }
}
else if( key == KEY_RIGHT )
{
else
{
it->m_expanded = true;
+ bChangedPosition = true;
}
}
}
if( it->m_expanded && it->size() )
{
it->m_expanded = false;
+ bChangedPosition = true;
}
else
{
}
}
}
+ if( needShow )
+ ensureVisible( toShow );
// Redraw the control
makeImage();
string::npos )
{
it = findItemAtPos(yPos);
- if( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
- && xPos < it->depth() * itemImageWidth() )
- {
- // Fold/unfold the item
- it->m_expanded = !it->m_expanded;
- }
- else
+ if( it != m_rTree.end() )
{
- // Unselect any previously selected item
- VarTree::Iterator it2;
- for( it2 = m_rTree.begin(); it2 != m_rTree.end();
- it2 = m_rTree.getNextVisibleItem( it2 ) )
+ if( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
+ && xPos < it->depth() * itemImageWidth() )
{
- it2->m_selected = false;
+ // Fold/unfold the item
+ it->m_expanded = !it->m_expanded;
+ bChangedPosition = true;
}
- // Select the new item
- 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;
+ }
}
}
}
}
m_rTree.getPositionVar().set( percentage );
}
+
+ /* We changed the nodes, let's fix teh position var */
+ if( bChangedPosition )
+ {
+ VarTree::Iterator it;
+ int i = 0;
+ int iFirst = 0;
+ for( it = m_rTree.begin(); it != m_rTree.end();
+ it = m_rTree.getNextVisibleItem( it ) )
+ {
+ i++;
+ if( it == m_firstPos )
+ {
+ iFirst = i;
+ break;
+ }
+ }
+ iFirst += maxItems();
+ if( iFirst >= m_rTree.visibleItems() ) iFirst = m_rTree.visibleItems();
+ float f_new = (float)iFirst / (float)m_rTree.visibleItems();
+ m_dontMove = true;
+ m_rTree.getPositionVar().set( 1.0 - f_new );
+ m_dontMove = false;
+ }
}
bool CtrlTree::mouseOver( int x, int y ) const
// Find the item to focus
int focusItemIndex = 0;
VarTree::Iterator it;
+
+ m_rTree.ensureExpanded( item );
+
for( it = m_rTree.begin(); it != m_rTree.end();
it = m_rTree.getNextVisibleItem( it ) )
{
- if( it->m_playing ) break;
+ if( it->m_id == item->m_id ) break;
focusItemIndex++;
}
- return ensureVisible( focusItemIndex );
+ return ensureVisible( focusItemIndex );
}
bool CtrlTree::ensureVisible( int focusItemIndex )
&& ( focusItemIndex < firstPosIndex
|| focusItemIndex > firstPosIndex + maxItems() ) )
{
- // Scroll to have the playing stream visible
+ // Scroll to have the wanted stream visible
VarPercent &rVarPos = m_rTree.getPositionVar();
rVarPos.set( 1.0 - (double)focusItemIndex /
(double)m_rTree.visibleItems() );
// Find the current playing stream
int playIndex = 0;
VarTree::Iterator it;
+
+ for( it = m_rTree.begin(); it != m_rTree.end();
+ it = m_rTree.getNextItem( it ) )
+ {
+ if( it->m_playing )
+ {
+ m_rTree.ensureExpanded( it );
+ break;
+ }
+ }
for( it = m_rTree.begin(); it != m_rTree.end();
it = m_rTree.getNextVisibleItem( it ) )
{
- if( it->m_playing ) break;
+ if( it->m_playing )
+ break;
playIndex++;
}
if( it == m_rTree.end() ) return;
+
ensureVisible( playIndex );
}
void CtrlTree::makeImage()
{
+ stats_TimerStart( getIntf(), "[Skins] Playlist image",
+ STATS_TIMER_SKINS_PLAYTREE_IMAGE );
if( m_pImage )
{
delete m_pImage;
const Position *pPos = getPosition();
if( !pPos )
{
+ stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
return;
}
int width = pPos->getWidth();
m_pImage->fillRect( 0, yPos, width, rectHeight,
m_selColor );
}
- it = m_rTree.getNextVisibleItem( it );
+ do
+ {
+ it = m_rTree.getNextVisibleItem( it );
+ } while( it->m_deleted );
}
}
}
{
uint32_t color = ( it->m_selected ? m_selColor : bgColor );
m_pImage->fillRect( 0, yPos, width, rectHeight, color );
- it = m_rTree.getNextVisibleItem( it );
+ do
+ {
+ it = m_rTree.getNextVisibleItem( it );
+ } while( it->m_deleted );
}
else
{
GenericBitmap *pText = m_rFont.drawString( *pStr, color, width - bitmapWidth * depth );
if( !pText )
{
+ stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
return;
}
if( it->size() )
yPos += (pText->getHeight() - ySrc );
delete pText;
}
+ do {
it = m_rTree.getNextVisibleItem( it );
+ } while( it->m_deleted );
}
- /* TODO: Reposition percentage var to accomodate if it's not suitable anymore
- * (if we expanded a node)
- */
+ stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
}
VarTree::Iterator CtrlTree::findItemAtPos( int pos )