]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/generic_window.cpp
5188da31711d13b16eb4430936e89e1c087ee628
[vlc] / modules / gui / skins2 / src / generic_window.cpp
1 /*****************************************************************************
2  * generic_window.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "generic_window.hpp"
26 #include "os_window.hpp"
27 #include "os_factory.hpp"
28 #include "../events/evt_refresh.hpp"
29
30
31 GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
32                               bool dragDrop, bool playOnDrop,
33                               GenericWindow *pParent ):
34     SkinObject( pIntf ), m_left( left ), m_top( top ), m_width( 0 ),
35     m_height( 0 ), m_varVisible( pIntf )
36 {
37     // Get the OSFactory
38     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
39
40     // Get the parent OSWindow, if any
41     OSWindow *pOSParent = NULL;
42     if( pParent )
43     {
44         pOSParent = pParent->m_pOsWindow;
45     }
46
47     // Create an OSWindow to handle OS specific processing
48     m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop,
49                                               pOSParent );
50
51     // Observe the visibility variable
52     m_varVisible.addObserver( this );
53 }
54
55
56 GenericWindow::~GenericWindow()
57 {
58     m_varVisible.delObserver( this );
59
60     if( m_pOsWindow )
61     {
62         delete m_pOsWindow;
63     }
64 }
65
66
67 void GenericWindow::processEvent( EvtRefresh &rEvtRefresh )
68 {
69     // Refresh the given area
70     refresh( rEvtRefresh.getXStart(), rEvtRefresh.getYStart(),
71              rEvtRefresh.getWidth(), rEvtRefresh.getHeight() );
72 }
73
74
75 void GenericWindow::show() const
76 {
77     m_varVisible.set( true );
78 }
79
80
81 void GenericWindow::hide() const
82 {
83     m_varVisible.set( false );
84 }
85
86
87 void GenericWindow::move( int left, int top )
88 {
89     // Update the window coordinates
90     m_left = left;
91     m_top = top;
92
93     m_pOsWindow->moveResize( left, top, m_width, m_height );
94 }
95
96
97 void GenericWindow::resize( int width, int height )
98 {
99     // Update the window size
100     m_width = width;
101     m_height = height;
102
103     m_pOsWindow->moveResize( m_left, m_top, width, height );
104 }
105
106
107 void GenericWindow::raise() const
108 {
109     m_pOsWindow->raise();
110 }
111
112
113 void GenericWindow::setOpacity( uint8_t value )
114 {
115     m_pOsWindow->setOpacity( value );
116 }
117
118
119 void GenericWindow::toggleOnTop( bool onTop ) const
120 {
121     m_pOsWindow->toggleOnTop( onTop );
122 }
123
124
125 void GenericWindow::onUpdate( Subject<VarBool, void*> &rVariable, void*arg )
126 {
127     if( m_varVisible.get() )
128     {
129         innerShow();
130     }
131     else
132     {
133         innerHide();
134     }
135 }
136
137
138 void GenericWindow::innerShow()
139 {
140     if( m_pOsWindow )
141     {
142         m_pOsWindow->show( m_left, m_top );
143     }
144 }
145
146
147 void GenericWindow::innerHide()
148 {
149     if( m_pOsWindow )
150     {
151         m_pOsWindow->hide();
152     }
153 }
154