Commit 41c0868c authored by Cyril Deguet's avatar Cyril Deguet

* generic_window.cpp: register window visibility variables in

 the var manager, to avoid a crash at exit when an expression
 'not window.isVisible' is used in a skin.
parent 895d129f
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "generic_window.hpp" #include "generic_window.hpp"
#include "os_window.hpp" #include "os_window.hpp"
#include "os_factory.hpp" #include "os_factory.hpp"
#include "var_manager.hpp"
#include "../events/evt_refresh.hpp" #include "../events/evt_refresh.hpp"
...@@ -32,7 +33,7 @@ GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top, ...@@ -32,7 +33,7 @@ GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
bool dragDrop, bool playOnDrop, bool dragDrop, bool playOnDrop,
GenericWindow *pParent ): GenericWindow *pParent ):
SkinObject( pIntf ), m_left( left ), m_top( top ), m_width( 0 ), SkinObject( pIntf ), m_left( left ), m_top( top ), m_width( 0 ),
m_height( 0 ), m_varVisible( pIntf ) m_height( 0 ), m_pVarVisible( NULL )
{ {
// Get the OSFactory // Get the OSFactory
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); OSFactory *pOsFactory = OSFactory::instance( getIntf() );
...@@ -48,14 +49,18 @@ GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top, ...@@ -48,14 +49,18 @@ GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop, m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop,
pOSParent ); pOSParent );
// Create the visibility variable and register it in the manager
m_pVarVisible = new VarBoolImpl( pIntf );
VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarVisible ) );
// Observe the visibility variable // Observe the visibility variable
m_varVisible.addObserver( this ); m_pVarVisible->addObserver( this );
} }
GenericWindow::~GenericWindow() GenericWindow::~GenericWindow()
{ {
m_varVisible.delObserver( this ); m_pVarVisible->delObserver( this );
if( m_pOsWindow ) if( m_pOsWindow )
{ {
...@@ -74,13 +79,13 @@ void GenericWindow::processEvent( EvtRefresh &rEvtRefresh ) ...@@ -74,13 +79,13 @@ void GenericWindow::processEvent( EvtRefresh &rEvtRefresh )
void GenericWindow::show() const void GenericWindow::show() const
{ {
m_varVisible.set( true ); m_pVarVisible->set( true );
} }
void GenericWindow::hide() const void GenericWindow::hide() const
{ {
m_varVisible.set( false ); m_pVarVisible->set( false );
} }
...@@ -124,7 +129,7 @@ void GenericWindow::toggleOnTop( bool onTop ) const ...@@ -124,7 +129,7 @@ void GenericWindow::toggleOnTop( bool onTop ) const
void GenericWindow::onUpdate( Subject<VarBool, void*> &rVariable, void*arg ) void GenericWindow::onUpdate( Subject<VarBool, void*> &rVariable, void*arg )
{ {
if( m_varVisible.get() ) if( m_pVarVisible->get() )
{ {
innerShow(); innerShow();
} }
......
...@@ -76,7 +76,7 @@ class GenericWindow: public SkinObject, public Observer<VarBool, void*> ...@@ -76,7 +76,7 @@ class GenericWindow: public SkinObject, public Observer<VarBool, void*>
int getHeight() const { return m_height; } int getHeight() const { return m_height; }
/// Give access to the visibility variable /// Give access to the visibility variable
VarBool &getVisibleVar() { return m_varVisible; } VarBool &getVisibleVar() { return *m_pVarVisible; }
/// Window type, mainly useful when overloaded (for VoutWindow) /// Window type, mainly useful when overloaded (for VoutWindow)
virtual string getType() const { return "Generic"; } virtual string getType() const { return "Generic"; }
...@@ -119,7 +119,7 @@ class GenericWindow: public SkinObject, public Observer<VarBool, void*> ...@@ -119,7 +119,7 @@ class GenericWindow: public SkinObject, public Observer<VarBool, void*>
/// OS specific implementation /// OS specific implementation
OSWindow *m_pOsWindow; OSWindow *m_pOsWindow;
/// Variable for the visibility of the window /// Variable for the visibility of the window
mutable VarBoolImpl m_varVisible; mutable VarBoolImpl *m_pVarVisible;
/// Method called when the observed variable is modified /// Method called when the observed variable is modified
virtual void onUpdate( Subject<VarBool, void*> &rVariable , void*); virtual void onUpdate( Subject<VarBool, void*> &rVariable , void*);
......
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