void TopWindow::processEvent( EvtMotion &rEvtMotion ) { // New control hit by the mouse CtrlGeneric *pNewHitControl = findHitControl( rEvtMotion.getXPos() - getLeft(), rEvtMotion.getYPos() - getTop() ); setLastHit( pNewHitControl ); /// Update the help text VarManager *pVarManager = VarManager::instance( getIntf() ); if( pNewHitControl ) { pVarManager->getHelpText().set( pNewHitControl->getHelpText() ); } // Send a motion event to the hit control, or to the control // that captured the mouse, if any CtrlGeneric *pActiveControl = pNewHitControl; if( m_pCapturingControl ) { pActiveControl = m_pCapturingControl; } if( pActiveControl ) { // Compute the coordinates relative to the window int xPos = rEvtMotion.getXPos() - getLeft(); int yPos = rEvtMotion.getYPos() - getTop(); // Send a motion event EvtMotion evt( getIntf(), xPos, yPos ); pActiveControl->handleEvent( evt ); } }
void VarText::set( const UString &rText ) { // Avoid an infinite loop if( rText == m_text ) { return; } m_text = rText; if( m_substVars ) { // Stop observing other variables delObservers(); VlcProc *pVlcProc = VlcProc::instance( getIntf() ); VarManager *pVarManager = VarManager::instance( getIntf() ); // Observe needed variables if( m_text.find( "$H" ) != UString::npos ) { pVarManager->getHelpText().addObserver( this ); } if( m_text.find( "$T" ) != UString::npos || m_text.find( "$t" ) != UString::npos || m_text.find( "$L" ) != UString::npos || m_text.find( "$l" ) != UString::npos || m_text.find( "$D" ) != UString::npos || m_text.find( "$d" ) != UString::npos ) { pVlcProc->getTimeVar().addObserver( this ); } if( m_text.find( "$V" ) != UString::npos ) { pVlcProc->getVolumeVar().addObserver( this ); } if( m_text.find( "$N" ) != UString::npos ) { pVlcProc->getStreamNameVar().addObserver( this ); } if( m_text.find( "$F" ) != UString::npos ) { pVlcProc->getStreamURIVar().addObserver( this ); } if( m_text.find( "$B" ) != UString::npos ) { pVlcProc->getStreamBitRateVar().addObserver( this ); } if( m_text.find( "$S" ) != UString::npos ) { pVlcProc->getStreamSampleRateVar().addObserver( this ); } if( m_text.find( "$R" ) != UString::npos ) { pVlcProc->getSpeedVar().addObserver( this ); } } notify(); }
void VarText::delObservers() { // Stop observing other variables VlcProc *pVlcProc = getIntf()->p_sys->p_vlcProc; VarManager *pVarManager = getIntf()->p_sys->p_varManager; if( pVlcProc ) { pVlcProc->getTimeVar().delObserver( this ); pVlcProc->getVolumeVar().delObserver( this ); pVlcProc->getSpeedVar().delObserver( this ); pVlcProc->getStreamNameVar().delObserver( this ); pVlcProc->getStreamURIVar().delObserver( this ); pVlcProc->getStreamBitRateVar().delObserver( this ); pVlcProc->getStreamSampleRateVar().delObserver( this ); } if( pVarManager ) pVarManager->getHelpText().delObserver( this ); }
const UString VarText::get() const { if( !m_substVars ) { // Do not substitute "$X" variables return m_text; } uint32_t pos; VlcProc *pVlcProc = VlcProc::instance( getIntf() ); // Fill a temporary UString object, and replace the escape characters // ($H for help, $T for current time, $L for time left, $D for duration, // $V for volume) UString temp( m_text ); // $H is processed first, in case the help string contains other variables // to replace. And it is replaced only once, in case one of these other // variables is $H... if( (pos = temp.find( "$H" )) != UString::npos ) { VarManager *pVarManager = VarManager::instance( getIntf() ); temp.replace( pos, 2, pVarManager->getHelpText().get() ); } while( (pos = temp.find( "$T" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringCurrTime().c_str() ); } while( (pos = temp.find( "$t" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringCurrTime(true).c_str() ); } while( (pos = temp.find( "$L" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringTimeLeft().c_str() ); } while( (pos = temp.find( "$l" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringTimeLeft(true).c_str() ); } while( (pos = temp.find( "$D" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringDuration().c_str() ); } while( (pos = temp.find( "$d" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringDuration(true).c_str() ); } while( (pos = temp.find( "$V" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getVolumeVar().getAsStringPercent().c_str() ); } while( (pos = temp.find( "$N" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamNameVar().get() ); } while( (pos = temp.find( "$F" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamURIVar().get() ); } while( (pos = temp.find( "$B" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamBitRateVar().get() ); } while( (pos = temp.find( "$S" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamSampleRateVar().get() ); } while( (pos = temp.find( "$R" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getSpeedVar().get() ); } return temp; }