Commit 3785da0d authored by Antoine Cellerier's avatar Antoine Cellerier

some more mouse control on playtree display/selection

parent 698c1a3d
...@@ -100,6 +100,24 @@ int CtrlTree::itemHeight() ...@@ -100,6 +100,24 @@ int CtrlTree::itemHeight()
return 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() int CtrlTree::maxItems()
{ {
const Position *pPos = getPosition(); const Position *pPos = getPosition();
...@@ -291,11 +309,84 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -291,11 +309,84 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
EvtMouse &rEvtMouse = (EvtMouse&)rEvent; EvtMouse &rEvtMouse = (EvtMouse&)rEvent;
const Position *pos = getPosition(); const Position *pos = getPosition();
int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight();
int xPos = rEvtMouse.getXPos() - pos->getLeft();
VarTree::Iterator it; VarTree::Iterator it;
int index = 0; int index = 0;
// TODO : add all other mouse controls if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) !=
/**/ if( rEvent.getAsString().find( "mouse:left:down" ) != 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 ) string::npos )
{ {
for( it = m_lastPos; it != m_rTree.end(); ) for( it = m_lastPos; it != m_rTree.end(); )
...@@ -321,10 +412,17 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -321,10 +412,17 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
{ {
if( index == yPos ) if( index == yPos )
{ {
it->m_selected = true; if( it->size() && xPos < it->depth() * itemImageWidth() )
m_pLastSelected = &*it; {
// Execute the action associated to this item it->m_expanded = !it->m_expanded;
m_rTree.action( &*it ); }
else
{
it->m_selected = true;
m_pLastSelected = &*it;
// Execute the action associated to this item
m_rTree.action( &*it );
}
} }
else else
{ {
...@@ -450,20 +548,7 @@ void CtrlTree::makeImage() ...@@ -450,20 +548,7 @@ void CtrlTree::makeImage()
} }
// fprintf( stderr, "done\n"); // fprintf( stderr, "done\n");
int bitmapWidth = 5; int bitmapWidth = itemImageWidth();
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;
// FIXME : Draw the items // FIXME : Draw the items
int yPos = 0; int yPos = 0;
......
...@@ -116,6 +116,9 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>, ...@@ -116,6 +116,9 @@ class CtrlTree: public CtrlGeneric, public Observer<VarTree>,
/// Compute the item's height (depends on fonts and images used) /// Compute the item's height (depends on fonts and images used)
int itemHeight(); int itemHeight();
/// Compute the width of an item's bitmap
int itemImageWidth();
/// Check if the tree must be scrolled /// Check if the tree must be scrolled
void autoScroll(); void autoScroll();
......
...@@ -63,6 +63,9 @@ void Playtree::delSelected() ...@@ -63,6 +63,9 @@ void Playtree::delSelected()
void Playtree::action( VarTree *pItem ) 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 ); vlc_mutex_lock( &m_pPlaylist->object_lock );
VarTree::Iterator it; VarTree::Iterator it;
if( pItem->size() ) if( pItem->size() )
......
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