1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "generic_window.hpp"
26 #include "os_window.hpp"
27 #include "os_factory.hpp"
28 #include "var_manager.hpp"
29 #include "../events/evt_refresh.hpp"
32 GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
33 bool dragDrop, bool playOnDrop,
34 GenericWindow *pParent, WindowType_t type ):
35 SkinObject( pIntf ), m_left( left ), m_top( top ), m_width( 0 ),
36 m_height( 0 ), m_pVarVisible( NULL )
39 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
41 // Get the parent OSWindow, if any
42 OSWindow *pOSParent = NULL;
45 pOSParent = pParent->m_pOsWindow;
48 // Create an OSWindow to handle OS specific processing
49 m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop,
52 // Create the visibility variable and register it in the manager
53 m_pVarVisible = new VarBoolImpl( pIntf );
54 VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarVisible ) );
56 // Observe the visibility variable
57 m_pVarVisible->addObserver( this );
61 GenericWindow::~GenericWindow()
63 m_pVarVisible->delObserver( this );
69 void GenericWindow::processEvent( EvtRefresh &rEvtRefresh )
71 // Refresh the given area
72 refresh( rEvtRefresh.getXStart(), rEvtRefresh.getYStart(),
73 rEvtRefresh.getWidth(), rEvtRefresh.getHeight() );
77 void GenericWindow::show() const
79 m_pVarVisible->set( true );
83 void GenericWindow::hide() const
85 m_pVarVisible->set( false );
89 void GenericWindow::move( int left, int top )
91 // Update the window coordinates
95 m_pOsWindow->moveResize( left, top, m_width, m_height );
99 void GenericWindow::resize( int width, int height )
101 // don't try when value is 0 (may crash)
102 if( !width || ! height )
105 // Update the window size
109 m_pOsWindow->moveResize( m_left, m_top, width, height );
113 void GenericWindow::raise() const
115 m_pOsWindow->raise();
119 void GenericWindow::setOpacity( uint8_t value )
121 m_pOsWindow->setOpacity( value );
125 void GenericWindow::toggleOnTop( bool onTop ) const
127 m_pOsWindow->toggleOnTop( onTop );
131 void GenericWindow::onUpdate( Subject<VarBool> &rVariable, void*arg )
133 if (&rVariable == m_pVarVisible )
135 if( m_pVarVisible->get() )
147 void GenericWindow::innerShow()
156 void GenericWindow::innerHide()
165 void* GenericWindow::getOSHandle() const
167 return m_pOsWindow->getOSHandle();
171 void GenericWindow::setParent( GenericWindow* pParent, int x, int y, int w, int h )
173 // Update the window size and position
176 m_width = ( w > 0 ) ? w : m_width;
177 m_height = ( h > 0 ) ? h : m_height;
179 void* handle = pParent ? pParent->getOSHandle() : NULL;
180 m_pOsWindow->reparent( handle, m_left, m_top, m_width, m_height );