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_generic.hpp"
00026 #include "../src/generic_layout.hpp"
00027 #include "../src/top_window.hpp"
00028 #include "../src/os_graphics.hpp"
00029 #include "../utils/position.hpp"
00030 #include "../utils/var_bool.hpp"
00031
00032
00033 CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
00034 VarBool *pVisible):
00035 SkinObject( pIntf ), m_pLayout( NULL ), m_pPosition( NULL ),
00036 m_help( rHelp ), m_pVisible( pVisible )
00037 {
00038
00039 if( m_pVisible )
00040 {
00041 m_pVisible->addObserver( this );
00042 }
00043 }
00044
00045
00046 CtrlGeneric::~CtrlGeneric()
00047 {
00048 if( m_pPosition )
00049 {
00050 delete m_pPosition;
00051 }
00052 if( m_pVisible )
00053 {
00054 m_pVisible->delObserver( this );
00055 }
00056 }
00057
00058
00059 void CtrlGeneric::setLayout( GenericLayout *pLayout,
00060 const Position &rPosition )
00061 {
00062 m_pLayout = pLayout;
00063 if( m_pPosition )
00064 {
00065 delete m_pPosition;
00066 }
00067 m_pPosition = new Position( rPosition );
00068 onPositionChange();
00069 }
00070
00071
00072 void CtrlGeneric::notifyLayout( int width, int height,
00073 int xOffSet, int yOffSet ) const
00074 {
00075
00076 if( m_pLayout )
00077 {
00078 m_pLayout->onControlUpdate( *this, width, height, xOffSet, yOffSet );
00079 }
00080 }
00081
00082
00083 void CtrlGeneric::notifyLayoutMaxSize( const OSGraphics *pImg1,
00084 const OSGraphics *pImg2 )
00085 {
00086 if( pImg1 == NULL )
00087 {
00088 if( pImg2 == NULL )
00089 {
00090 notifyLayout();
00091 }
00092 else
00093 {
00094 notifyLayout( pImg2->getWidth(), pImg2->getHeight() );
00095 }
00096 }
00097 else
00098 {
00099 if( pImg2 == NULL )
00100 {
00101 notifyLayout( pImg1->getWidth(), pImg1->getHeight() );
00102 }
00103 else
00104 {
00105 notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ),
00106 max( pImg1->getHeight(), pImg2->getHeight() ) );
00107 }
00108 }
00109 }
00110
00111
00112 void CtrlGeneric::captureMouse() const
00113 {
00114
00115 if( m_pLayout )
00116 {
00117 m_pLayout->onControlCapture( *this );
00118 }
00119 }
00120
00121
00122 void CtrlGeneric::releaseMouse() const
00123 {
00124
00125 if( m_pLayout )
00126 {
00127 m_pLayout->onControlRelease( *this );
00128 }
00129 }
00130
00131
00132 void CtrlGeneric::notifyTooltipChange() const
00133 {
00134 TopWindow *pWin = getWindow();
00135 if( pWin )
00136 {
00137
00138 pWin->onTooltipChange( *this );
00139 }
00140 }
00141
00142
00143 TopWindow *CtrlGeneric::getWindow() const
00144 {
00145 if( m_pLayout )
00146 {
00147 return m_pLayout->getWindow();
00148 }
00149 return NULL;
00150 }
00151
00152
00153 bool CtrlGeneric::isVisible() const
00154 {
00155 return !m_pVisible || m_pVisible->get();
00156 }
00157
00158
00159 void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable )
00160 {
00161
00162 if( &rVariable == m_pVisible )
00163 {
00164
00165 notifyLayout();
00166 }
00167 else
00168 {
00169
00170 onVarBoolUpdate( (VarBool&)rVariable );
00171 }
00172 }
00173