From 0029800ea0592ab34f2d785de2871910928c1718 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Tue, 12 May 2009 19:51:02 +0000 Subject: [PATCH] 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. --- changelog | 1 + players_changelog | 1 + src/gui/widgets/password_box.cpp | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/changelog b/changelog index 06c9c995ca6..74b82ee696e 100644 --- a/changelog +++ b/changelog @@ -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) diff --git a/players_changelog b/players_changelog index 902bc7938ae..f080c304102 100644 --- a/players_changelog +++ b/players_changelog @@ -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. diff --git a/src/gui/widgets/password_box.cpp b/src/gui/widgets/password_box.cpp index 77630b3a99e..4a791619945 100644 --- a/src/gui/widgets/password_box.cpp +++ b/src/gui/widgets/password_box.cpp @@ -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);