Commit 1c41fce0 authored by Erwan Tulou's avatar Erwan Tulou

skins2: add accessors to VarTree

parent 3b3251c4
...@@ -170,14 +170,14 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, ...@@ -170,14 +170,14 @@ void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree,
else if( arg->i_type == 3 ) // item-del else if( arg->i_type == 3 ) // item-del
{ {
/* Make sure firstPos is valid */ /* Make sure firstPos is valid */
while( m_firstPos->m_deleted && while( m_firstPos->isDeleted() &&
m_firstPos != (m_flat ? m_rTree.firstLeaf() m_firstPos != (m_flat ? m_rTree.firstLeaf()
: m_rTree.begin()) ) : m_rTree.begin()) )
{ {
m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos ) m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos )
: m_rTree.getPrevVisibleItem( m_firstPos ); : m_rTree.getPrevVisibleItem( m_firstPos );
} }
if( m_firstPos->m_deleted ) if( m_firstPos->isDeleted() )
m_firstPos = m_rTree.begin(); m_firstPos = m_rTree.begin();
if( arg->b_visible == true ) if( arg->b_visible == true )
...@@ -277,7 +277,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -277,7 +277,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
: m_rTree.getNextVisibleItem( it )) ) : m_rTree.getNextVisibleItem( it )) )
{ {
if( &*it == m_pLastSelected ) break; if( &*it == m_pLastSelected ) break;
if( !it->m_selected ) it_sel = it; if( !it->isSelected() ) it_sel = it;
} }
/* Delete selected stuff */ /* Delete selected stuff */
...@@ -290,14 +290,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -290,14 +290,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
it = (m_flat ? m_rTree.getNextLeaf( it ) it = (m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it )) ) : m_rTree.getNextVisibleItem( it )) )
{ {
if( it->m_selected ) if( it->isSelected() )
m_pLastSelected = &*it; m_pLastSelected = &*it;
} }
/* if everything was deleted, use it_sel as last selection */ /* if everything was deleted, use it_sel as last selection */
if( !m_pLastSelected ) if( !m_pLastSelected )
{ {
it_sel->m_selected = true; it_sel->setSelected( true );
m_pLastSelected = &*it_sel; m_pLastSelected = &*it_sel;
} }
...@@ -372,7 +372,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -372,7 +372,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
|| &*it != m_pLastSelected ) || &*it != m_pLastSelected )
{ {
bool nextWasSelected = ( &*next == m_pLastSelected ); bool nextWasSelected = ( &*next == m_pLastSelected );
it->m_selected = nextWasSelected; it->setSelected( nextWasSelected );
if( nextWasSelected ) if( nextWasSelected )
{ {
m_pLastSelected = &*it; m_pLastSelected = &*it;
...@@ -387,7 +387,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -387,7 +387,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
&& next != it->parent()->end() ) && next != it->parent()->end() )
|| &*it != m_pLastSelected ) || &*it != m_pLastSelected )
{ {
(*it).m_selected = previousWasSelected; it->setSelected( previousWasSelected );
} }
if( previousWasSelected ) if( previousWasSelected )
{ {
...@@ -405,7 +405,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -405,7 +405,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
: m_rTree.getNextVisibleItem( it ) ) == m_rTree.end() : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end()
&& &*it == m_pLastSelected ) && &*it == m_pLastSelected )
{ {
(*it).m_selected = true; it->setSelected( true );
} }
} }
else if( key == KEY_RIGHT ) else if( key == KEY_RIGHT )
...@@ -413,12 +413,12 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -413,12 +413,12 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
// Go down one level (and expand node) // Go down one level (and expand node)
if( &*it == m_pLastSelected ) if( &*it == m_pLastSelected )
{ {
if( it->m_expanded ) if( it->isExpanded() )
{ {
if( it->size() ) if( it->size() )
{ {
it->m_selected = false; it->setSelected( false );
it->begin()->m_selected = true; it->begin()->setSelected( true );
m_pLastSelected = &*(it->begin()); m_pLastSelected = &*(it->begin());
} }
else else
...@@ -428,7 +428,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -428,7 +428,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
} }
else else
{ {
it->m_expanded = true; it->setExpanded( true );
bChangedPosition = true; bChangedPosition = true;
} }
} }
...@@ -438,18 +438,18 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -438,18 +438,18 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
// Go up one level (and close node) // Go up one level (and close node)
if( &*it == m_pLastSelected ) if( &*it == m_pLastSelected )
{ {
if( it->m_expanded && it->size() ) if( it->isExpanded() && it->size() )
{ {
it->m_expanded = false; it->setExpanded( false );
bChangedPosition = true; bChangedPosition = true;
} }
else else
{ {
if( it->parent() && it->parent() != &m_rTree) if( it->parent() && it->parent() != &m_rTree)
{ {
it->m_selected = false; it->setSelected( false );
m_pLastSelected = it->parent(); m_pLastSelected = it->parent();
m_pLastSelected->m_selected = true; m_pLastSelected->setSelected( true );
} }
} }
} }
...@@ -511,7 +511,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -511,7 +511,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
nextSelect = true; nextSelect = true;
} }
} }
it->m_selected = (*it).m_selected || select; it->setSelected( it->isSelected() || select );
select = nextSelect; select = nextSelect;
} }
// Redraw the control // Redraw the control
...@@ -525,7 +525,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -525,7 +525,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
it = findItemAtPos( yPos ); it = findItemAtPos( yPos );
if( it != m_rTree.end() ) if( it != m_rTree.end() )
{ {
it->m_selected = !it->m_selected; it->toggleSelected();
m_pLastSelected = &*it; m_pLastSelected = &*it;
} }
// Redraw the control // Redraw the control
...@@ -556,7 +556,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -556,7 +556,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
nextSelect = true; nextSelect = true;
} }
} }
it->m_selected = select; it->setSelected( select );
select = nextSelect; select = nextSelect;
} }
// Redraw the control // Redraw the control
...@@ -574,7 +574,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -574,7 +574,7 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
&& !m_flat ) && !m_flat )
{ {
// Fold/unfold the item // Fold/unfold the item
it->m_expanded = !it->m_expanded; it->toggleExpanded();
bChangedPosition = true; bChangedPosition = true;
} }
else else
...@@ -586,12 +586,12 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -586,12 +586,12 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
it2 = m_flat ? m_rTree.getNextLeaf( it2 ) it2 = m_flat ? m_rTree.getNextLeaf( it2 )
: m_rTree.getNextVisibleItem( it2 ) ) : m_rTree.getNextVisibleItem( it2 ) )
{ {
it2->m_selected = false; it2->setSelected( false );
} }
// Select the new item // Select the new item
if( it != m_rTree.end() ) if( it != m_rTree.end() )
{ {
it->m_selected = true; it->setSelected( true );
m_pLastSelected = &*it; m_pLastSelected = &*it;
} }
} }
...@@ -696,7 +696,7 @@ bool CtrlTree::ensureVisible( VarTree::Iterator item ) ...@@ -696,7 +696,7 @@ bool CtrlTree::ensureVisible( VarTree::Iterator item )
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ) ) : m_rTree.getNextVisibleItem( it ) )
{ {
if( it->m_id == item->m_id ) break; if( it->getId() == item->getId() ) break;
focusItemIndex++; focusItemIndex++;
} }
return ensureVisible( focusItemIndex ); return ensureVisible( focusItemIndex );
...@@ -744,7 +744,7 @@ void CtrlTree::autoScroll() ...@@ -744,7 +744,7 @@ void CtrlTree::autoScroll()
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextItem( it ) ) : m_rTree.getNextItem( it ) )
{ {
if( it->m_playing ) if( it->isPlaying() )
{ {
m_rTree.ensureExpanded( it ); m_rTree.ensureExpanded( it );
break; break;
...@@ -756,7 +756,7 @@ void CtrlTree::autoScroll() ...@@ -756,7 +756,7 @@ void CtrlTree::autoScroll()
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ) ) : m_rTree.getNextVisibleItem( it ) )
{ {
if( it->m_playing ) if( it->isPlaying() )
{ {
ensureVisible( playIndex ); ensureVisible( playIndex );
break; break;
...@@ -807,7 +807,7 @@ void CtrlTree::makeImage() ...@@ -807,7 +807,7 @@ void CtrlTree::makeImage()
{ {
if( it != m_rTree.end() ) if( it != m_rTree.end() )
{ {
if( (*it).m_selected ) if( it->isSelected() )
{ {
int rectHeight = __MIN( i_itemHeight, height - yPos ); int rectHeight = __MIN( i_itemHeight, height - yPos );
m_pImage->fillRect( 0, yPos, width, rectHeight, m_pImage->fillRect( 0, yPos, width, rectHeight,
...@@ -817,7 +817,7 @@ void CtrlTree::makeImage() ...@@ -817,7 +817,7 @@ void CtrlTree::makeImage()
{ {
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ); : m_rTree.getNextVisibleItem( it );
} while( it != m_rTree.end() && it->m_deleted ); } while( it != m_rTree.end() && it->isDeleted() );
} }
} }
} }
...@@ -834,13 +834,13 @@ void CtrlTree::makeImage() ...@@ -834,13 +834,13 @@ void CtrlTree::makeImage()
m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor ); m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
else else
{ {
uint32_t color = ( it->m_selected ? m_selColor : bgColor ); uint32_t color = ( it->isSelected() ? m_selColor : bgColor );
m_pImage->fillRect( 0, yPos, width, rectHeight, color ); m_pImage->fillRect( 0, yPos, width, rectHeight, color );
do do
{ {
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ); : m_rTree.getNextVisibleItem( it );
} while( it != m_rTree.end() && it->m_deleted ); } while( it != m_rTree.end() && it->isDeleted() );
} }
bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 ); bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
} }
...@@ -853,8 +853,8 @@ void CtrlTree::makeImage() ...@@ -853,8 +853,8 @@ void CtrlTree::makeImage()
while( it != m_rTree.end() && yPos < height ) while( it != m_rTree.end() && yPos < height )
{ {
const GenericBitmap *m_pCurBitmap; const GenericBitmap *m_pCurBitmap;
UString *pStr = (UString*)(it->m_cString.get()); UString *pStr = it->getString();
uint32_t color = ( it->m_playing ? m_playColor : m_fgColor ); uint32_t color = ( it->isPlaying() ? m_playColor : m_fgColor );
// Draw the text // Draw the text
if( pStr != NULL ) if( pStr != NULL )
...@@ -867,7 +867,7 @@ void CtrlTree::makeImage() ...@@ -867,7 +867,7 @@ void CtrlTree::makeImage()
return; return;
} }
if( it->size() ) if( it->size() )
m_pCurBitmap = it->m_expanded ? m_pOpenBitmap : m_pClosedBitmap; m_pCurBitmap = it->isExpanded() ? m_pOpenBitmap : m_pClosedBitmap;
else else
m_pCurBitmap = m_pItemBitmap; m_pCurBitmap = m_pItemBitmap;
...@@ -904,7 +904,7 @@ void CtrlTree::makeImage() ...@@ -904,7 +904,7 @@ void CtrlTree::makeImage()
{ {
it = m_flat ? m_rTree.getNextLeaf( it ) it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ); : m_rTree.getNextVisibleItem( it );
} while( it != m_rTree.end() && it->m_deleted ); } while( it != m_rTree.end() && it->isDeleted() );
} }
stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE ); stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
} }
......
...@@ -68,16 +68,24 @@ public: ...@@ -68,16 +68,24 @@ public:
/// Remove all elements from the children's list /// Remove all elements from the children's list
virtual void clear(); virtual void clear();
/// \todo Use accessors for these fields ? inline int getId() { return m_id; }
int m_id; inline void *getData() { return m_pData; }
UStringPtr m_cString; inline UString* getString() {return (UString*)m_cString.get(); }
bool m_selected; inline void setString( UStringPtr val ) { m_cString = val; }
bool m_playing;
bool m_expanded;
bool m_deleted;
void *m_pData;
inline bool isReadonly() { return m_readonly; }; inline bool isReadonly() { return m_readonly; };
inline bool isSelected() { return m_selected; };
inline bool isPlaying() { return m_playing; };
inline bool isExpanded() { return m_expanded; };
inline bool isDeleted() { return m_deleted; };
inline void setSelected( bool val ) { m_selected = val; }
inline void setPlaying( bool val ) { m_playing = val; }
inline void setExpanded( bool val ) { m_expanded = val; }
inline void setDeleted( bool val ) { m_deleted = val; }
inline void toggleSelected() { m_selected = !m_selected; }
inline void toggleExpanded() { m_expanded = !m_expanded; }
/// Get the number of children /// Get the number of children
int size() const { return m_children.size(); } int size() const { return m_children.size(); }
...@@ -196,7 +204,16 @@ private: ...@@ -196,7 +204,16 @@ private:
/// Pointer to parent node /// Pointer to parent node
VarTree *m_pParent; VarTree *m_pParent;
int m_id;
void *m_pData;
UStringPtr m_cString;
/// indicators
bool m_readonly; bool m_readonly;
bool m_selected;
bool m_playing;
bool m_expanded;
bool m_deleted;
/// Variable type /// Variable type
static const string m_type; static const string m_type;
......
...@@ -53,7 +53,7 @@ void Playtree::delSelected() ...@@ -53,7 +53,7 @@ void Playtree::delSelected()
playlist_Lock( getIntf()->p_sys->p_playlist ); playlist_Lock( getIntf()->p_sys->p_playlist );
for( it = begin(); it != end(); it = getNextItem( it ) ) for( it = begin(); it != end(); it = getNextItem( it ) )
{ {
if( it->m_selected && !it->isReadonly() ) if( it->isSelected() && !it->isReadonly() )
{ {
it->cascadeDelete(); it->cascadeDelete();
} }
...@@ -65,10 +65,10 @@ void Playtree::delSelected() ...@@ -65,10 +65,10 @@ void Playtree::delSelected()
it = begin(); it = begin();
while( it != end() ) while( it != end() )
{ {
if( it->m_deleted ) if( it->isDeleted() )
{ {
VarTree::Iterator it2; VarTree::Iterator it2;
playlist_item_t *p_item = (playlist_item_t *)(it->m_pData); playlist_item_t *p_item = (playlist_item_t *)(it->getData());
if( p_item->i_children == -1 ) if( p_item->i_children == -1 )
{ {
playlist_DeleteFromInput( getIntf()->p_sys->p_playlist, playlist_DeleteFromInput( getIntf()->p_sys->p_playlist,
...@@ -97,7 +97,7 @@ void Playtree::action( VarTree *pItem ) ...@@ -97,7 +97,7 @@ void Playtree::action( VarTree *pItem )
playlist_Lock( m_pPlaylist ); playlist_Lock( m_pPlaylist );
VarTree::Iterator it; VarTree::Iterator it;
playlist_item_t *p_item = (playlist_item_t *)pItem->m_pData; playlist_item_t *p_item = (playlist_item_t *)pItem->getData();
playlist_item_t *p_parent = p_item; playlist_item_t *p_parent = p_item;
while( p_parent ) while( p_parent )
{ {
...@@ -129,9 +129,9 @@ void Playtree::onUpdateItem( int id ) ...@@ -129,9 +129,9 @@ void Playtree::onUpdateItem( int id )
if( it != end() ) if( it != end() )
{ {
// Update the item // Update the item
playlist_item_t* pNode = (playlist_item_t*)(it->m_pData); playlist_item_t* pNode = (playlist_item_t*)(it->getData());
UString *pName = new UString( getIntf(), pNode->p_input->psz_name ); UString *pName = new UString( getIntf(), pNode->p_input->psz_name );
it->m_cString = UStringPtr( pName ); it->setString( UStringPtr( pName ) );
} }
else else
{ {
...@@ -151,7 +151,7 @@ void Playtree::onUpdateCurrent( bool b_active ) ...@@ -151,7 +151,7 @@ void Playtree::onUpdateCurrent( bool b_active )
Iterator it = findById( m_currentItem->i_id ); Iterator it = findById( m_currentItem->i_id );
if( it != end() ) if( it != end() )
it->m_playing = false; it->setPlaying( false );
m_currentItem = NULL; m_currentItem = NULL;
} }
else else
...@@ -167,7 +167,7 @@ void Playtree::onUpdateCurrent( bool b_active ) ...@@ -167,7 +167,7 @@ void Playtree::onUpdateCurrent( bool b_active )
Iterator it = findById( current->i_id ); Iterator it = findById( current->i_id );
if( it != end() ) if( it != end() )
it->m_playing = true; it->setPlaying( true );
m_currentItem = current; m_currentItem = current;
playlist_Unlock( m_pPlaylist ); playlist_Unlock( m_pPlaylist );
...@@ -189,12 +189,12 @@ void Playtree::onDelete( int i_id ) ...@@ -189,12 +189,12 @@ void Playtree::onDelete( int i_id )
{ {
VarTree* parent = item->parent(); VarTree* parent = item->parent();
item->m_deleted = true; item->setDeleted( true );
tree_update descr; tree_update descr;
descr.i_id = i_id; descr.i_id = i_id;
descr.i_type = 3; descr.i_type = 3;
descr.b_visible = parent ? parent->m_expanded : true; descr.b_visible = parent ? parent->isExpanded() : true;
notify( &descr ); notify( &descr );
if( parent ) if( parent )
...@@ -232,7 +232,7 @@ void Playtree::onAppend( playlist_add_t *p_add ) ...@@ -232,7 +232,7 @@ void Playtree::onAppend( playlist_add_t *p_add )
tree_update descr; tree_update descr;
descr.i_id = p_add->i_item; descr.i_id = p_add->i_item;
descr.i_parent = p_add->i_node; descr.i_parent = p_add->i_node;
descr.b_visible = node->m_expanded; descr.b_visible = node->isExpanded();
descr.i_type = 2; descr.i_type = 2;
notify( &descr ); notify( &descr );
} }
...@@ -269,7 +269,7 @@ void Playtree::buildTree() ...@@ -269,7 +269,7 @@ void Playtree::buildTree()
/* Set the root's name */ /* Set the root's name */
UString *pName = new UString( getIntf(), UString *pName = new UString( getIntf(),
m_pPlaylist->p_root_category->p_input->psz_name ); m_pPlaylist->p_root_category->p_input->psz_name );
m_cString = UStringPtr( pName ); setString( UStringPtr( pName ) );
buildNode( m_pPlaylist->p_root_category, *this ); buildNode( m_pPlaylist->p_root_category, *this );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment