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 "generic_layout.hpp"
00026 #include "top_window.hpp"
00027 #include "os_factory.hpp"
00028 #include "os_graphics.hpp"
00029 #include "../controls/ctrl_generic.hpp"
00030
00031
00032 GenericLayout::GenericLayout( intf_thread_t *pIntf, int width, int height,
00033 int minWidth, int maxWidth, int minHeight,
00034 int maxHeight ):
00035 SkinObject( pIntf ), m_pWindow( NULL ), m_width( width ),
00036 m_height( height ), m_minWidth( minWidth ), m_maxWidth( maxWidth ),
00037 m_minHeight( minHeight ), m_maxHeight( maxHeight )
00038 {
00039
00040 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
00041
00042 m_pImage = pOsFactory->createOSGraphics( width, height );
00043 }
00044
00045
00046 GenericLayout::~GenericLayout()
00047 {
00048 if( m_pImage )
00049 {
00050 delete m_pImage;
00051 }
00052 }
00053
00054
00055 void GenericLayout::setWindow( TopWindow *pWindow )
00056 {
00057 m_pWindow = pWindow;
00058 }
00059
00060
00061 void GenericLayout::onControlCapture( const CtrlGeneric &rCtrl )
00062 {
00063
00064 TopWindow *pWindow = getWindow();
00065 if( pWindow )
00066 {
00067 pWindow->onControlCapture( rCtrl );
00068 }
00069 }
00070
00071
00072 void GenericLayout::onControlRelease( const CtrlGeneric &rCtrl )
00073 {
00074
00075 TopWindow *pWindow = getWindow();
00076 if( pWindow )
00077 {
00078 pWindow->onControlRelease( rCtrl );
00079 }
00080 }
00081
00082
00083 void GenericLayout::addControl( CtrlGeneric *pControl,
00084 const Position &rPosition, int layer )
00085 {
00086 if( pControl )
00087 {
00088
00089 pControl->setLayout( this, rPosition );
00090
00091
00092 pControl->draw( *m_pImage, rPosition.getLeft(), rPosition.getTop() );
00093
00094
00095
00096 list<LayeredControl>::iterator it;
00097 for( it = m_controlList.begin(); it != m_controlList.end(); it++ )
00098 {
00099 if( layer < (*it).m_layer )
00100 {
00101 m_controlList.insert( it, LayeredControl( pControl, layer ) );
00102 break;
00103 }
00104 }
00105
00106 if( it == m_controlList.end() )
00107 {
00108 m_controlList.push_back( LayeredControl( pControl, layer ) );
00109 }
00110 }
00111 else
00112 {
00113 msg_Dbg( getIntf(), "Adding NULL control in the layout" );
00114 }
00115 }
00116
00117
00118 const list<LayeredControl> &GenericLayout::getControlList() const
00119 {
00120 return m_controlList;
00121 }
00122
00123
00124 void GenericLayout::onControlUpdate( const CtrlGeneric &rCtrl,
00125 int width, int height,
00126 int xOffSet, int yOffSet )
00127 {
00128
00129 if( width <= 0 || height <= 0 )
00130 {
00131 refreshAll();
00132 return;
00133 }
00134
00135 const Position *pPos = rCtrl.getPosition();
00136 if( pPos )
00137 {
00138 refreshRect( pPos->getLeft() + xOffSet,
00139 pPos->getTop() + yOffSet,
00140 width, height );
00141 }
00142 }
00143
00144
00145 void GenericLayout::resize( int width, int height )
00146 {
00147 if( width == m_width && height == m_height )
00148 {
00149 return;
00150 }
00151
00152
00153 m_width = width;
00154 m_height = height;
00155
00156
00157 if( m_pImage )
00158 {
00159 delete m_pImage;
00160 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
00161 m_pImage = pOsFactory->createOSGraphics( width, height );
00162 }
00163
00164
00165 list<LayeredControl>::const_iterator iter;
00166 for( iter = m_controlList.begin(); iter != m_controlList.end(); iter++ )
00167 {
00168 (*iter).m_pControl->onResize();
00169 const Position *pPos = (*iter).m_pControl->getPosition();
00170 if( pPos )
00171 {
00172 (*iter).m_pControl->draw( *m_pImage, pPos->getLeft(),
00173 pPos->getTop() );
00174 }
00175 }
00176
00177
00178 TopWindow *pWindow = getWindow();
00179 if( pWindow )
00180 {
00181
00182 pWindow->refresh( 0, 0, width, height );
00183 pWindow->resize( width, height );
00184 pWindow->refresh( 0, 0, width, height );
00185
00186
00187 pWindow->updateShape();
00188 pWindow->refresh( 0, 0, width, height );
00189 }
00190 }
00191
00192
00193 void GenericLayout::refreshAll()
00194 {
00195 refreshRect( 0, 0, m_width, m_height );
00196 }
00197
00198
00199 void GenericLayout::refreshRect( int x, int y, int width, int height )
00200 {
00201
00202 list<LayeredControl>::const_iterator iter;
00203 list<LayeredControl>::const_iterator iterVideo = m_controlList.end();
00204 for( iter = m_controlList.begin(); iter != m_controlList.end(); iter++ )
00205 {
00206 CtrlGeneric *pCtrl = (*iter).m_pControl;
00207 const Position *pPos = pCtrl->getPosition();
00208 if( pCtrl->isVisible() && pPos )
00209 {
00210 pCtrl->draw( *m_pImage, pPos->getLeft(), pPos->getTop() );
00211
00212
00213 if( pCtrl->getType() == "video" && pCtrl->getPosition() )
00214 iterVideo = iter;
00215 }
00216 }
00217
00218
00219 TopWindow *pWindow = getWindow();
00220 if( pWindow )
00221 {
00222
00223 if( x < 0 )
00224 x = 0;
00225 if( y < 0)
00226 y = 0;
00227 if( x + width > m_width )
00228 width = m_width - x;
00229 if( y + height > m_height )
00230 height = m_height - y;
00231
00232
00233 if( iterVideo == m_controlList.end() )
00234 {
00235
00236 pWindow->refresh( x, y, width, height );
00237 }
00238 else
00239 {
00240
00241
00242
00243
00244
00245
00246
00247
00248 int xx = iterVideo->m_pControl->getPosition()->getLeft();
00249 int yy = iterVideo->m_pControl->getPosition()->getTop();
00250 int ww = iterVideo->m_pControl->getPosition()->getWidth();
00251 int hh = iterVideo->m_pControl->getPosition()->getHeight();
00252
00253
00254 if( y < yy )
00255 pWindow->refresh( x, y, width, yy - y );
00256
00257 if( x < xx )
00258 pWindow->refresh( x, y, xx - x, height );
00259
00260 if( y + height > yy + hh )
00261 pWindow->refresh( x, yy + hh, width, y + height - (yy + hh) );
00262
00263 if( x + width > xx + ww )
00264 pWindow->refresh( xx + ww, y, x + width - (xx + ww), height );
00265 }
00266 }
00267 }
00268
00269
00270 const list<Anchor*>& GenericLayout::getAnchorList() const
00271 {
00272 return m_anchorList;
00273 }
00274
00275
00276 void GenericLayout::addAnchor( Anchor *pAnchor )
00277 {
00278 m_anchorList.push_back( pAnchor );
00279 }
00280