gui1: Rework textbox event forwarding to eliminate duplicate...

...(actually quadruplicate) events.  Changed from 2012-12-23T06:10:46Z!shadowm@wesnoth.org.

Due to the way focusing works, the focus switch in the middle of the
forwarding action would create a duplicate event for the origin textbox,
resulting in a duplicate event for the target (a total of four events to
process).

Instead, make the implementation of gui::textbox::handle_event()
forwarding-aware, and provide a wrapper for the events engine
implementation to use by default.
This commit is contained in:
Ignacio R. Morelle 2012-12-29 03:25:05 +00:00
parent fccd55815b
commit d8d4ce1654
2 changed files with 10 additions and 9 deletions

View file

@ -386,6 +386,11 @@ bool textbox::requires_event_focus(const SDL_Event* event) const
}
void textbox::handle_event(const SDL_Event& event)
{
handle_event(event, false);
}
void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
{
if(!enabled())
return;
@ -457,14 +462,14 @@ void textbox::handle_event(const SDL_Event& event)
//if we don't have the focus, then see if we gain the focus,
//otherwise return
if(focus(&event) == false) {
if(!was_forwarded && focus(&event) == false) {
if (!mouse_locked() && event.type == SDL_MOUSEMOTION && point_in_rect(mousex, mousey, loc))
events::focus_handler(this);
return;
}
if(event.type != SDL_KEYDOWN || focus(&event) != true) {
if(event.type != SDL_KEYDOWN || (!was_forwarded && focus(&event) != true)) {
draw();
return;
}
@ -616,13 +621,7 @@ void textbox::handle_event(const SDL_Event& event)
void textbox::pass_event_to_target(const SDL_Event& event)
{
if(edit_target_ && edit_target_->editable()) {
set_focus(false);
edit_target_->set_focus(true);
edit_target_->handle_event(event);
edit_target_->set_focus(false);
set_focus(true);
edit_target_->handle_event(event, true);
}
}

View file

@ -84,6 +84,8 @@ private:
textbox* edit_target_;
void handle_event(const SDL_Event& event, bool was_forwarded);
void handle_event(const SDL_Event& event);
void pass_event_to_target(const SDL_Event& event);