]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_generic.cpp
49d3ac7d22107b305035a0cd4c86a7b5aad2d293
[vlc] / modules / gui / skins2 / controls / ctrl_generic.cpp
1 /*****************************************************************************
2  * ctrl_generic.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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include "ctrl_generic.hpp"
26 #include "../src/generic_layout.hpp"
27 #include "../src/top_window.hpp"
28 #include "../src/os_graphics.hpp"
29 #include "../utils/position.hpp"
30 #include "../utils/var_bool.hpp"
31
32
33 CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
34                           VarBool *pVisible):
35     SkinObject( pIntf ), m_pLayout( NULL ), m_pPosition( NULL ),
36     m_help( rHelp ), m_pVisible( pVisible )
37 {
38     // Observe the visibility variable
39     if( m_pVisible )
40     {
41         m_pVisible->addObserver( this );
42     }
43 }
44
45
46 CtrlGeneric::~CtrlGeneric()
47 {
48     if( m_pPosition )
49     {
50         delete m_pPosition;
51     }
52     if( m_pVisible )
53     {
54         m_pVisible->delObserver( this );
55     }
56 }
57
58
59 void CtrlGeneric::setLayout( GenericLayout *pLayout,
60                              const Position &rPosition )
61 {
62     m_pLayout = pLayout;
63     if( m_pPosition )
64     {
65         delete m_pPosition;
66     }
67     m_pPosition = new Position( rPosition );
68     onPositionChange();
69 }
70
71
72 void CtrlGeneric::notifyLayout( int width, int height,
73                                 int xOffSet, int yOffSet ) const
74 {
75     // Notify the layout
76     if( m_pLayout )
77     {
78         m_pLayout->onControlUpdate( *this, width, height, xOffSet, yOffSet );
79     }
80 }
81
82
83 void CtrlGeneric::notifyLayoutMaxSize( const OSGraphics *pImg1,
84                                        const OSGraphics *pImg2 )
85 {
86     if( pImg1 == NULL )
87     {
88         if( pImg2 == NULL )
89         {
90             notifyLayout();
91         }
92         else
93         {
94             notifyLayout( pImg2->getWidth(), pImg2->getHeight() );
95         }
96     }
97     else
98     {
99         if( pImg2 == NULL )
100         {
101             notifyLayout( pImg1->getWidth(), pImg1->getHeight() );
102         }
103         else
104         {
105             notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ),
106                           max( pImg1->getHeight(), pImg2->getHeight() ) );
107         }
108     }
109 }
110
111
112 void CtrlGeneric::captureMouse() const
113 {
114     // Tell the layout we want to capture the mouse
115     if( m_pLayout )
116     {
117         m_pLayout->onControlCapture( *this );
118     }
119 }
120
121
122 void CtrlGeneric::releaseMouse() const
123 {
124     // Tell the layout we want to release the mouse
125     if( m_pLayout )
126     {
127         m_pLayout->onControlRelease( *this );
128     }
129 }
130
131
132 void CtrlGeneric::notifyTooltipChange() const
133 {
134     TopWindow *pWin = getWindow();
135     if( pWin )
136     {
137         // Notify the window
138         pWin->onTooltipChange( *this );
139     }
140 }
141
142
143 TopWindow *CtrlGeneric::getWindow() const
144 {
145     if( m_pLayout )
146     {
147         return m_pLayout->getWindow();
148     }
149     return NULL;
150 }
151
152
153 bool CtrlGeneric::isVisible() const
154 {
155     return !m_pVisible || m_pVisible->get();
156 }
157
158
159 void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable )
160 {
161     // Is it the visibility variable ?
162     if( &rVariable == m_pVisible )
163     {
164         // Redraw the layout
165         notifyLayout();
166     }
167     else
168     {
169         // Call the user-defined callback
170         onVarBoolUpdate( (VarBool&)rVariable );
171     }
172 }
173