1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "ctrl_move.hpp"
26 #include "../events/evt_generic.hpp"
27 #include "../events/evt_mouse.hpp"
28 #include "../events/evt_motion.hpp"
29 #include "../src/top_window.hpp"
30 #include "../src/window_manager.hpp"
31 #include "../utils/position.hpp"
34 CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
35 CtrlFlat &rCtrl, TopWindow &rWindow,
36 const UString &rHelp, VarBool *pVisible ):
37 CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
38 m_rWindowManager( rWindowManager ),
39 m_rCtrl( rCtrl ), m_rWindow( rWindow ),
40 m_cmdMovingMoving( this ),
41 m_cmdStillMoving( this ),
42 m_cmdMovingStill( this )
49 m_fsm.addState( "moving" );
50 m_fsm.addState( "still" );
53 m_fsm.addTransition( "moving", "mouse:left:up:none", "still",
55 m_fsm.addTransition( "still", "mouse:left:down:none", "moving",
57 m_fsm.addTransition( "moving", "motion", "moving", &m_cmdMovingMoving );
59 m_fsm.setState( "still" );
63 bool CtrlMove::mouseOver( int x, int y ) const
65 return m_rCtrl.mouseOver( x, y );
69 void CtrlMove::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h )
71 m_rCtrl.draw( rImage, xDest, yDest, w, h );
75 void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
77 CtrlGeneric::setLayout( pLayout, rPosition );
78 // Set the layout of the decorated control as well
79 m_rCtrl.setLayout( pLayout, rPosition );
83 void CtrlMove::unsetLayout( )
85 m_rCtrl.unsetLayout();
86 CtrlGeneric::unsetLayout();
90 const Position *CtrlMove::getPosition() const
92 return m_rCtrl.getPosition();
96 void CtrlMove::onResize()
102 void CtrlMove::handleEvent( EvtGeneric &rEvent )
105 m_fsm.handleTransition( rEvent.getAsString() );
106 // Transmit the event to the decorated control
107 // XXX: Is it really a good idea?
108 m_rCtrl.handleEvent( rEvent );
112 void CtrlMove::CmdStillMoving::execute()
114 EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
116 m_pParent->m_xPos = pEvtMouse->getXPos();
117 m_pParent->m_yPos = pEvtMouse->getYPos();
119 m_pParent->captureMouse();
121 m_pParent->m_rWindowManager.startMove( m_pParent->m_rWindow );
125 void CtrlMove::CmdMovingMoving::execute()
127 EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
129 int xNewLeft = pEvtMotion->getXPos() - m_pParent->m_xPos +
130 m_pParent->m_rWindow.getLeft();
131 int yNewTop = pEvtMotion->getYPos() - m_pParent->m_yPos +
132 m_pParent->m_rWindow.getTop();
134 m_pParent->m_rWindowManager.move( m_pParent->m_rWindow, xNewLeft, yNewTop );
138 void CtrlMove::CmdMovingStill::execute()
140 m_pParent->releaseMouse();
142 m_pParent->m_rWindowManager.stopMove();