Create new events for getting and losing focus.

Uses the new notifications to send the events, this means only the
widget getting or losing the focus gets the event not it's parents.

Also comment out the old code to handle mouse focus.
This commit is contained in:
Mark de Wever 2009-10-10 15:36:37 +00:00
parent 7a1962c00a
commit 0788c3d81e
6 changed files with 36 additions and 12 deletions

View File

@ -595,6 +595,8 @@ std::ostream& operator<<(std::ostream& stream, const tevent event)
case SDL_KEY_DOWN : stream << "SDL key down"; break;
case NOTIFY_REMOVAL : stream << "notify removal"; break;
case RECEIVE_KEYBOARD_FOCUS : stream << "receive keyboard focus"; break;
case LOSE_KEYBOARD_FOCUS : stream << "lose keyboard focus"; break;
}
return stream;

View File

@ -97,6 +97,8 @@ enum tevent {
* Send by a widget to notify others it's
* being destroyed.
*/
, RECEIVE_KEYBOARD_FOCUS /**< Widget gets keyboard focus. */
, LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */
};
/**
@ -175,7 +177,9 @@ typedef
*/
typedef
boost::mpl::set<
boost::mpl::int_<NOTIFY_REMOVAL>
boost::mpl::int_<NOTIFY_REMOVAL>
, boost::mpl::int_<RECEIVE_KEYBOARD_FOCUS>
, boost::mpl::int_<LOSE_KEYBOARD_FOCUS>
>
tset_event_notification;

View File

@ -194,7 +194,6 @@ public:
* event. This can be used to capture the keyboard.
*/
virtual void focus(tevent_handler&) {}
#endif
/***** ***** ***** ***** keyboard ***** ***** ***** *****/
@ -219,7 +218,6 @@ public:
*/
virtual void lose_keyboard_focus(tevent_handler& /*event_handler*/) {}
#ifdef GUI2_OLD_EVENT_HANDLING
/**
* A key is pressed.
*

View File

@ -335,13 +335,15 @@ void tevent_handler::mouse_capture(const bool capture)
void tevent_handler::keyboard_capture(twidget* widget)
{
if(keyboard_focus_) {
keyboard_focus_->lose_keyboard_focus(*this);
get_window().fire(event::LOSE_KEYBOARD_FOCUS, *keyboard_focus_, NULL);
}
keyboard_focus_ = widget;
if(keyboard_focus_) {
keyboard_focus_->receive_keyboard_focus(*this);
get_window().fire(event::RECEIVE_KEYBOARD_FOCUS
, *keyboard_focus_
, NULL);
}
}

View File

@ -33,15 +33,20 @@ ttext_::ttext_()
, key_press_callback_()
, text_changed_callback_()
{
connect_signal<event::SDL_KEY_DOWN>(boost::bind(
&ttext_::signal_handler_sdl_key_down, this, _2, _3, _5, _6, _7));
#ifdef __unix__
// pastes on UNIX systems.
connect_signal<event::MIDDLE_BUTTON_CLICK>(boost::bind(
&ttext_::signal_handler_middle_button_click, this, _2, _3));
#endif
connect_signal<event::SDL_KEY_DOWN>(boost::bind(
&ttext_::signal_handler_sdl_key_down, this, _2, _3, _5, _6, _7));
connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(boost::bind(
&ttext_::signal_handler_receive_keyboard_focus, this, _2));
connect_signal<event::LOSE_KEYBOARD_FOCUS>(boost::bind(
&ttext_::signal_handler_lose_keyboard_focus, this, _2));
}
#ifdef GUI2_OLD_EVENT_HANDLING
@ -84,7 +89,6 @@ void ttext_::mouse_middle_button_click(tevent_handler&)
#endif
}
#endif
void ttext_::receive_keyboard_focus(tevent_handler& /*event_handler*/)
{
@ -100,7 +104,6 @@ void ttext_::lose_keyboard_focus(tevent_handler& /*event_handler*/)
set_state(ENABLED);
}
#ifdef GUI2_OLD_EVENT_HANDLING
void ttext_::key_press(tevent_handler& /*event*/,
bool& handled, SDLKey key, SDLMod modifier, Uint16 unicode)
{
@ -473,5 +476,19 @@ void ttext_::signal_handler_sdl_key_down(const event::tevent event
}
void ttext_::signal_handler_receive_keyboard_focus(const event::tevent event)
{
DBG_GUI_E << get_control_type() << "[" << id() << "]: " << event << ".\n";
set_state(FOCUSSED);
}
void ttext_::signal_handler_lose_keyboard_focus(const event::tevent event)
{
DBG_GUI_E << get_control_type() << "[" << id() << "]: " << event << ".\n";
set_state(ENABLED);
}
} // namespace gui2

View File

@ -50,7 +50,6 @@ public:
/** Inherited from tevent_executor. */
void mouse_middle_button_click(tevent_handler&);
#endif
/** Inherited from tevent_executor. */
void receive_keyboard_focus(tevent_handler& event_handler);
@ -58,7 +57,6 @@ public:
/** Inherited from tevent_executor. */
void lose_keyboard_focus(tevent_handler& event_handler);
#ifdef GUI2_OLD_EVENT_HANDLING
/** Inherited from tevent_executor. */
void key_press(tevent_handler& event,
bool& handled, SDLKey key, SDLMod modifier, Uint16 unicode);
@ -430,6 +428,9 @@ protected:
void signal_handler_sdl_key_down(const event::tevent event, bool& handled
, const SDLKey key, SDLMod modifier, const Uint16 unicode);
void signal_handler_receive_keyboard_focus(const event::tevent event);
void signal_handler_lose_keyboard_focus(const event::tevent event);
};
} // namespace gui2