]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/top_window.cpp
Qt: cache "no-art" pixmap as well
[vlc] / modules / gui / skins2 / src / top_window.cpp
index 2f5472fe22d4adf8b54ed6d824b986a2129f5142..1b355ebf0fa891d6fbd7815578b3e4ea2f9f6c21 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * top_window.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $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
@@ -19,7 +19,7 @@
  *
  * 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 "top_window.hpp"
 #include "os_window.hpp"
 #include "os_factory.hpp"
 #include "theme.hpp"
-#include "dialogs.hpp"
 #include "var_manager.hpp"
 #include "../commands/cmd_on_top.hpp"
+#include "../commands/cmd_dialogs.hpp"
 #include "../controls/ctrl_generic.hpp"
+#include "../events/evt_refresh.hpp"
 #include "../events/evt_enter.hpp"
 #include "../events/evt_focus.hpp"
 #include "../events/evt_leave.hpp"
+#include "../events/evt_menu.hpp"
 #include "../events/evt_motion.hpp"
 #include "../events/evt_mouse.hpp"
 #include "../events/evt_key.hpp"
 
 TopWindow::TopWindow( intf_thread_t *pIntf, int left, int top,
                       WindowManager &rWindowManager,
-                      bool dragDrop, bool playOnDrop ):
-    GenericWindow( pIntf, left, top, dragDrop, playOnDrop,
-                   NULL),
-    m_rWindowManager( rWindowManager ), m_pActiveLayout( NULL ),
-    m_pLastHitControl( NULL ), m_pCapturingControl( NULL ),
-    m_pFocusControl( NULL ), m_currModifier( 0 )
+                      bool dragDrop, bool playOnDrop, bool visible ):
+    GenericWindow( pIntf, left, top, dragDrop, playOnDrop, NULL ),
+    m_visible( visible ), m_rWindowManager( rWindowManager ),
+    m_pActiveLayout( NULL ), m_pLastHitControl( NULL ),
+    m_pCapturingControl( NULL ), m_pFocusControl( NULL ), m_currModifier( 0 )
 {
     // Register as a moving window
     m_rWindowManager.registerWindow( *this );
+
+    // Create the "maximized" variable and register it in the manager
+    m_pVarMaximized = new VarBoolImpl( pIntf );
+    VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarMaximized ) );
 }
 
 
@@ -67,9 +72,41 @@ TopWindow::~TopWindow()
 }
 
 
+void TopWindow::processEvent( EvtRefresh &rEvtRefresh )
+{
+    // We override the behaviour defined in GenericWindow, because we don't
+    // want to draw on a video control!
+    if( m_pActiveLayout == NULL )
+    {
+        GenericWindow::processEvent( rEvtRefresh );
+    }
+    else
+    {
+        m_pActiveLayout->computeRefresh( rEvtRefresh.getXStart(),
+                                         rEvtRefresh.getYStart(),
+                                         rEvtRefresh.getWidth(),
+                                         rEvtRefresh.getHeight() );
+    }
+}
+
+
 void TopWindow::processEvent( EvtFocus &rEvtFocus )
 {
-//    fprintf(stderr, rEvtFocus.getAsString().c_str()) ;
+//    fprintf(stderr, rEvtFocus.getAsString().c_str());
+}
+
+
+void TopWindow::processEvent( EvtMenu &rEvtMenu )
+{
+    Popup *pPopup = m_rWindowManager.getActivePopup();
+    // We should never receive a menu event when there is no active popup!
+    if( pPopup == NULL )
+    {
+        msg_Warn( getIntf(), "unexpected menu event, ignoring" );
+        return;
+    }
+
+    pPopup->handleEvent( rEvtMenu );
 }
 
 
@@ -130,8 +167,8 @@ void TopWindow::processEvent( EvtMouse &rEvtMouse )
     // Change the focused control
     if( rEvtMouse.getAction() == EvtMouse::kDown )
     {
-        // Raise all the windows
-        m_rWindowManager.raiseAll( *this );
+        // Raise the window
+        m_rWindowManager.raise( *this );
 
         if( pNewHitControl && pNewHitControl->isFocusable() )
         {
@@ -181,22 +218,19 @@ void TopWindow::processEvent( EvtKey &rEvtKey )
     }
 
     // Only do the action when the key is down
-    if( rEvtKey.getAsString().find( "key:down") != string::npos )
+    if( rEvtKey.getKeyState() == EvtKey::kDown )
     {
-        //XXX not to be hardcoded !
+        //XXX not to be hardcoded!
         // Ctrl-S = Change skin
         if( (rEvtKey.getMod() & EvtInput::kModCtrl) &&
             rEvtKey.getKey() == 's' )
         {
-            Dialogs *pDialogs = Dialogs::instance( getIntf() );
-            if( pDialogs != NULL )
-            {
-                pDialogs->showChangeSkin();
-            }
+            CmdDlgChangeSkin cmd( getIntf() );
+            cmd.execute();
             return;
         }
 
-        //XXX not to be hardcoded !
+        //XXX not to be hardcoded!
         // Ctrl-T = Toggle on top
         if( (rEvtKey.getMod() & EvtInput::kModCtrl) &&
             rEvtKey.getKey() == 't' )
@@ -206,31 +240,14 @@ void TopWindow::processEvent( EvtKey &rEvtKey )
             return;
         }
 
-        vlc_value_t val;
-        // Set the key
-        val.i_int = rEvtKey.getKey();
-        // Set the modifiers
-        if( rEvtKey.getMod() & EvtInput::kModAlt )
-        {
-            val.i_int |= KEY_MODIFIER_ALT;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModCtrl )
-        {
-            val.i_int |= KEY_MODIFIER_CTRL;
-        }
-        if( rEvtKey.getMod() & EvtInput::kModShift )
-        {
-            val.i_int |= KEY_MODIFIER_SHIFT;
-        }
-
-        var_Set( getIntf()->p_vlc, "key-pressed", val );
+        var_SetInteger( getIntf()->p_libvlc, "key-pressed",
+                        rEvtKey.getModKey() );
     }
 
