Fixed UTF-8 handling in the password textbox.

A multi-character in the textbox had its length determined with the
number of characters instead of number of UTF-8 glyphs.
This commit is contained in:
Mark de Wever 2009-05-12 19:51:02 +00:00
parent dbb3d626e9
commit 0029800ea0
3 changed files with 15 additions and 3 deletions

View File

@ -102,6 +102,7 @@ Version 1.7.0-svn:
* Debug actions "Create unit" and "Change side" used on unit in a village
now causes a capture of that village.
* Rewrote the layout algoritm (still a work in progress)
* Fixed an multi-character UTF-8 handling bug in the password textbox
* WML Engine:
* Added [show_objectives] tag and allowed [show_if] tag in [objective]
tags. (bug #13042)

View File

@ -48,6 +48,7 @@ Version 1.7.0-svn:
installing one, and with its entry selected.
* Improved the sorting of the XP and traits columns in the unit list dialog
(part of bug #13360).
* Fixed the MP password textbox handling of special characters.
* Miscellaneous and bugfixes
* Fixed missing unit graphics when loading a start-of-scenario savegame.

View File

@ -18,13 +18,23 @@
#include "gui/widgets/password_box.hpp"
#include "gui/auxiliary/log.hpp"
#include "serialization/string_utils.hpp"
namespace gui2 {
namespace {
size_t get_text_length(const std::string& str)
{
return utils::string_to_wstring(str).size();
}
} // namespace
void tpassword_box::set_value(const std::string& text) {
ttext_box::set_value(text);
real_value_ = get_value();
ttext_box::set_value(std::string(real_value_.size(), '*'));
ttext_box::set_value(std::string(get_text_length(real_value_), '*'));
}
void tpassword_box::insert_char(const Uint16 unicode) {
@ -64,7 +74,7 @@ void tpassword_box::handle_key_delete(SDLMod /*modifier*/, bool& handled) {
handled = true;
if(get_selection_length() != 0) {
delete_selection();
} else if (get_selection_start() < text().size()) {
} else if (get_selection_start() < get_text_length(text())) {
delete_char(false);
}
@ -98,7 +108,7 @@ void tpassword_box::post_function() {
// Get the input back and make ttext_box forget it
real_value_ = get_value();
ttext_box::set_value(std::string(real_value_.size(), '*'));
ttext_box::set_value(std::string(get_text_length(real_value_), '*'));
// See above
set_selection_start(selection_start);