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_resize.hpp"
00026 #include "../events/evt_generic.hpp"
00027 #include "../events/evt_mouse.hpp"
00028 #include "../events/evt_motion.hpp"
00029 #include "../src/generic_layout.hpp"
00030 #include "../src/os_factory.hpp"
00031 #include "../utils/position.hpp"
00032 #include "../commands/async_queue.hpp"
00033 #include "../commands/cmd_resize.hpp"
00034
00035
00036 CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
00037 GenericLayout &rLayout, const UString &rHelp,
00038 VarBool *pVisible ):
00039 CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
00040 m_rLayout( rLayout ), m_cmdOutStill( this ),
00041 m_cmdStillOut( this ),
00042 m_cmdStillStill( this ),
00043 m_cmdStillResize( this ),
00044 m_cmdResizeStill( this ),
00045 m_cmdResizeResize( this )
00046 {
00047 m_pEvt = NULL;
00048 m_xPos = 0;
00049 m_yPos = 0;
00050
00051
00052 m_fsm.addState( "out" );
00053 m_fsm.addState( "still" );
00054 m_fsm.addState( "resize" );
00055
00056
00057 m_fsm.addTransition( "out", "enter", "still", &m_cmdOutStill );
00058 m_fsm.addTransition( "still", "leave", "out", &m_cmdStillOut );
00059 m_fsm.addTransition( "still", "motion", "still", &m_cmdStillStill );
00060 m_fsm.addTransition( "resize", "mouse:left:up:none", "still",
00061 &m_cmdResizeStill );
00062 m_fsm.addTransition( "still", "mouse:left:down:none", "resize",
00063 &m_cmdStillResize );
00064 m_fsm.addTransition( "resize", "motion", "resize", &m_cmdResizeResize );
00065
00066 m_fsm.setState( "still" );
00067 }
00068
00069
00070 bool CtrlResize::mouseOver( int x, int y ) const
00071 {
00072 return m_rCtrl.mouseOver( x, y );
00073 }
00074
00075
00076 void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest )
00077 {
00078 m_rCtrl.draw( rImage, xDest, yDest );
00079 }
00080
00081
00082 void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
00083 {
00084 CtrlGeneric::setLayout( pLayout, rPosition );
00085
00086 m_rCtrl.setLayout( pLayout, rPosition );
00087 }
00088
00089
00090 const Position *CtrlResize::getPosition() const
00091 {
00092 return m_rCtrl.getPosition();
00093 }
00094
00095
00096 void CtrlResize::handleEvent( EvtGeneric &rEvent )
00097 {
00098 m_pEvt = &rEvent;
00099 m_fsm.handleTransition( rEvent.getAsString() );
00100
00101
00102 m_rCtrl.handleEvent( rEvent );
00103 }
00104
00105
00106 void CtrlResize::CmdOutStill::execute()
00107 {
00108 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00109 pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00110 }
00111
00112
00113 void CtrlResize::CmdStillOut::execute()
00114 {
00115 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00116 pOsFactory->changeCursor( OSFactory::kDefaultArrow );
00117 }
00118
00119
00120 void CtrlResize::CmdStillStill::execute()
00121 {
00122 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00123 pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00124 }
00125
00126
00127 void CtrlResize::CmdStillResize::execute()
00128 {
00129 EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
00130
00131
00132 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00133 pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00134
00135 m_pParent->m_xPos = pEvtMouse->getXPos();
00136 m_pParent->m_yPos = pEvtMouse->getYPos();
00137
00138 m_pParent->captureMouse();
00139
00140 m_pParent->m_width = m_pParent->m_rLayout.getWidth();
00141 m_pParent->m_height = m_pParent->m_rLayout.getHeight();
00142 }
00143
00144
00145 void CtrlResize::CmdResizeStill::execute()
00146 {
00147
00148 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00149 pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00150
00151 m_pParent->releaseMouse();
00152 }
00153
00154
00155 void CtrlResize::CmdResizeResize::execute()
00156 {
00157 EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
00158
00159
00160 OSFactory *pOsFactory = OSFactory::instance( m_pParent->getIntf() );
00161 pOsFactory->changeCursor( OSFactory::kResizeNWSE );
00162
00163 int newWidth = pEvtMotion->getXPos() - m_pParent->m_xPos + m_pParent->m_width;
00164 int newHeight = pEvtMotion->getYPos() - m_pParent->m_yPos + m_pParent->m_height;
00165
00166
00167 if( newWidth < m_pParent->m_rLayout.getMinWidth() )
00168 {
00169 newWidth = m_pParent->m_rLayout.getMinWidth();
00170 }
00171 if( newWidth > m_pParent->m_rLayout.getMaxWidth() )
00172 {
00173 newWidth = m_pParent->m_rLayout.getMaxWidth();
00174 }
00175 if( newHeight < m_pParent->m_rLayout.getMinHeight() )
00176 {
00177 newHeight = m_pParent->m_rLayout.getMinHeight();
00178 }
00179 if( newHeight > m_pParent->m_rLayout.getMaxHeight() )
00180 {
00181 newHeight = m_pParent->m_rLayout.getMaxHeight();
00182 }
00183
00184
00185 CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(), m_pParent->m_rLayout,
00186 newWidth, newHeight );
00187
00188 AsyncQueue *pQueue = AsyncQueue::instance( m_pParent->getIntf() );
00189 pQueue->remove( "resize" );
00190 pQueue->push( CmdGenericPtr( pCmd ) );
00191 }