00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED__
00019 #define __GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED__
00020
00021 #include "events.hpp"
00022 #include "gui/widgets/helper.hpp"
00023 #include "gui/widgets/widget.hpp"
00024
00025 #include "SDL.h"
00026
00027 class t_string;
00028
00029 namespace gui2{
00030
00031 class twindow;
00032
00033 class tevent_handler : public events::handler
00034 {
00035 public:
00036 tevent_handler();
00037
00038 virtual ~tevent_handler() { leave(); }
00039
00040 void process_events() { events::pump(); }
00041
00042
00043 void handle_event(const SDL_Event& event);
00044
00045 virtual twindow& get_window() = 0;
00046 virtual const twindow& get_window() const = 0;
00047
00048
00049 virtual twidget* find_widget(const tpoint& coordinate,
00050 const bool must_be_active) = 0;
00051
00052
00053 virtual const twidget* find_widget(const tpoint& coordinate,
00054 const bool must_be_active) const = 0;
00055
00056 void mouse_capture(const bool capture = true);
00057 void keyboard_capture(twidget* widget) { keyboard_focus_ = widget; }
00058
00059 tpoint get_mouse() const;
00060
00061
00062
00063 void show_tooltip(const t_string& tooltip, const unsigned timeout);
00064 void remove_tooltip();
00065 void show_help_popup(const t_string& help_popup, const unsigned timeout);
00066 void remove_help_popup();
00067
00068 private:
00069
00070 struct tmouse_button {
00071
00072 tmouse_button(const std::string& name,
00073 void (tevent_executor::*down) (tevent_handler&),
00074 void (tevent_executor::*up) (tevent_handler&),
00075 void (tevent_executor::*click) (tevent_handler&),
00076 void (tevent_executor::*double_click) (tevent_handler&),
00077 bool (tevent_executor::*wants_double_click) () const) :
00078 last_click_stamp(0),
00079 focus(0),
00080 name(name),
00081 down(down),
00082 up(up),
00083 click(click),
00084 double_click(double_click),
00085 wants_double_click(wants_double_click),
00086 is_down(false)
00087 {}
00088
00089
00090 Uint32 last_click_stamp;
00091
00092
00093
00094
00095 twidget* focus;
00096
00097
00098 const std::string name;
00099
00100
00101
00102
00103 void (tevent_executor::*down) (tevent_handler&);
00104 void (tevent_executor::*up) (tevent_handler&);
00105 void (tevent_executor::*click) (tevent_handler&);
00106 void (tevent_executor::*double_click) (tevent_handler&);
00107 bool (tevent_executor::*wants_double_click) () const;
00108
00109
00110 bool is_down;
00111 };
00112
00113
00114
00115 events::event_context event_context_;
00116
00117 int mouse_x_;
00118 int mouse_y_;
00119
00120 tmouse_button left_;
00121 tmouse_button middle_;
00122 tmouse_button right_;
00123
00124 bool hover_pending_;
00125 unsigned hover_id_;
00126 SDL_Rect hover_box_;
00127
00128 bool had_hover_;
00129
00130
00131 twidget* tooltip_;
00132 twidget* help_popup_;
00133
00134
00135 twidget* mouse_focus_;
00136 bool mouse_captured_;
00137
00138 twidget* keyboard_focus_;
00139
00140 void mouse_enter(const SDL_Event& event, twidget* mouse_over);
00141 void mouse_move(const SDL_Event& event, twidget* mouse_over);
00142 void mouse_hover(const SDL_Event& event, twidget* mouse_over);
00143 void mouse_leave(const SDL_Event& event, twidget* mouse_over);
00144
00145
00146 void mouse_button_down(const SDL_Event& event, twidget* mouse_over, tmouse_button& button);
00147 void mouse_button_up(const SDL_Event& event, twidget* mouse_over, tmouse_button& button);
00148 void mouse_click(twidget* widget, tmouse_button& button);
00149
00150 void set_hover(const bool test_on_widget = false);
00151
00152 void key_down(const SDL_Event& event);
00153
00154 virtual void do_show_tooltip(const tpoint& location, const t_string& tooltip) = 0;
00155 virtual void do_remove_tooltip() = 0;
00156 virtual void do_show_help_popup(const tpoint& location, const t_string& help_popup) = 0;
00157 virtual void do_remove_help_popup() = 0;
00158 };
00159
00160 }
00161
00162 #endif