Commit b26f433d authored by Olivier Teulière's avatar Olivier Teulière

* skins2: prevent a window from using the layout of another window

parent d3bbcab8
...@@ -28,33 +28,19 @@ ...@@ -28,33 +28,19 @@
#include "../src/theme.hpp" #include "../src/theme.hpp"
CmdLayout::CmdLayout( intf_thread_t *pIntf, const string &windowId, CmdLayout::CmdLayout( intf_thread_t *pIntf, TopWindow &rWindow,
const string &layoutId ): GenericLayout &rLayout ):
CmdGeneric( pIntf ), m_windowId( windowId ), m_layoutId( layoutId ) CmdGeneric( pIntf ), m_rWindow( rWindow ), m_rLayout( rLayout )
{ {
} }
void CmdLayout::execute() void CmdLayout::execute()
{ {
// Get the window and the layout
if( !getIntf()->p_sys->p_theme ) if( !getIntf()->p_sys->p_theme )
{ {
return; return;
} }
TopWindow *pWindow = getIntf()->p_sys->p_theme->getWindowManager().setActiveLayout( m_rWindow,
getIntf()->p_sys->p_theme->getWindowById( m_windowId ); m_rLayout );
GenericLayout *pLayout =
getIntf()->p_sys->p_theme->getLayoutById( m_layoutId );
if( !pWindow || !pLayout )
{
msg_Err( getIntf(), "Cannot change layout (%s, %s)",
m_windowId.c_str(), m_layoutId.c_str() );
return;
}
// XXX TODO: check that the layout isn't a layout of another window
getIntf()->p_sys->p_theme->getWindowManager().setActiveLayout( *pWindow,
*pLayout );
} }
...@@ -26,15 +26,16 @@ ...@@ -26,15 +26,16 @@
#define CMD_LAYOUT_HPP #define CMD_LAYOUT_HPP
#include "cmd_generic.hpp" #include "cmd_generic.hpp"
#include <string>
class TopWindow;
class GenericLayout;
/// "Change layout" command /// "Change layout" command
class CmdLayout: public CmdGeneric class CmdLayout: public CmdGeneric
{ {
public: public:
CmdLayout( intf_thread_t *pIntf, const string &windowId, CmdLayout( intf_thread_t *pIntf, TopWindow &rWindow,
const string &layoutId ); GenericLayout &rLayout );
virtual ~CmdLayout() {} virtual ~CmdLayout() {}
/// This method does the real job of the command /// This method does the real job of the command
...@@ -44,8 +45,8 @@ class CmdLayout: public CmdGeneric ...@@ -44,8 +45,8 @@ class CmdLayout: public CmdGeneric
virtual string getType() const { return "change layout"; } virtual string getType() const { return "change layout"; }
private: private:
string m_windowId; TopWindow &m_rWindow;
string m_layoutId; GenericLayout &m_rLayout;
}; };
#endif #endif
...@@ -199,7 +199,27 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme ) ...@@ -199,7 +199,27 @@ CmdGeneric *Interpreter::parseAction( const string &rAction, Theme *pTheme )
int rightPos = rAction.find( ")", windowId.size() + 11 ); int rightPos = rAction.find( ")", windowId.size() + 11 );
string layoutId = rAction.substr( windowId.size() + 11, string layoutId = rAction.substr( windowId.size() + 11,
rightPos - (windowId.size() + 11) ); rightPos - (windowId.size() + 11) );
pCommand = new CmdLayout( getIntf(), windowId, layoutId );
TopWindow *pWin = pTheme->getWindowById( windowId );
GenericLayout *pLayout = pTheme->getLayoutById( layoutId );
if( !pWin )
{
msg_Err( getIntf(), "Unknown window (%s)", windowId.c_str() );
}
else if( !pLayout )
{
msg_Err( getIntf(), "Unknown layout (%s)", layoutId.c_str() );
}
// Check that the layout doesn't correspond to another window
else if( pWin != pLayout->getWindow() )
{
msg_Err( getIntf(), "Layout %s is not associated to window %s",
layoutId.c_str(), windowId.c_str() );
}
else
{
pCommand = new CmdLayout( getIntf(), *pWin, *pLayout );
}
} }
else if( rAction.find( ".show()" ) != string::npos ) else if( rAction.find( ".show()" ) != string::npos )
{ {
......
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