The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
handler.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program 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  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GUI_WIDGETS_AUXILIARY_EVENT_HANDLER_HPP_INCLUDED
16 #define GUI_WIDGETS_AUXILIARY_EVENT_HANDLER_HPP_INCLUDED
17 #ifdef BOOST_MPL_LIMIT_SET_SIZE
18 #undef BOOST_MPL_LIMIT_SET_SIZE
19 #endif
20 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
21 #define BOOST_MPL_LIMIT_SET_SIZE 30
22 
23 #include <boost/mpl/set.hpp>
24 
25 #include <iosfwd>
26 
27 namespace gui2
28 {
29 
30 namespace event
31 {
32 
33 class tdispatcher;
34 
35 class tmanager
36 {
37 public:
38  tmanager();
39  ~tmanager();
40 };
41 
42 /**
43  * The event send to the dispatcher.
44  *
45  * Events prefixed by SDL are (semi)-real SDL events. The handler does some
46  * minor decoding like splitting the button down event to the proper event but
47  * nothing more. Events without an SDL prefix are generated by another signal
48  * eg the windows signal handler for SDL_MOUSE_MOTION can generate a
49  * MOUSE_ENTER, MOUSE_MOTION and MOUSE_LEAVE event and send that to it's
50  * children.
51  *
52  * @note When adding a new entry to the enum also add a unit test.
53  */
54 enum tevent {
55  DRAW /**< Periodic redraw request. */
56  ,
57  CLOSE_WINDOW /**< A request to close the current window. */
58  ,
60  * A SDL resize request, coordinate is the
61  * new window size.
62  */
63  ,
64  SDL_MOUSE_MOTION /**< A SDL mouse motion event. */
65  ,
66  MOUSE_ENTER /**< A mouse enter event for a widget. */
67  ,
68  MOUSE_MOTION /**< A mouse motion event for a widget. */
69  ,
70  MOUSE_LEAVE /**< A mouse leave event for a widget. */
71  ,
72  SDL_LEFT_BUTTON_DOWN /**< A SDL left mouse button down event. */
73  ,
74  SDL_LEFT_BUTTON_UP /**< A SDL left mouse button up event. */
75  ,
77  * A left mouse button down event for a widget.
78  */
79  ,
81  * A left mouse button up event for a widget.
82  */
83  ,
85  * A left mouse button click event for a
86  * widget.
87  */
88  ,
90  * A left mouse button double click event for
91  * a widget.
92  */
93  ,
94  SDL_MIDDLE_BUTTON_DOWN /**< A SDL middle mouse button down event. */
95  ,
96  SDL_MIDDLE_BUTTON_UP /**< A SDL middle mouse button up event. */
97  ,
98  MIDDLE_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
99  ,
100  MIDDLE_BUTTON_UP /**< See LEFT_BUTTON_UP. */
101  ,
102  MIDDLE_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
103  ,
104  MIDDLE_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
105  ,
106  SDL_RIGHT_BUTTON_DOWN /**< A SDL right mouse button down event. */
107  ,
108  SDL_RIGHT_BUTTON_UP /**< A SDL right mouse button up event. */
109  ,
110  RIGHT_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
111  ,
112  RIGHT_BUTTON_UP /**< See LEFT_BUTTON_UP. */
113  ,
114  RIGHT_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
115  ,
116  RIGHT_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
117  ,
118  SDL_WHEEL_LEFT /**< A SDL wheel left event. */
119  ,
120  SDL_WHEEL_RIGHT /**< A SDL wheel right event. */
121  ,
122  SDL_WHEEL_UP /**< A SDL wheel up event. */
123  ,
124  SDL_WHEEL_DOWN /**< A SDL wheel down event. */
125  ,
126  SDL_KEY_DOWN /**< A SDL key down event. */
127  ,
129  * Send by a widget to notify others it's
130  * being destroyed.
131  */
132  ,
134  * Send by a widget to notify others its
135  * contents or state are modified.
136  *
137  * What modified means is documented per
138  * widget. If not documented the modified
139  * means nothing.
140  */
141  ,
142  RECEIVE_KEYBOARD_FOCUS /**< Widget gets keyboard focus. */
143  ,
144  LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */
145  ,
147  * Request the widget to show its hover
148  * tooltip.
149  */
150  ,
152  * Request the widget to show its hover
153  * tooltip.
154  */
155  ,
157  * The main application window is activated.
158  */
159  ,
161  * Request for somebody to show the tooltip
162  * based on the data send.
163  */
164  ,
166  * Request the widget to show its hover
167  * helptip.
168  */
169  ,
171  * Request for somebody to show the helptip
172  * based on the data send.
173  */
174  ,
176  * Request for somebody to place the widget.
177  * This may also cause updating of more
178  * layout parts.
179  */
180 };
181 
182 /**
183  * Helper for catching use error of tdispatcher::connect_signal.
184  *
185  * This helper is needed as a user can't supply the wrong kind of callback
186  * functions to tdispatcher::connect_signal. If a wrong callback would be send
187  * it will never get called.
188  *
189  * This version is for callbacks without extra parameters.
190  * NOTE some mouse functions like MOUSE_ENTER don't send the mouse coordinates
191  * to the callback function so they are also in this category.
192  */
193 typedef boost::mpl::set<boost::mpl::int_<DRAW>,
194  boost::mpl::int_<CLOSE_WINDOW>,
195  boost::mpl::int_<MOUSE_ENTER>,
196  boost::mpl::int_<MOUSE_LEAVE>,
197  boost::mpl::int_<LEFT_BUTTON_DOWN>,
198  boost::mpl::int_<LEFT_BUTTON_UP>,
199  boost::mpl::int_<LEFT_BUTTON_CLICK>,
200  boost::mpl::int_<LEFT_BUTTON_DOUBLE_CLICK>,
201  boost::mpl::int_<MIDDLE_BUTTON_DOWN>,
202  boost::mpl::int_<MIDDLE_BUTTON_UP>,
203  boost::mpl::int_<MIDDLE_BUTTON_CLICK>,
204  boost::mpl::int_<MIDDLE_BUTTON_DOUBLE_CLICK>,
205  boost::mpl::int_<RIGHT_BUTTON_DOWN>,
206  boost::mpl::int_<RIGHT_BUTTON_UP>,
207  boost::mpl::int_<RIGHT_BUTTON_CLICK>,
208  boost::mpl::int_<RIGHT_BUTTON_DOUBLE_CLICK> >
210 
211 /**
212  * Helper for catching use error of tdispatcher::connect_signal.
213  *
214  * This version is for callbacks with a coordinate as extra parameter.
215  */
216 typedef boost::mpl::set<boost::mpl::int_<SDL_VIDEO_RESIZE>,
217  boost::mpl::int_<SDL_MOUSE_MOTION>,
218  boost::mpl::int_<MOUSE_MOTION>,
219  boost::mpl::int_<SDL_LEFT_BUTTON_DOWN>,
220  boost::mpl::int_<SDL_LEFT_BUTTON_UP>,
221  boost::mpl::int_<SDL_MIDDLE_BUTTON_DOWN>,
222  boost::mpl::int_<SDL_MIDDLE_BUTTON_UP>,
223  boost::mpl::int_<SDL_RIGHT_BUTTON_DOWN>,
224  boost::mpl::int_<SDL_RIGHT_BUTTON_UP>,
225  boost::mpl::int_<SHOW_TOOLTIP>,
226  boost::mpl::int_<SHOW_HELPTIP>,
227  boost::mpl::int_<SDL_WHEEL_UP>,
228  boost::mpl::int_<SDL_WHEEL_DOWN>,
229  boost::mpl::int_<SDL_WHEEL_LEFT>,
230  boost::mpl::int_<SDL_WHEEL_RIGHT> > tset_event_mouse;
231 
232 /**
233  * Helper for catching use error of tdispatcher::connect_signal.
234  *
235  * This version is for callbacks with the keyboard values (these haven't been
236  * determined yet).
237  */
238 typedef boost::mpl::set<boost::mpl::int_<SDL_KEY_DOWN> > tset_event_keyboard;
239 
240 /**
241  * Helper for catching use error of tdispatcher::connect_signal.
242  *
243  * This version is for callbacks with a sender aka notification messages. Like
244  *the
245  * ones in tset_event it has no extra parameters, but this version is only
246  * send to the target and not using the pre and post queue.
247  */
248 typedef boost::mpl::set<boost::mpl::int_<NOTIFY_REMOVAL>,
249  boost::mpl::int_<NOTIFY_MODIFIED>,
250  boost::mpl::int_<RECEIVE_KEYBOARD_FOCUS>,
251  boost::mpl::int_<LOSE_KEYBOARD_FOCUS>,
252  boost::mpl::int_<NOTIFY_REMOVE_TOOLTIP>,
253  boost::mpl::int_<SDL_ACTIVATE> >
255 
256 /**
257  * Helper for catching use error of tdispatcher::connect_signal.
258  *
259  * This version is for callbacks with a sender aka notification messages.
260  * Unlike the notifications this message is send through the chain. The event
261  * is send from a widget all the way up to the window, who always is the
262  * receiver of the message (unless somebody grabbed it before).
263  */
264 typedef boost::mpl::set<boost::mpl::int_<MESSAGE_SHOW_TOOLTIP>,
265  boost::mpl::int_<MESSAGE_SHOW_HELPTIP>,
266  boost::mpl::int_<REQUEST_PLACEMENT> >
268 
269 /**
270  * Connects a dispatcher to the event handler.
271  *
272  * @param dispatcher The dispatcher to connect.
273  */
274 void connect_dispatcher(tdispatcher* dispatcher);
275 
276 /**
277  * Disconnects a dispatcher to the event handler.
278  *
279  * @param dispatcher The dispatcher to disconnect.
280  */
281 void disconnect_dispatcher(tdispatcher* dispatcher);
282 
283 /**
284  * Initializes the location of the mouse.
285  *
286  * After a layout of the window the mouse location needs to be updated to
287  * test whether it entered or left a widget. Also after closing a window it's
288  * needed to send a dummy mouse move.
289  */
290 void init_mouse_location();
291 
292 /**
293  * Captures the mouse.
294  *
295  * A dispatcher can capture the mouse, when for example it's pressed on a
296  * button, this means all mouse events after that are send to that widget.
297  *
298  * @param dispatcher The dispatcher which should get the mouse
299  * focus.
300  */
301 void capture_mouse(tdispatcher* dispatcher);
302 
303 /**
304  * Releases a captured mouse.
305  *
306  * @param dispatcher The dispatcher which should release the mouse
307  * capture.
308  */
309 void release_mouse(tdispatcher* dispatcher);
310 
311 /**
312  * Captures the keyboard.
313  *
314  * A dispatcher can capture the keyboard, when for example it's pressed on a
315  * button, this means all keyboard events after that are send to that widget.
316  *
317  * @param dispatcher The dispatcher which should get the keyboard
318  * focus.
319  */
320 void capture_keyboard(tdispatcher* dispatcher);
321 
322 std::ostream& operator<<(std::ostream& stream, const tevent event);
323 
324 } // namespace event
325 
326 /**
327  * Is a dialog open?
328  *
329  * @note added as backwards compatibility for gui::is_in_dialog.
330  */
331 bool is_in_dialog();
332 
333 } // namespace gui2
334 
335 #endif
Widget loses keyboard focus.
Definition: handler.hpp:144
Request for somebody to show the tooltip based on the data send.
Definition: handler.hpp:160
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:116
A SDL middle mouse button up event.
Definition: handler.hpp:96
A mouse leave event for a widget.
Definition: handler.hpp:70
A left mouse button double click event for a widget.
Definition: handler.hpp:89
A request to close the current window.
Definition: handler.hpp:57
boost::mpl::set< boost::mpl::int_< DRAW >, boost::mpl::int_< CLOSE_WINDOW >, boost::mpl::int_< MOUSE_ENTER >, boost::mpl::int_< MOUSE_LEAVE >, boost::mpl::int_< LEFT_BUTTON_DOWN >, boost::mpl::int_< LEFT_BUTTON_UP >, boost::mpl::int_< LEFT_BUTTON_CLICK >, boost::mpl::int_< LEFT_BUTTON_DOUBLE_CLICK >, boost::mpl::int_< MIDDLE_BUTTON_DOWN >, boost::mpl::int_< MIDDLE_BUTTON_UP >, boost::mpl::int_< MIDDLE_BUTTON_CLICK >, boost::mpl::int_< MIDDLE_BUTTON_DOUBLE_CLICK >, boost::mpl::int_< RIGHT_BUTTON_DOWN >, boost::mpl::int_< RIGHT_BUTTON_UP >, boost::mpl::int_< RIGHT_BUTTON_CLICK >, boost::mpl::int_< RIGHT_BUTTON_DOUBLE_CLICK > > tset_event
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:209
A mouse enter event for a widget.
Definition: handler.hpp:66
boost::mpl::set< boost::mpl::int_< SDL_VIDEO_RESIZE >, boost::mpl::int_< SDL_MOUSE_MOTION >, boost::mpl::int_< MOUSE_MOTION >, boost::mpl::int_< SDL_LEFT_BUTTON_DOWN >, boost::mpl::int_< SDL_LEFT_BUTTON_UP >, boost::mpl::int_< SDL_MIDDLE_BUTTON_DOWN >, boost::mpl::int_< SDL_MIDDLE_BUTTON_UP >, boost::mpl::int_< SDL_RIGHT_BUTTON_DOWN >, boost::mpl::int_< SDL_RIGHT_BUTTON_UP >, boost::mpl::int_< SHOW_TOOLTIP >, boost::mpl::int_< SHOW_HELPTIP >, boost::mpl::int_< SDL_WHEEL_UP >, boost::mpl::int_< SDL_WHEEL_DOWN >, boost::mpl::int_< SDL_WHEEL_LEFT >, boost::mpl::int_< SDL_WHEEL_RIGHT > > tset_event_mouse
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:230
See LEFT_BUTTON_UP.
Definition: handler.hpp:100
Widget gets keyboard focus.
Definition: handler.hpp:142
std::ostream & operator<<(std::ostream &stream, const tevent event)
Definition: handler.cpp:826
bool is_in_dialog()
Is a dialog open?
Definition: handler.cpp:960
Base class for event handling.
Definition: dispatcher.hpp:122
A left mouse button down event for a widget.
Definition: handler.hpp:76
boost::mpl::set< boost::mpl::int_< MESSAGE_SHOW_TOOLTIP >, boost::mpl::int_< MESSAGE_SHOW_HELPTIP >, boost::mpl::int_< REQUEST_PLACEMENT > > tset_event_message
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:267
Request the widget to show its hover helptip.
Definition: handler.hpp:165
See LEFT_BUTTON_UP.
Definition: handler.hpp:112
See LEFT_BUTTON_DOWN.
Definition: handler.hpp:110
A left mouse button click event for a widget.
Definition: handler.hpp:84
A SDL mouse motion event.
Definition: handler.hpp:64
void init_mouse_location()
Initializes the location of the mouse.
Definition: handler.cpp:788
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
GLuint GLuint stream
Definition: glew.h:5239
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:104
See LEFT_BUTTON_DOWN.
Definition: handler.hpp:98
A SDL wheel right event.
Definition: handler.hpp:120
A SDL resize request, coordinate is the new window size.
Definition: handler.hpp:59
Periodic redraw request.
Definition: handler.hpp:55
A SDL middle mouse button down event.
Definition: handler.hpp:94
Request for somebody to show the helptip based on the data send.
Definition: handler.hpp:170
void release_mouse(tdispatcher *dispatcher)
Releases a captured mouse.
Definition: handler.cpp:808
Send by a widget to notify others its contents or state are modified.
Definition: handler.hpp:133
A SDL wheel left event.
Definition: handler.hpp:118
A SDL left mouse button up event.
Definition: handler.hpp:74
A mouse motion event for a widget.
Definition: handler.hpp:68
A SDL wheel up event.
Definition: handler.hpp:122
Request for somebody to place the widget.
Definition: handler.hpp:175
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
Request the widget to show its hover tooltip.
Definition: handler.hpp:146
A left mouse button up event for a widget.
Definition: handler.hpp:80
boost::mpl::set< boost::mpl::int_< NOTIFY_REMOVAL >, boost::mpl::int_< NOTIFY_MODIFIED >, boost::mpl::int_< RECEIVE_KEYBOARD_FOCUS >, boost::mpl::int_< LOSE_KEYBOARD_FOCUS >, boost::mpl::int_< NOTIFY_REMOVE_TOOLTIP >, boost::mpl::int_< SDL_ACTIVATE > > tset_event_notification
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:254
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:114
void connect_dispatcher(tdispatcher *dispatcher)
Connects a dispatcher to the event handler.
Definition: handler.cpp:774
A SDL left mouse button down event.
Definition: handler.hpp:72
A SDL right mouse button down event.
Definition: handler.hpp:106
Send by a widget to notify others it's being destroyed.
Definition: handler.hpp:128
void capture_mouse(tdispatcher *dispatcher)
Captures the mouse.
Definition: handler.cpp:801
Request the widget to show its hover tooltip.
Definition: handler.hpp:151
A SDL wheel down event.
Definition: handler.hpp:124
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:102
cl_event event
Definition: glew.h:3070
A SDL right mouse button up event.
Definition: handler.hpp:108
void disconnect_dispatcher(tdispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
Definition: handler.cpp:781
The main application window is activated.
Definition: handler.hpp:156
A SDL key down event.
Definition: handler.hpp:126
boost::mpl::set< boost::mpl::int_< SDL_KEY_DOWN > > tset_event_keyboard
Helper for catching use error of tdispatcher::connect_signal.
Definition: handler.hpp:238
void capture_keyboard(tdispatcher *dispatcher)
Captures the keyboard.
Definition: handler.cpp:817