Support UTF-32 in edit box, ryzom/ryzomcore#335

develop
kaetemi 4 years ago
parent 1a045e437e
commit 932a612f53

@ -137,6 +137,20 @@ public:
CComputedString &output,
bool keep800x600Ratio= true);
/**
* Same as computeString but do not make vertex buffers and primitives
*/
void computeStringInfo (NLMISC::CUtfStringView sv,
size_t len,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
uint32 fontSize,
bool embolden,
bool oblique,
IDriver *driver,
CComputedString &output,
bool keep800x600Ratio= true);
/**
* Same as computeString but do not make vertex buffers and primitives
*/

@ -382,6 +382,11 @@ public:
_FontManager->computeStringInfo (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
}
void computeStringInfo (NLMISC::CUtfStringView sv, CComputedString& output, size_t len)
{
_FontManager->computeStringInfo (sv, len, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio);
}
/// Debug : write to the disk the texture cache
void dumpCache (const char *filename)
{

@ -104,6 +104,7 @@ public:
void erase(uint32 i) ;
virtual CStringInfo getStringInfo (uint32 i);
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv);
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len);
void clear() ;
void printAt(float x, float y, uint32 i) ;

@ -275,6 +275,11 @@ public:
* The returned string info is in pixel size per default.
*/
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv) = 0;
/**
* Get a string information from the ucstring
* The returned string info is in pixel size per default.
*/
virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len) = 0;
/**
* empty the map
*/

