]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/generic_layout.hpp
7574f1fc087ca01f9e4fd5cd2bd05d8fbbcf4719
[vlc] / modules / gui / skins2 / src / generic_layout.hpp
1 /*****************************************************************************
2  * generic_layout.hpp
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 #ifndef GENERIC_LAYOUT_HPP
26 #define GENERIC_LAYOUT_HPP
27
28 #include "skin_common.hpp"
29 #include "top_window.hpp"
30 #include "../utils/pointer.hpp"
31 #include "../utils/position.hpp"
32
33 #include <list>
34
35 class Anchor;
36 class OSGraphics;
37 class CtrlGeneric;
38 class CtrlVideo;
39 class VarBoolImpl;
40
41
42 /// Control and its associated layer
43 struct LayeredControl
44 {
45     LayeredControl( CtrlGeneric *pControl, int layer ):
46         m_pControl( pControl ), m_layer( layer ) {}
47
48     /// Pointer on the control
49     CtrlGeneric *m_pControl;
50     /// Layer number
51     int m_layer;
52 };
53
54
55 /// Base class for layouts
56 class GenericLayout: public SkinObject
57 {
58     public:
59         GenericLayout( intf_thread_t *pIntf, int width, int height,
60                        int minWidth, int maxWidth, int minHeight,
61                        int maxHeight );
62
63         virtual ~GenericLayout();
64
65         /// Attach the layout to a window
66         virtual void setWindow( TopWindow *pWindow );
67
68         /// Get the associated window, if any
69         virtual TopWindow *getWindow() const { return m_pWindow; }
70
71         /// Called by a control which wants to capture the mouse
72         virtual void onControlCapture( const CtrlGeneric &rCtrl );
73
74         /// Called by a control which wants to release the mouse
75         virtual void onControlRelease( const CtrlGeneric &rCtrl );
76
77         /// Refresh the window
78         virtual void refreshAll();
79
80         /// Refresh a rectangular portion of the window
81         virtual void refreshRect( int x, int y, int width, int height );
82
83         /// Get the image of the layout
84         virtual OSGraphics *getImage() const { return m_pImage; }
85
86         /// Get the position of the layout (relative to the screen)
87         /**
88          * Note: These values are different from the m_rect.getLeft() and
89          * m_rect.getTop(), which always return 0.
90          * The latter methods are there as a "root rect" for the panels and
91          * controls, since each control knows its parent rect, but returns
92          * coordinates relative to the root rect.
93          */
94         virtual int getLeft() const { return m_pWindow->getLeft(); }
95         virtual int getTop() const { return m_pWindow->getTop(); }
96
97         /// Get the size of the layout
98         virtual int getWidth() const { return m_rect.getWidth(); }
99         virtual int getHeight() const { return m_rect.getHeight(); }
100         virtual const GenericRect &getRect() const { return m_rect; }
101
102         /// Get the minimum and maximum size of the layout
103         virtual int getMinWidth() const { return m_minWidth; }
104         virtual int getMaxWidth() const { return m_maxWidth; }
105         virtual int getMinHeight() const { return m_minHeight; }
106         virtual int getMaxHeight() const { return m_maxHeight; }
107
108         /// Resize the layout
109         virtual void resize( int width, int height );
110
111         /**
112          * Add a control in the layout at the given position, and
113          * the optional given layer
114          */
115         virtual void addControl( CtrlGeneric *pControl,
116                                  const Position &rPosition,
117                                  int layer );
118
119         /// Get the list of the controls in this layout, by layer order
120         virtual const list<LayeredControl> &getControlList() const;
121
122         /// Called by a control when its image has changed
123         /**
124          * The arguments indicate the size of the rectangle to refresh,
125          * and the offset (from the control position) of this rectangle.
126          * Use a negative width or height to refresh the layout completely
127          */
128         virtual void onControlUpdate( const CtrlGeneric &rCtrl,
129                                       int width, int height,
130                                       int xOffSet, int yOffSet );
131
132         /// Get the list of the anchors of this layout
133         virtual const list<Anchor*>& getAnchorList() const;
134
135         /// Add an anchor to this layout
136         virtual void addAnchor( Anchor *pAnchor );
137
138         /// Called when the layout is shown
139         virtual void onShow();
140
141         /// Called when the layout is hidden
142         virtual void onHide();
143
144         /// Give access to the "active layout" variable
145         // FIXME: we give read/write access
146         VarBoolImpl &getActiveVar() { return *m_pVarActive; }
147
148     private:
149         /// Parent window of the layout
150         TopWindow *m_pWindow;
151         /// Layout size
152         SkinsRect m_rect;
153         int m_minWidth, m_maxWidth;
154         int m_minHeight, m_maxHeight;
155         /// Image of the layout
156         OSGraphics *m_pImage;
157         /// List of the controls in the layout
158         list<LayeredControl> m_controlList;
159         /// Video control
160         CtrlVideo *m_pVideoControl;
161         /// List of the anchors in the layout
162         list<Anchor*> m_anchorList;
163         /// Flag to know if the layout is visible
164         bool m_visible;
165         /// Variable for the "active state" of the layout
166         /**
167          * Note: the layout is not an observer on this variable, because it
168          * cannot be changed externally (i.e. without an explicit change of
169          * layout). This way, we avoid using a setActiveLayoutInner method.
170          */
171         mutable VarBoolImpl *m_pVarActive;
172 };
173
174
175 typedef CountedPtr<GenericLayout> GenericLayoutPtr;
176
177
178 #endif