]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/window_manager.hpp
* modules/gui/skins2/*: More simplifications of the same kind
[vlc] / modules / gui / skins2 / src / window_manager.hpp
1 /*****************************************************************************
2  * window_manager.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 WINDOW_MANAGER_HPP
26 #define WINDOW_MANAGER_HPP
27
28 #include "skin_common.hpp"
29 #include "top_window.hpp"
30 #include <list>
31 #include <map>
32 #include <set>
33 #include <utility>
34
35
36 class GenericFont;
37 class GenericLayout;
38 class Anchor;
39 class Tooltip;
40 class Popup;
41
42
43 /// Window manager for skin windows
44 class WindowManager: public SkinObject
45 {
46     public:
47         /// Direction of the resizing
48         enum Direction_t
49         {
50             kResizeE,   // East
51             kResizeSE,  // South-East
52             kResizeS,   // South
53             kNone       // Reserved for internal use
54         };
55
56         /// Constructor
57         WindowManager( intf_thread_t *pIntf);
58
59         /// Destructor
60         virtual ~WindowManager();
61
62         /// Add a window to the list of known windows. Necessary if you want
63         /// your window to be movable...
64         void registerWindow( TopWindow &rWindow );
65
66         /// Remove a previously registered window
67         void unregisterWindow( TopWindow &rWindow );
68
69         /// Tell the window manager that a move is initiated for rWindow
70         void startMove( TopWindow &rWindow );
71
72         /// Tell the window manager that the current move ended
73         void stopMove();
74
75         /**
76          * Move the rWindow window to (left, top), and move all its
77          * anchored windows.
78          * If a new anchoring is detected, the windows will move accordingly.
79          */
80         void move( TopWindow &rWindow, int left, int top ) const;
81
82         /// Tell the window manager that a resize is initiated for rWindow
83         void startResize( GenericLayout &rLayout, Direction_t direction );
84
85         /// Tell the window manager that the current resizing ended
86         void stopResize();
87
88         /**
89          * Resize the rWindow window to (width, height), and move all its
90          * anchored windows, if some anchors are moved during the resizing.
91          * If a new anchoring is detected, the windows will move (or resize)
92          * accordingly.
93          */
94         void resize( GenericLayout &rLayout, int width, int height ) const;
95
96         /// Raise all the registered windows
97         void raiseAll() const;
98
99         /// Show all the registered windows
100         void showAll( bool firstTime = false ) const;
101
102         /// Hide all the registered windows
103         void hideAll() const;
104
105         /// Synchronize the windows with their visibility variable
106         void synchVisibility() const;
107
108         /// Raise the given window
109         void raise( TopWindow &rWindow ) const { rWindow.raise(); }
110
111         /// Show the given window
112         void show( TopWindow &rWindow ) const { rWindow.show(); }
113
114         /// Hide the given window
115         void hide( TopWindow &rWindow ) const { rWindow.hide(); }
116
117         /// Toggle all the windows on top
118         void toggleOnTop();
119
120         /// Set the magnetism of screen edges
121         void setMagnetValue( int magnet ) { m_magnet = magnet; }
122
123         /// Set the alpha value of the static windows
124         void setAlphaValue( int alpha ) { m_alpha = alpha; }
125
126         /// Set the alpha value of the moving windows
127         void setMoveAlphaValue( int moveAlpha ) { m_moveAlpha = moveAlpha; }
128
129         /// Create the tooltip window
130         void createTooltip( const GenericFont &rTipFont );
131
132         /// Show the tooltip window
133         void showTooltip();
134
135         /// Hide the tooltip window
136         void hideTooltip();
137
138         /// Add a layout of the given window. This new layout will be the
139         /// active one.
140         void addLayout( TopWindow &rWindow, GenericLayout &rLayout );
141
142         /// Change the active layout of the given window
143         void setActiveLayout( TopWindow &rWindow, GenericLayout &rLayout );
144
145         /// Mark the given popup as active
146         void setActivePopup( Popup &rPopup ) { m_pPopup = &rPopup; }
147
148         /// Return the active popup, or NULL if none is active
149         Popup * getActivePopup() const { return m_pPopup; }
150
151     private:
152         /// Some useful typedefs for lazy people like me
153         typedef set<TopWindow*> WinSet_t;
154         typedef list<Anchor*> AncList_t;
155
156         /// Dependencies map
157         /**
158          * This map represents the graph of anchored windows: it associates
159          * to a given window all the windows that are directly anchored by it.
160          * This is not transitive, i.e. if a is in m_dep[b] and if b is in
161          * m_dep[c], it doesn't mean that a is in m_dep[c] (in fact, it
162          * would be extremely rare...)
163          */
164         map<TopWindow*, WinSet_t> m_dependencies;
165         /// Store all the windows
166         WinSet_t m_allWindows;
167         /// Store the moving windows; this set is updated at every start of
168         /// move.
169         WinSet_t m_movingWindows;
170         /**
171          * Store the moving windows in the context of resizing
172          * These sets are updated at every start of move
173          */
174         //@{
175         WinSet_t m_resizeMovingE;
176         WinSet_t m_resizeMovingS;
177         WinSet_t m_resizeMovingSE;
178         //@}
179         /// Indicate whether the windows are currently on top
180         VariablePtr m_cVarOnTop;
181         /// Magnetism of the screen edges (= scope of action)
182         int m_magnet;
183         /// Alpha value of the static windows
184         int m_alpha;
185         /// Alpha value of the moving windows
186         int m_moveAlpha;
187         /// Direction of the current resizing
188         Direction_t m_direction;
189         /// Tooltip
190         Tooltip *m_pTooltip;
191         /// Active popup, if any
192         Popup *m_pPopup;
193
194         /// Recursively build a set of windows anchored to the one given.
195         void buildDependSet( WinSet_t &rWinSet, TopWindow *pWindow );
196
197         /// Check anchoring
198         /**
199          * This function updates xOffset and yOffset, to take care of a new
200          * anchoring (if any)
201          */
202         void checkAnchors( TopWindow *pWindow,
203                            int &xOffset, int &yOffset ) const;
204 };
205
206
207 #endif