@ -63,16 +63,16 @@ namespace NLGUI
virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc);
/// Accessors
ucstring getInputString() const { return _InputString; }
const ucstring &getInputStringRef() const { return _InputString; }
u32string getInputString() const { return _InputString; }
const u32string &getInputStringRef() const { return _InputString; }
const ucstring &getPrompt() const { return _Prompt; }
/** Set the prompt
* NB : line returns are encoded as '\n', not '\r\n'
*/
void setPrompt(const ucstring &s) { _Prompt = s; }
void setInputString(const ucstring &str);
void setInputStringRef(const ucstring &str) {_InputString = str; };
void setInputString(const u32string &str);
void setInputStringRef(const u32string &str) {_InputString = str; };
void setInputStringAsInt(sint32 val);
sint32 getInputStringAsInt() const;
void setInputStringAsInt64(sint64 val);
@ -81,6 +81,8 @@ namespace NLGUI
float getInputStringAsFloat() const;
void setInputStringAsUtf8(const std::string &str);
std::string getInputStringAsUtf8() const;
void setInputStringAsUtf16(const ucstring &str);
ucstring getInputStringAsUtf16() const;
void setColor(NLMISC::CRGBA col);
@ -119,7 +121,7 @@ namespace NLGUI
sint32 getMaxHistoric() const {return _MaxHistoric;}
sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;}
void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;}
const ucstring &getHistoric(uint32 index) const {return _Historic[index];}
const u32string &getHistoric(uint32 index) const {return _Historic[index];}
uint32 getNumHistoric() const {return (uint32)_Historic.size ();}
// Get on change action handler
@ -188,7 +190,7 @@ namespace NLGUI
REFLECT_LUA_METHOD("setFocusOnText", luaSetFocusOnText);
REFLECT_LUA_METHOD("cancelFocusOnText", luaCancelFocusOnText);
REFLECT_STRING("input_string", getInputStringAsUtf8, setInputStringAsUtf8);
REFLECT_UCSTRING("uc_input_string", getInputString, setInputString);
REFLECT_UCSTRING("uc_input_string", getInputStringAsUtf16, setInputStringAsUtf16);
REFLECT_EXPORT_END
/** Restore the original value of the edit box.
@ -227,16 +229,16 @@ namespace NLGUI
// Text info
ucstring _Prompt;
ucstring _InputString;
u32string _InputString;
CViewText *_ViewText;
// undo / redo
ucstring _StartInputString; // value of the input string when focus was acuired first
ucstring _ModifiedInputString;
u32string _StartInputString; // value of the input string when focus was acuired first
u32string _ModifiedInputString;
// Historic info
typedef std::deque<ucstring> THistoric;
typedef std::deque<u32string> THistoric;
THistoric _Historic;
uint32 _MaxHistoric;
sint32 _CurrentHistoricIndex;

@ -30,6 +30,8 @@ namespace NLMISC {
class CUtfStringView
{
public:
inline CUtfStringView() : m_Str(NULL), m_Size(0), m_Iterator(utf32Iterator) {}
inline CUtfStringView(const char *utf8Str) : m_Str(utf8Str), m_Size(strlen(utf8Str)), m_Iterator(utf8Iterator) {}
inline CUtfStringView(const char *utf8Str, size_t len): m_Str(utf8Str), m_Size(len), m_Iterator(utf8Iterator)
{
@ -75,9 +77,24 @@ public:
m_Char = 0;
}
}
inline void operator+=(ptrdiff_t a)
{
while (m_Addr)
{
++(*this);
}
}
inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; }
inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; }
inline const u32char &operator*() const { return m_Char; }
const_iterator() : m_View(*(CUtfStringView *)NULL), m_Addr(NULL), m_Char(0) { }
const_iterator &operator=(const const_iterator &other)
{
if(this == &other) return *this;
this->~const_iterator();
return *new(this) const_iterator(other);
}
private:
friend class CUtfStringView;
inline const_iterator(const CUtfStringView &view, const void *addr) : m_View(view), m_Addr(addr), m_Char(addr ? view.m_Iterator(&m_Addr) : 0) { }
@ -98,12 +115,28 @@ public:
inline bool empty() const { return !m_Size; }
const void *ptr() const { return m_Str; }
inline CUtfStringView substr(const iterator &begin, const iterator &end) const
{
return CUtfStringView(begin.m_Addr, (ptrdiff_t)end.m_Addr - (ptrdiff_t)begin.m_Addr, m_Iterator);
}
inline bool endsWith(char c) { nlassert(c < 0x80); return *((char *)m_Str + m_Size - 1) == c; }
CUtfStringView &operator=(const CUtfStringView &other)
{
if(this == &other) return *this;
this->~CUtfStringView();
return *new(this) CUtfStringView(other);
}
private:
typedef u32char (*TIterator)(const void **addr);
static u32char utf8Iterator(const void **addr);
static u32char utf16Iterator(const void **addr);
static u32char utf32Iterator(const void **addr);
inline CUtfStringView(const void *str, size_t len, TIterator it) : m_Str(str), m_Size(len), m_Iterator(it) { }
const void *const m_Str; // String
const size_t m_Size; // Size in bytes
const TIterator m_Iterator;

@ -237,6 +237,22 @@ void CFontManager::computeStringInfo ( NLMISC::CUtfStringView sv,
IDriver *driver,
CComputedString &output,
bool keep800x600Ratio )
{
computeStringInfo(sv, sv.largestSize(), fontGen, color, fontSize, embolden, oblique, driver, output, keep800x600Ratio);
}
// ***************************************************************************
void CFontManager::computeStringInfo ( NLMISC::CUtfStringView sv,
size_t len,
CFontGenerator *fontGen,
const NLMISC::CRGBA &color,
uint32 fontSize,
bool embolden,
bool oblique,
IDriver *driver,
CComputedString &output,
bool keep800x600Ratio )
{
output.Color = color;
@ -274,7 +290,8 @@ void CFontManager::computeStringInfo ( NLMISC::CUtfStringView sv,
CTextureFont::SLetterKey k;
CTextureFont::SLetterInfo *pLI;
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it)
size_t idx = 0;
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end && idx < len; ++it, ++idx)
{
// Creating font
k.Char = *it;

@ -286,6 +286,13 @@ UTextContext::CStringInfo CTextContextUser::getStringInfo(NLMISC::CUtfStringVie
_TextContext.computeStringInfo(sv, _CacheString);
return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine);
}
UTextContext::CStringInfo CTextContextUser::getStringInfo(NLMISC::CUtfStringView sv, size_t len)
{
H_AUTO2;
_TextContext.computeStringInfo(sv, _CacheString, len);
return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine);
}
void CTextContextUser::clear()
{
H_AUTO2;

@ -21,6 +21,7 @@
#include "stdpch.h"
#include "nel/gui/group_editbox.h"
#include "nel/misc/command.h"
#include "nel/misc/utf_string_view.h"
#include "nel/gui/view_text.h"
#include "nel/misc/xml_auto_ptr.h"
#include "nel/gui/interface_options.h"
@ -826,11 +827,12 @@ namespace NLGUI
}
// ----------------------------------------------------------------------------
void CGroupEditBox::writeString(const ucstring &str, bool replace, bool atEnd)
void CGroupEditBox::writeString(const ucstring &str16, bool replace, bool atEnd)
{
u32string str = CUtfStringView(str16).toUtf32();
sint length = (sint)str.length();
ucstring toAppend;
u32string toAppend;
// filter character depending on the entry type
switch (_EntryType)
{
@ -963,7 +965,7 @@ namespace NLGUI
{
length = _MaxNumChar - (sint)_InputString.length();
}
ucstring toAdd = toAppend.substr(0, length);
u32string toAdd = toAppend.substr(0, length);
sint32 minPos;
sint32 maxPos;
if (_CurrSelection == this)
@ -1013,7 +1015,7 @@ namespace NLGUI
_CursorAtPreviousLineEnd = false;
if (_ClearOnEscape)
{
setInputString(ucstring(""));
setInputString(u32string());
triggerOnChangeAH();
}
CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
@ -1059,8 +1061,9 @@ namespace NLGUI
{
if (isKeyRETURN)
{
ucstring copyStr= _InputString;
if ((uint) std::count(copyStr.begin(), copyStr.end(), '\n') >= _MaxNumReturn)
//ucstring copyStr= _InputString;
//if ((uint) std::count(copyStr.begin(), copyStr.end(), '\n') >= _MaxNumReturn)
if ((uint)std::count(_InputString.begin(), _InputString.end(), '\n') >= _MaxNumReturn)
break;
}
@ -1121,11 +1124,11 @@ namespace NLGUI
if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX))
{
// estimate new string
ucstring copyStr= _InputString;
ucstring::iterator it = copyStr.begin() + _CursorPos;
u32string copyStr= _InputString;
u32string::iterator it = copyStr.begin() + _CursorPos;
copyStr.insert(it, c);
sint32 value;
fromString(copyStr.toString(), value);
fromString(CUtfStringView(copyStr).toUtf8(), value);
// if out of bounds, abort char
if(value<_IntegerMinValue || value>_IntegerMaxValue)
return;
@ -1134,12 +1137,12 @@ namespace NLGUI
if(_EntryType==PositiveInteger && (_PositiveIntegerMinValue!=0 || _PositiveIntegerMaxValue!=UINT_MAX))
{
// estimate new string
ucstring copyStr= _InputString;
ucstring::iterator it = copyStr.begin() + _CursorPos;
u32string copyStr= _InputString;
u32string::iterator it = copyStr.begin() + _CursorPos;
copyStr.insert(it, c);
// \todo yoyo: this doesn't really work i think....
uint32 value;
fromString(copyStr.toString(), value);
fromString(CUtfStringView(copyStr).toUtf8(), value);
// if out of bounds, abort char
if(value<_PositiveIntegerMinValue || value>_PositiveIntegerMaxValue)
return;
@ -1148,7 +1151,7 @@ namespace NLGUI
if ((uint) _InputString.length() < _MaxNumChar)
{
makeTopWindow();
ucstring::iterator it = _InputString.begin() + _CursorPos;
u32string::iterator it = _InputString.begin() + _CursorPos;
_InputString.insert(it, c);
++ _CursorPos;
triggerOnChangeAH();
@ -1229,11 +1232,11 @@ namespace NLGUI
{
makeTopWindow();
// for french, deutsch and russian, be aware of unicode
std::string command = _InputString.substr(1).toUtf8();
std::string command = CUtfStringView(_InputString.substr(1)).toUtf8();
ICommand::expand(command);
// then back to ucstring
_InputString.fromUtf8(command);
_InputString = '/' + _InputString;
// then back to u32string
_InputString = CUtfStringView('/' + command).toUtf32();
_InputString = _InputString;
_CursorPos = (sint32)_InputString.length();
_CursorAtPreviousLineEnd = false;
triggerOnChangeAH();
@ -1260,7 +1263,7 @@ namespace NLGUI
// else delete last character
else if(_InputString.size () > 0 && _CursorPos != 0)
{
ucstring::iterator it = _InputString.begin() + (_CursorPos - 1);
u32string::iterator it = _InputString.begin() + (_CursorPos - 1);
_InputString.erase(it);
-- _CursorPos;
_CursorAtPreviousLineEnd = false;
@ -1439,7 +1442,7 @@ namespace NLGUI
}
else
{
usTmp = _Prompt + _InputString;
usTmp = _Prompt + CUtfStringView(_InputString).toUtf16();
}
_ViewText->setText (usTmp);
}
@ -1622,7 +1625,7 @@ namespace NLGUI
// ----------------------------------------------------------------------------
void CGroupEditBox::setInputString(const ucstring &str)
void CGroupEditBox::setInputString(const u32string &str)
{
_InputString = str;
if (_CursorPos > (sint32) str.length())
@ -1641,7 +1644,7 @@ namespace NLGUI
void CGroupEditBox::setDefaultInputString(const ucstring &str)
{
_DefaultInputString= true;
setInputString(str);
setInputString(CUtfStringView(str).toUtf32());
}
@ -1649,35 +1652,35 @@ namespace NLGUI
sint32 CGroupEditBox::getInputStringAsInt() const
{
sint32 value;
fromString(_InputString.toString(), value);
fromString(getInputStringAsUtf8(), value);
return value;
}
// ***************************************************************************
void CGroupEditBox::setInputStringAsInt(sint32 val)
{
setInputString(NLMISC::toString(val));
setInputStringAsUtf8(NLMISC::toString(val));
}
// ***************************************************************************
sint64 CGroupEditBox::getInputStringAsInt64() const
{
sint64 value;
fromString(_InputString.toString(), value);
fromString(getInputStringAsUtf8(), value);
return value;
}
// ***************************************************************************
void CGroupEditBox::setInputStringAsInt64(sint64 val)
{
setInputString(NLMISC::toString(val));
setInputStringAsUtf8(NLMISC::toString(val));
}
// ***************************************************************************
float CGroupEditBox::getInputStringAsFloat() const
{
float value;
fromString(_InputString.toString(), value);
fromString(getInputStringAsUtf8(), value);
return value;
}
@ -1685,14 +1688,14 @@ namespace NLGUI
void CGroupEditBox::setInputStringAsFloat(float val)
{
string fmt= "%." + NLMISC::toString(_MaxFloatPrec) + "f";
setInputString(NLMISC::toString(fmt.c_str(), val));
setInputStringAsUtf8(NLMISC::toString(fmt.c_str(), val));
}
// ***************************************************************************
void CGroupEditBox::cutSelection()
{
sint32 minPos= min(_CursorPos, _SelectCursorPos);
sint32 maxPos= max(_CursorPos, _SelectCursorPos);
ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos);
ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos);
// cut the selection
if(!_InputString.empty())
{
@ -1706,10 +1709,10 @@ namespace NLGUI
// ***************************************************************************
ucstring CGroupEditBox::getSelection()
{
sint32 minPos= min(_CursorPos, _SelectCursorPos);
sint32 maxPos= max(_CursorPos, _SelectCursorPos);
ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos);
ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos);
// get the selection
return _InputString.substr(minPos, maxPos-minPos);
return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf16();
}
@ -1738,13 +1741,25 @@ namespace NLGUI
// ***************************************************************************
void CGroupEditBox::setInputStringAsUtf8(const std::string &str)
{
setInputString(ucstring::makeFromUtf8(str));
setInputString(CUtfStringView(str).toUtf32());
}
// ***************************************************************************
std::string CGroupEditBox::getInputStringAsUtf8() const
{
return _InputString.toUtf8();
return CUtfStringView(_InputString).toUtf8();
}
// ***************************************************************************
void CGroupEditBox::setInputStringAsUtf16(const ucstring &str)
{
setInputString(CUtfStringView(str).toUtf32());
}
// ***************************************************************************
ucstring CGroupEditBox::getInputStringAsUtf16() const
{
return CUtfStringView(_InputString).toUtf16();
}
// ***************************************************************************
@ -1755,7 +1770,7 @@ namespace NLGUI
return;
// set the string and maybe execute
setInputString((ucchar) '/' + command);
setInputString(CUtfStringView((ucchar) '/' + command).toUtf32());
if (execute)
{
// stop selection
@ -1810,13 +1825,30 @@ namespace NLGUI
// ***************************************************************************
void CGroupEditBox::serialConfig(NLMISC::IStream &f)
{
f.serialVersion(0);
uint version = f.serialVersion(1);
if(_DefaultInputString) // Don't want to save the default input
{
_DefaultInputString= false;
_InputString.clear();
}
f.serial(_InputString);
if (version < 1)
{
ucstring str;
if (!f.isReading())
str = CUtfStringView(_InputString).toUtf16();
f.serial(str);
if (f.isReading())
_InputString = CUtfStringView(str).toUtf32();
}
else
{
std::string str;
if (!f.isReading())
str = CUtfStringView(_InputString).toUtf8();
f.serial(str);
if (f.isReading())
_InputString = CUtfStringView(str).toUtf32();
}
f.serial(_CursorPos);
f.serial(_PrevNumLine);
if (f.isReading())
@ -1838,7 +1870,7 @@ namespace NLGUI
void CGroupEditBox::onQuit()
{
// clear the text and restore backup pos before final save
setInputString(ucstring(""));
setInputString(u32string());
_CurrSelection = NULL;
}
@ -1846,7 +1878,7 @@ namespace NLGUI
void CGroupEditBox::onLoadConfig()
{
// config is not saved when there's an empty string, so restore that default state.
setInputString(ucstring(""));
setInputString(u32string());
_CurrSelection = NULL;
_PrevNumLine = 1;
}
@ -1861,7 +1893,7 @@ namespace NLGUI
if (_DefaultInputString)
{
_DefaultInputString= false;
setInputString(ucstring());
setInputString(u32string());
}
_CanRedo = false;
_CanUndo = false;

@ -27,6 +27,7 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/rgba.h"
#include "nel/misc/algo.h"
#include "nel/misc/utf_string_view.h"
#include "nel/gui/libwww.h"
#include "nel/gui/group_html.h"
#include "nel/gui/group_list.h"
@ -3023,7 +3024,7 @@ namespace NLGUI
CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb"));
if (eb)
{
eb->setInputString(decodeHTMLEntities(content));
eb->setInputString(CUtfStringView(decodeHTMLEntities(content)).toUtf32());
if (style.hasStyle("background-color"))
{
CViewBitmap *bg = dynamic_cast<CViewBitmap*>(eb->getView("bg"));

@ -2466,9 +2466,8 @@ namespace NLGUI
if ((uint) (index - charIndex) > currWord.NumSpaces)
{
// get the x position
ucstring subStr = currWord.Text.substr(0, index - charIndex - currWord.NumSpaces);
// compute the size
UTextContext::CStringInfo si = TextContext->getStringInfo(subStr);
UTextContext::CStringInfo si = TextContext->getStringInfo(currWord.Text, (ptrdiff_t)index - charIndex - currWord.NumSpaces);
fx = px + si.StringWidth + currWord.NumSpaces * currLine.getSpaceWidth();
x = fx / _Scale;
@ -2496,9 +2495,8 @@ namespace NLGUI
else
{
// get the x position
ucstring subStr = _Text.substr(0, index);
// compute the size
UTextContext::CStringInfo si = TextContext->getStringInfo(subStr);
UTextContext::CStringInfo si = TextContext->getStringInfo(_Text, index);
y = 0;
x = (sint) ceilf(si.StringWidth / _Scale);
}
@ -2511,12 +2509,13 @@ namespace NLGUI
float px = 0.f;
UTextContext::CStringInfo si;
ucstring singleChar(" ");
uint i;
for (i = 0; i < textValue.length(); ++i)
u32string singleChar(1, ' ');
uint i = 0;
NLMISC::CUtfStringView sv(textValue);
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++i)
{
// get character width
singleChar[0] = textValue[i];
singleChar[0] = *it;
si = textContext.getStringInfo(singleChar);
px += si.StringWidth;
// the character is at the i - 1 position

@ -1686,7 +1686,7 @@ public:
ucstring sSurName = ucstring("NotSet");
CGroupEditBox *pGEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(sEditBoxPath));
if (pGEB != NULL)
sFirstName = pGEB->getInputString();
sFirstName = pGEB->getInputStringAsUtf16();
else
nlwarning ("can't get edit box name : %s",sEditBoxPath.c_str());
@ -2562,7 +2562,7 @@ static void setTextField(CInterfaceGroup* scenarioWnd, const std::string &uiName
viewText->setText(text);
CGroupEditBox* editBox = dynamic_cast<CGroupEditBox*>(result);
if(editBox)
editBox->setInputString(text);
editBox->setInputStringAsUtf16(text);
}
}
@ -2826,7 +2826,7 @@ class CAHScenarioControl : public IActionHandler
{
CGroupEditBox* editBox = dynamic_cast<CGroupEditBox*>(result);
if(editBox)
editBox->setInputString(description);
editBox->setInputStringAsUtf16(description);
}
}
}
@ -2977,7 +2977,7 @@ class CAHLoadScenario : public IActionHandler
{
CGroupEditBox* editBox = dynamic_cast<CGroupEditBox*>(result);
if(editBox)
description = editBox->getInputString().toString();
description = editBox->getInputStringAsUtf8();
}
// races

@ -27,6 +27,7 @@ using namespace NLMISC;
#include "nel/gui/action_handler.h"
#include "nel/gui/group_editbox.h"
#include "nel/misc/utf_string_view.h"
#include "interface_manager.h"
#include "../client_chat_manager.h"
#include "people_interraction.h"
@ -56,7 +57,7 @@ extern CClientChatManager ChatMngr;
// ***************************************************************************
// used for character classifiction (when the user press Ctrl-arrow)
static inline uint getCharacterCategory(ucchar c)
static inline uint getCharacterCategory(u32char c)
{
if (c == ' ') return 0;
if (c > 127 || isalpha((char) c)) return 1; // alpha & other characters
@ -69,7 +70,7 @@ static inline uint getCharacterCategory(ucchar c)
/** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed)
* It returns the new index
*/
static uint skipUCCharsRight(uint startPos, const ucstring &str)
static uint skipUCCharsRight(uint startPos, const u32string &str)
{
uint pos = startPos;
uint endIndex = (uint)str.length();
@ -86,7 +87,7 @@ static uint skipUCCharsRight(uint startPos, const ucstring &str)
/** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed)
* It returns the new index
*/
static uint skipUCCharsLeft(uint startPos, const ucstring &str)
static uint skipUCCharsLeft(uint startPos, const u32string &str)
{
uint pos = startPos;
-- pos;
@ -362,7 +363,7 @@ class CAHEditPreviousLine : public CAHEdit
if (_GroupEdit->getMaxHistoric() && (! _GroupEdit->getViewText()->getMultiLine()))
{
// Get the start of the string.
ucstring startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
// Search all historic string that match startStr.
for(sint i=_GroupEdit->getCurrentHistoricIndex()+1;i<(sint)_GroupEdit->getNumHistoric();i++)
@ -434,7 +435,7 @@ class CAHEditNextLine : public CAHEdit
if( (! _GroupEdit->getViewText()->getMultiLine()) && _GroupEdit->getMaxHistoric() && _GroupEdit->getCurrentHistoricIndex()>0)
{
// Get the start of the string.
ucstring startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
// Search all historic string that match startStr.
for(sint i=_GroupEdit->getCurrentHistoricIndex()-1;i>=0;i--)
@ -520,8 +521,8 @@ protected:
// else cut forwards
else if(_GroupEdit->getCursorPos() < (sint32) _GroupEdit->getInputStringRef().length())
{
ucstring inputString = _GroupEdit->getInputStringRef();
ucstring::iterator it = inputString.begin() + _GroupEdit->getCursorPos();
u32string inputString = _GroupEdit->getInputStringRef();
u32string::iterator it = inputString.begin() + _GroupEdit->getCursorPos();
inputString.erase(it);
_GroupEdit->setInputStringRef (inputString);
if (!_GroupEdit->getAHOnChange().empty())
@ -638,7 +639,7 @@ class CAHEditExpandOrCycleTell : public CAHEdit
void actionPart ()
{
// If the line starts with '/tell ', do not try to expand
static const ucstring TELL_STR("/tell ");
static const u32string TELL_STR(CUtfStringView("/tell ").toUtf32());
if (_GroupEdit->getInputString().substr(0, TELL_STR.length()) != TELL_STR)
{
if (_GroupEdit->expand()) return;

@ -129,7 +129,7 @@ void CInterfaceItemEdition::CItemEditionWindow::infoReceived()
{
if ( pIS->Family == ITEMFAMILY::SCROLL)
{
editBoxLarge->setInputString(itemInfo.CustomText);
editBoxLarge->setInputStringAsUtf16(itemInfo.CustomText);
editLarge->setActive(true);
editBoxLarge->setActive(true);
@ -147,7 +147,7 @@ void CInterfaceItemEdition::CItemEditionWindow::infoReceived()
strFindReplace(customText, "%mfc", ucstring());
}
editBoxShort->setInputString(customText);
editBoxShort->setInputStringAsUtf16(customText);
editShort->setActive(true);
editBoxShort->setActive(true);
@ -239,8 +239,8 @@ void CInterfaceItemEdition::CItemEditionWindow::begin()
closeButton->setActive(false);
group->setActive(true);
editBoxShort->setInputString(ucstring());
editBoxLarge->setInputString(ucstring());
editBoxShort->setInputString(u32string());
editBoxLarge->setInputString(u32string());
display->setTextFormatTaged(ucstring());
@ -250,7 +250,7 @@ void CInterfaceItemEdition::CItemEditionWindow::begin()
// If we already have item info
if ( pIS->Family == ITEMFAMILY::SCROLL)
{
editBoxLarge->setInputString(itemInfo.CustomText);
editBoxLarge->setInputStringAsUtf16(itemInfo.CustomText);
editLarge->setActive(true);
editBoxLarge->setActive(true);
@ -269,7 +269,7 @@ void CInterfaceItemEdition::CItemEditionWindow::begin()
strFindReplace(customText, "%mfc", ucstring());
}
editBoxShort->setInputString(customText);
editBoxShort->setInputStringAsUtf16(customText);
editShort->setActive(true);
editBoxShort->setActive(true);
@ -297,8 +297,8 @@ void CInterfaceItemEdition::CItemEditionWindow::begin()
closeButton->setActive(true);
group->setActive(false);
editBoxShort->setInputString(ucstring());
editBoxLarge->setInputString(ucstring());
editBoxShort->setInputString(u32string());
editBoxLarge->setInputString(u32string());
display->setTextFormatTaged(ucstring());
// Finish the display or add the waiter
@ -406,11 +406,11 @@ void CInterfaceItemEdition::CItemEditionWindow::validate()
if (group && editShort && editBoxShort && editLarge && editBoxLarge && display && editButtons && closeButton && background)
{
bool textValid = editShort->getActive();
ucstring text = editBoxShort->getInputString();
ucstring text = editBoxShort->getInputStringAsUtf16();
if (!textValid)
{
textValid = editLarge->getActive();
text = editBoxLarge->getInputString();
text = editBoxLarge->getInputStringAsUtf16();
}
if (textValid)

@ -718,7 +718,7 @@ void CActionPhraseFaber::startMpSelection(uint itemReqLine, uint mpSlot)
if (eb)
{
CWidgetManager::getInstance()->setCaptureKeyboard(eb);
eb->setInputString(toString(maxQuantity));
eb->setInputStringAsUtf8(toString(maxQuantity));
eb->setSelectionAll();
}
}

@ -70,10 +70,10 @@ class CHandlerGuildCreate : public IActionHandler
CGroupEditBox *pDesc = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(guildDescWin));
ucstring guildName = pGEB->getInputString();
ucstring guildName = pGEB->getInputStringAsUtf16();
ucstring guildDesc;
if (pDesc != NULL) guildDesc = pDesc->getInputString();
if (pDesc != NULL) guildDesc = pDesc->getInputStringAsUtf16();
uint64 icon = CGuildManager::iconMake((uint8)pCS->getGuildBack(), (uint8)pCS->getGuildSymbol(),
pCS->getInvertGuildSymbol(), pCS->getGuildColor1(), pCS->getGuildColor2());

@ -333,7 +333,7 @@ uint32 CBotChatPageTrade::getCurrItemQuantity() const
CGroupEditBox *ed = dynamic_cast<CGroupEditBox *>(ig->getGroup("header_opened:standard_price:quantity:edit:eb"));
if (!ed) return std::numeric_limits<uint32>::max();
uint32 intQuantity;
if (fromString(ed->getInputString().toString(), intQuantity))
if (fromString(ed->getInputStringAsUtf8(), intQuantity))
{
return intQuantity;
}
@ -1465,7 +1465,7 @@ void CBotChatPageTrade::setupPriceGroupQuantity(CInterfaceGroup *priceGroup, sin
CGroupEditBox *eb = dynamic_cast<CGroupEditBox *>(quantityGroup->getGroup("edit:eb"));
if (eb)
{
eb->setInputString(toString(defaultQuantity));
eb->setInputStringAsUtf8(toString(defaultQuantity));
}
}
}
@ -1569,7 +1569,7 @@ void CBotChatPageTrade::setupResellGroup(bool sellMode, uint defaultQuantity, CI
{
sint32 resaleMargin= NLGUI::CDBManager::getInstance()->getDbProp( "UI:SAVE:TRADE_ITEM:RESALE_MARGIN" )->getValue32();
clamp(resaleMargin, 0, (sint32)MaxResaleMargin);
eb->setInputString( toString( resaleMargin ) );
eb->setInputStringAsUtf8( toString( resaleMargin ) );
eb->setPositiveIntegerMaxValue(MaxResaleMargin);
}
}
@ -1725,8 +1725,8 @@ void CBotChatPageTrade::startChangeBuyFilterDialog(const std::string &dbext, con
sint rangeMax= 0;
if(dbRangeMin) rangeMin= dbRangeMin->getValue32();
if(dbRangeMax) rangeMax= dbRangeMax->getValue32();
if(edMin) edMin->setInputString(toString(rangeMin));
if(edMax) edMax->setInputString(toString(rangeMax));
if(edMin) edMin->setInputStringAsUtf8(toString(rangeMin));
if(edMax) edMax->setInputStringAsUtf8(toString(rangeMax));
if(edMin) edMin->setPositiveIntegerMaxValue(maxValue);
if(edMax) edMax->setPositiveIntegerMaxValue(maxValue);
@ -1754,8 +1754,8 @@ void CBotChatPageTrade::resetBuyFilterDialog()
sint rangeMin= 0;
sint rangeMax= _FilterBuyDlgMaxValue;
// write result in EditBox, and in db
if(edMin) edMin->setInputString(toString(rangeMin));
if(edMax) edMax->setInputString(toString(rangeMax));
if(edMin) edMin->setInputStringAsUtf8(toString(rangeMin));
if(edMax) edMax->setInputStringAsUtf8(toString(rangeMax));
if(dbRangeMin) dbRangeMin->setValue32(rangeMin);
if(dbRangeMax) dbRangeMax->setValue32(rangeMax);

@ -363,7 +363,7 @@ void CChatWindow::setCommand(const ucstring &command,bool execute)
void CChatWindow::setEntry(const ucstring &entry)
{
if (!_EB) return;
_EB->setInputString(entry);
_EB->setInputStringAsUtf16(entry);
}
//=================================================================================
@ -1273,7 +1273,7 @@ public:
{
CGroupEditBox *pEB = dynamic_cast<CGroupEditBox*>(pCaller);
if (pEB == NULL) return;
ucstring text = pEB->getInputString();
ucstring text = pEB->getInputStringAsUtf16();
// If the line is empty, do nothing
if(text.empty())
return;
@ -1289,7 +1289,7 @@ public:
// Parse any tokens in the text
if ( ! CInterfaceManager::parseTokens(text))
{
pEB->setInputString (string(""));
pEB->setInputString (u32string());
return;
}
@ -1329,7 +1329,7 @@ public:
}
}
// Clear input string
pEB->setInputString (ucstring(""));
pEB->setInputString (u32string());
CGroupContainer *gc = static_cast< CGroupContainer* >( pEB->getEnclosingContainer() );
if (gc)

@ -279,7 +279,7 @@ void CDBGroupBuildPhrase::clearBuildingPhrase()
// Empty the name
if(_UserSentenceName)
{
_UserSentenceName->setInputString(ucstring());
_UserSentenceName->setInputString(u32string());
}
// update Display
@ -373,7 +373,7 @@ void CDBGroupBuildPhrase::startComposition(const CSPhraseCom &phrase)
// set the editable name.
if(_UserSentenceName)
_UserSentenceName->setInputString(name);
_UserSentenceName->setInputStringAsUtf16(name);
}
@ -1790,7 +1790,7 @@ void CDBGroupBuildPhrase::buildCurrentPhrase(CSPhraseCom &newPhrase)
// Set the Name
if(_UserSentenceName)
{
newPhrase.Name= _UserSentenceName->getInputString();
newPhrase.Name= _UserSentenceName->getInputStringAsUtf16();
}
}

@ -141,12 +141,12 @@ static void popupLandMarkNameDialog()
const CUserLandMark userLM = map->getUserLandMark(LastSelectedLandMark);
NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:LANDMARKTYPE" )->setValue8(cb->getTextPos(userLM.Type));
eb->setInputString(userLM.Title);
eb->setInputStringAsUtf16(userLM.Title);
}
else
{
NLGUI::CDBManager::getInstance()->getDbProp( "UI:TEMP:LANDMARKTYPE" )->setValue8(cb->getTextPos(CUserLandMark::Misc));
eb->setInputString(ucstring());
eb->setInputStringAsUtf16(ucstring());
}
CWidgetManager::getInstance()->setCaptureKeyboard(eb);
@ -3882,7 +3882,7 @@ class CAHLandMarkFilter : public IActionHandler
CGroupEditBox* eb = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(group));
if (!eb) return;
text = eb->getInputString().toUtf8();
text = eb->getInputStringAsUtf8();
}
map->setLandmarkFilter(text);
@ -3988,7 +3988,7 @@ class CAHValidateUserLandMarkName : public IActionHandler
CGroupMap *map = dynamic_cast<CGroupMap *>(LastSelectedLandMark->getParent());
if (!map) return;
// update existing landmark
map->updateUserLandMark(LastSelectedLandMark, eb->getInputString(), landMarkType);
map->updateUserLandMark(LastSelectedLandMark, eb->getInputStringAsUtf16(), landMarkType);
}
else
{
@ -3996,11 +3996,11 @@ class CAHValidateUserLandMarkName : public IActionHandler
if (!LastClickedMap) return;
if( UseUserPositionForLandMark )
{
LastClickedMap->addUserLandMark(LastClickedMap->getPlayerPos(), eb->getInputString(), landMarkType);
LastClickedMap->addUserLandMark(LastClickedMap->getPlayerPos(), eb->getInputStringAsUtf16(), landMarkType);
}
else
{
LastClickedMap->addUserLandMark(LastClickedMap->getRightClickLastPos(), eb->getInputString(), landMarkType);
LastClickedMap->addUserLandMark(LastClickedMap->getRightClickLastPos(), eb->getInputStringAsUtf16(), landMarkType);
}
LastClickedMap->invalidateCoords();
}

