1 /*****************************************************************************
2  * window_manager.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id: ede1f878ac8296eb85065c3a107d8bb8043b9904 $
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 along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 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 "../utils/position.hpp"
31 #include <list>
32 #include <map>
33 #include <set>
34 #include <utility>
35 
36 
37 class GenericFont;
38 class GenericLayout;
39 class Anchor;
40 class Tooltip;
41 class Popup;
42 
43 
44 /// Window manager for skin windows
45 class WindowManager: public SkinObject
46 {
47 public:
48     /// Direction of the resizing
49     enum Direction_t
50     {
51         kResizeE,   // East
52         kResizeSE,  // South-East
53         kResizeS,   // South
54         kNone       // Reserved for internal use
55     };
56     WindowManager( intf_thread_t *pIntf );
57     virtual ~WindowManager();
58 
59     /**
60      * Add a window to the list of known windows. Necessary if you want
61      * your window to be movable...
62      */
63     void registerWindow( TopWindow &rWindow );
64 
65     /// Remove a previously registered window
66     void unregisterWindow( TopWindow &rWindow );
67 
68     /// Tell the window manager that a move is initiated for rWindow
69     void startMove( TopWindow &rWindow );
70 
71     /// Tell the window manager that the current move ended
72     void stopMove();
73 
74     /**
75      * Move the rWindow window to (left, top), and move all its
76      * anchored windows.
77      * If a new anchoring is detected, the windows will move accordingly.
78      */
79     void move( TopWindow &rWindow, int left, int top ) const;
80 
81     /// Tell the window manager that a resize is initiated for rLayout
82     void startResize( GenericLayout &rLayout, Direction_t direction );
83 
84     /// Tell the window manager that the current resizing ended
85     void stopResize();
86 
87     /**
88      * Resize the rLayout layout to (width, height), and move all its
89      * anchored windows, if some anchors are moved during the resizing.
90      * If a new anchoring is detected, the windows will move (or resize)
91      * accordingly.
92      */
93     void resize( GenericLayout &rLayout, int width, int height ) const;
94 
95     /// Maximize the given window
96     void maximize( TopWindow &rWindow );
97 
98     /// Unmaximize the given window
99     void unmaximize( TopWindow &rWindow );
100 
101     /// Raise all the registered windows
102     void raiseAll() const;
103 
104     /// Show all the registered windows
105     void showAll( bool firstTime = false ) const;
106 
107     /// Hide all the registered windows
108     void hideAll() const;
109 
110     /// Synchronize the windows with their visibility variable
111     void synchVisibility() const;
112 
113     /// Save the current visibility of the windows
114     void saveVisibility();
115 
116     /// Restore the saved visibility of the windows
117     void restoreVisibility() const;
118 
119     /// Raise the given window
raise(TopWindow & rWindow) const120     void raise( TopWindow &rWindow ) const { rWindow.raise(); }
121 
122     /// Show the given window
123     void show( TopWindow &rWindow ) const;
124 
125     /// Hide the given window
hide(TopWindow & rWindow) const126     void hide( TopWindow &rWindow ) const { rWindow.hide(); }
127 
128     /// Set/unset all the windows on top
129     void setOnTop( bool b_ontop );
130 
131     /// Toggle all the windows on top
132     void toggleOnTop();
133 
134     /// Set the magnetism of screen edges
setMagnetValue(int magnet)135     void setMagnetValue( int magnet ) { m_magnet = magnet; }
136 
137     /// Set the alpha value of the static windows
setAlphaValue(int alpha)138     void setAlphaValue( int alpha )
139         { m_alpha = (m_opacity != 255) ? m_opacity : alpha; }
140 
141     /// Set the alpha value of the moving windows
setMoveAlphaValue(int moveAlpha)142     void setMoveAlphaValue( int moveAlpha )
143         { m_moveAlpha = (m_opacity != 255) ? m_opacity : moveAlpha; }
144 
145     /// Create the tooltip window
146     void createTooltip( const GenericFont &rTipFont );
147 
148     /// Show the tooltip window
149     void showTooltip();
150 
151     /// Hide the tooltip window
152     void hideTooltip();
153 
154     /// Add a layout of the given window. This new layout will be the
155     /// active one.
156     void addLayout( TopWindow &rWindow, GenericLayout &rLayout );
157 
158     /// Change the active layout of the given window
159     void setActiveLayout( TopWindow &rWindow, GenericLayout &rLayout );
160 
161     /// Mark the given popup as active
setActivePopup(Popup & rPopup)162     void setActivePopup( Popup &rPopup ) { m_pPopup = &rPopup; }
163 
164     /// Return the active popup, or NULL if none is active
getActivePopup() const165     Popup * getActivePopup() const { return m_pPopup; }
166 
167     /// getter to know whether opacity is needed
isOpacityNeeded() const168     bool isOpacityNeeded() const
169     { return (m_opacityEnabled && (m_alpha != 255 || m_moveAlpha != 255 )); }
170 
171 private:
172     /// Some useful typedefs for lazy people like me
173     typedef std::set<TopWindow*> WinSet_t;
174     typedef std::list<Anchor*> AncList_t;
175 
176     /// Dependencies map
177     /**
178      * This map represents the graph of anchored windows: it associates
179      * to a given window all the windows that are directly anchored by it.
180      * This is not transitive, i.e. if a is in m_dep[b] and if b is in
181      * m_dep[c], it doesn't mean that a is in m_dep[c] (in fact, it
182      * would be extremely rare...)
183      */
184     std::map<TopWindow*, WinSet_t> m_dependencies;
185     /// Store all the windows
186     WinSet_t m_allWindows;
187     /**
188      * Store the windows that were visible when saveVisibility() was
189      * last called.
190      */
191     WinSet_t m_savedWindows;
192     /// Store the moving windows
193     /**
194      * This set is updated at every start of move.
195      */
196     WinSet_t m_movingWindows;
197     /**
198      * Store the moving windows in the context of resizing
199      * These sets are updated at every start of move
200      */
201     //@{
202     WinSet_t m_resizeMovingE;
203     WinSet_t m_resizeMovingS;
204     WinSet_t m_resizeMovingSE;
205     //@}
206     /// Indicate whether the windows are currently on top
207     VariablePtr m_cVarOnTop;
208     /// Magnetism of the screen edges (= scope of action)
209     int m_magnet;
210     /// Alpha value of the static windows
211     int m_alpha;
212     /// Alpha value of the moving windows
213     int m_moveAlpha;
214     /// transparency set by user
215     bool m_opacityEnabled;
216     /// opacity overridden by user
217     int m_opacity;
218     /// Direction of the current resizing
219     Direction_t m_direction;
220     /// Rect of the last maximized window
221     SkinsRect m_maximizeRect;
222     /// Tooltip
223     Tooltip *m_pTooltip;
224     /// Active popup, if any
225     Popup *m_pPopup;
226 
227     /// Recursively build a set of windows anchored to the one given.
228     void buildDependSet( WinSet_t &rWinSet, TopWindow *pWindow );
229 
230     /// Check anchoring
231     /**
232      * This function updates xOffset and yOffset, to take care of a new
233      * anchoring (if any)
234      */
235     void checkAnchors( TopWindow *pWindow, int &xOffset, int &yOffset ) const;
236 };
237 
238 
239 #endif
240