]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_generic.cpp
* all: split GenericWindow into GenericWindow (general interface for
[vlc] / modules / gui / skins2 / controls / ctrl_generic.cpp
1 /*****************************************************************************
2  * ctrl_generic.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
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() const
73 {
74     // Notify the layout
75     if( m_pLayout )
76     {
77         m_pLayout->onControlUpdate( *this );
78     }
79 }
80
81
82 void CtrlGeneric::captureMouse() const
83 {
84     // Tell the layout we want to capture the mouse
85     if( m_pLayout )
86     {
87         m_pLayout->onControlCapture( *this );
88     }
89 }
90
91
92 void CtrlGeneric::releaseMouse() const
93 {
94     // Tell the layout we want to release the mouse
95     if( m_pLayout )
96     {
97         m_pLayout->onControlRelease( *this );
98     }
99 }
100
101
102 void CtrlGeneric::notifyTooltipChange() const
103 {
104     TopWindow *pWin = getWindow();
105     if( pWin )
106     {
107         // Notify the window
108         pWin->onTooltipChange( *this );
109     }
110 }
111
112
113 TopWindow *CtrlGeneric::getWindow() const
114 {
115     if( m_pLayout )
116     {
117         return m_pLayout->getWindow();
118     }
119     return NULL;
120 }
121
122
123 bool CtrlGeneric::isVisible() const
124 {
125     return !m_pVisible || m_pVisible->get();
126 }
127
128
129 void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable )
130 {
131     // Is it the visibily variable ?
132     if( &rVariable == m_pVisible )
133     {
134         // Redraw the layout
135         notifyLayout();
136     }
137     else
138     {
139         // Call the user-defined callback
140         onVarBoolUpdate( (VarBool&)rVariable );
141     }
142 }
143