@ -2755,7 +2755,7 @@ class CHandlerInvSearchButton : public IActionHandler
{
CWidgetManager::getInstance()->setCaptureKeyboard(eb);
eb->setSelectionAll();
filter = eb->getInputString();
filter = eb->getInputStringAsUtf16();
}
CDBGroupListSheetBag *pList = dynamic_cast<CDBGroupListSheetBag*>(CWidgetManager::getInstance()->getElementFromId(btn->getParent()->getId() + ":bag_list"));
@ -2805,10 +2805,10 @@ class CHandlerInvSetSearch : public IActionHandler
std::string id = pCaller->getParent()->getParent()->getId();
CDBGroupListSheetBag *pList = dynamic_cast<CDBGroupListSheetBag*>(CWidgetManager::getInstance()->getElementFromId(id + ":bag_list"));
if (pList != NULL) pList->setSearchFilter(eb->getInputString());
if (pList != NULL) pList->setSearchFilter(eb->getInputStringAsUtf16());
CDBGroupIconListBag *pIcons = dynamic_cast<CDBGroupIconListBag*>(CWidgetManager::getInstance()->getElementFromId(id + ":bag_icons"));
if (pIcons != NULL) pIcons->setSearchFilter(eb->getInputString());
if (pIcons != NULL) pIcons->setSearchFilter(eb->getInputStringAsUtf16());
}
};
REGISTER_ACTION_HANDLER( CHandlerInvSetSearch, "inv_set_search" );

