Adonthell  0.4
win_manager.h
Go to the documentation of this file.
1 /*
2  (C) Copyright 2000/2001/2004 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file win_manager.h
21  *
22  * @author Joel Vennin
23  * @brief Declares the win_manager class.
24  */
25 
26 #ifndef _WIN_MANAGER_
27 #define _WIN_MANAGER_
28 
29 #include "str_hash.h"
30 #include "win_theme.h"
31 #include "win_ttf.h"
32 
33 #ifndef SWIG
34 using namespace std;
35 #endif
36 
37 /**
38  * The window manager takes care of basic GUI functions, such as
39  * %input focus, window state updates and displaying everything in
40  * the right order.
41  * It also provides centralised access to fonts and themes, so
42  * that they can be used by different windows without having to
43  * load them multiple times.
44  * For something to appear on screen, it has to be passes to the
45  * window manager.
46  *
47  * Before the window manager can be used, adonthell::main() has
48  * to be called. This instanciates a window manager object and
49  * makes it available to other classes via the static
50  * win_manager::active pointer. All windows added to that instance
51  * have access to the input focus, although only one window can
52  * own it at any given time.
53  *
54  * Another call to adonthell::main() will create a new window
55  * manager instance that grabs the input focus. As long as it
56  * is in existance, none of the parent windows are updated, nor may
57  * they recieve the focus. A call to adonthell::main_quit() will
58  * delete the topmost window manager and return focus to the underlying
59  * windows.
60  *
61  * That way it is possible to create a hierarchie of windows, where
62  * where only windows on the same level may share the input focus,
63  * but only those on the highest level receive input.
64  */
66 {
67 public:
68  /**
69  * Standard constructor
70  */
71  win_manager ();
72 
73  /**
74  * Destructor
75  */
76  ~win_manager ();
77 
78  /**
79  * @name Window handling methods
80  *
81  */
82  //@{
83 
84  /**
85  * Add a window to the window manager.
86  *
87  * @param wnd The window to be added
88  */
89  void add (win_base *wnd);
90 
91  // static bool exist (win_base *);
92 
93  /**
94  * Remove a window from the window manager. The
95  * window is erased from the window list, but not deleted.
96  * If it had the %input focus, it is passed on to the topmost
97  * window, i.e. the last one in the window list (if such a
98  * window exists).
99  *
100  * @param wnd The window to be removed
101  */
102  void remove (win_base *wnd);
103 
104  /**
105  * Update the state of all top level windows. Calls the
106  * %update() method of all windows in the window list. If
107  * that method returns 0, it will be removed from the window
108  * list and deleted.
109  */
110  void update ();
111 
112  /**
113  * Checks for user input. Calls the %input_update() method of
114  * the window that has the %input focus.
115  *
116  * @sa set_focus ()
117  */
118  void input_update ();
119 
120  /**
121  * Draws <b>all</b> windows. If the window hierarchie consists
122  * of multiple levels, the lowest windows are drawn first. Within
123  * each level, windows are drawn in the order they appear in the
124  * window list.
125  */
126  void draw ();
127 
128  /**
129  * Gives the input focus to wnd. Only one window can have the
130  * focus at a time, so focus will be removed from the window
131  * that had it so far. Only the window with the focus will
132  * receive user input.
133  *
134  * @sa input_update ()
135  */
136  void set_focus (win_base *wnd);
137 
138  /**
139  * Closes and deletes all windows of the current level.
140  */
141  void destroy ();
142 
143 #ifndef SWIG
144  /**
145  * Pointer to the active, i.e. topmost window manager.
146  */
148 #endif
149 
150  /**
151  * Use this method to get the active manger from Python
152  */
154  {
155  return active;
156  }
157  //@}
158 
159  /**
160  * @name Theme and font related methods
161  *
162  */
163  //@{
164 
165  /**
166  * Empty for now
167  */
168  static void init (const string & font);
169 
170  /**
171  * Delete all themes and fonts currently loaded.
172  */
173  static void cleanup ();
174 
175  /**
176  * Load a theme from disk.
177  *
178  * @param name The name of the theme to load.
179  */
180  static void add_theme (string name);
181 
182  /**
183  * Delete a theme.
184  *
185  * @param name The name of the theme to delete.
186  * @return
187  * @li true in case of success.
188  * @li false in case of error.
189  */
190  static bool remove_theme (string name);
191 
192  /**
193  * Returns a pointer to a theme. Loads the theme from disk
194  * if it isn't in memory yet.
195  *
196  * @param name The name of the theme to get.
197  * @return Pointer to the theme.
198  */
199  static win_theme *get_theme (string name);
200 
201  /**
202  * Load a font from disk.
203  *
204  * @param name The name of the font to load.
205  */
206  static void add_font (string name);
207 
208  /**
209  * Delete a font.
210  *
211  * @param name The name of the font to delete.
212  * @return
213  * @li true in case of success.
214  * @li false in case of error.
215  */
216  static bool remove_font (string name);
217 
218  /**
219  * Returns a pointer to a font. Loads the font from disk
220  * if it isn't in memory yet.
221  *
222  * @param name The name of the font to get.
223  * @return Pointer to the font.
224  */
225  static win_font *get_font (string name);
226 
227  //@}
228 
229  private:
230 #ifndef SWIG
231  static hash_map<string, win_theme *> theme;
232  static hash_map<string, win_ttf *> font;
233 
234  list<win_base *> wnd_list;
235  list<win_base *>::iterator current;
236  win_base *wnd_focus;
237  win_manager *prev;
238  static string font_file;
239 #endif // SWIG
240 };
241 
242 #endif
243 
static win_manager * active
Pointer to the active, i.e.
Definition: win_manager.h:147
Definition: str_hash.h:71
Declares the hash<string> type, to be able to declare hash_maps with strings as keys.
The window manager takes care of basic GUI functions, such as input focus, window state updates and d...
Definition: win_manager.h:65
static win_manager * get_active()
Use this method to get the active manger from Python.
Definition: win_manager.h:153
Common properties for each win_base&#39;s object.
Definition: win_base.h:51