Author: mordante
Date: Sun Mar 13 11:18:57 2011
New Revision: 48884

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48884&view=rev
Log:
Tooltips no longer capture the keyboard.

Fixes bug #17797.

Modified:
    trunk/changelog
    trunk/src/gui/auxiliary/event/dispatcher.cpp
    trunk/src/gui/auxiliary/event/dispatcher.hpp
    trunk/src/gui/auxiliary/event/handler.cpp
    trunk/src/gui/widgets/window.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=48884&r1=48883&r2=48884&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Sun Mar 13 11:18:57 2011
@@ -38,6 +38,7 @@
    * Implemented: The expose event in gui2.
    * Fixed: Image widget now honors its minimum and maximum size.
    * Fixed: Black lines in the minimap.
+   * Fixed: tooltips no longer capture the keyboard (bug #17797).
  * WML engine:
    * Added support for map_passable and leader_passable for [placement]
    * Allow [color_range] and [color_palette] nodes to be inserted at top-level

Modified: trunk/src/gui/auxiliary/event/dispatcher.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/event/dispatcher.cpp?rev=48884&r1=48883&r2=48884&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/event/dispatcher.cpp (original)
+++ trunk/src/gui/auxiliary/event/dispatcher.cpp Sun Mar 13 11:18:57 2011
@@ -28,6 +28,7 @@
 
 tdispatcher::tdispatcher()
        : mouse_behaviour_(all)
+       , want_keyboard_input_(true)
        , signal_queue_()
        , signal_mouse_queue_()
        , signal_keyboard_queue_()

Modified: trunk/src/gui/auxiliary/event/dispatcher.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/event/dispatcher.hpp?rev=48884&r1=48883&r2=48884&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/event/dispatcher.hpp (original)
+++ trunk/src/gui/auxiliary/event/dispatcher.hpp Sun Mar 13 11:18:57 2011
@@ -510,6 +510,7 @@
        }
 
        /***** ***** ***** setters/getters ***** ***** *****/
+
        void set_mouse_behaviour(const tmouse_behaviour mouse_behaviour)
        {
                mouse_behaviour_ = mouse_behaviour;
@@ -518,6 +519,16 @@
        tmouse_behaviour get_mouse_behaviour() const
        {
                return mouse_behaviour_;
+       }
+
+       void set_want_keyboard_input(const bool want_keyboard_input)
+       {
+               want_keyboard_input_ = want_keyboard_input;
+       }
+
+       bool get_want_keyboard_input() const
+       {
+               return want_keyboard_input_;
        }
 
        /** Helper struct to generate the various signal types. */
@@ -668,6 +679,18 @@
        /** The mouse behaviour for the dispatcher. */
        tmouse_behaviour mouse_behaviour_;
 
+       /**
+        * Does the dispatcher want to receive keyboard input.
+        *
+        * @todo The entire mouse and keyboard handling can use a code review to
+        * seen whether it might be combined in one flag field. At the moment 
the
+        * keyboard doesn't look whether a dialog has the mouse focus before
+        * sending the event, so maybe we should add an active dispatcher to 
keep
+        * track of it. But since at the moment there are only non-modal windows
+        * and tooltips it's not a problem.
+        */
+       bool want_keyboard_input_;
+
        /** Signal queue for callbacks in tset_event. */
        tsignal_queue<tsignal_function> signal_queue_;
 

Modified: trunk/src/gui/auxiliary/event/handler.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/event/handler.cpp?rev=48884&r1=48883&r2=48884&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/event/handler.cpp (original)
+++ trunk/src/gui/auxiliary/event/handler.cpp Sun Mar 13 11:18:57 2011
@@ -193,6 +193,14 @@
         *                               event.
         */
        void mouse_button_down(const tpoint& position, const Uint8 button);
+
+       /**
+        * Gets the dispatcher that wants to receive the keyboard input.
+        *
+        * @returns                   The dispatcher.
+        * @retval NULL               No dispatcher found.
+        */
+       tdispatcher* keyboard_dispatcher();
 
        /**
         * Fires a key down event.
@@ -567,6 +575,23 @@
        }
 }
 
+tdispatcher* thandler::keyboard_dispatcher()
+{
+       if(keyboard_focus_) {
+               return keyboard_focus_;
+       }
+
+       for(std::vector<tdispatcher*>::reverse_iterator ritor =
+                       dispatchers_.rbegin(); ritor != dispatchers_.rend(); 
++ritor) {
+
+               if((**ritor).get_want_keyboard_input()) {
+                       return *ritor;
+               }
+       }
+
+       return NULL;
+}
+
 void thandler::key_down(const SDL_KeyboardEvent& event)
 {
        const hotkey::hotkey_item& hk = hotkey::get_hotkey(event);
@@ -581,14 +606,13 @@
 
 bool thandler::hotkey_pressed(const hotkey::hotkey_item& key)
 {
-       tdispatcher* focus = keyboard_focus_
-                       ? keyboard_focus_
-                       : dispatchers_.back();
-       if(!focus) {
+       tdispatcher* dispatcher = keyboard_dispatcher();
+
+       if(!dispatcher) {
                return false;
        }
 
-       return focus->execute_hotkey(key.get_id());
+       return dispatcher->execute_hotkey(key.get_id());
 }
 
 void thandler::key_down(const SDLKey key
@@ -597,20 +621,12 @@
 {
        DBG_GUI_E << "Firing: " << SDL_KEY_DOWN << ".\n";
 
-       assert(!dispatchers_.empty());
-
-       if(keyboard_focus_) {
-               keyboard_focus_->fire(SDL_KEY_DOWN
-                               , dynamic_cast<twidget&>(*keyboard_focus_)
+       if(tdispatcher* dispatcher = keyboard_dispatcher()) {
+               dispatcher->fire(SDL_KEY_DOWN
+                               , dynamic_cast<twidget&>(*dispatcher)
                                , key
                                , modifier
                                , unicode);
-       } else {
-               dispatchers_.back()->fire(SDL_KEY_DOWN
-                               , dynamic_cast<twidget&>(*dispatchers_.back())
-                               , key
-                               , modifier
-                               , unicode);
        }
 }
 
@@ -618,13 +634,8 @@
 {
        DBG_GUI_E << "Firing: " << event << ".\n";
 
-       assert(!dispatchers_.empty());
-
-       if(keyboard_focus_) {
-               keyboard_focus_->fire(event, 
dynamic_cast<twidget&>(*keyboard_focus_));
-       } else {
-               dispatchers_.back()->fire(event
-                               , dynamic_cast<twidget&>(*dispatchers_.back()));
+       if(tdispatcher* dispatcher = keyboard_dispatcher()) {
+               dispatcher->fire(event, dynamic_cast<twidget&>(*dispatcher));
        }
 }
 
@@ -703,6 +714,8 @@
 {
        assert(handler);
        assert(dispatcher);
+       assert(dispatcher->get_want_keyboard_input());
+
        handler->keyboard_focus_ = dispatcher;
 }
 

Modified: trunk/src/gui/widgets/window.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=48884&r1=48883&r2=48884&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Sun Mar 13 11:18:57 2011
@@ -501,6 +501,7 @@
        assert(status_ == NEW);
 
        set_mouse_behaviour(event::tdispatcher::none);
+       set_want_keyboard_input(false);
 
        show_mode_ = tooltip;
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to