@ -1148,7 +1148,7 @@ void CModalContainerEditCmd::onChangeAction()
CGroupEditBox *pEB= dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId( sWin ));
if( pEB )
{
pEB->setInputString(ucstring(""));
pEB->setInputString(u32string());
}
NLGUI::CDBManager::getInstance()->getDbProp( sDB )->setValue32(1);
}

@ -886,7 +886,7 @@ public:
if (pCS != NULL) pCS->readFromMacro(pMCM->CurrentEditMacro);
// Name
CGroupEditBox *pEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(GROUP_NEWMACRO_EDIT_NAME));
if (pEB != NULL) pEB->setInputString(pMCM->CurrentEditMacro.Name);
if (pEB != NULL) pEB->setInputStringAsUtf8(pMCM->CurrentEditMacro.Name);
// Commands
CGroupList *pList = dynamic_cast<CGroupList*>(CWidgetManager::getInstance()->getElementFromId(GROUP_NEWMACRO_COMMANDS));
if (pList == NULL) return;

@ -2199,7 +2199,7 @@ public:
if (gc)
{
CGroupEditBox *geb = dynamic_cast<CGroupEditBox *>(gc->getGroup("add_contact_eb:eb"));
geb->setInputString(ucstring(""));
geb->setInputString(u32string());
}
CAHManager::getInstance()->runActionHandler("enter_modal", pCaller, sParams);
}
@ -2250,18 +2250,18 @@ public:
if (peopleList)
{
// don't add if it is the player name
if (!ClientCfg.Local && (UserEntity->getEntityName() == geb->getInputString()))
if (!ClientCfg.Local && (UserEntity->getEntityName() == geb->getInputStringAsUtf16()))
{
displayVisibleSystemMsg(CI18N::get("uiCantAddYourSelfInContactList"));
}
else
{
PeopleInterraction.askAddContact(geb->getInputString(), peopleList);
geb->setInputString(ucstring(""));
PeopleInterraction.askAddContact(geb->getInputStringAsUtf16(), peopleList);
geb->setInputString(u32string());
}
}
}
geb->setInputString(ucstring(""));
geb->setInputString(u32string());
}
}
}
@ -2389,7 +2389,7 @@ public:
if (eb)
{
CWidgetManager::getInstance()->setCaptureKeyboard(eb);
eb->setInputString(ucstring(""));
eb->setInputString(u32string());
}
//
if (gc->getActive())
@ -2416,7 +2416,7 @@ class CHandlerValidatePartyChatName : public IActionHandler
if (!gc) return;
CGroupEditBox *eb = dynamic_cast<CGroupEditBox *>(gc->getGroup("eb"));
if (!eb) return;
ucstring title = eb->getInputString();
ucstring title = eb->getInputStringAsUtf16();
// TODO GAMEDEV : create (or join ?) a new channel. Each channel (party chat) should have a unique name in the game
// moreover, it should not have the name of another available chat window (for example, it shouldn't be named 'Around Me')

