Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

ctrl_generic.cpp

00001 /*****************************************************************************
00002  * ctrl_generic.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: ctrl_generic.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
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     // Observe the visibility variable
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     // Notify the layout
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     // Tell the layout we want to capture the mouse
00115     if( m_pLayout )
00116     {
00117         m_pLayout->onControlCapture( *this );
00118     }
00119 }
00120 
00121 
00122 void CtrlGeneric::releaseMouse() const
00123 {
00124     // Tell the layout we want to release the mouse
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         // Notify the window
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     // Is it the visibility variable ?
00162     if( &rVariable == m_pVisible )
00163     {
00164         // Redraw the layout
00165         notifyLayout();
00166     }
00167     else
00168     {
00169         // Call the user-defined callback
00170         onVarBoolUpdate( (VarBool&)rVariable );
00171     }
00172 }
00173 

Generated on Tue Dec 20 10:14:41 2005 for vlc-0.8.4a by  doxygen 1.4.2