]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_generic.cpp
That's safe to delete NULL.
[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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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     delete m_pPosition;
49     if( m_pVisible )
50     {
51         m_pVisible->delObserver( this );
52     }
53 }
54
55
56 void CtrlGeneric::setLayout( GenericLayout *pLayout,
57                              const Position &rPosition )
58 {
59     m_pLayout = pLayout;
60     delete m_pPosition;
61     m_pPosition = new Position( rPosition );
62     onPositionChange();
63 }
64
65
66 void CtrlGeneric::notifyLayout( int width, int height,
67                                 int xOffSet, int yOffSet ) const
68 {
69     // Notify the layout
70     if( m_pLayout )
71     {
72         m_pLayout->onControlUpdate( *this, width, height, xOffSet, yOffSet );
73     }
74 }
75
76
77 void CtrlGeneric::notifyLayoutMaxSize( const Box *pImg1, const Box *pImg2 )
78 {
79     if( pImg1 == NULL )
80     {
81         if( pImg2 == NULL )
82         {
83             notifyLayout();
84         }
85         else
86         {
87             notifyLayout( pImg2->getWidth(), pImg2->getHeight() );
88         }
89     }
90     else
91     {
92         if( pImg2 == NULL )
93         {
94             notifyLayout( pImg1->getWidth(), pImg1->getHeight() );
95         }
96         else
97         {
98             notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ),
99                           max( pImg1->getHeight(), pImg2->getHeight() ) );
100         }
101     }
102 }
103
104
105 void CtrlGeneric::captureMouse() const
106 {
107     // Tell the layout we want to capture the mouse
108     if( m_pLayout )
109     {
110         m_pLayout->onControlCapture( *this );
111     }
112 }
113
114
115 void CtrlGeneric::releaseMouse() const
116 {
117     // Tell the layout we want to release the mouse
118     if( m_pLayout )
119     {
120         m_pLayout->onControlRelease( *this );
121     }
122 }
123
124
125 void CtrlGeneric::notifyTooltipChange() const
126 {
127     TopWindow *pWin = getWindow();
128     if( pWin )
129     {
130         // Notify the window
131         pWin->onTooltipChange( *this );
132     }
133 }
134
135
136 TopWindow *CtrlGeneric::getWindow() const
137 {
138     if( m_pLayout )
139     {
140         return m_pLayout->getWindow();
141     }
142     return NULL;
143 }
144
145
146 bool CtrlGeneric::isVisible() const
147 {
148     return !m_pVisible || m_pVisible->get();
149 }
150
151
152 void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable, void *arg  )
153 {
154     // Is it the visibility variable ?
155     if( &rVariable == m_pVisible )
156     {
157         // Redraw the layout
158         notifyLayout();
159     }
160     else
161     {
162         // Call the user-defined callback
163         onVarBoolUpdate( (VarBool&)rVariable );
164     }
165 }
166