@ -876,7 +876,7 @@ class CHandlerContactEntry : public IActionHandler
{
CGroupEditBox *pEB = dynamic_cast<CGroupEditBox*>(pCaller);
if (pEB == NULL) return;
ucstring text = pEB->getInputString();
ucstring text = pEB->getInputStringAsUtf16();
// If the line is empty, do nothing
if(text.empty())
return;
@ -884,7 +884,7 @@ class CHandlerContactEntry : public IActionHandler
// Parse any tokens in the text
if ( ! CInterfaceManager::parseTokens(text))
{
pEB->setInputString (string(""));
pEB->setInputString (u32string());
return;
}
@ -895,7 +895,7 @@ class CHandlerContactEntry : public IActionHandler
// TODO : have NLMISC::ICommand accept unicode strings
std::string str = text.toUtf8().substr(1);
NLMISC::ICommand::execute( str, g_log );
pEB->setInputString (string(""));
pEB->setInputString (u32string());
return;
}
// Well, we could have used CChatWindow class to handle this, but CPeopleList was written earlier, so for now
@ -908,7 +908,7 @@ class CHandlerContactEntry : public IActionHandler
// Simply do a tell on the player
ChatMngr.tell(playerName.toString(), text);
pEB->setInputString (string(""));
pEB->setInputString (u32string());
if (gc)
{
// Restore position of enclosing container if it hasn't been moved/scaled/poped by the user

@ -808,7 +808,7 @@ void initLoginScreen()
CGroupEditBox *pGEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN));
if (pGEB != NULL && (pGEB->getInputString().empty()))
{
pGEB->setInputString(l);
pGEB->setInputStringAsUtf8(l);
}
CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_PASSWORD "|select_all=false");
}
@ -830,8 +830,8 @@ void initAutoLogin()
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CGroupEditBox *pGEBLog = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN));
CGroupEditBox *pGEBPwd = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_PASSWORD));
pGEBLog->setInputString(LoginLogin);
pGEBPwd->setInputString(LoginPassword);
pGEBLog->setInputStringAsUtf8(LoginLogin);
pGEBPwd->setInputStringAsUtf8(LoginPassword);
CAHManager::getInstance()->runActionHandler("on_login", NULL, "");
if (ClientCfg.R2Mode)
@ -1379,8 +1379,8 @@ class CAHOnLogin : public IActionHandler
return;
}
LoginLogin = pGEBLog->getInputString().toString(); // FIXME: Unicode login
LoginPassword = pGEBPwd->getInputString().toString();
LoginLogin = pGEBLog->getInputStringAsUtf8();
LoginPassword = pGEBPwd->getInputStringAsUtf8();
onlogin();
}
@ -2394,7 +2394,7 @@ bool initCreateAccount()
{
CGroupEditBox * eb = dynamic_cast<CGroupEditBox*>(createAccountUI->findFromShortId(editBoxes[i] + ":eb"));
if(eb)
eb->setInputString(ucstring(""));
eb->setInputString(u32string());
}
// conditions button
@ -2581,7 +2581,7 @@ class CAHOnCreateAccountSubmit : public IActionHandler
{
CGroupEditBox * eb = dynamic_cast<CGroupEditBox*>(createAccountUI->findFromShortId(editBoxes[i] + ":eb"));
if(eb)
results[i] = eb->getInputString().toUtf8();
results[i] = eb->getInputStringAsUtf8();
}
// text
@ -2735,11 +2735,11 @@ class CAHCreateAccountLogin : public IActionHandler
{
CGroupEditBox * eb = dynamic_cast<CGroupEditBox*>(createAccountUI->findFromShortId("eb_login:eb"));
if(eb)
LoginLogin = eb->getInputString().toUtf8();
LoginLogin = eb->getInputStringAsUtf8();
eb = dynamic_cast<CGroupEditBox*>(createAccountUI->findFromShortId("eb_password:eb"));
if(eb)
LoginPassword = eb->getInputString().toUtf8();
LoginPassword = eb->getInputStringAsUtf8();
onlogin(false);
}

@ -7484,7 +7484,7 @@ class CAHInviteCharacter : public IActionHandler
CGroupEditBox *geb = dynamic_cast<CGroupEditBox *>(fatherGC->getGroup("add_contact_eb:eb"));
if (geb && !geb->getInputString().empty())
{
string charName = geb->getInputString().toString();
string charName = geb->getInputStringAsUtf8();
CSessionBrowserImpl & sessionBrowser = CSessionBrowserImpl::getInstance();
sessionBrowser.inviteCharacterByName(sessionBrowser.getCharId(), charName);
@ -7506,7 +7506,7 @@ class CAHInviteCharacter : public IActionHandler
CAHManager::getInstance()->runActionHandler("enter_modal", pCaller, "group=ui:interface:warning_newcomer");
}
geb->setInputString(ucstring(""));
geb->setInputString(u32string());
}
}
}

Loading…
Cancel
Save