-    // Always store the modifier, which can be needed for scroll events
+    // Always store the modifier, which can be needed for scroll events.
     m_currModifier = rEvtKey.getMod();
 }
 
-
 void TopWindow::processEvent( EvtScroll &rEvtScroll )
 {
     // Raise the windows
@@ -255,20 +272,11 @@ void TopWindow::processEvent( EvtScroll &rEvtScroll )
     }
     else
     {
-        // Treat the scroll event as a hotkey
-        vlc_value_t val;
-        if( rEvtScroll.getDirection() == EvtScroll::kUp )
-        {
-            val.i_int = KEY_MOUSEWHEELUP;
-        }
-        else
-        {
-            val.i_int = KEY_MOUSEWHEELDOWN;
-        }
-        // Add the modifiers
-        val.i_int |= m_currModifier;
+        // Treat the scroll event as a hotkey plus current modifiers
+        int i = (rEvtScroll.getDirection() == EvtScroll::kUp ?
+                 KEY_MOUSEWHEELUP : KEY_MOUSEWHEELDOWN) | m_currModifier;
 
-        var_Set( getIntf()->p_vlc, "key-pressed", val );
+        var_SetInteger( getIntf()->p_libvlc, "key-pressed", i );
     }
 }
 
@@ -292,28 +300,66 @@ void TopWindow::refresh( int left, int top, int width, int height )
 
 void TopWindow::setActiveLayout( GenericLayout *pLayout )
 {
+    bool isVisible = getVisibleVar().get();
+    if( m_pActiveLayout )
+    {
+        if( isVisible )
+        {
+            m_pActiveLayout->onHide();
+        }
+        // The current layout becomes inactive
+        m_pActiveLayout->getActiveVar().set( false );
+    }
+
     pLayout->setWindow( this );
     m_pActiveLayout = pLayout;
     // Get the size of the layout and resize the window
     resize( pLayout->getWidth(), pLayout->getHeight() );
-    updateShape();
-    pLayout->refreshAll();
+
+    if( isVisible )
+    {
+        pLayout->onShow();
+    }
+
+    // The new layout is active
+    pLayout->getActiveVar().set( true );
+}
+
+
+const GenericLayout& TopWindow::getActiveLayout() const
+{
+    return *m_pActiveLayout;
 }
 
 
 void TopWindow::innerShow()
 {
-    // First, refresh the layout and update the shape of the window
+    // First, refresh the layout
     if( m_pActiveLayout )
     {
-        updateShape();
-        m_pActiveLayout->refreshAll();
+        m_pActiveLayout->onShow();
     }
+
     // Show the window
     GenericWindow::innerShow();
+
+    // place the top window on the screen (after show!)
+    move( getLeft(), getTop() );
 }
 
+
+void TopWindow::innerHide()
+{
+    if( m_pActiveLayout )
+    {
+        // Notify the active layout
+        m_pActiveLayout->onHide();
+    }
+    // Hide the window
+    GenericWindow::innerHide();
+}
+
+
 void TopWindow::updateShape()
 {
     // Set the shape of the window
@@ -328,18 +374,6 @@ void TopWindow::updateShape()
 }
 
 
-const list<Anchor*> TopWindow::getAnchorList() const
-{
-    return m_anchorList;
-}
-
-
-void TopWindow::addAnchor( Anchor *pAnchor )
-{
-    m_anchorList.push_back( pAnchor );
-}
-
-
 void TopWindow::onControlCapture( const CtrlGeneric &rCtrl )
 {
     // Set the capturing control
@@ -356,7 +390,7 @@ void TopWindow::onControlRelease( const CtrlGeneric &rCtrl )
     }
     else
     {
-        msg_Dbg( getIntf(), "Control had not captured the mouse" );
+        msg_Dbg( getIntf(), "control had not captured the mouse" );
     }
 
     // Send an enter event to the control under the mouse, if it doesn't
@@ -385,9 +419,18 @@ void TopWindow::onTooltipChange( const CtrlGeneric &rCtrl )
     // Check that the control is the active one
     if( m_pLastHitControl && m_pLastHitControl == &rCtrl )
     {
-        // Set the tooltip text variable
-        VarManager *pVarManager = VarManager::instance( getIntf() );
-        pVarManager->getTooltipText().set( rCtrl.getTooltipText() );
+        if( rCtrl.getTooltipText().size() )
+        {
+            // Set the tooltip text variable
+            VarManager *pVarManager = VarManager::instance( getIntf() );
+            pVarManager->getTooltipText().set( rCtrl.getTooltipText() );
+            m_rWindowManager.showTooltip();
+        }
+        else
+        {
+            // Nothing to display, so hide the tooltip
+            m_rWindowManager.hideTooltip();
+        }
     }
 }
 
@@ -427,7 +470,7 @@ CtrlGeneric *TopWindow::findHitControl( int xPos, int yPos )
         }
         else
         {
-            msg_Dbg( getIntf(), "Control at NULL position" );
+            msg_Dbg( getIntf(), "control at NULL position" );
         }
     }