gui1: Forward keyboard-based selection or cursor manipulation events...

...from non-editable textboxes

This effectively removes the selection/cursor manipulation part of
2012-12-23T06:10:31Z!shadowm@wesnoth.org. Without obvious visual cues as to what textbox has the current
focus it is only good for confusing users. Additionally, at least two
existing GUI-based IRC programs seem to do without selection/cursor
manipulation on the channel/query view box.
This commit is contained in:
Ignacio R. Morelle 2012-12-29 03:26:11 +00:00
parent d8d4ce1654
commit 08e60f36e2
3 changed files with 47 additions and 41 deletions

View file

@ -17,8 +17,7 @@ Version 1.11.1+svn:
* Updated translations: Italian, Portuguese, Portuguese (Brazil)
* User interface:
* Allow copying the selection in the old (default) lobby using
Ctrl+C/Command+C, as well as manipulating the selection with Shift+<Arrow
keys> (bug #5877)
Ctrl+C/Command+C (bug #5877)
* WML engine:
* [unit_overlay] and [remove_unit_overlay] now return a more meaningful
error message if the image= key is missing

View file

@ -21,8 +21,7 @@ Version 1.11.1+svn:
* User interface:
* Allow copying the selection in the old (default) lobby using
Ctrl+C/Command+C, as well as manipulating the selection with Shift+<Arrow
keys.
Ctrl+C/Command+C.
* Miscellaneous and bug fixes:
* The undo stack is preserved across a save-reload.

View file

@ -480,50 +480,58 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
const int c = key.sym;
const int old_cursor = cursor_;
if(c == SDLK_LEFT && cursor_ > 0)
--cursor_;
if(c == SDLK_RIGHT && cursor_ < static_cast<int>(text_.size()))
++cursor_;
// ctrl-a, ctrl-e and ctrl-u are readline style shortcuts, even on Macs
if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
cursor_ = text_.size();
if(c == SDLK_HOME || (c == SDLK_a && (modifiers & KMOD_CTRL)))
cursor_ = 0;
if((old_cursor != cursor_) && (modifiers & KMOD_SHIFT)) {
if(selstart_ == -1)
selstart_ = old_cursor;
selend_ = cursor_;
}
if(editable_ && c == SDLK_BACKSPACE) {
changed = true;
if(is_selection()) {
erase_selection();
} else if(cursor_ > 0) {
if(editable_) {
if(c == SDLK_LEFT && cursor_ > 0)
--cursor_;
text_.erase(text_.begin()+cursor_);
if(c == SDLK_RIGHT && cursor_ < static_cast<int>(text_.size()))
++cursor_;
// ctrl-a, ctrl-e and ctrl-u are readline style shortcuts, even on Macs
if(c == SDLK_END || (c == SDLK_e && (modifiers & KMOD_CTRL)))
cursor_ = text_.size();
if(c == SDLK_HOME || (c == SDLK_a && (modifiers & KMOD_CTRL)))
cursor_ = 0;
if((old_cursor != cursor_) && (modifiers & KMOD_SHIFT)) {
if(selstart_ == -1)
selstart_ = old_cursor;
selend_ = cursor_;
}
} else if(c == SDLK_LEFT || c == SDLK_RIGHT || c == SDLK_END || c == SDLK_HOME) {
pass_event_to_target(event);
}
if(editable_ && c == SDLK_u && (modifiers & KMOD_CTRL)) { // clear line
changed = true;
cursor_ = 0;
text_.resize(0);
}
if(editable_ && c == SDLK_DELETE && !text_.empty()) {
changed = true;
if(is_selection()) {
erase_selection();
} else {
if(cursor_ < static_cast<int>(text_.size())) {
if(editable_) {
if(c == SDLK_BACKSPACE) {
changed = true;
if(is_selection()) {
erase_selection();
} else if(cursor_ > 0) {
--cursor_;
text_.erase(text_.begin()+cursor_);
}
}
if(c == SDLK_u && (modifiers & KMOD_CTRL)) { // clear line
changed = true;
cursor_ = 0;
text_.resize(0);
}
if(c == SDLK_DELETE && !text_.empty()) {
changed = true;
if(is_selection()) {
erase_selection();
} else {
if(cursor_ < static_cast<int>(text_.size())) {
text_.erase(text_.begin()+cursor_);
}
}
}
} else if(c == SDLK_BACKSPACE || c == SDLK_DELETE || (c == SDLK_u && (modifiers & KMOD_CTRL))) {
pass_event_to_target(event);
}
wchar_t character = key.unicode;