Avoid sending events to deactivated controls.

Before the activation status of widgets wasn't checked for keyboard
events (patch #1645).
This commit is contained in:
Mark de Wever 2010-04-26 20:15:35 +00:00
parent c1685e40ce
commit 3f3e55c7a6
2 changed files with 20 additions and 5 deletions

View file

@ -49,6 +49,7 @@ Version 1.9.0-svn:
screen
* Added the total number of villages to the status table lists
* Added a new attack dialog, available for testing with --new-widgets
* Patch #1645: Fixed a bug sending keyboard events to deactivated controls
* WML Engine:
* Deprecated [set_variable]'s random key, use rand instead
* Renamed [unit][status] healable to unhealable so it can default to 'no'

View file

@ -787,10 +787,16 @@ void tdistributor::signal_handler_sdl_key_down(const SDLKey key
DBG_GUI_E << LOG_HEADER << event::SDL_KEY_DOWN << ".\n";
if(keyboard_focus_) {
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN << ".\n";
if(owner_.fire(event::SDL_KEY_DOWN
, *keyboard_focus_, key, modifier, unicode)) {
return;
// Attempt to cast to control, to avoid sending events if the
// widget is disabled. If the cast fails, we assume the widget
// is enabled and ready to receive events.
tcontrol* control = dynamic_cast<tcontrol*>(keyboard_focus_);
if(!control || control->get_active()) {
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN << ".\n";
if(owner_.fire(event::SDL_KEY_DOWN
, *keyboard_focus_, key, modifier, unicode)) {
return;
}
}
}
@ -816,7 +822,15 @@ void tdistributor::signal_handler_sdl_key_down(const SDLKey key
*/
continue;
}
// Attempt to cast to control, to avoid sending events if the
// widget is disabled. If the cast fails, we assume the widget
// is enabled and ready to receive events.
tcontrol* control = dynamic_cast<tcontrol*>(keyboard_focus_);
if(control != NULL && !control->get_active()) {
continue;
}
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN << ".\n";
if(owner_.fire(event::SDL_KEY_DOWN
, **ritor, key, modifier, unicode)) {