1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN (Centrale Réseaux) and its contributors
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., 59 Temple Place - Suite 330, Boston, MA 02111, 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, &transMovingMoving ),
41 m_cmdStillMoving( this, &transStillMoving ),
42 m_cmdMovingStill( this, &transMovingStill )
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 )
71 m_rCtrl.draw( rImage, xDest, yDest );
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 const Position *CtrlMove::getPosition() const
85 return m_rCtrl.getPosition();
89 void CtrlMove::handleEvent( EvtGeneric &rEvent )
92 m_fsm.handleTransition( rEvent.getAsString() );
93 // Transmit the event to the decorated control
94 // XXX: Is it really a good idea?
95 m_rCtrl.handleEvent( rEvent );
99 void CtrlMove::transStillMoving( SkinObject *pCtrl )
101 CtrlMove *pThis = (CtrlMove*)pCtrl;
102 EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
104 pThis->m_xPos = pEvtMouse->getXPos();
105 pThis->m_yPos = pEvtMouse->getYPos();
107 pThis->captureMouse();
109 pThis->m_rWindowManager.startMove( pThis->m_rWindow );
113 void CtrlMove::transMovingMoving( SkinObject *pCtrl )
115 CtrlMove *pThis = (CtrlMove*)pCtrl;
116 EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
118 int xNewLeft = pEvtMotion->getXPos() - pThis->m_xPos +
119 pThis->m_rWindow.getLeft();
120 int yNewTop = pEvtMotion->getYPos() - pThis->m_yPos +
121 pThis->m_rWindow.getTop();
123 pThis->m_rWindowManager.move( pThis->m_rWindow, xNewLeft, yNewTop );
127 void CtrlMove::transMovingStill( SkinObject *pCtrl )
129 CtrlMove *pThis = (CtrlMove*)pCtrl;
131 pThis->releaseMouse();
133 pThis->m_rWindowManager.stopMove();