mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-20 23:14:27 +00:00
Convert the GUI2 text API to take strings.
This change makes it easier to use the SDL2 text input events.
This commit is contained in:
parent
b3403e29e8
commit
abee16b16e
@ -212,7 +212,7 @@ class ttrigger_keyboard
|
||||
public:
|
||||
ttrigger_keyboard(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
: key_(key), modifier_(modifier), unicode_(unicode)
|
||||
{
|
||||
}
|
||||
@ -229,14 +229,14 @@ public:
|
||||
private:
|
||||
SDLKey key_;
|
||||
SDLMod modifier_;
|
||||
Uint16 unicode_;
|
||||
utf8::string unicode_;
|
||||
};
|
||||
|
||||
bool tdispatcher::fire(const tevent event,
|
||||
twidget& target,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
assert(find<tset_event_keyboard>(event, tevent_in_set()));
|
||||
return fire_event<tsignal_keyboard_function>(
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "gui/auxiliary/event/handler.hpp"
|
||||
#include "hotkey/hotkey_command.hpp"
|
||||
#include "sdl/compat.hpp"
|
||||
#include "serialization/unicode.hpp"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
@ -70,7 +71,8 @@ typedef boost::function<void(tdispatcher& dispatcher,
|
||||
bool& halt,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)> tsignal_keyboard_function;
|
||||
const utf8::string& unicode)>
|
||||
tsignal_keyboard_function;
|
||||
|
||||
/**
|
||||
* Callback function signature.
|
||||
@ -181,7 +183,7 @@ public:
|
||||
twidget& target,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode);
|
||||
const utf8::string& unicode);
|
||||
|
||||
/**
|
||||
* Fires an event which takes notification parameters.
|
||||
|
@ -692,7 +692,7 @@ void tdistributor::keyboard_remove_from_chain(twidget* widget)
|
||||
|
||||
void tdistributor::signal_handler_sdl_key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
/** @todo Test whether recursion protection is needed. */
|
||||
|
||||
|
@ -308,7 +308,7 @@ private:
|
||||
|
||||
void signal_handler_sdl_key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode);
|
||||
const utf8::string& unicode);
|
||||
|
||||
void signal_handler_notify_removal(tdispatcher& widget, const tevent event);
|
||||
};
|
||||
|
@ -254,8 +254,9 @@ private:
|
||||
* @param modifier The SDL key modifiers used.
|
||||
* @param unicode The unicode value for the key pressed.
|
||||
*/
|
||||
void
|
||||
key_down(const SDLKey key, const SDLMod modifier, const Uint16 unicode);
|
||||
void key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const utf8::string& unicode);
|
||||
|
||||
/**
|
||||
* Fires a keyboard event which has no parameters.
|
||||
@ -714,9 +715,11 @@ void thandler::key_down(const SDL_KeyboardEvent& event)
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
key_down(event.keysym.sym,
|
||||
static_cast<const SDL_Keymod>(event.keysym.mod),
|
||||
0);
|
||||
"");
|
||||
#else
|
||||
key_down(event.keysym.sym, event.keysym.mod, event.keysym.unicode);
|
||||
key_down(event.keysym.sym,
|
||||
event.keysym.mod,
|
||||
::implementation::ucs4char_to_string(event.keysym.unicode));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -734,7 +737,7 @@ bool thandler::hotkey_pressed(const hotkey::hotkey_item& key)
|
||||
|
||||
void thandler::key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
DBG_GUI_E << "Firing: " << SDL_KEY_DOWN << ".\n";
|
||||
|
||||
|
@ -52,7 +52,7 @@ void tpassword_box::set_value(const std::string& text)
|
||||
ttext_box::set_value(std::string(get_text_length(real_value_), '*'));
|
||||
}
|
||||
|
||||
void tpassword_box::insert_char(const Uint16 unicode)
|
||||
void tpassword_box::insert_char(const utf8::string& unicode)
|
||||
{
|
||||
pre_function();
|
||||
ttext_box::insert_char(unicode);
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void insert_char(const Uint16 unicode);
|
||||
void insert_char(const utf8::string& unicode);
|
||||
void delete_char(const bool before_cursor);
|
||||
|
||||
void paste_selection(const bool mouse);
|
||||
|
@ -127,11 +127,11 @@ void ttext_::set_cursor(const size_t offset, const bool select)
|
||||
}
|
||||
}
|
||||
|
||||
void ttext_::insert_char(const Uint16 unicode)
|
||||
void ttext_::insert_char(const utf8::string& unicode)
|
||||
{
|
||||
delete_selection();
|
||||
|
||||
if(text_.insert_unicode(selection_start_, unicode)) {
|
||||
if(text_.insert_text(selection_start_, unicode)) {
|
||||
|
||||
// Update status
|
||||
set_cursor(selection_start_ + 1, false);
|
||||
@ -277,15 +277,15 @@ void ttext_::handle_key_delete(SDLMod /*modifier*/, bool& handled)
|
||||
void ttext_::handle_key_default(bool& handled,
|
||||
SDLKey /*key*/,
|
||||
SDLMod /*modifier*/,
|
||||
Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
DBG_GUI_E << LOG_SCOPE_HEADER << '\n';
|
||||
|
||||
if(unicode >= 32 && unicode != 127) {
|
||||
handled = true;
|
||||
insert_char(unicode);
|
||||
fire(event::NOTIFY_MODIFIED, *this, NULL);
|
||||
}
|
||||
// if(unicode >= 32 && unicode != 127) {
|
||||
handled = true;
|
||||
insert_char(unicode);
|
||||
fire(event::NOTIFY_MODIFIED, *this, NULL);
|
||||
// }
|
||||
}
|
||||
|
||||
void ttext_::signal_handler_middle_button_click(const event::tevent event,
|
||||
@ -302,7 +302,7 @@ void ttext_::signal_handler_sdl_key_down(const event::tevent event,
|
||||
bool& handled,
|
||||
const SDLKey key,
|
||||
SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
@ -155,7 +155,7 @@ protected:
|
||||
*
|
||||
* @param unicode The unicode value of the character to insert.
|
||||
*/
|
||||
virtual void insert_char(const Uint16 unicode);
|
||||
virtual void insert_char(const utf8::string& unicode);
|
||||
|
||||
/**
|
||||
* Deletes the character.
|
||||
@ -423,7 +423,7 @@ protected:
|
||||
virtual void handle_key_default(bool& handled,
|
||||
SDLKey key,
|
||||
SDLMod modifier,
|
||||
Uint16 unicode);
|
||||
const utf8::string& unicode);
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -446,7 +446,7 @@ private:
|
||||
bool& handled,
|
||||
const SDLKey key,
|
||||
SDLMod modifier,
|
||||
const Uint16 unicode);
|
||||
const utf8::string& unicode);
|
||||
|
||||
void signal_handler_receive_keyboard_focus(const event::tevent event);
|
||||
void signal_handler_lose_keyboard_focus(const event::tevent event);
|
||||
|
@ -298,7 +298,7 @@ bool ttext_box::history_down()
|
||||
void ttext_box::handle_key_default(bool& handled,
|
||||
SDLKey key,
|
||||
SDLMod modifier,
|
||||
Uint16 unicode)
|
||||
const utf8::string& unicode)
|
||||
{
|
||||
if(key == SDLK_TAB && (modifier & KMOD_CTRL)) {
|
||||
if(!(modifier & KMOD_SHIFT)) {
|
||||
|
@ -236,7 +236,7 @@ private:
|
||||
void handle_key_default(bool& handled,
|
||||
SDLKey key,
|
||||
SDLMod modifier,
|
||||
Uint16 unicode);
|
||||
const utf8::string& unicode);
|
||||
|
||||
/** Inherited from ttext_. */
|
||||
void handle_key_clear_line(SDLMod modifier, bool& handled);
|
||||
|
Loading…
x
Reference in New Issue
Block a user