]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_generic.cpp
* all: support of animated bitmaps in skins: there are new attributes
[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 Box *pImg1, const Box *pImg2 )
84 {
85     if( pImg1 == NULL )
86     {
87         if( pImg2 == NULL )
88         {
89             notifyLayout();
90         }
91         else
92         {
93             notifyLayout( pImg2->getWidth(), pImg2->getHeight() );
94         }
95     }
96     else
97     {
98         if( pImg2 == NULL )
99         {
100             notifyLayout( pImg1->getWidth(), pImg1->getHeight() );
101         }
102         else
103         {
104             notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ),
105                           max( pImg1->getHeight(), pImg2->getHeight() ) );
106         }
107     }
108 }
109
110
111 void CtrlGeneric::captureMouse() const
112 {
113     // Tell the layout we want to capture the mouse
114     if( m_pLayout )
115     {
116         m_pLayout->onControlCapture( *this );
117     }
118 }
119
120
121 void CtrlGeneric::releaseMouse() const
122 {
123     // Tell the layout we want to release the mouse
124     if( m_pLayout )
125     {
126         m_pLayout->onControlRelease( *this );
127     }
128 }
129
130
131 void CtrlGeneric::notifyTooltipChange() const
132 {
133     TopWindow *pWin = getWindow();
134     if( pWin )
135     {
136         // Notify the window
137         pWin->onTooltipChange( *this );
138     }
139 }
140
141
142 TopWindow *CtrlGeneric::getWindow() const
143 {
144     if( m_pLayout )
145     {
146         return m_pLayout->getWindow();
147     }
148     return NULL;
149 }
150
151
152 bool CtrlGeneric::isVisible() const
153 {
154     return !m_pVisible || m_pVisible->get();
155 }
156
157
158 void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable )
159 {
160     // Is it the visibility variable ?
161     if( &rVariable == m_pVisible )
162     {
163         // Redraw the layout
164         notifyLayout();
165     }
166     else
167     {
168         // Call the user-defined callback
169         onVarBoolUpdate( (VarBool&)rVariable );
170     }
171 }
172