void CtrlText::handleEvent( EvtGeneric &rEvent ) { // Save the event to use it in callbacks m_pEvt = &rEvent; m_fsm.handleTransition( rEvent.getAsString() ); }
void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) { if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); // Get the position of the control const Position *pPos = getPosition(); // Get the value corresponding to the position of the mouse EvtMouse &rEvtMouse = (EvtMouse&)rEvent; int x = rEvtMouse.getXPos(); int y = rEvtMouse.getYPos(); m_rVariable.set( m_rCurve.getNearestPercent( (int)((x - pPos->getLeft()) / factorX), (int)((y - pPos->getTop()) / factorY) ) ); // Forward the clic to the cursor EvtMouse evt( getIntf(), x, y, EvtMouse::kLeft, EvtMouse::kDown ); TopWindow *pWin = getWindow(); if( pWin && m_pCursor ) { EvtEnter evtEnter( getIntf() ); // XXX It was not supposed to be implemented like that !! pWin->forwardEvent( evtEnter, *m_pCursor ); pWin->forwardEvent( evt, *m_pCursor ); } } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { int direction = ((EvtScroll&)rEvent).getDirection(); float percentage = m_rVariable.get(); if( direction == EvtScroll::kUp ) { percentage += SCROLL_STEP; } else { percentage -= SCROLL_STEP; } m_rVariable.set( percentage ); } }
void CtrlMove::handleEvent( EvtGeneric &rEvent ) { m_pEvt = &rEvent; m_fsm.handleTransition( rEvent.getAsString() ); // Transmit the event to the decorated control // XXX: Is it really a good idea? m_rCtrl.handleEvent( rEvent ); }
void CtrlImage::handleEvent( EvtGeneric &rEvent ) { // No FSM for this simple transition if( rEvent.getAsString() == "mouse:right:up:none" ) { CmdDlgShowPopupMenu cmd( getIntf() ); cmd.execute(); } else if( rEvent.getAsString() == "mouse:left:up:none" ) { CmdDlgHidePopupMenu cmd( getIntf() ); cmd.execute(); } else if( rEvent.getAsString() == "mouse:left:dblclick:none" ) { m_rCommand.execute(); } }
void CtrlCheckbox::handleEvent( EvtGeneric &rEvent ) { m_fsm.handleTransition( rEvent.getAsString() ); }
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_flat ? m_rTree.firstLeaf() : m_rTree.begin(); for( it = (m_flat ? m_rTree.firstLeaf() : m_rTree.begin()); it != m_rTree.end(); it = (m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it )) ) { if( &*it == m_pLastSelected ) break; if( !it->isSelected() ) it_sel = it; } /* Delete selected stuff */ m_rTree.delSelected(); /* Verify if there is still sthg selected (e.g read-only items) */ m_pLastSelected = NULL; for( it = (m_flat ? m_rTree.firstLeaf() : m_rTree.begin()); it != m_rTree.end(); it = (m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it )) ) { if( it->isSelected() ) m_pLastSelected = &*it; } /* if everything was deleted, use it_sel as last selection */ if( !m_pLastSelected ) { it_sel->setSelected( true ); m_pLastSelected = &*it_sel; } // Redraw the control makeImage(); notifyLayout(); } else if( key == KEY_PAGEDOWN ) { it = m_firstPos; int i = (int)(maxItems()*1.5); while( i >= 0 ) { VarTree::Iterator it_old = it; it = m_flat ? m_rTree.getNextLeaf( 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(); } } else if (key == KEY_PAGEUP ) { it = m_firstPos; int i = maxItems(); while( i >= maxItems()/2 ) { it = m_flat ? m_rTree.getPrevLeaf( it ) : m_rTree.getPrevVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == ( m_flat ? m_rTree.firstLeaf() : m_rTree.begin() ) ) { break; } i--; } ensureVisible( it ); makeImage(); notifyLayout(); } else if ( key == KEY_UP || key == KEY_DOWN || key == KEY_LEFT || key == KEY_RIGHT || key == KEY_ENTER || key == ' ' ) { for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); if( key == KEY_UP ) { // Scroll up one item if( ( it->parent() && it != it->parent()->begin() ) || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); it->setSelected( nextWasSelected ); if( nextWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( ( it->parent() && next != it->parent()->end() ) || &*it != m_pLastSelected ) { it->setSelected( previousWasSelected ); } if( previousWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } // Fix last tree item selection if( ( m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end() && &*it == m_pLastSelected ) { it->setSelected( true ); } } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) if( &*it == m_pLastSelected ) { if( it->isExpanded() ) { if( it->size() ) { it->setSelected( false ); it->begin()->setSelected( true ); m_pLastSelected = &*(it->begin()); } else { m_rTree.action( &*it ); } } else { it->setExpanded( true ); bChangedPosition = true; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { if( it->isExpanded() && it->size() ) { it->setExpanded( false ); bChangedPosition = true; } else { if( it->parent() && it->parent() != &m_rTree) { it->setSelected( false ); m_pLastSelected = it->parent(); m_pLastSelected->setSelected( true ); } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { m_rTree.action( &*it ); } } } if( needShow ) ensureVisible( toShow ); // Redraw the control makeImage(); notifyLayout(); } else { // other keys to be forwarded to vlc core EvtKey& rEvtKey = (EvtKey&)rEvent; var_SetInteger( getIntf()->p_libvlc, "key-pressed", rEvtKey.getModKey() ); } } else if( rEvent.getAsString().find( "mouse:left" ) != string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); int xPos = rEvtMouse.getXPos() - pos->getLeft(); VarTree::Iterator it; if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->setSelected( it->isSelected() || select ); select = nextSelect; } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != string::npos ) { // Invert the selection of the item it = findItemAtPos( yPos ); if( it != m_rTree.end() ) { it->toggleSelected(); m_pLastSelected = &*it; } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->setSelected( select ); select = nextSelect; } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { if( ( it->size() && xPos > (it->depth() - 1) * itemImageWidth() && xPos < it->depth() * itemImageWidth() ) && !m_flat ) { // Fold/unfold the item it->toggleExpanded(); bChangedPosition = true; } else { // Unselect any previously selected item VarTree::Iterator it2; for( it2 = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it2 != m_rTree.end(); it2 = m_flat ? m_rTree.getNextLeaf( it2 ) : m_rTree.getNextVisibleItem( it2 ) ) { it2->setSelected( false ); } // Select the new item if( it != m_rTree.end() ) { it->setSelected( true ); m_pLastSelected = &*it; } } } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { // Execute the action associated to this item m_rTree.action( &*it ); } // Redraw the control makeImage(); notifyLayout(); } } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { // XXX ctrl_slider.cpp has two more (but slightly different) // XXX implementations of `scroll'. Figure out where it belongs. int direction = static_cast<EvtScroll&>(rEvent).getDirection(); double percentage = m_rTree.getPositionVar().get(); double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ); if( direction == EvtScroll::kUp ) { percentage += step; } else { percentage -= step; } m_rTree.getPositionVar().set( percentage ); } /* We changed the nodes, let's fix the position var */ if( bChangedPosition ) { VarTree::Iterator it; int iFirst = 0; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { if( it == m_firstPos ) break; iFirst++; } int indexMax = ( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ) - 1; float f_new = (float)iFirst / (float)indexMax; m_dontMove = true; m_rTree.getPositionVar().set( 1.0 - f_new ); m_dontMove = false; } }
void CtrlList::handleEvent( EvtGeneric &rEvent ) { if( rEvent.getAsString().find( "key:down" ) != std::string::npos ) { int key = ((EvtKey&)rEvent).getKey(); VarList::Iterator it = m_rList.begin(); bool previousWasSelected = false; while( it != m_rList.end() ) { VarList::Iterator next = it; ++next; if( key == KEY_UP ) { // Scroll up one item if( it != m_rList.begin() || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); (*it).m_selected = nextWasSelected; if( nextWasSelected ) { m_pLastSelected = &*it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( next != m_rList.end() || &*it != m_pLastSelected ) { (*it).m_selected = previousWasSelected; } if( previousWasSelected ) { m_pLastSelected = &*it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } } it = next; } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left" ) != std::string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int yPos = m_lastPos + ( rEvtMouse.getYPos() - pos->getTop() ) / (m_rFont.getSize() + LINE_INTERVAL); VarList::Iterator it; int index = 0; if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != std::string::npos ) { // Flag to know if the current item must be selected bool select = false; for( it = m_rList.begin(); it != m_rList.end(); ++it ) { bool nextSelect = select; if( index == yPos || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } (*it).m_selected = (*it).m_selected || select; select = nextSelect; index++; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = ! (*it).m_selected; m_pLastSelected = &*it; break; } index++; } } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != std::string::npos ) { // Flag to know if the current item must be selected bool select = false; for( it = m_rList.begin(); it != m_rList.end(); ++it ) { bool nextSelect = select; if( index == yPos || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } (*it).m_selected = select; select = nextSelect; index++; } } else if( rEvent.getAsString().find( "mouse:left:down" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = true; m_pLastSelected = &*it; } else { (*it).m_selected = false; } index++; } } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = true; m_pLastSelected = &*it; // Execute the action associated to this item m_rList.action( &*it ); } else { (*it).m_selected = false; } index++; } } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "scroll" ) != std::string::npos ) { int direction = ((EvtScroll&)rEvent).getDirection(); double percentage = m_rList.getPositionVar().get(); double step = 2.0 / (double)m_rList.size(); if( direction == EvtScroll::kUp ) { percentage += step; } else { percentage -= step; } m_rList.getPositionVar().set( percentage ); } }
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_flat ? m_rTree.firstLeaf() : m_rTree.begin(); for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( 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_flat ? m_rTree.getNextLeaf( 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_flat ? m_rTree.getPrevLeaf( it ) : m_rTree.getPrevVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == ( m_flat ? m_rTree.firstLeaf() : m_rTree.begin() ) ) { break; } i--; } ensureVisible( it ); makeImage(); notifyLayout(); return; } for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); if( key == KEY_UP ) { // Scroll up one item if( ( it->parent() && it != it->parent()->begin() ) || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); it->m_selected = nextWasSelected; if( nextWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( ( it->parent() && next != it->parent()->end() ) || &*it != m_pLastSelected ) { (*it).m_selected = previousWasSelected; } if( previousWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } // Fix last tree item selection if( ( m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end() && &*it == m_pLastSelected ) { (*it).m_selected = true; } } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) if( &*it == m_pLastSelected ) { if( it->m_expanded ) { if( it->size() ) { it->m_selected = false; it->begin()->m_selected = true; m_pLastSelected = &*(it->begin()); } else { m_rTree.action( &*it ); } } else { it->m_expanded = true; bChangedPosition = true; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { if( it->m_expanded && it->size() ) { it->m_expanded = false; bChangedPosition = true; } else { if( it->parent() && it->parent() != &m_rTree) { it->m_selected = false; m_pLastSelected = it->parent(); m_pLastSelected->m_selected = true; } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { m_rTree.action( &*it ); } } } if( needShow ) ensureVisible( toShow ); // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left" ) != string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); int xPos = rEvtMouse.getXPos() - pos->getLeft(); VarTree::Iterator it; if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->m_selected = (*it).m_selected || select; select = nextSelect; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != string::npos ) { // Invert the selection of the item it = findItemAtPos( yPos ); if( it != m_rTree.end() ) { it->m_selected = !it->m_selected; m_pLastSelected = &*it; } } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->m_selected = select; select = nextSelect; } } else if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { if( ( it->size() && xPos > (it->depth() - 1) * itemImageWidth() && xPos < it->depth() * itemImageWidth() ) && !m_flat ) { // Fold/unfold the item it->m_expanded = !it->m_expanded; bChangedPosition = true; } else { // Unselect any previously selected item VarTree::Iterator it2; for( it2 = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it2 != m_rTree.end(); it2 = m_flat ? m_rTree.getNextLeaf( 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; } } } } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { // Execute the action associated to this item m_rTree.action( &*it ); } } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { int direction = ((EvtScroll&)rEvent).getDirection(); double percentage = m_rTree.getPositionVar().get(); double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ); if( direction == EvtScroll::kUp ) { percentage += step; } else { percentage -= step; } 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_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { i++; if( it == m_firstPos ) { iFirst = i; break; } } iFirst += maxItems(); if( iFirst >= m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ) iFirst = m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems(); float f_new = (float)iFirst / (float)( m_flat ? m_rTree.countLeafs() :m_rTree.visibleItems() ); m_dontMove = true; m_rTree.getPositionVar().set( 1.0 - f_new ); m_dontMove = false; } }
void CtrlTree::handleEvent( EvtGeneric &rEvent ) { bool needShow = false; bool needRefresh = false; Iterator toShow = m_firstPos; if( rEvent.getAsString().find( "key:down" ) != string::npos ) { int key = ((EvtKey&)rEvent).getKey(); /* Delete the selection */ if( key == KEY_DELETE ) { /* Delete selected stuff */ m_rTree.delSelected(); } else if( key == KEY_PAGEDOWN ) { int numSteps = (int)m_capacity / 2; VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.increment( -numSteps ); } else if( key == KEY_PAGEUP ) { int numSteps = (int)m_capacity / 2; VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.increment( numSteps ); } else if( key == KEY_UP ) { // Scroll up one item m_rTree.unselectTree(); if( m_lastClicked != m_rTree.end() ) { if( --m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } } if( m_lastClicked == m_rTree.end() ) { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else if( key == KEY_DOWN ) { // Scroll down one item m_rTree.unselectTree(); if( m_lastClicked != m_rTree.end() ) { Iterator it_old = m_lastClicked; if( ++m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { it_old->setSelected( true ); m_lastClicked = it_old; } } else { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) Iterator& it = m_lastClicked; if( it != m_rTree.end() ) { if( !m_flat && !it->isExpanded() && it->size() ) { it->setExpanded( true ); needRefresh = true; } else { m_rTree.unselectTree(); Iterator it_old = m_lastClicked; if( ++m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { it_old->setSelected( true ); m_lastClicked = it_old; } needRefresh = true; needShow = true; toShow = m_lastClicked; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) Iterator& it = m_lastClicked; if( it != m_rTree.end() ) { if( m_flat ) { m_rTree.unselectTree(); if( --m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else { if( it->isExpanded() ) { it->setExpanded( false ); needRefresh = true; } else { Iterator it_parent = it.getParent(); if( it_parent != m_rTree.end() ) { it->setSelected( false ); m_lastClicked = it_parent; m_lastClicked->setSelected( true ); needRefresh = true; needShow = true; toShow = m_lastClicked; } } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( m_lastClicked != m_rTree.end() ) { m_rTree.action( &*m_lastClicked ); } } else { // other keys to be forwarded to vlc core EvtKey& rEvtKey = (EvtKey&)rEvent; var_SetInteger( getIntf()->p_libvlc, "key-pressed", rEvtKey.getModKey() ); } } else if( rEvent.getAsString().find( "mouse:left" ) != string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int xPos = rEvtMouse.getXPos() - pos->getLeft(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); Iterator itClicked = findItemAtPos( yPos ); if( itClicked != m_rTree.end() ) { if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != string::npos ) { // Flag to know if the current item must be selected bool select = false; for( Iterator it = m_firstPos; it != m_rTree.end(); ++it ) { bool nextSelect = select; if( it == itClicked || it == m_lastClicked ) { if( select ) { nextSelect = false; } else { select = true; if( itClicked != m_lastClicked ) nextSelect = true; } } it->setSelected( it->isSelected() || select ); select = nextSelect; needRefresh = true; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != string::npos ) { // Invert the selection of the item itClicked->toggleSelected(); m_lastClicked = itClicked; needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != string::npos ) { bool select = false; for( Iterator it = m_firstPos; it != m_rTree.end(); ++it ) { bool nextSelect = select; if( it == itClicked || it == m_lastClicked ) { if( select ) { nextSelect = false; } else { select = true; if( itClicked != m_lastClicked ) nextSelect = true; } } it->setSelected( select ); select = nextSelect; } needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { if( !m_flat && itClicked->size() && xPos > (itClicked->depth() - 1) * itemImageWidth() && xPos < itClicked->depth() * itemImageWidth() ) { // Fold/unfold the item itClicked->toggleExpanded(); } else { // Unselect any previously selected item m_rTree.unselectTree(); // Select the new item itClicked->setSelected( true ); m_lastClicked = itClicked; } needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != string::npos ) { // Execute the action associated to this item m_rTree.action( &*itClicked ); } } } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { int direction = static_cast<EvtScroll&>(rEvent).getDirection(); if( direction == EvtScroll::kUp ) m_rTree.getPositionVar().increment( +1 ); else m_rTree.getPositionVar().increment( -1 ); } else if( rEvent.getAsString().find( "drag:over" ) != string::npos ) { EvtDragOver& evt = static_cast<EvtDragOver&>(rEvent); const Position *pos = getPosition(); int yPos = ( evt.getYPos() - pos->getTop() ) / itemHeight(); Iterator it = findItemAtPos( yPos ); if( it != m_itOver ) { m_itOver = it; needRefresh = true; } } else if( rEvent.getAsString().find( "drag:drop" ) != string::npos ) { EvtDragDrop& evt = static_cast<EvtDragDrop&>(rEvent); Playtree& rPlaytree = static_cast<Playtree&>(m_rTree); VarTree& item = ( m_itOver != m_rTree.end() ) ? *m_itOver : m_rTree; rPlaytree.insertItems( item, evt.getFiles(), false ); m_itOver = m_rTree.end(); needRefresh = true; } else if( rEvent.getAsString().find( "drag:leave" ) != string::npos ) { m_itOver = m_rTree.end(); needRefresh = true; } if( needShow ) { if( toShow == m_rTree.end() || !ensureVisible( toShow ) ) needRefresh = true; } if( needRefresh ) { setSliderFromFirst(); makeImage(); notifyLayout(); } }