Let the new dispatcher do the event handling.

The old code remains but ifdef'ed out so can be restored if needed.
This commit is contained in:
Mark de Wever 2009-10-11 13:36:37 +00:00
parent ac4fad5a53
commit 99bd003b89
5 changed files with 98 additions and 0 deletions

View File

@ -21,6 +21,8 @@
#define GETTEXT_DOMAIN "wesnoth-lib"
#ifdef GUI2_OLD_EVENT_DISPATCHER
#include "clipboard.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/widget.hpp"
@ -1291,4 +1293,5 @@ void tevent_handler::sdl_wheel(const event::tevent event)
*/
} // namespace gui2
#endif

View File

@ -20,6 +20,8 @@
#ifndef GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED
#define GUI_WIDGETS_EVENT_INFO_HPP_INCLUDED
#ifdef GUI2_OLD_EVENT_DISPATCHER
#ifdef GUI2_OLD_EVENT_HANDLING
#include "events.hpp"
#endif
@ -524,3 +526,4 @@ private:
} // namespace gui2
#endif
#endif

View File

@ -55,6 +55,7 @@ twidget::~twidget()
p = p->parent();
}
#ifdef GUI2_OLD_EVENT_DISPATCHER
twindow* window = get_window();
if(!window) {
return;
@ -64,6 +65,13 @@ twidget::~twidget()
if(!linked_group_.empty()) {
window->remove_linked_widget(linked_group_, this);
}
#else
if(!linked_group_.empty()) {
if(twindow* window = get_window()) {
window->remove_linked_widget(linked_group_, this);
}
}
#endif
}
void twidget::set_id(const std::string& id)

View File

@ -38,6 +38,10 @@
#include <boost/bind.hpp>
#ifndef GUI2_OLD_EVENT_DISPATCHER
#include "gui/auxiliary/event/distributor.hpp"
#endif
namespace gui2{
unsigned twindow::sunset_ = 0;
@ -214,7 +218,9 @@ twindow::twindow(CVideo& video,
const unsigned maximum_height,
const std::string& definition)
: tpanel()
#ifdef GUI2_OLD_EVENT_DISPATCHER
, tevent_handler()
#endif
, cursor::setter(cursor::NORMAL)
, video_(video)
, status_(NEW)
@ -244,6 +250,10 @@ twindow::twindow(CVideo& video,
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
, debug_layout_(new tdebug_layout_graph(this))
#endif
#ifndef GUI2_OLD_EVENT_DISPATCHER
, event_distributor_(new event::tdistributor(
*this, event::tdispatcher::front_child))
#endif
{
// We load the config in here as exception.
// Our caller did update the screen size so no need for us to do that again.
@ -263,7 +273,9 @@ twindow::twindow(CVideo& video,
connect();
#endif
#ifdef GUI2_OLD_EVENT_DISPATCHER
connect_signals(*this);
#endif
connect_signal<event::DRAW>(boost::bind(&twindow::draw, this));
@ -302,6 +314,9 @@ twindow::~twindow()
delete debug_layout_;
#endif
#ifndef GUI2_OLD_EVENT_DISPATCHER
delete event_distributor_;
#endif
}
twindow* twindow::window_instance(const unsigned handle)
@ -875,8 +890,13 @@ void twindow::layout()
generate_dot_file("layout_finished", LAYOUT);
need_layout_ = false;
#ifdef GUI2_OLD_EVENT_DISPATCHER
// The widgets might have moved so set the mouse location properly.
init_mouse_location();
#else
assert(event_distributor_);
event_distributor_->init_mouse_location();
#endif
}
void twindow::layout_linked_widgets()
@ -1155,6 +1175,33 @@ void twindow_implementation::layout(twindow& window,
}
}
#ifndef GUI2_OLD_EVENT_DISPATCHER
void twindow::mouse_capture(const bool capture)
{
assert(event_distributor_);
event_distributor_->capture_mouse(capture);
}
void twindow::keyboard_capture(twidget* widget)
{
assert(event_distributor_);
event_distributor_->keyboard_capture(widget);
}
void twindow::add_to_keyboard_chain(twidget* widget)
{
assert(event_distributor_);
event_distributor_->keyboard_add_to_chain(widget);
}
void twindow::remove_from_keyboard_chain(twidget* widget)
{
assert(event_distributor_);
event_distributor_->keyboard_remove_from_chain(widget);
}
#endif
void twindow::signal_handler_sdl_video_resize(
const event::tevent event, bool& handled, const tpoint& new_size)
{

View File

@ -42,13 +42,20 @@ namespace gui2{
class tdialog;
class tdebug_layout_graph;
#ifndef GUI2_OLD_EVENT_DISPATCHER
namespace event {
class tdistributor;
} // namespace event
#endif
/**
* base class of top level items, the only item
* which needs to store the final canvase to draw on
*/
class twindow
: public tpanel
#ifdef GUI2_OLD_EVENT_DISPATCHER
, public tevent_handler
#endif
, public cursor::setter
{
friend class tdebug_layout_graph;
@ -582,6 +589,36 @@ public:
const unsigned) {}
#endif
#ifndef GUI2_OLD_EVENT_DISPATCHER
event::tdistributor* event_distributor_;
public:
// mouse and keyboard_capture should be renamed and stored in the
// dispatcher. Chaining probably should remain exclusive to windows.
void mouse_capture(const bool capture = true);
void keyboard_capture(twidget* widget);
/**
* Adds the widget to the keyboard chain.
*
* @todo rename to keyboard_add_to_chain.
* @param widget The widget to add to the chain. The widget
* should be valid widget, which hasn't been
* added to the chain yet.
*/
void add_to_keyboard_chain(twidget* widget);
/**
* Remove the widget from the keyborad chain.
*
* @todo rename to keyboard_remove_from_chain.
*
* @parameter widget The widget to be removed from the chain.
*/
void remove_from_keyboard_chain(twidget* widget);
private:
#endif
/***** ***** ***** signal handlers ***** ****** *****/
void signal_handler_sdl_video_resize(