]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/generic_window.cpp
Qt: cache "no-art" pixmap as well
[vlc] / modules / gui / skins2 / src / generic_window.cpp
index 4710ae2d0d2345bc19dbad48ae8b553404942cba..609f1e337013a44a6e1911dfacb801c943244455 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "generic_window.hpp"
 #include "os_window.hpp"
 #include "os_factory.hpp"
+#include "var_manager.hpp"
 #include "../events/evt_refresh.hpp"
 
 
 GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
                               bool dragDrop, bool playOnDrop,
-                              GenericWindow *pParent ):
+                              GenericWindow *pParent, WindowType_t type ):
     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() );
 
     // Get the parent OSWindow, if any
@@ -46,21 +47,22 @@ GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
 
     // Create an OSWindow to handle OS specific processing
     m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop,
-                                              pOSParent );
+                                              pOSParent, type );
+
+    // 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
-    m_varVisible.addObserver( this );
+    m_pVarVisible->addObserver( this );
 }
 
 
 GenericWindow::~GenericWindow()
 {
-    m_varVisible.delObserver( this );
+    m_pVarVisible->delObserver( this );
 
-    if( m_pOsWindow )
-    {
-        delete m_pOsWindow;
-    }
+    delete m_pOsWindow;
 }
 
 
@@ -74,13 +76,13 @@ void GenericWindow::processEvent( EvtRefresh &rEvtRefresh )
 
 void GenericWindow::show() const
 {
-    m_varVisible.set( true );
+    m_pVarVisible->set( true );
 }
 
 
 void GenericWindow::hide() const
 {
-    m_varVisible.set( false );
+    m_pVarVisible->set( false );
 }
 
 
@@ -96,6 +98,10 @@ void GenericWindow::move( int left, int top )
 
 void GenericWindow::resize( int width, int height )
 {
+    // don't try when value is 0 (may crash)
+    if( !width || ! height )
+        return;
+
     // Update the window size
     m_width = width;
     m_height = height;
@@ -122,15 +128,18 @@ void GenericWindow::toggleOnTop( bool onTop ) const
 }
 
 
-void GenericWindow::onUpdate( Subject<VarBool> &rVariable )
+void GenericWindow::onUpdate( Subject<VarBool> &rVariable, void*arg )
 {
-    if( m_varVisible.get() )
-    {
-        innerShow();
-    }
-    else
+    if (&rVariable == m_pVarVisible )
     {
-        innerHide();
+        if( m_pVarVisible->get() )
+        {
+            innerShow();
+        }
+        else
+        {
+            innerHide();
+        }
     }
 }
 
@@ -139,7 +148,7 @@ void GenericWindow::innerShow()
 {
     if( m_pOsWindow )
     {
-        m_pOsWindow->show( m_left, m_top );
+        m_pOsWindow->show();
     }
 }
 
@@ -152,3 +161,21 @@ void GenericWindow::innerHide()
     }
 }
 
+
+void* GenericWindow::getOSHandle() const
+{
+    return m_pOsWindow->getOSHandle();
+}
+
+
+void GenericWindow::setParent( GenericWindow* pParent, int x, int y, int w, int h )
+{
+    // Update the window size and position
+    m_left = x;
+    m_top = y;
+    m_width  = ( w > 0 ) ? w : m_width;
+    m_height = ( h > 0 ) ? h : m_height;
+
+    void* handle = pParent ? pParent->getOSHandle() : NULL;
+    m_pOsWindow->reparent( handle, m_left, m_top, m_width, m_height );
+}