00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "ctrl_move.hpp"
00026 #include "../events/evt_generic.hpp"
00027 #include "../events/evt_mouse.hpp"
00028 #include "../events/evt_motion.hpp"
00029 #include "../src/top_window.hpp"
00030 #include "../src/window_manager.hpp"
00031 #include "../utils/position.hpp"
00032
00033
00034 CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
00035 CtrlFlat &rCtrl, TopWindow &rWindow,
00036 const UString &rHelp, VarBool *pVisible ):
00037 CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
00038 m_rWindowManager( rWindowManager ),
00039 m_rCtrl( rCtrl ), m_rWindow( rWindow ),
00040 m_cmdMovingMoving( this ),
00041 m_cmdStillMoving( this ),
00042 m_cmdMovingStill( this )
00043 {
00044 m_pEvt = NULL;
00045 m_xPos = 0;
00046 m_yPos = 0;
00047
00048
00049 m_fsm.addState( "moving" );
00050 m_fsm.addState( "still" );
00051
00052
00053 m_fsm.addTransition( "moving", "mouse:left:up:none", "still",
00054 &m_cmdMovingStill );
00055 m_fsm.addTransition( "still", "mouse:left:down:none", "moving",
00056 &m_cmdStillMoving );
00057 m_fsm.addTransition( "moving", "motion", "moving", &m_cmdMovingMoving );
00058
00059 m_fsm.setState( "still" );
00060 }
00061
00062
00063 bool CtrlMove::mouseOver( int x, int y ) const
00064 {
00065 return m_rCtrl.mouseOver( x, y );
00066 }
00067
00068
00069 void CtrlMove::draw( OSGraphics &rImage, int xDest, int yDest )
00070 {
00071 m_rCtrl.draw( rImage, xDest, yDest );
00072 }
00073
00074
00075 void CtrlMove::setLayout( GenericLayout *pLayout, const Position &rPosition )
00076 {
00077 CtrlGeneric::setLayout( pLayout, rPosition );
00078
00079 m_rCtrl.setLayout( pLayout, rPosition );
00080 }
00081
00082
00083 const Position *CtrlMove::getPosition() const
00084 {
00085 return m_rCtrl.getPosition();
00086 }
00087
00088
00089 void CtrlMove::handleEvent( EvtGeneric &rEvent )
00090 {
00091 m_pEvt = &rEvent;
00092 m_fsm.handleTransition( rEvent.getAsString() );
00093
00094
00095 m_rCtrl.handleEvent( rEvent );
00096 }
00097
00098
00099 void CtrlMove::CmdStillMoving::execute()
00100 {
00101 EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
00102
00103 m_pParent->m_xPos = pEvtMouse->getXPos();
00104 m_pParent->m_yPos = pEvtMouse->getYPos();
00105
00106 m_pParent->captureMouse();
00107
00108 m_pParent->m_rWindowManager.startMove( m_pParent->m_rWindow );
00109 }
00110
00111
00112 void CtrlMove::CmdMovingMoving::execute()
00113 {
00114 EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
00115
00116 int xNewLeft = pEvtMotion->getXPos() - m_pParent->m_xPos +
00117 m_pParent->m_rWindow.getLeft();
00118 int yNewTop = pEvtMotion->getYPos() - m_pParent->m_yPos +
00119 m_pParent->m_rWindow.getTop();
00120
00121 m_pParent->m_rWindowManager.move( m_pParent->m_rWindow, xNewLeft, yNewTop );
00122 }
00123
00124
00125 void CtrlMove::CmdMovingStill::execute()
00126 {
00127 m_pParent->releaseMouse();
00128
00129 m_pParent->m_rWindowManager.stopMove();
00130 }