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_button.hpp"
00026 #include "../events/evt_generic.hpp"
00027 #include "../src/generic_bitmap.hpp"
00028 #include "../src/os_factory.hpp"
00029 #include "../src/os_graphics.hpp"
00030 #include "../commands/cmd_generic.hpp"
00031
00032
00033 CtrlButton::CtrlButton( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
00034 const GenericBitmap &rBmpOver,
00035 const GenericBitmap &rBmpDown, CmdGeneric &rCommand,
00036 const UString &rTooltip, const UString &rHelp,
00037 VarBool *pVisible ):
00038 CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
00039 m_rCommand( rCommand ), m_tooltip( rTooltip ),
00040 m_cmdUpOverDownOver( this ), m_cmdDownOverUpOver( this ),
00041 m_cmdDownOverDown( this ), m_cmdDownDownOver( this ),
00042 m_cmdUpOverUp( this ), m_cmdUpUpOver( this ),
00043 m_cmdDownUp( this ), m_cmdUpHidden( this ),
00044 m_cmdHiddenUp( this )
00045 {
00046
00047 OSFactory *pOsFactory = OSFactory::instance( pIntf );
00048 m_pImgUp = pOsFactory->createOSGraphics( rBmpUp.getWidth(),
00049 rBmpUp.getHeight() );
00050 m_pImgUp->drawBitmap( rBmpUp, 0, 0 );
00051 m_pImgDown = pOsFactory->createOSGraphics( rBmpDown.getWidth(),
00052 rBmpDown.getHeight() );
00053 m_pImgDown->drawBitmap( rBmpDown, 0, 0 );
00054 m_pImgOver = pOsFactory->createOSGraphics( rBmpOver.getWidth(),
00055 rBmpOver.getHeight() );
00056 m_pImgOver->drawBitmap( rBmpOver, 0, 0 );
00057
00058
00059 m_fsm.addState( "up" );
00060 m_fsm.addState( "down" );
00061 m_fsm.addState( "upOver" );
00062 m_fsm.addState( "downOver" );
00063 m_fsm.addState( "hidden" );
00064
00065
00066 m_fsm.addTransition( "upOver", "mouse:left:down", "downOver",
00067 &m_cmdUpOverDownOver );
00068 m_fsm.addTransition( "upOver", "mouse:left:dblclick", "downOver",
00069 &m_cmdUpOverDownOver );
00070 m_fsm.addTransition( "downOver", "mouse:left:up", "upOver",
00071 &m_cmdDownOverUpOver );
00072 m_fsm.addTransition( "downOver", "leave", "down", &m_cmdDownOverDown );
00073 m_fsm.addTransition( "down", "enter", "downOver", &m_cmdDownDownOver );
00074 m_fsm.addTransition( "upOver", "leave", "up", &m_cmdUpOverUp );
00075 m_fsm.addTransition( "up", "enter", "upOver", &m_cmdUpUpOver );
00076 m_fsm.addTransition( "down", "mouse:left:up", "up", &m_cmdDownUp );
00077
00078
00079 m_fsm.addTransition( "up", "special:hide", "hidden", &m_cmdUpHidden );
00080 m_fsm.addTransition( "down", "special:hide", "hidden", &m_cmdUpHidden );
00081 m_fsm.addTransition( "upOver", "special:hide", "hidden", &m_cmdUpHidden );
00082 m_fsm.addTransition( "downOver", "special:hide", "hidden", &m_cmdUpHidden );
00083 m_fsm.addTransition( "hidden", "special:show", "up", &m_cmdHiddenUp );
00084
00085
00086 m_fsm.setState( "up" );
00087 m_pImg = m_pImgUp;
00088 }
00089
00090
00091 CtrlButton::~CtrlButton()
00092 {
00093 SKINS_DELETE( m_pImgUp );
00094 SKINS_DELETE( m_pImgDown );
00095 SKINS_DELETE( m_pImgOver );
00096 }
00097
00098
00099 void CtrlButton::handleEvent( EvtGeneric &rEvent )
00100 {
00101 m_fsm.handleTransition( rEvent.getAsString() );
00102 }
00103
00104
00105 bool CtrlButton::mouseOver( int x, int y ) const
00106 {
00107 if( m_pImg )
00108 {
00109 return m_pImg->hit( x, y );
00110 }
00111 else
00112 {
00113 return false;
00114 }
00115 }
00116
00117
00118 void CtrlButton::draw( OSGraphics &rImage, int xDest, int yDest )
00119 {
00120 if( m_pImg )
00121 {
00122
00123 rImage.drawGraphics( *m_pImg, 0, 0, xDest, yDest );
00124 }
00125 }
00126
00127
00128 void CtrlButton::CmdUpOverDownOver::execute()
00129 {
00130 m_pParent->captureMouse();
00131 const OSGraphics *pOldImg = m_pParent->m_pImg;
00132 m_pParent->m_pImg = m_pParent->m_pImgDown;
00133 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00134 }
00135
00136
00137 void CtrlButton::CmdDownOverUpOver::execute()
00138 {
00139 m_pParent->releaseMouse();
00140 const OSGraphics *pOldImg = m_pParent->m_pImg;
00141 m_pParent->m_pImg = m_pParent->m_pImgUp;
00142 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00143
00144 m_pParent->m_rCommand.execute();
00145 }
00146
00147
00148 void CtrlButton::CmdDownOverDown::execute()
00149 {
00150 const OSGraphics *pOldImg = m_pParent->m_pImg;
00151 m_pParent->m_pImg = m_pParent->m_pImgUp;
00152 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00153 }
00154
00155
00156 void CtrlButton::CmdDownDownOver::execute()
00157 {
00158 const OSGraphics *pOldImg = m_pParent->m_pImg;
00159 m_pParent->m_pImg = m_pParent->m_pImgDown;
00160 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00161 }
00162
00163
00164 void CtrlButton::CmdUpUpOver::execute()
00165 {
00166 const OSGraphics *pOldImg = m_pParent->m_pImg;
00167 m_pParent->m_pImg = m_pParent->m_pImgOver;
00168 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00169 }
00170
00171
00172 void CtrlButton::CmdUpOverUp::execute()
00173 {
00174 const OSGraphics *pOldImg = m_pParent->m_pImg;
00175 m_pParent->m_pImg = m_pParent->m_pImgUp;
00176 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00177 }
00178
00179
00180 void CtrlButton::CmdDownUp::execute()
00181 {
00182 m_pParent->releaseMouse();
00183 }
00184
00185
00186 void CtrlButton::CmdUpHidden::execute()
00187 {
00188 const OSGraphics *pOldImg = m_pParent->m_pImg;
00189 m_pParent->m_pImg = NULL;
00190 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00191 }
00192
00193
00194 void CtrlButton::CmdHiddenUp::execute()
00195 {
00196 const OSGraphics *pOldImg = m_pParent->m_pImg;
00197 m_pParent->m_pImg = m_pParent->m_pImgUp;
00198 m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImg );
00199 }
00200