00001 /* $Id: handler.hpp 54167 2012-05-13 13:33:24Z mordante $ */ 00002 /* 00003 Copyright (C) 2009 - 2012 by Mark de Wever <koraq@xs4all.nl> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef GUI_WIDGETS_AUXILIARY_EVENT_HANDLER_HPP_INCLUDED 00017 #define GUI_WIDGETS_AUXILIARY_EVENT_HANDLER_HPP_INCLUDED 00018 00019 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS 00020 #define BOOST_MPL_LIMIT_SET_SIZE 30 00021 00022 #include <boost/mpl/set.hpp> 00023 00024 #include <iosfwd> 00025 00026 namespace gui2 { 00027 00028 namespace event { 00029 00030 class tdispatcher; 00031 00032 class tmanager 00033 { 00034 public: 00035 tmanager(); 00036 ~tmanager(); 00037 }; 00038 00039 /** 00040 * The event send to the dispatcher. 00041 * 00042 * Events prefixed by SDL are (semi)-real SDL events. The handler does some 00043 * minor decoding like splitting the button down event to the proper event but 00044 * nothing more. Events without an SDL prefix are generated by another signal 00045 * eg the windows signal handler for SDL_MOUSE_MOTION can generate a 00046 * MOUSE_ENTER, MOUSE_MOTION and MOUSE_LEAVE event and send that to it's 00047 * children. 00048 * 00049 * @note When adding a new entry to the enum also add a unit test. 00050 */ 00051 enum tevent { 00052 DRAW /**< Periodic redraw request. */ 00053 00054 , CLOSE_WINDOW /**< A request to close the current window. */ 00055 , SDL_VIDEO_RESIZE /**< 00056 * A SDL resize request, coordinate is the 00057 * new window size. 00058 */ 00059 00060 , SDL_MOUSE_MOTION /**< A SDL mouse motion event. */ 00061 , MOUSE_ENTER /**< A mouse enter event for a widget. */ 00062 , MOUSE_MOTION /**< A mouse motion event for a widget. */ 00063 , MOUSE_LEAVE /**< A mouse leave event for a widget. */ 00064 00065 , SDL_LEFT_BUTTON_DOWN /**< A SDL left mouse button down event. */ 00066 , SDL_LEFT_BUTTON_UP /**< A SDL left mouse button up event. */ 00067 , LEFT_BUTTON_DOWN /**< 00068 * A left mouse button down event for a wiget. 00069 */ 00070 , LEFT_BUTTON_UP /**< 00071 * A left mouse button up event for a wiget. 00072 */ 00073 , LEFT_BUTTON_CLICK /**< 00074 * A left mouse button click event for a 00075 * wiget. 00076 */ 00077 , LEFT_BUTTON_DOUBLE_CLICK /**< 00078 * A left mouse button double click event for 00079 * a wiget. 00080 */ 00081 , SDL_MIDDLE_BUTTON_DOWN /**< A SDL middle mouse button down event. */ 00082 , SDL_MIDDLE_BUTTON_UP /**< A SDL middle mouse button up event. */ 00083 , MIDDLE_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */ 00084 , MIDDLE_BUTTON_UP /**< See LEFT_BUTTON_UP. */ 00085 , MIDDLE_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */ 00086 , MIDDLE_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */ 00087 00088 , SDL_RIGHT_BUTTON_DOWN /**< A SDL right mouse button down event. */ 00089 , SDL_RIGHT_BUTTON_UP /**< A SDL right mouse button up event. */ 00090 , RIGHT_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */ 00091 , RIGHT_BUTTON_UP /**< See LEFT_BUTTON_UP. */ 00092 , RIGHT_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */ 00093 , RIGHT_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */ 00094 00095 , SDL_WHEEL_LEFT /**< A SDL wheel left event. */ 00096 , SDL_WHEEL_RIGHT /**< A SDL wheel right event. */ 00097 , SDL_WHEEL_UP /**< A SDL wheel up event. */ 00098 , SDL_WHEEL_DOWN /**< A SDL wheel down event. */ 00099 00100 , SDL_KEY_DOWN /**< A SDL key down event. */ 00101 00102 , NOTIFY_REMOVAL /**< 00103 * Send by a widget to notify others it's 00104 * being destroyed. 00105 */ 00106 , NOTIFY_MODIFIED /**< 00107 * Send by a widget to notify others its 00108 * contents or state are modified. 00109 * 00110 * What modified means is documented per 00111 * widget. If not documented the modified 00112 * means nothing. 00113 */ 00114 00115 , RECEIVE_KEYBOARD_FOCUS /**< Widget gets keyboard focus. */ 00116 , LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */ 00117 , SHOW_TOOLTIP /**< 00118 * Request the widget to show its hover 00119 * tooltip. 00120 */ 00121 , NOTIFY_REMOVE_TOOLTIP /**< 00122 * Request the widget to show its hover 00123 * tooltip. 00124 */ 00125 , SDL_ACTIVATE /**< 00126 * The main application window is activated. 00127 */ 00128 00129 , MESSAGE_SHOW_TOOLTIP /**< 00130 * Request for somebody to show the tooltip 00131 * based on the data send. 00132 */ 00133 , SHOW_HELPTIP /**< 00134 * Request the widget to show its hover 00135 * helptip. 00136 */ 00137 , MESSAGE_SHOW_HELPTIP /**< 00138 * Request for somebody to show the helptip 00139 * based on the data send. 00140 */ 00141 , REQUEST_PLACEMENT /**< 00142 * Request for somebody to place the widget. 00143 * This may also cause updating of more 00144 * layoyt parts. 00145 */ 00146 }; 00147 00148 /** 00149 * Helper for catching use error of tdispatcher::connect_signal. 00150 * 00151 * This helper is needed as a user can't supply the wrong kind of callback 00152 * functions to tdispatcher::connect_signal. If a wrong callback would be send 00153 * it will never get called. 00154 * 00155 * This version is for callbacks without extra parameters. 00156 * NOTE some mouse functions like MOUSE_ENTER don't send the mouse coordinates 00157 * to the callback function so they are also in this catagory. 00158 */ 00159 typedef 00160 boost::mpl::set< 00161 boost::mpl::int_<DRAW> 00162 , boost::mpl::int_<CLOSE_WINDOW> 00163 , boost::mpl::int_<MOUSE_ENTER> 00164 , boost::mpl::int_<MOUSE_LEAVE> 00165 , boost::mpl::int_<LEFT_BUTTON_DOWN> 00166 , boost::mpl::int_<LEFT_BUTTON_UP> 00167 , boost::mpl::int_<LEFT_BUTTON_CLICK> 00168 , boost::mpl::int_<LEFT_BUTTON_DOUBLE_CLICK> 00169 , boost::mpl::int_<MIDDLE_BUTTON_DOWN> 00170 , boost::mpl::int_<MIDDLE_BUTTON_UP> 00171 , boost::mpl::int_<MIDDLE_BUTTON_CLICK> 00172 , boost::mpl::int_<MIDDLE_BUTTON_DOUBLE_CLICK> 00173 , boost::mpl::int_<RIGHT_BUTTON_DOWN> 00174 , boost::mpl::int_<RIGHT_BUTTON_UP> 00175 , boost::mpl::int_<RIGHT_BUTTON_CLICK> 00176 , boost::mpl::int_<RIGHT_BUTTON_DOUBLE_CLICK> 00177 > 00178 tset_event; 00179 00180 /** 00181 * Helper for catching use error of tdispatcher::connect_signal. 00182 * 00183 * This version is for callbacks with a coordinate as extra parameter. 00184 */ 00185 typedef 00186 boost::mpl::set< 00187 boost::mpl::int_<SDL_VIDEO_RESIZE> 00188 , boost::mpl::int_<SDL_MOUSE_MOTION> 00189 , boost::mpl::int_<MOUSE_MOTION> 00190 , boost::mpl::int_<SDL_LEFT_BUTTON_DOWN> 00191 , boost::mpl::int_<SDL_LEFT_BUTTON_UP> 00192 , boost::mpl::int_<SDL_MIDDLE_BUTTON_DOWN> 00193 , boost::mpl::int_<SDL_MIDDLE_BUTTON_UP> 00194 , boost::mpl::int_<SDL_RIGHT_BUTTON_DOWN> 00195 , boost::mpl::int_<SDL_RIGHT_BUTTON_UP> 00196 , boost::mpl::int_<SHOW_TOOLTIP> 00197 , boost::mpl::int_<SHOW_HELPTIP> 00198 , boost::mpl::int_<SDL_WHEEL_UP> 00199 , boost::mpl::int_<SDL_WHEEL_DOWN> 00200 , boost::mpl::int_<SDL_WHEEL_LEFT> 00201 , boost::mpl::int_<SDL_WHEEL_RIGHT> 00202 > 00203 tset_event_mouse; 00204 00205 /** 00206 * Helper for catching use error of tdispatcher::connect_signal. 00207 * 00208 * This version is for callbacks with the keyboard values (these haven't been 00209 * determined yet). 00210 */ 00211 typedef 00212 boost::mpl::set< 00213 boost::mpl::int_<SDL_KEY_DOWN> 00214 > 00215 tset_event_keyboard; 00216 00217 /** 00218 * Helper for catching use error of tdispatcher::connect_signal. 00219 * 00220 * This version is for callbacks with a sender aka notification messages. Like the 00221 * onces in tset_event it has no extra parameters, but this version is only 00222 * send to the target and not using the pre and post queue. 00223 */ 00224 typedef 00225 boost::mpl::set< 00226 boost::mpl::int_<NOTIFY_REMOVAL> 00227 , boost::mpl::int_<NOTIFY_MODIFIED> 00228 , boost::mpl::int_<RECEIVE_KEYBOARD_FOCUS> 00229 , boost::mpl::int_<LOSE_KEYBOARD_FOCUS> 00230 , boost::mpl::int_<NOTIFY_REMOVE_TOOLTIP> 00231 , boost::mpl::int_<SDL_ACTIVATE> 00232 > 00233 tset_event_notification; 00234 00235 /** 00236 * Helper for catching use error of tdispatcher::connect_signal. 00237 * 00238 * This version is for callbacks with a sender aka notification messages. 00239 * Unlike the notifications this message is send through the chain. The event 00240 * is send from a widget all the way up to the window, who always is the 00241 * receiver of the message (unless somebody grabbed it before). 00242 */ 00243 typedef 00244 boost::mpl::set< 00245 boost::mpl::int_<MESSAGE_SHOW_TOOLTIP> 00246 , boost::mpl::int_<MESSAGE_SHOW_HELPTIP> 00247 , boost::mpl::int_<REQUEST_PLACEMENT> 00248 > 00249 tset_event_message; 00250 00251 /** 00252 * Connects a dispatcher to the event handler. 00253 * 00254 * @param dispatcher The dispatcher to connect. 00255 */ 00256 void connect_dispatcher(tdispatcher* dispatcher); 00257 00258 /** 00259 * Disconnects a dispatcher to the event handler. 00260 * 00261 * @param dispatcher The dispatcher to disconnect. 00262 */ 00263 void disconnect_dispatcher(tdispatcher* dispatcher); 00264 00265 /** 00266 * Initializes the location of the mouse. 00267 * 00268 * After a layout of the window the mouse location needs to be updated to 00269 * test whether it entered or left a widget. Also after closing a window it's 00270 * needed to send a dummy mouse move. 00271 */ 00272 void init_mouse_location(); 00273 00274 /** 00275 * Captures the mouse. 00276 * 00277 * A dispatcher can capture the mouse, when for example it's pressed on a 00278 * button, this means all mouse events after that are send to that widget. 00279 * 00280 * @param dispatcher The dispatcher which should get the mouse 00281 * focus. 00282 */ 00283 void capture_mouse(tdispatcher* dispatcher); 00284 00285 /** 00286 * Releases a captured mouse. 00287 * 00288 * @param dispatcher The dispatcher which should release the mouse 00289 * capture. 00290 */ 00291 void release_mouse(tdispatcher* dispatcher); 00292 00293 /** 00294 * Captures the keyboard. 00295 * 00296 * A dispatcher can capture the keyboard, when for example it's pressed on a 00297 * button, this means all keyboard events after that are send to that widget. 00298 * 00299 * @param dispatcher The dispatcher which should get the keyboard 00300 * focus. 00301 */ 00302 void capture_keyboard(tdispatcher* dispatcher); 00303 00304 std::ostream& operator<<(std::ostream& stream, const tevent event); 00305 00306 } // namespace event 00307 00308 /** 00309 * Is a dialog open? 00310 * 00311 * @note added as backwards compatibility for gui::is_in_dialog. 00312 */ 00313 bool is_in_dialog(); 00314 00315 } // namespace gui2 00316 00317 #endif 00318
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:53 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |