kaetemi 4 years ago
parent ac799e444d
commit 376dd2aff1

@ -38,7 +38,7 @@ namespace NLGUI
private: private:
// stylesheet currently parsed // stylesheet currently parsed
ucstring _Style; std::string _Style;
// keep track of current position in _Style // keep track of current position in _Style
size_t _Position; size_t _Position;
@ -70,49 +70,49 @@ namespace NLGUI
void preprocess(); void preprocess();
// parse selectors + combinators // parse selectors + combinators
std::vector<CCssSelector> parse_selector(const ucstring &sel, std::string &pseudoElement) const; std::vector<CCssSelector> parse_selector(const std::string &sel, std::string &pseudoElement) const;
// parse selector and style // parse selector and style
void parseRule(const ucstring &selectorString, const ucstring &styleString); void parseRule(const std::string &selectorString, const std::string &styleString);
inline bool is_eof() const inline bool is_eof() const
{ {
return _Position >= _Style.size(); return _Position >= _Style.size();
} }
inline bool is_whitespace(ucchar ch) const inline bool is_whitespace(char ch) const
{ {
return (ch == (ucchar)' ' || ch == (ucchar)'\t' || ch == (ucchar)'\n'); return (ch == ' ' || ch == '\t' || ch == '\n');
} }
inline bool is_hex(ucchar ch) const inline bool is_hex(char ch) const
{ {
return ((ch >= (ucchar)'0' && ch <= (ucchar)'9') || return ((ch >= '0' && ch <= '9') ||
(ch >= (ucchar)'a' && ch <= (ucchar)'f') || (ch >= 'a' && ch <= 'f') ||
(ch >= (ucchar)'A' && ch <= (ucchar)'F')); (ch >= 'A' && ch <= 'F'));
} }
inline bool maybe_escape() const inline bool maybe_escape() const
{ {
// escaping newline (\n) only allowed inside strings // escaping newline (\n) only allowed inside strings
return (_Style.size() - _Position) >= 1 && _Style[_Position] == (ucchar)'\\' && _Style[_Position+1] != '\n'; return (_Style.size() - _Position) >= 1 && _Style[_Position] == '\\' && _Style[_Position+1] != '\n';
} }
inline bool is_quote(ucchar ch) const inline bool is_quote(char ch) const
{ {
return ch== (ucchar)'"' || ch == (ucchar)'\''; return ch== '"' || ch == '\'';
} }
inline bool is_block_open(ucchar ch) const inline bool is_block_open(char ch) const
{ {
return ch == (ucchar)'{' || ch == (ucchar)'[' || ch == (ucchar)'('; return ch == (char)'{' || ch == (char)'[' || ch == (char)'(';
} }
inline bool is_block_close(ucchar ch, ucchar open) const inline bool is_block_close(char ch, char open) const
{ {
return ((open == '{' && ch == (ucchar)'}') || return ((open == '{' && ch == (char)'}') ||
(open == '[' && ch == (ucchar)']') || (open == '[' && ch == (char)']') ||
(open == '(' && ch == (ucchar)')')); (open == '(' && ch == (char)')'));
} }
inline bool is_comment_open() const inline bool is_comment_open() const
@ -120,25 +120,25 @@ namespace NLGUI
if (_Position+1 > _Style.size()) if (_Position+1 > _Style.size())
return false; return false;
return _Style[_Position] == (ucchar)'/' && _Style[_Position+1] == (ucchar)'*'; return _Style[_Position] == (char)'/' && _Style[_Position+1] == (char)'*';
} }
inline bool is_nonascii(ucchar ch) const inline bool is_nonascii(char ch) const
{ {
return ch >= 0x80 /*&& ch <= 255*/; return ch >= 0x80 /*&& ch <= 255*/;
} }
inline bool is_alpha(ucchar ch) const inline bool is_alpha(char ch) const
{ {
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
} }
inline bool is_digit(ucchar ch) const inline bool is_digit(char ch) const
{ {
return ch >= '0' && ch <= '9'; return ch >= '0' && ch <= '9';
} }
inline bool is_nmchar(ucchar ch) const inline bool is_nmchar(char ch) const
{ {
// checking escape here does not check if next char is '\n' or not // checking escape here does not check if next char is '\n' or not
return ch == '_' || ch == '-' || is_alpha(ch) || is_digit(ch) || is_nonascii(ch) || ch == '\\'/*is_escape(ch)*/; return ch == '_' || ch == '-' || is_alpha(ch) || is_digit(ch) || is_nonascii(ch) || ch == '\\'/*is_escape(ch)*/;

@ -82,13 +82,13 @@ public:
return _Key; return _Key;
} }
// return the char that has been pressed. The key event type MUST be 'keychar', else => assert // return the char that has been pressed. The key event type MUST be 'keychar', else => assert
ucchar getChar() const u32char getChar() const
{ {
nlassert(_KeyEvent == keychar); nlassert(_KeyEvent == keychar);
return _Char; return _Char;
} }
// return the string that has been sent. The key event type MUST be 'keystring', else => assert // return the string that has been sent. The key event type MUST be 'keystring', else => assert
ucstring getString() const std::string getString() const
{ {
nlassert(_KeyEvent == keystring); nlassert(_KeyEvent == keystring);
return _String; return _String;
@ -141,9 +141,9 @@ private:
union union
{ {
NLMISC::TKey _Key; NLMISC::TKey _Key;
ucchar _Char; u32char _Char;
}; };
ucstring _String; std::string _String;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

@ -248,6 +248,13 @@ namespace NLGUI
// Get the header color draw. NB: depends if grayed, and if active. // Get the header color draw. NB: depends if grayed, and if active.
NLMISC::CRGBA getDrawnHeaderColor () const; NLMISC::CRGBA getDrawnHeaderColor () const;
std::string getTitleRaw () const;
void setTitleRaw (const std::string &title);
std::string getTitleOpenedRaw () const;
void setTitleOpenedRaw (const std::string &title);
std::string getTitleClosedRaw () const;
void setTitleClosedRaw (const std::string &title);
ucstring getUCTitleOpened () const; ucstring getUCTitleOpened () const;
void setUCTitleOpened (const ucstring &title); void setUCTitleOpened (const ucstring &title);
ucstring getUCTitleClosed () const; ucstring getUCTitleClosed () const;
@ -287,9 +294,15 @@ namespace NLGUI
REFLECT_STRING("title", getTitle, setTitle); REFLECT_STRING("title", getTitle, setTitle);
REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened); REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened);
REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed); REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed);
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened);
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); REFLECT_STRING("title_raw", getTitleRaw, setTitleRaw);
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); REFLECT_STRING("title_opened_raw", getTitleOpenedRaw, setTitleOpenedRaw);
REFLECT_STRING("title_closed_raw", getTitleClosedRaw, setTitleClosedRaw);
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // FIXME: Lua UTF-8
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // FIXME: Lua UTF-8
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // FIXME: Lua UTF-8
REFLECT_STRING("title_color", getTitleColorAsString, setTitleColorAsString); REFLECT_STRING("title_color", getTitleColorAsString, setTitleColorAsString);
REFLECT_SINT32("pop_min_h", getPopupMinH, setPopupMinH); REFLECT_SINT32("pop_min_h", getPopupMinH, setPopupMinH);
REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH); REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH);

@ -65,15 +65,15 @@ namespace NLGUI
/// Accessors /// Accessors
std::string getInputString() const; std::string getInputString() const;
std::string getPrompt() const; std::string getPrompt() const;
const u32string &getInputStringRef() const { return _InputString; } const ::u32string &getInputStringRef() const { return _InputString; }
const u32string &getPromptRef() const { return _Prompt; } const ::u32string &getPromptRef() const { return _Prompt; }
/** Set the prompt /** Set the prompt
* NB : line returns are encoded as '\n', not '\r\n' * NB : line returns are encoded as '\n', not '\r\n'
*/ */
void setPrompt(const std::string &s); void setPrompt(const std::string &s);
void setInputString(const std::string &str); void setInputString(const std::string &str);
void setInputStringRef(const u32string &str) {_InputString = str; }; void setInputStringRef(const ::u32string &str) {_InputString = str; };
void setInputStringAsInt(sint32 val); void setInputStringAsInt(sint32 val);
sint32 getInputStringAsInt() const; sint32 getInputStringAsInt() const;
void setInputStringAsInt64(sint64 val); void setInputStringAsInt64(sint64 val);
@ -82,8 +82,8 @@ namespace NLGUI
float getInputStringAsFloat() const; float getInputStringAsFloat() const;
void setInputStringAsUtf16(const ucstring &str); void setInputStringAsUtf16(const ucstring &str);
ucstring getInputStringAsUtf16() const; ucstring getInputStringAsUtf16() const;
void setInputStringAsUtf32(const u32string &str); void setInputStringAsUtf32(const ::u32string &str);
u32string getInputStringAsUtf32() const { return _InputString; } ::u32string getInputStringAsUtf32() const { return _InputString; }
void setColor(NLMISC::CRGBA col); void setColor(NLMISC::CRGBA col);
@ -98,7 +98,7 @@ namespace NLGUI
static CGroupEditBox *getMenuFather() { return _MenuFather; } static CGroupEditBox *getMenuFather() { return _MenuFather; }
void setCommand(const ucstring &command, bool execute); void setCommand(const std::string &command, bool execute);
// Stop parent from blinking // Stop parent from blinking
void stopParentBlink() { if (_Parent) _Parent->disableBlink(); } void stopParentBlink() { if (_Parent) _Parent->disableBlink(); }
@ -122,7 +122,7 @@ namespace NLGUI
sint32 getMaxHistoric() const {return _MaxHistoric;} sint32 getMaxHistoric() const {return _MaxHistoric;}
sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;} sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;}
void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;} void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;}
const u32string &getHistoric(uint32 index) const {return _Historic[index];} const ::u32string &getHistoric(uint32 index) const {return _Historic[index];}
uint32 getNumHistoric() const {return (uint32)_Historic.size ();} uint32 getNumHistoric() const {return (uint32)_Historic.size ();}
// Get on change action handler // Get on change action handler
@ -140,7 +140,7 @@ namespace NLGUI
// Paste the selection into buffer // Paste the selection into buffer
void paste(); void paste();
// Write the string into buffer // Write the string into buffer
void writeString(const ucstring &str, bool replace = true, bool atEnd = true); void writeString(const ucstring &str, bool replace = true, bool atEnd = true); // UTF-16 because of Clipboard implementation
// Expand the expression (true if there was a '/' at the start of the line) // Expand the expression (true if there was a '/' at the start of the line)
bool expand(); bool expand();
@ -171,7 +171,7 @@ namespace NLGUI
virtual void onKeyboardCaptureLost(); virtual void onKeyboardCaptureLost();
// set the input string as "default". will be reseted at first click (used for user information) // set the input string as "default". will be reseted at first click (used for user information)
void setDefaultInputString(const ucstring &str); void setDefaultInputString(const std::string &str);
// For Interger and PositiveInteger, can specify min and max values // For Interger and PositiveInteger, can specify min and max values
void setIntegerMinValue(sint32 minValue) {_IntegerMinValue=minValue;} void setIntegerMinValue(sint32 minValue) {_IntegerMinValue=minValue;}
@ -229,17 +229,17 @@ namespace NLGUI
NLMISC::CRGBA _BackSelectColor; NLMISC::CRGBA _BackSelectColor;
// Text info // Text info
u32string _Prompt; ::u32string _Prompt;
u32string _InputString; ::u32string _InputString;
CViewText *_ViewText; CViewText *_ViewText;
// undo / redo // undo / redo
u32string _StartInputString; // value of the input string when focus was acuired first ::u32string _StartInputString; // value of the input string when focus was acuired first
u32string _ModifiedInputString; ::u32string _ModifiedInputString;
// Historic info // Historic info
typedef std::deque<u32string> THistoric; typedef std::deque<::u32string> THistoric;
THistoric _Historic; THistoric _Historic;
uint32 _MaxHistoric; uint32 _MaxHistoric;
sint32 _CurrentHistoricIndex; sint32 _CurrentHistoricIndex;
@ -276,7 +276,7 @@ namespace NLGUI
bool _CanRedo : 1; bool _CanRedo : 1;
bool _CanUndo : 1; bool _CanUndo : 1;
std::vector<char> _NegativeFilter; std::vector<u32char> _NegativeFilter;
sint _CursorTexID; sint _CursorTexID;
sint32 _CursorWidth; sint32 _CursorWidth;
@ -299,13 +299,13 @@ namespace NLGUI
void handleEventString(const NLGUI::CEventDescriptorKey &event); void handleEventString(const NLGUI::CEventDescriptorKey &event);
void setup(); void setup();
void triggerOnChangeAH(); void triggerOnChangeAH();
void appendStringFromClipboard(const ucstring &str); void appendStringFromClipboard(const ucstring &str); // UTF-16 because of Clipboard implementation
ucstring getSelection(); ucstring getSelection(); // UTF-16 because of Clipboard implementation
static CGroupEditBox *_MenuFather; static CGroupEditBox *_MenuFather;
static bool isValidAlphaNumSpace(ucchar c) static bool isValidAlphaNumSpace(u32char c)
{ {
if (c > 255) return false; if (c > 255) return false;
char ac = (char) c; char ac = (char) c;
@ -315,7 +315,7 @@ namespace NLGUI
ac==' '; ac==' ';
} }
static bool isValidAlphaNum(ucchar c) static bool isValidAlphaNum(u32char c)
{ {
if (c > 255) return false; if (c > 255) return false;
char ac = (char) c; char ac = (char) c;
@ -324,7 +324,7 @@ namespace NLGUI
(ac >= 'A' && ac <= 'Z'); (ac >= 'A' && ac <= 'Z');
} }
static bool isValidAlpha(ucchar c) static bool isValidAlpha(u32char c)
{ {
if (c > 255) return false; if (c > 255) return false;
char ac = (char) c; char ac = (char) c;
@ -332,13 +332,13 @@ namespace NLGUI
(ac >= 'A' && ac <= 'Z'); (ac >= 'A' && ac <= 'Z');
} }
static bool isValidPlayerNameChar(ucchar c) static bool isValidPlayerNameChar(u32char c)
{ {
// valid player name (with possible shard prefix / suffix format // valid player name (with possible shard prefix / suffix format
return isValidAlpha(c) || c=='.' || c=='(' || c==')'; return isValidAlpha(c) || c=='.' || c=='(' || c==')';
} }
static bool isValidFilenameChar(ucchar c) static bool isValidFilenameChar(u32char c)
{ {
if (c == '\\' || if (c == '\\' ||
c == '/' || c == '/' ||
@ -352,12 +352,12 @@ namespace NLGUI
return true; return true;
} }
// //
bool isFiltered(ucchar c) bool isFiltered(u32char c)
{ {
uint length = (uint)_NegativeFilter.size(); ptrdiff_t length = _NegativeFilter.size();
for (uint k = 0; k < length; ++k) for (ptrdiff_t k = 0; k < length; ++k)
{ {
if ((ucchar) _NegativeFilter[k] == c) return true; if (_NegativeFilter[k] == c) return true;
} }
return false; return false;
} }

@ -320,16 +320,16 @@ namespace NLGUI
void clearContext(); void clearContext();
// Translate a char // Translate a char
bool translateChar(ucchar &output, ucchar input, ucchar lastChar) const; bool translateChar(u32char &output, u32char input, u32char lastChar) const;
// Add a string in the current paragraph // Add a string in the current paragraph
void addString(const ucstring &str); void addString(const std::string &str);
// Add an image in the current paragraph // Add an image in the current paragraph
void addImage(const std::string &id, const std::string &img, bool reloadImg=false, const CStyleParams &style = CStyleParams()); void addImage(const std::string &id, const std::string &img, bool reloadImg=false, const CStyleParams &style = CStyleParams());
// Add a text area in the current paragraph // Add a text area in the current paragraph
CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content, uint maxlength); CInterfaceGroup *addTextArea (const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const std::string &content, uint maxlength);
// Add a combo box in the current paragraph // Add a combo box in the current paragraph
CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name); CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name);
@ -350,9 +350,9 @@ namespace NLGUI
void flushString(); void flushString();
// Set the title // Set the title
void setTitle (const ucstring &title);
void setTitle (const std::string &title); void setTitle (const std::string &title);
std::string getTitle() const; std::string getTitle() const;
void setTitleRaw (const std::string &title);
// Lookup a url in local file system // Lookup a url in local file system
bool lookupLocalFile (std::string &result, const char *url, bool isUrl); bool lookupLocalFile (std::string &result, const char *url, bool isUrl);
@ -392,10 +392,10 @@ namespace NLGUI
bool _TrustedDomain; bool _TrustedDomain;
// Title prefix // Title prefix
ucstring _TitlePrefix; std::string _TitlePrefix;
// Title string // Title string
ucstring _TitleString; std::string _TitleString;
// Need to browse next update coords.. // Need to browse next update coords..
bool _BrowseNextTime; bool _BrowseNextTime;
@ -644,7 +644,7 @@ namespace NLGUI
std::string Name; std::string Name;
// Variable value // Variable value
ucstring Value; std::string Value;
// Text area group // Text area group
CInterfaceGroup *TextArea; CInterfaceGroup *TextArea;
@ -747,7 +747,7 @@ namespace NLGUI
// Current node is a text area // Current node is a text area
bool _TextArea; bool _TextArea;
std::string _TextAreaTemplate; std::string _TextAreaTemplate;
ucstring _TextAreaContent; std::string _TextAreaContent;
std::string _TextAreaName; std::string _TextAreaName;
uint _TextAreaRow; uint _TextAreaRow;
uint _TextAreaCols; uint _TextAreaCols;
@ -755,7 +755,7 @@ namespace NLGUI
// current mode is in select option // current mode is in select option
bool _SelectOption; bool _SelectOption;
ucstring _SelectOptionStr; std::string _SelectOptionStr;
// Current node is a object // Current node is a object
std::string _ObjectType; std::string _ObjectType;
@ -826,7 +826,7 @@ namespace NLGUI
void spliceFragment(std::list<CHtmlElement>::iterator src); void spliceFragment(std::list<CHtmlElement>::iterator src);
// decode all HTML entities // decode all HTML entities
static ucstring decodeHTMLEntities(const ucstring &str); static std::string decodeHTMLEntities(const std::string &str);
struct CDataImageDownload struct CDataImageDownload
{ {

@ -222,7 +222,7 @@ namespace NLGUI
int luaSetLineMaxW(CLuaState &ls); int luaSetLineMaxW(CLuaState &ls);
REFLECT_EXPORT_START(CViewText, CViewBase) REFLECT_EXPORT_START(CViewText, CViewBase)
REFLECT_STRING("text", getText, setText); REFLECT_STRING("text_raw", getText, setText);
REFLECT_STRING("hardtext", getHardText, setHardText); REFLECT_STRING("hardtext", getHardText, setHardText);
// REFLECT_UCSTRING("uc_text", getTextAsUtf16, setTextAsUtf16); // Deprecate uc_ functions // REFLECT_UCSTRING("uc_text", getTextAsUtf16, setTextAsUtf16); // Deprecate uc_ functions
REFLECT_UCSTRING("uc_hardtext", getHardTextAsUtf16, setHardTextAsUtf16); REFLECT_UCSTRING("uc_hardtext", getHardTextAsUtf16, setHardTextAsUtf16);
@ -262,8 +262,8 @@ namespace NLGUI
// width of the font in pixel. Just a Hint for tabing format (computed with '_') // width of the font in pixel. Just a Hint for tabing format (computed with '_')
float _FontWidth; float _FontWidth;
// strings to use when computing font size // strings to use when computing font size
ucstring _FontSizingChars; ::u32string _FontSizingChars;
ucstring _FontSizingFallback; ::u32string _FontSizingFallback;
// height of the font in pixel. // height of the font in pixel.
// use getFontHeight // use getFontHeight
float _FontHeight; float _FontHeight;

@ -320,11 +320,11 @@ public:
class CEventChar : public CEventKey class CEventChar : public CEventKey
{ {
public: public:
CEventChar (ucchar c, TKeyButton button, IEventEmitter* emitter) : CEventKey (button, emitter, EventCharId), _Raw(true) CEventChar (u32char c, TKeyButton button, IEventEmitter* emitter) : CEventKey (button, emitter, EventCharId), _Raw(true)
{ {
Char=c; Char=c;
} }
ucchar Char; u32char Char;
virtual CEvent *clone() const {return new CEventChar(*this);} virtual CEvent *clone() const {return new CEventChar(*this);}
void setRaw( bool raw ) { _Raw = raw; } void setRaw( bool raw ) { _Raw = raw; }
@ -341,11 +341,11 @@ private:
class CEventString : public CEventKey class CEventString : public CEventKey
{ {
public: public:
CEventString (const ucstring &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId) CEventString (const std::string &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId)
{ {
String = str; String = str;
} }
ucstring String; std::string String;
virtual CEvent *clone() const {return new CEventString(*this);} virtual CEvent *clone() const {return new CEventString(*this);}
}; };

@ -54,11 +54,11 @@ public:
inline CUtfStringView(const ucstring &utf16Str) : m_Str(utf16Str.c_str()), m_Size(utf16Str.size() << 1), m_Iterator(utf16Iterator) {} inline CUtfStringView(const ucstring &utf16Str) : m_Str(utf16Str.c_str()), m_Size(utf16Str.size() << 1), m_Iterator(utf16Iterator) {}
inline CUtfStringView(const ucchar *utf16Str) : m_Str(utf16Str), m_Size(strlen((const char *)utf16Str) & (ptrdiff_t)(-2)), m_Iterator(utf16Iterator) {} inline CUtfStringView(const ucchar *utf16Str) : m_Str(utf16Str), m_Size(strlen((const char *)utf16Str) & (ptrdiff_t)(-2)), m_Iterator(utf16Iterator) {}
inline CUtfStringView(const u32string &utf32Str) : m_Str(utf32Str.c_str()), m_Size(utf32Str.size() << 2), m_Iterator(utf32Iterator) {} inline CUtfStringView(const ::u32string &utf32Str) : m_Str(utf32Str.c_str()), m_Size(utf32Str.size() << 2), m_Iterator(utf32Iterator) {}
std::string toUtf8(bool reEncode = false) const; // Makes a copy std::string toUtf8(bool reEncode = false) const; // Makes a copy
ucstring toUtf16(bool reEncode = false) const; // Makes a copy ucstring toUtf16(bool reEncode = false) const; // Makes a copy
u32string toUtf32() const; // Makes a copy ::u32string toUtf32() const; // Makes a copy
std::wstring toWide() const; // Platform dependent, UTF-16 or UTF-32. Makes a copy. std::wstring toWide() const; // Platform dependent, UTF-16 or UTF-32. Makes a copy.
std::string toAscii() const; // Returns only values 0-127, 7-bit ASCII. Makes a copy. std::string toAscii() const; // Returns only values 0-127, 7-bit ASCII. Makes a copy.

@ -1265,6 +1265,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
return 0; return 0;
} }
// https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-unichar
if (message == WM_UNICHAR)
return (wParam == UNICODE_NOCHAR);
return DefWindowProcW(hWnd, message, wParam, lParam); return DefWindowProcW(hWnd, message, wParam, lParam);
} }

@ -183,6 +183,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
return 0; return 0;
} }
// https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-unichar
if (message == WM_UNICHAR)
return (wParam == UNICODE_NOCHAR);
return trapMessage ? 0 : DefWindowProcW(hWnd, message, wParam, lParam); return trapMessage ? 0 : DefWindowProcW(hWnd, message, wParam, lParam);
} }

@ -29,6 +29,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include "nel/misc/debug.h" #include "nel/misc/debug.h"
#include "nel/misc/utf_string_view.h"
#ifdef DEBUG_NEW #ifdef DEBUG_NEW
#define new DEBUG_NEW #define new DEBUG_NEW
@ -537,8 +538,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
if (c > 0) if (c > 0)
{ {
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
ucstring ucstr; ::u32string ucstr = NLMISC::CUtfStringView(Text).toUtf32();
ucstr.fromUtf8(Text);
CEventChar *charEvent = new CEventChar (ucstr[0], getKeyButton(event.xbutton.state), this); CEventChar *charEvent = new CEventChar (ucstr[0], getKeyButton(event.xbutton.state), this);
@ -549,7 +549,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
#else #else
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++)
{ {
CEventChar *charEvent = new CEventChar ((ucchar)(unsigned char)Text[i], getKeyButton(event.xbutton.state), this); CEventChar *charEvent = new CEventChar ((u32char)(unsigned char)Text[i], getKeyButton(event.xbutton.state), this);
// raw if not processed by IME // raw if not processed by IME
charEvent->setRaw(keyCode != 0); charEvent->setRaw(keyCode != 0);

@ -65,7 +65,7 @@ namespace NLGUI
_Rules.clear(); _Rules.clear();
_Style.clear(); _Style.clear();
_Style.fromUtf8(cssString); _Style = cssString;
preprocess(); preprocess();
_Position = 0; _Position = 0;
@ -73,7 +73,7 @@ namespace NLGUI
{ {
skipWhitespace(); skipWhitespace();
if (_Style[_Position] == (ucchar)'@') if (_Style[_Position] == '@')
readAtRule(); readAtRule();
else else
readRule(); readRule();
@ -89,13 +89,13 @@ namespace NLGUI
// style: "color: red; font-size: 10px;" // style: "color: red; font-size: 10px;"
// //
// @internal // @internal
void CCssParser::parseRule(const ucstring &selectorString, const ucstring &styleString) void CCssParser::parseRule(const std::string &selectorString, const std::string &styleString)
{ {
std::vector<ucstring> selectors; std::vector<std::string> selectors;
NLMISC::explode(selectorString, ucstring(","), selectors); NLMISC::explode(selectorString, std::string(","), selectors);
TStyleVec props; TStyleVec props;
props = parseDecls(styleString.toUtf8()); props = parseDecls(styleString);
// duplicate props to each selector in selector list, // duplicate props to each selector in selector list,
// example 'div > p, h1' creates 'div>p' and 'h1' // example 'div > p, h1' creates 'div>p' and 'h1'
@ -129,7 +129,7 @@ namespace NLGUI
skipIdentifier(); skipIdentifier();
// skip at-rule statement // skip at-rule statement
while(!is_eof() && _Style[_Position] != (ucchar)';') while(!is_eof() && _Style[_Position] != ';')
{ {
if (maybe_escape()) if (maybe_escape())
{ {
@ -174,9 +174,9 @@ namespace NLGUI
_Position++; _Position++;
else if (is_quote(_Style[_Position])) else if (is_quote(_Style[_Position]))
skipString(); skipString();
else if (_Style[_Position] == (ucchar)'[') else if (_Style[_Position] == '[')
skipBlock(); skipBlock();
else if (_Style[_Position] == (ucchar)'{') else if (_Style[_Position] == '{')
break; break;
else else
_Position++; _Position++;
@ -184,7 +184,7 @@ namespace NLGUI
if (!is_eof()) if (!is_eof())
{ {
ucstring selector; std::string selector;
selector.append(_Style, start, _Position - start); selector.append(_Style, start, _Position - start);
skipWhitespace(); skipWhitespace();
@ -194,7 +194,7 @@ namespace NLGUI
skipBlock(); skipBlock();
if (_Position <= _Style.size()) if (_Position <= _Style.size())
{ {
ucstring rules; std::string rules;
rules.append(_Style, start + 1, _Position - start - 2); rules.append(_Style, start + 1, _Position - start - 2);
parseRule(selector, rules); parseRule(selector, rules);
@ -215,7 +215,7 @@ namespace NLGUI
for(uint i=0; i<6 && is_hex(_Style[_Position]); i++) for(uint i=0; i<6 && is_hex(_Style[_Position]); i++)
_Position++; _Position++;
if (_Style[_Position] == (ucchar)' ') if (_Style[_Position] == ' ')
_Position++; _Position++;
} }
else if (_Style[_Position] != 0x0A) else if (_Style[_Position] != 0x0A)
@ -246,23 +246,23 @@ namespace NLGUI
// cannot start with digit // cannot start with digit
valid = false; valid = false;
} }
else if ((_Position - start) == 0 && _Style[_Position-1] == (ucchar)'-') else if ((_Position - start) == 0 && _Style[_Position-1] == '-')
{ {
// cannot start with -# // cannot start with -#
valid = false; valid = false;
} }
} }
else if (_Style[_Position] == (ucchar)'_') else if (_Style[_Position] == '_')
{ {
// valid // valid
} }
else if (_Style[_Position] >= 0x0080) else if (_Style[_Position] >= 0x80)
{ {
// valid // valid
} }
else if (_Style[_Position] == (ucchar)'-') else if (_Style[_Position] == '-')
{ {
if ((_Position - start) == 1 && _Style[_Position-1] == (ucchar)'-') if ((_Position - start) == 1 && _Style[_Position-1] == '-')
{ {
// cannot start with -- // cannot start with --
valid = false; valid = false;
@ -285,7 +285,7 @@ namespace NLGUI
// @internal // @internal
void CCssParser::skipBlock() void CCssParser::skipBlock()
{ {
ucchar startChar = _Style[_Position]; char startChar = _Style[_Position];
// block start // block start
_Position++; _Position++;
@ -311,7 +311,7 @@ namespace NLGUI
// @internal // @internal
void CCssParser::skipString() void CCssParser::skipString()
{ {
ucchar endChar = _Style[_Position]; char endChar = _Style[_Position];
// quote start // quote start
_Position++; _Position++;
@ -338,7 +338,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
// parse selector list // parse selector list
// @internal // @internal
std::vector<CCssSelector> CCssParser::parse_selector(const ucstring &sel, std::string &pseudoElement) const std::vector<CCssSelector> CCssParser::parse_selector(const std::string &sel, std::string &pseudoElement) const
{ {
std::vector<CCssSelector> result; std::vector<CCssSelector> result;
CCssSelector current; CCssSelector current;
@ -346,10 +346,10 @@ namespace NLGUI
pseudoElement.clear(); pseudoElement.clear();
bool failed = false; bool failed = false;
ucstring::size_type start = 0, pos = 0; std::string::size_type start = 0, pos = 0;
while(pos < sel.size()) while(pos < sel.size())
{ {
ucstring uc; std::string uc;
uc = sel[pos]; uc = sel[pos];
if (is_nmchar(sel[pos]) && current.empty()) if (is_nmchar(sel[pos]) && current.empty())
{ {
@ -358,7 +358,7 @@ namespace NLGUI
while(pos < sel.size() && is_nmchar(sel[pos])) while(pos < sel.size() && is_nmchar(sel[pos]))
pos++; pos++;
current.Element = toLower(sel.substr(start, pos - start).toUtf8()); current.Element = toLower(sel.substr(start, pos - start));
start = pos; start = pos;
continue; continue;
} }
@ -371,7 +371,7 @@ namespace NLGUI
while(pos < sel.size() && is_nmchar(sel[pos])) while(pos < sel.size() && is_nmchar(sel[pos]))
pos++; pos++;
current.Id = toLower(sel.substr(start, pos - start).toUtf8()); current.Id = toLower(sel.substr(start, pos - start));
start = pos; start = pos;
} }
else if (sel[pos] == '.') else if (sel[pos] == '.')
@ -383,7 +383,7 @@ namespace NLGUI
while(pos < sel.size() && (is_nmchar(sel[pos]) || sel[pos] == '.')) while(pos < sel.size() && (is_nmchar(sel[pos]) || sel[pos] == '.'))
pos++; pos++;
current.setClass(toLower(sel.substr(start, pos - start).toUtf8())); current.setClass(toLower(sel.substr(start, pos - start)));
start = pos; start = pos;
} }
else if (sel[pos] == '[') else if (sel[pos] == '[')
@ -399,9 +399,9 @@ namespace NLGUI
start = pos; start = pos;
} }
ucstring key; std::string key;
ucstring value; std::string value;
ucchar op = ' '; char op = ' ';
// key // key
while(pos < sel.size() && is_nmchar(sel[pos])) while(pos < sel.size() && is_nmchar(sel[pos]))
@ -420,7 +420,7 @@ namespace NLGUI
if (sel[pos] == ']') if (sel[pos] == ']')
{ {
current.addAttribute(key.toUtf8()); current.addAttribute(key);
} }
else else
{ {
@ -496,14 +496,14 @@ namespace NLGUI
// [value="attr" i] // [value="attr" i]
if (value.size() > 2 && value[value.size()-2] == ' ') if (value.size() > 2 && value[value.size()-2] == ' ')
{ {
ucchar lastChar = value[value.size()-1]; char lastChar = value[value.size()-1];
if (lastChar == 'i' || lastChar == 'I' || lastChar == 's' || lastChar == 'S') if (lastChar == 'i' || lastChar == 'I' || lastChar == 's' || lastChar == 'S')
{ {
value = value.substr(0, value.size()-2); value = value.substr(0, value.size()-2);
cs = !((lastChar == 'i' || lastChar == 'I')); cs = !((lastChar == 'i' || lastChar == 'I'));
} }
} }
current.addAttribute(key.toUtf8(), trimQuotes(value).toUtf8(), (char)op, cs); current.addAttribute(key, trimQuotes(value), (char)op, cs);
} // op error } // op error
} // no value } // no value
@ -549,7 +549,7 @@ namespace NLGUI
} }
} }
std::string key = toLower(sel.substr(start, pos - start).toUtf8()); std::string key = toLower(sel.substr(start, pos - start));
if (key.empty()) if (key.empty())
{ {
failed = true; failed = true;
@ -647,7 +647,7 @@ namespace NLGUI
size_t start; size_t start;
size_t charsLeft; size_t charsLeft;
bool quote = false; bool quote = false;
ucchar quoteChar; char quoteChar;
while(!is_eof()) while(!is_eof())
{ {
charsLeft = _Style.size() - _Position - 1; charsLeft = _Style.size() - _Position - 1;
@ -660,8 +660,8 @@ namespace NLGUI
if (charsLeft >= 1 && _Style[_Position] == 0x0D && _Style[_Position+1] == 0x0A) if (charsLeft >= 1 && _Style[_Position] == 0x0D && _Style[_Position+1] == 0x0A)
len++; len++;
ucstring tmp; std::string tmp;
tmp += 0x000A; tmp += 0x0A;
_Style.replace(_Position, 1, tmp); _Style.replace(_Position, 1, tmp);
} }
else if (_Style[_Position] == 0x00) else if (_Style[_Position] == 0x00)
@ -686,12 +686,12 @@ namespace NLGUI
} }
else if (!quote && is_comment_open()) else if (!quote && is_comment_open())
{ {
size_t pos = _Style.find(ucstring("*/"), _Position + 2); size_t pos = _Style.find("*/", _Position + 2);
if (pos == std::string::npos) if (pos == std::string::npos)
pos = _Style.size(); pos = _Style.size();
_Style.erase(_Position, pos - _Position + 2); _Style.erase(_Position, pos - _Position + 2);
ucstring uc; std::string uc;
uc = _Style[_Position]; uc = _Style[_Position];
// _Position is already at correct place // _Position is already at correct place

@ -3955,8 +3955,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitle (const std::string &title) void CGroupContainer::setTitle (const std::string &title)
{ {
if (_Localize) setUCTitle (CI18N::get(title)); if (_Localize) setTitleRaw (CI18N::get(title));
else setUCTitle (title); else setTitleRaw (title);
} }
// *************************************************************************** // ***************************************************************************
@ -3968,8 +3968,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitleOpened (const std::string &title) void CGroupContainer::setTitleOpened (const std::string &title)
{ {
if (_Localize) setUCTitleOpened (CI18N::get(title)); if (_Localize) setTitleOpenedRaw (CI18N::get(title));
else setUCTitleOpened (title); else setTitleOpenedRaw (title);
} }
// *************************************************************************** // ***************************************************************************
@ -3981,51 +3981,87 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitleClosed (const std::string &title) void CGroupContainer::setTitleClosed (const std::string &title)
{ {
if (_Localize) setUCTitleClosed (CI18N::get(title)); if (_Localize) setTitleClosedRaw (CI18N::get(title));
else setUCTitleClosed (title); else setTitleClosedRaw (title);
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitleOpened(const ucstring &title) void CGroupContainer::setTitleOpenedRaw(const std::string &title)
{ {
_TitleTextOpened = title.toUtf8(); _TitleTextOpened = title;
if (_TitleOpened != NULL) if (_TitleOpened != NULL)
_TitleOpened->setText (title.toUtf8()); _TitleOpened->setText (title);
invalidateCoords(); invalidateCoords();
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitleClosed(const ucstring &title) void CGroupContainer::setTitleClosedRaw(const std::string &title)
{ {
_TitleTextClosed = title.toUtf8(); _TitleTextClosed = title;
if (_TitleClosed != NULL) if (_TitleClosed != NULL)
_TitleClosed->setText (_TitleTextClosed); _TitleClosed->setText (_TitleTextClosed);
invalidateCoords(); invalidateCoords();
} }
// ***************************************************************************
void CGroupContainer::setTitleRaw(const std::string &title)
{
setTitleOpenedRaw(title);
setTitleClosedRaw(title);
}
// ***************************************************************************
std::string CGroupContainer::getTitleRaw () const
{
return getTitleOpened();
}
// ***************************************************************************
std::string CGroupContainer::getTitleOpenedRaw () const
{
return _TitleTextOpened;
}
// ***************************************************************************
std::string CGroupContainer::getTitleClosedRaw () const
{
return _TitleTextClosed;
}
// ***************************************************************************
void CGroupContainer::setUCTitleOpened(const ucstring &title)
{
setTitleOpenedRaw(title.toUtf8());
}
// ***************************************************************************
void CGroupContainer::setUCTitleClosed(const ucstring &title)
{
setTitleClosedRaw(title.toUtf8());
}
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitle(const ucstring &title) void CGroupContainer::setUCTitle(const ucstring &title)
{ {
setUCTitleOpened(title); setTitleRaw(title.toUtf8());
setUCTitleClosed(title);
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitle () const ucstring CGroupContainer::getUCTitle () const
{ {
return getUCTitleOpened(); return ucstring::makeFromUtf8(getTitleRaw());
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitleOpened () const ucstring CGroupContainer::getUCTitleOpened () const
{ {
return _TitleTextOpened; return ucstring::makeFromUtf8(getTitleOpenedRaw());
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitleClosed () const ucstring CGroupContainer::getUCTitleClosed () const
{ {
return _TitleTextClosed; return ucstring::makeFromUtf8(getTitleClosedRaw());
} }
// *************************************************************************** // ***************************************************************************

@ -96,7 +96,7 @@ namespace NLGUI
_ViewTextDeltaX(0) _ViewTextDeltaX(0)
{ {
_Prompt = u32string(1, (u32char)'>'); _Prompt = ::u32string(1, (u32char)'>');
_BackSelectColor= CRGBA::White; _BackSelectColor= CRGBA::White;
_TextSelectColor= CRGBA::Black; _TextSelectColor= CRGBA::Black;
} }
@ -264,9 +264,9 @@ namespace NLGUI
std::string s; std::string s;
s.reserve( _NegativeFilter.size() ); s.reserve( _NegativeFilter.size() );
std::vector< char >::const_iterator itr; std::vector< u32char >::const_iterator itr;
for( itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr ) for (itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr)
s.push_back( *itr ); CUtfStringView::append(s, *itr);
return s; return s;
} }
@ -450,10 +450,10 @@ namespace NLGUI
if( name == "negative_filter" ) if( name == "negative_filter" )
{ {
_NegativeFilter.clear(); _NegativeFilter.clear();
::u32string::size_type i;
std::string::size_type i; ::u32string ustr = CUtfStringView(value).toUtf32();
for( i = 0; i < value.size(); i++ ) for( i = 0; i < ustr.size(); i++ )
_NegativeFilter.push_back( value[ i ] ); _NegativeFilter.push_back(ustr[i]);
} }
else else
CInterfaceGroup::setProperty( name, value ); CInterfaceGroup::setProperty( name, value );
@ -539,9 +539,9 @@ namespace NLGUI
std::string s; std::string s;
s.reserve( _NegativeFilter.size() ); s.reserve( _NegativeFilter.size() );
std::vector< char >::const_iterator itr; std::vector< u32char >::const_iterator itr;
for( itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr ) for( itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr )
s.push_back( *itr ); CUtfStringView::append(s, *itr);
xmlSetProp( node, BAD_CAST "negative_filter", BAD_CAST s.c_str() ); xmlSetProp( node, BAD_CAST "negative_filter", BAD_CAST s.c_str() );
@ -657,9 +657,11 @@ namespace NLGUI
prop = (char*) xmlGetProp( cur, (xmlChar*)"negative_filter" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"negative_filter" );
if (prop) if (prop)
{ {
uint length = (uint)strlen(prop); _NegativeFilter.clear();
_NegativeFilter.resize(length); ::u32string::size_type i;
std::copy((const char *) prop, (const char *) prop + length, _NegativeFilter.begin()); ::u32string ustr = CUtfStringView(prop).toUtf32();
for( i = 0; i < ustr.size(); i++ )
_NegativeFilter.push_back(ustr[i]);
} }
return true; return true;
@ -829,10 +831,10 @@ namespace NLGUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void CGroupEditBox::writeString(const ucstring &str16, bool replace, bool atEnd) void CGroupEditBox::writeString(const ucstring &str16, bool replace, bool atEnd)
{ {
u32string str = CUtfStringView(str16).toUtf32(); ::u32string str = CUtfStringView(str16).toUtf32();
sint length = (sint)str.length(); sint length = (sint)str.length();
u32string toAppend; ::u32string toAppend;
// filter character depending on the entry type // filter character depending on the entry type
switch (_EntryType) switch (_EntryType)
{ {
@ -854,7 +856,7 @@ namespace NLGUI
} }
} }
// remove '\r' characters // remove '\r' characters
toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (ucchar) '\r'), toAppend.end()); toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (u32char) '\r'), toAppend.end());
} }
break; break;
@ -965,7 +967,7 @@ namespace NLGUI
{ {
length = _MaxNumChar - (sint)_InputString.length(); length = _MaxNumChar - (sint)_InputString.length();
} }
u32string toAdd = toAppend.substr(0, length); ::u32string toAdd = toAppend.substr(0, length);
sint32 minPos; sint32 minPos;
sint32 maxPos; sint32 maxPos;
if (_CurrSelection == this) if (_CurrSelection == this)
@ -1015,7 +1017,7 @@ namespace NLGUI
_CursorAtPreviousLineEnd = false; _CursorAtPreviousLineEnd = false;
if (_ClearOnEscape) if (_ClearOnEscape)
{ {
setInputStringAsUtf32(u32string()); setInputStringAsUtf32(::u32string());
triggerOnChangeAH(); triggerOnChangeAH();
} }
CWidgetManager::getInstance()->setCaptureKeyboard(NULL); CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
@ -1077,7 +1079,7 @@ namespace NLGUI
cutSelection(); cutSelection();
} }
ucchar c = isKeyRETURN ? '\n' : rEDK.getChar(); u32char c = isKeyRETURN ? '\n' : rEDK.getChar();
if (isFiltered(c)) return; if (isFiltered(c)) return;
switch(_EntryType) switch(_EntryType)
{ {
@ -1124,8 +1126,8 @@ namespace NLGUI
if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX)) if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX))
{ {
// estimate new string // estimate new string
u32string copyStr= _InputString; ::u32string copyStr= _InputString;
u32string::iterator it = copyStr.begin() + _CursorPos; ::u32string::iterator it = copyStr.begin() + _CursorPos;
copyStr.insert(it, c); copyStr.insert(it, c);
sint32 value; sint32 value;
fromString(CUtfStringView(copyStr).toUtf8(), value); fromString(CUtfStringView(copyStr).toUtf8(), value);
@ -1137,8 +1139,8 @@ namespace NLGUI
if(_EntryType==PositiveInteger && (_PositiveIntegerMinValue!=0 || _PositiveIntegerMaxValue!=UINT_MAX)) if(_EntryType==PositiveInteger && (_PositiveIntegerMinValue!=0 || _PositiveIntegerMaxValue!=UINT_MAX))
{ {
// estimate new string // estimate new string
u32string copyStr= _InputString; ::u32string copyStr= _InputString;
u32string::iterator it = copyStr.begin() + _CursorPos; ::u32string::iterator it = copyStr.begin() + _CursorPos;
copyStr.insert(it, c); copyStr.insert(it, c);
// \todo yoyo: this doesn't really work i think.... // \todo yoyo: this doesn't really work i think....
uint32 value; uint32 value;
@ -1151,7 +1153,7 @@ namespace NLGUI
if ((uint) _InputString.length() < _MaxNumChar) if ((uint) _InputString.length() < _MaxNumChar)
{ {
makeTopWindow(); makeTopWindow();
u32string::iterator it = _InputString.begin() + _CursorPos; ::u32string::iterator it = _InputString.begin() + _CursorPos;
_InputString.insert(it, c); _InputString.insert(it, c);
++ _CursorPos; ++ _CursorPos;
triggerOnChangeAH(); triggerOnChangeAH();
@ -1263,7 +1265,7 @@ namespace NLGUI
// else delete last character // else delete last character
else if(_InputString.size () > 0 && _CursorPos != 0) else if(_InputString.size () > 0 && _CursorPos != 0)
{ {
u32string::iterator it = _InputString.begin() + (_CursorPos - 1); ::u32string::iterator it = _InputString.begin() + (_CursorPos - 1);
_InputString.erase(it); _InputString.erase(it);
-- _CursorPos; -- _CursorPos;
_CursorAtPreviousLineEnd = false; _CursorAtPreviousLineEnd = false;
@ -1436,7 +1438,7 @@ namespace NLGUI
std::string usTmp; std::string usTmp;
if (_EntryType == Password) if (_EntryType == Password)
{ {
usTmp = CUtfStringView(_Prompt + u32string(_InputString.size(), 0x2022)).toUtf8(); usTmp = CUtfStringView(_Prompt + ::u32string(_InputString.size(), 0x2022)).toUtf8();
} }
else else
{ {
@ -1634,7 +1636,7 @@ namespace NLGUI
{ {
setInputStringAsUtf32(CUtfStringView(str).toUtf32()); setInputStringAsUtf32(CUtfStringView(str).toUtf32());
} }
void CGroupEditBox::setInputStringAsUtf32(const u32string &str) void CGroupEditBox::setInputStringAsUtf32(const ::u32string &str)
{ {
_InputString = str; _InputString = str;
if (_CursorPos > (sint32) str.length()) if (_CursorPos > (sint32) str.length())
@ -1650,10 +1652,10 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupEditBox::setDefaultInputString(const ucstring &str) void CGroupEditBox::setDefaultInputString(const std::string &str)
{ {
_DefaultInputString= true; _DefaultInputString= true;
setInputStringAsUtf32(CUtfStringView(str).toUtf32()); setInputString(str);
} }
// *************************************************************************** // ***************************************************************************
@ -1771,14 +1773,14 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
void CGroupEditBox::setCommand(const ucstring &command, bool execute) void CGroupEditBox::setCommand(const std::string &command, bool execute)
{ {
// do nothing if frozen // do nothing if frozen
if(_Frozen) if(_Frozen)
return; return;
// set the string and maybe execute // set the string and maybe execute
setInputStringAsUtf16((ucchar) '/' + command); setInputString('/' + command);
if (execute) if (execute)
{ {
// stop selection // stop selection
@ -1878,7 +1880,7 @@ namespace NLGUI
void CGroupEditBox::onQuit() void CGroupEditBox::onQuit()
{ {
// clear the text and restore backup pos before final save // clear the text and restore backup pos before final save
setInputStringAsUtf32(u32string()); setInputStringAsUtf32(::u32string());
_CurrSelection = NULL; _CurrSelection = NULL;
} }
@ -1886,7 +1888,7 @@ namespace NLGUI
void CGroupEditBox::onLoadConfig() void CGroupEditBox::onLoadConfig()
{ {
// config is not saved when there's an empty string, so restore that default state. // config is not saved when there's an empty string, so restore that default state.
setInputStringAsUtf32(u32string()); setInputStringAsUtf32(::u32string());
_CurrSelection = NULL; _CurrSelection = NULL;
_PrevNumLine = 1; _PrevNumLine = 1;
} }
@ -1901,7 +1903,7 @@ namespace NLGUI
if (_DefaultInputString) if (_DefaultInputString)
{ {
_DefaultInputString= false; _DefaultInputString= false;
setInputStringAsUtf32(u32string()); setInputStringAsUtf32(::u32string());
} }
_CanRedo = false; _CanRedo = false;
_CanUndo = false; _CanUndo = false;

@ -1034,7 +1034,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::addText (const char * buf, int len) void CGroupHTML::addText (const char *buf, int len)
{ {
if (_Browsing) if (_Browsing)
{ {
@ -1042,44 +1042,43 @@ namespace NLGUI
return; return;
// Build a UTF8 string // Build a UTF8 string
string inputString(buf, buf+len);
if (_ParsingLua && _TrustedDomain) if (_ParsingLua && _TrustedDomain)
{ {
// we are parsing a lua script // we are parsing a lua script
_LuaScript += inputString; _LuaScript += string(buf, buf + len);
// no more to do // no more to do
return; return;
} }
// Build a unicode string // Build a unicode string
ucstring inputUCString; CUtfStringView inputStringView(buf, len);
inputUCString.fromUtf8(inputString);
// Build the final unicode string // Build the final unicode string
ucstring tmp; string tmp;
tmp.reserve(len); tmp.reserve(len);
uint ucLen = (uint)inputUCString.size(); u32char lastChar = 0;
for (uint i=0; i<ucLen; i++) u32char inputStringView0 = *inputStringView.begin();
for (CUtfStringView::iterator it(inputStringView.begin()), end(inputStringView.end()); it != end; ++it)
{ {
ucchar output; u32char output;
bool keep; bool keep;
// special treatment for 'nbsp' (which is returned as a discreet space) // special treatment for 'nbsp' (which is returned as a discreet space)
if (inputString.size() == 1 && inputString[0] == 32) if (len == 1 && inputStringView0 == 32)
{ {
// this is a nbsp entity // this is a nbsp entity
output = inputUCString[i]; output = *it;
keep = true; keep = true;
} }
else else
{ {
// not nbsp, use normal white space removal routine // not nbsp, use normal white space removal routine
keep = translateChar (output, inputUCString[i], (tmp.empty())?0:tmp[tmp.size()-1]); keep = translateChar (output, *it, lastChar);
} }
if (keep) if (keep)
{ {
tmp.push_back(output); CUtfStringView::append(tmp, output);
lastChar = output;
} }
} }
@ -1293,7 +1292,7 @@ namespace NLGUI
pos++; pos++;
} }
token = content.substr(start, pos - start); token = content.substr(start, pos - start);
addString(ucstring::makeFromUtf8(token)); addString(token);
// skip closing quote // skip closing quote
pos++; pos++;
@ -1376,7 +1375,7 @@ namespace NLGUI
if (elm.hasAttribute(token)) if (elm.hasAttribute(token))
{ {
addString(ucstring::makeFromUtf8(elm.getAttribute(token))); addString(elm.getAttribute(token));
} }
} }
else else
@ -1562,7 +1561,7 @@ namespace NLGUI
else else
if( name == "title_prefix" ) if( name == "title_prefix" )
{ {
return _TitlePrefix.toString(); return _TitlePrefix;
} }
else else
if( name == "background_color" ) if( name == "background_color" )
@ -2224,7 +2223,7 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "type", BAD_CAST "html" ); xmlSetProp( node, BAD_CAST "type", BAD_CAST "html" );
xmlSetProp( node, BAD_CAST "url", BAD_CAST _URL.c_str() ); xmlSetProp( node, BAD_CAST "url", BAD_CAST _URL.c_str() );
xmlSetProp( node, BAD_CAST "title_prefix", BAD_CAST _TitlePrefix.toString().c_str() ); xmlSetProp( node, BAD_CAST "title_prefix", BAD_CAST _TitlePrefix.c_str() );
xmlSetProp( node, BAD_CAST "background_color", BAD_CAST toString( BgColor ).c_str() ); xmlSetProp( node, BAD_CAST "background_color", BAD_CAST toString( BgColor ).c_str() );
xmlSetProp( node, BAD_CAST "error_color", BAD_CAST toString( ErrorColor ).c_str() ); xmlSetProp( node, BAD_CAST "error_color", BAD_CAST toString( ErrorColor ).c_str() );
xmlSetProp( node, BAD_CAST "link_color", BAD_CAST toString( LinkColor ).c_str() ); xmlSetProp( node, BAD_CAST "link_color", BAD_CAST toString( LinkColor ).c_str() );
@ -2669,7 +2668,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
bool CGroupHTML::translateChar(ucchar &output, ucchar input, ucchar lastCharParam) const bool CGroupHTML::translateChar(u32char &output, u32char input, u32char lastCharParam) const
{ {
// Keep this char ? // Keep this char ?
bool keep = true; bool keep = true;
@ -2691,13 +2690,13 @@ namespace NLGUI
else else
{ {
// Get the last char // Get the last char
ucchar lastChar = lastCharParam; u32char lastChar = lastCharParam;
if (lastChar == 0) if (lastChar == 0)
lastChar = getLastChar(); lastChar = getLastChar();
keep = ((lastChar != (ucchar)' ') && keep = ((lastChar != (u32char)' ') &&
(lastChar != 0)) || getPRE() || (_CurrentViewImage && (lastChar == 0)); (lastChar != 0)) || getPRE() || (_CurrentViewImage && (lastChar == 0));
if(!getPRE()) if(!getPRE())
input = ' '; input = (u32char)' ';
} }
} }
break; break;
@ -2710,11 +2709,11 @@ namespace NLGUI
else else
{ {
// Get the last char // Get the last char
ucchar lastChar = lastCharParam; u32char lastChar = lastCharParam;
if (lastChar == 0) if (lastChar == 0)
lastChar = getLastChar(); lastChar = getLastChar();
keep = ((lastChar != (ucchar)' ') && keep = ((lastChar != (u32char)' ') &&
(lastChar != (ucchar)'\n') && (lastChar != (u32char)'\n') &&
(lastChar != 0)) || getPRE() || (_CurrentViewImage && (lastChar == 0)); (lastChar != 0)) || getPRE() || (_CurrentViewImage && (lastChar == 0));
} }
} }
@ -2753,9 +2752,9 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::addString(const ucstring &str) void CGroupHTML::addString(const std::string &str)
{ {
string tmpStr = str.toUtf8(); string tmpStr = str;
if (_Localize) if (_Localize)
{ {
@ -2968,7 +2967,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
CInterfaceGroup *CGroupHTML::addTextArea(const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const ucstring &content, uint maxlength) CInterfaceGroup *CGroupHTML::addTextArea(const std::string &templateName, const char *name, uint rows, uint cols, bool multiLine, const std::string &content, uint maxlength)
{ {
// In a paragraph ? // In a paragraph ?
if (!_Paragraph) if (!_Paragraph)
@ -3024,7 +3023,7 @@ namespace NLGUI
CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb")); CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb"));
if (eb) if (eb)
{ {
eb->setInputString(CUtfStringView(decodeHTMLEntities(content)).toUtf8()); eb->setInputString(decodeHTMLEntities(content));
if (style.hasStyle("background-color")) if (style.hasStyle("background-color"))
{ {
CViewBitmap *bg = dynamic_cast<CViewBitmap*>(eb->getView("bg")); CViewBitmap *bg = dynamic_cast<CViewBitmap*>(eb->getView("bg"));
@ -3310,7 +3309,7 @@ namespace NLGUI
{ {
if (_CurrentViewLink) if (_CurrentViewLink)
{ {
u32string str = CUtfStringView(_CurrentViewLink->getText()).toUtf32(); // FIXME: Optimize reverse UTF iteration ::u32string str = CUtfStringView(_CurrentViewLink->getText()).toUtf32(); // FIXME: Optimize reverse UTF iteration
if (!str.empty()) if (!str.empty())
return str[str.length()-1]; return str[str.length()-1];
} }
@ -3402,7 +3401,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::setTitle (const ucstring &title) void CGroupHTML::setTitleRaw (const std::string &title)
{ {
CInterfaceElement *parent = getParent(); CInterfaceElement *parent = getParent();
if (parent) if (parent)
@ -3412,7 +3411,7 @@ namespace NLGUI
CGroupContainer *container = dynamic_cast<CGroupContainer*>(parent); CGroupContainer *container = dynamic_cast<CGroupContainer*>(parent);
if (container) if (container)
{ {
container->setUCTitle (title); container->setTitleRaw (title);
} }
} }
} }
@ -3420,21 +3419,18 @@ namespace NLGUI
void CGroupHTML::setTitle(const std::string &title) void CGroupHTML::setTitle(const std::string &title)
{ {
ucstring uctitle;
uctitle.fromUtf8(title);
_TitleString.clear(); _TitleString.clear();
if(!_TitlePrefix.empty()) if(!_TitlePrefix.empty())
{ {
_TitleString = _TitlePrefix + " - "; _TitleString = _TitlePrefix + " - ";
} }
_TitleString += uctitle; _TitleString += title;
setTitle(_TitleString); setTitleRaw(_TitleString);
} }
std::string CGroupHTML::getTitle() const { std::string CGroupHTML::getTitle() const {
return _TitleString.toUtf8(); return _TitleString;
}; };
// *************************************************************************** // ***************************************************************************
@ -4685,9 +4681,7 @@ namespace NLGUI
CLuaIHM::checkArgType(ls, funcName, 3, LUA_TBOOLEAN); CLuaIHM::checkArgType(ls, funcName, 3, LUA_TBOOLEAN);
string name = ls.toString(1); string name = ls.toString(1);
string text = ls.toString(2);
ucstring text;
text.fromUtf8(ls.toString(2));
if (!_Forms.empty()) if (!_Forms.empty())
{ {
@ -4717,7 +4711,7 @@ namespace NLGUI
const char *funcName = "addString"; const char *funcName = "addString";
CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgCount(ls, funcName, 1);
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
addString(ucstring::makeFromUtf8(ls.toString(1))); addString(ls.toString(1));
return 0; return 0;
} }
@ -4945,7 +4939,7 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
inline bool isDigit(ucchar c, uint base = 16) inline bool isDigit(char c, uint base = 16)
{ {
if (c>='0' && c<='9') return true; if (c>='0' && c<='9') return true;
if (base != 16) return false; if (base != 16) return false;
@ -4955,7 +4949,7 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
inline ucchar convertHexDigit(ucchar c) inline char convertHexDigit(char c)
{ {
if (c>='0' && c<='9') return c-'0'; if (c>='0' && c<='9') return c-'0';
if (c>='A' && c<='F') return c-'A'+10; if (c>='A' && c<='F') return c-'A'+10;
@ -4964,9 +4958,10 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupHTML::decodeHTMLEntities(const ucstring &str) std::string CGroupHTML::decodeHTMLEntities(const std::string &str)
{ {
ucstring result; std::string result;
result.reserve(str.size() + (str.size() >> 2));
uint last, pos; uint last, pos;
for (uint i=0; i<str.length(); ++i) for (uint i=0; i<str.length(); ++i)
@ -5002,13 +4997,13 @@ namespace NLGUI
continue; continue;
} }
ucchar c = 0; u32char c = 0;
// convert digits to unicode character // convert digits to unicode character
while (pos<last) c = convertHexDigit(str[pos++]) + c*ucchar(base); while (pos < last) c = convertHexDigit(str[pos++]) + (c * u32char(base));
// append our new character to the result string // append our new character to the result string
result += c; CUtfStringView::append(result, c);
// move 'i' forward to point at the ';' .. the for(...) will increment i to point to next char // move 'i' forward to point at the ';' .. the for(...) will increment i to point to next char
i = last; i = last;
@ -5017,10 +5012,10 @@ namespace NLGUI
} }
// special xml characters // special xml characters
if (str.substr(i+1,5)==ucstring("quot;")) { i+=5; result+='\"'; continue; } if (str.substr(i+1,5)=="quot;") { i+=5; result+='\"'; continue; }
if (str.substr(i+1,4)==ucstring("amp;")) { i+=4; result+='&'; continue; } if (str.substr(i+1,4)=="amp;") { i+=4; result+='&'; continue; }
if (str.substr(i+1,3)==ucstring("lt;")) { i+=3; result+='<'; continue; } if (str.substr(i+1,3)=="lt;") { i+=3; result+='<'; continue; }
if (str.substr(i+1,3)==ucstring("gt;")) { i+=3; result+='>'; continue; } if (str.substr(i+1,3)=="gt;") { i+=3; result+='>'; continue; }
} }
// all the special cases are catered for... treat this as a normal character // all the special cases are catered for... treat this as a normal character
@ -5563,8 +5558,7 @@ namespace NLGUI
{ {
if (!_Paragraph || _Paragraph->getNumChildren() == 0) if (!_Paragraph || _Paragraph->getNumChildren() == 0)
{ {
ucstring tmp("\n"); addString("\n");
addString(tmp);
} }
else else
{ {
@ -6086,8 +6080,7 @@ namespace NLGUI
{ {
// Get the string name // Get the string name
string name = elm.getAttribute("name"); string name = elm.getAttribute("name");
ucstring ucValue; string ucValue = elm.getAttribute("value");
ucValue.fromUtf8(elm.getAttribute("value"));
uint size = 20; uint size = 20;
uint maxlength = 1024; uint maxlength = 1024;
@ -6121,12 +6114,12 @@ namespace NLGUI
string normal = elm.getAttribute("src"); string normal = elm.getAttribute("src");
string pushed; string pushed;
string over; string over;
ucstring ucValue = ucstring("on"); string ucValue = "on";
bool checked = elm.hasAttribute("checked"); bool checked = elm.hasAttribute("checked");
// TODO: unknown if empty attribute should override or not // TODO: unknown if empty attribute should override or not
if (elm.hasNonEmptyAttribute("value")) if (elm.hasNonEmptyAttribute("value"))
ucValue.fromUtf8(elm.getAttribute("value")); ucValue = elm.getAttribute("value");
if (type == "radio") if (type == "radio")
{ {
@ -6191,8 +6184,7 @@ namespace NLGUI
string name = elm.getAttribute("name"); string name = elm.getAttribute("name");
// Get the value // Get the value
ucstring ucValue; string ucValue = elm.getAttribute("value");
ucValue.fromUtf8(elm.getAttribute("value"));
// Add an entry // Add an entry
CGroupHTML::CForm::CEntry entry; CGroupHTML::CForm::CEntry entry;
@ -6224,8 +6216,7 @@ namespace NLGUI
if (elm.hasNonEmptyAttribute("value")) if (elm.hasNonEmptyAttribute("value"))
fromString(elm.getAttribute("value"), _UL.back().Value); fromString(elm.getAttribute("value"), _UL.back().Value);
ucstring str; string str = _UL.back().getListMarkerText();
str.fromUtf8(_UL.back().getListMarkerText());
addString (str); addString (str);
// list-style-type: outside // list-style-type: outside
@ -6429,7 +6420,7 @@ namespace NLGUI
// use option text as value // use option text as value
if (!elm.hasAttribute("value")) if (!elm.hasAttribute("value"))
{ {
_Forms.back().Entries.back().SelectValues.back() = _SelectOptionStr.toUtf8(); _Forms.back().Entries.back().SelectValues.back() = _SelectOptionStr;
} }
// insert the parsed text into the select control // insert the parsed text into the select control
@ -6437,7 +6428,7 @@ namespace NLGUI
if (cb) if (cb)
{ {
uint lineIndex = cb->getNumTexts(); uint lineIndex = cb->getNumTexts();
cb->addText(_SelectOptionStr.toUtf8()); cb->addText(_SelectOptionStr);
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex) if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{ {
cb->setGrayed(lineIndex, true); cb->setGrayed(lineIndex, true);
@ -6449,7 +6440,7 @@ namespace NLGUI
if (sb) if (sb)
{ {
uint lineIndex = sb->getNumLine(); uint lineIndex = sb->getNumLine();
sb->addLine(_SelectOptionStr.toUtf8(), "", ""); sb->addLine(_SelectOptionStr, "", "");
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex) if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{ {

@ -118,9 +118,10 @@ namespace NLGUI
// Letter size // Letter size
// - "_" that should be the character with the lowest part // - "_" that should be the character with the lowest part
// - A with an accent for the highest part // - A with an accent for the highest part
_FontSizingChars.fromUtf8("_\xc3\x84"); // https://www.compart.com/en/unicode/U+00C4
_FontSizingChars = { (u32char)'_', 0x000000C4 };
// fallback if SizingChars are not supported by font // fallback if SizingChars are not supported by font
_FontSizingFallback.fromUtf8("|"); _FontSizingFallback = { (u32char)'|' };
computeFontSize (); computeFontSize ();
} }
@ -396,12 +397,12 @@ namespace NLGUI
else else
if ( name == "sizing_chars" ) if ( name == "sizing_chars" )
{ {
return _FontSizingChars.toUtf8(); return CUtfStringView(_FontSizingChars).toUtf8();
} }
else else
if ( name == "sizing_fallback" ) if ( name == "sizing_fallback" )
{ {
return _FontSizingFallback.toUtf8(); return CUtfStringView(_FontSizingFallback).toUtf8();
} }
else else
return ""; return "";
@ -688,13 +689,13 @@ namespace NLGUI
else else
if( name == "sizing_chars" ) if( name == "sizing_chars" )
{ {
_FontSizingChars.fromUtf8(value); _FontSizingChars = CUtfStringView(value).toUtf32();
return true; return true;
} }
else else
if( name == "sizing_fallback" ) if( name == "sizing_fallback" )
{ {
_FontSizingFallback.fromUtf8(value); _FontSizingFallback = CUtfStringView(value).toUtf32();
return true; return true;
} }
else else
@ -766,8 +767,8 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() ); xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() );
xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() ); xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() );
xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() ); xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() );
xmlSetProp( node, BAD_CAST "sizing_chars", BAD_CAST _FontSizingChars.toUtf8().c_str() ); xmlSetProp( node, BAD_CAST "sizing_chars", BAD_CAST CUtfStringView(_FontSizingChars).toUtf8().c_str() );
xmlSetProp( node, BAD_CAST "sizing_fallback", BAD_CAST _FontSizingFallback.toUtf8().c_str() ); xmlSetProp( node, BAD_CAST "sizing_fallback", BAD_CAST CUtfStringView(_FontSizingFallback).toUtf8().c_str() );
return true; return true;
} }
@ -953,16 +954,16 @@ namespace NLGUI
} }
// "_Ä" lowest/highest chars (underscore, A+diaeresis) // "_Ä" lowest/highest chars (underscore, A+diaeresis)
_FontSizingChars.fromUtf8("_\xc3\x84"); _FontSizingChars = { (u32char)'_', 0x000000C4 };
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_chars" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_chars" );
if (prop) if (prop)
_FontSizingChars.fromUtf8((const char*)prop); _FontSizingChars = CUtfStringView((const char*)prop).toUtf32();
// fallback if SizingChars are not supported by font // fallback if SizingChars are not supported by font
_FontSizingFallback.fromUtf8("|"); _FontSizingFallback = { (u32char)'|' };
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_fallback" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_fallback" );
if (prop) if (prop)
_FontSizingFallback.fromUtf8((const char*)prop); _FontSizingFallback = CUtfStringView((const char*)prop).toUtf32();
computeFontSize (); computeFontSize ();
} }
@ -1468,9 +1469,9 @@ namespace NLGUI
void CViewText::setFontSizing(const std::string &chars, const std::string &fallback) void CViewText::setFontSizing(const std::string &chars, const std::string &fallback)
{ {
_FontSizingChars.clear(); _FontSizingChars.clear();
_FontSizingChars.fromUtf8(chars); _FontSizingChars = CUtfStringView(chars).toUtf32();
_FontSizingFallback.clear(); _FontSizingFallback.clear();
_FontSizingFallback.fromUtf8(fallback); _FontSizingFallback = CUtfStringView(fallback).toUtf32();
} }
// *************************************************************************** // ***************************************************************************
@ -1683,7 +1684,7 @@ namespace NLGUI
nMaxWidth *= _Scale; nMaxWidth *= _Scale;
//for (i = 0; i < textSize; ++i) //for (i = 0; i < textSize; ++i)
CUtfStringView sv(_Text); CUtfStringView sv(_Text);
u32string ucStrLetter(1, ' '); ::u32string ucStrLetter(1, ' ');
for (CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++i) for (CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++i)
{ {
if(isFormatTagChange(i, formatTagIndex)) if(isFormatTagChange(i, formatTagIndex))
@ -1863,7 +1864,7 @@ namespace NLGUI
uint i; uint i;
for(i= (uint)spaceEnd;i<(uint)_Text.length();i++) for(i= (uint)spaceEnd;i<(uint)_Text.length();i++)
{ {
ucchar c= _Text[i]; char c= _Text[i];
if(c==' ' || c=='\n') if(c==' ' || c=='\n')
break; break;
// If change of color tag, stop the word, but don't take the new color now. // If change of color tag, stop the word, but don't take the new color now.
@ -1950,7 +1951,7 @@ namespace NLGUI
else else
{ {
float px = numSpaces * _SpaceWidth; float px = numSpaces * _SpaceWidth;
u32string oneChar(1, ' '); ::u32string oneChar(1, ' ');
CUtfStringView wsv(wordValue); CUtfStringView wsv(wordValue);
CUtfStringView::iterator wit(wsv.begin()), wend(wsv.end()); CUtfStringView::iterator wit(wsv.begin()), wend(wsv.end());
for (; wit != wend; ++wit) for (; wit != wend; ++wit)
@ -2198,7 +2199,7 @@ namespace NLGUI
if (_ClampRight) if (_ClampRight)
{ {
CUtfStringView sv(_Text); CUtfStringView sv(_Text);
u32string ucStrLetter = u32string(1, (u32char)' '); ::u32string ucStrLetter = u32string(1, (u32char)' ');
for (CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it) for (CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it)
{ {
ucStrLetter[0] = *it; ucStrLetter[0] = *it;
@ -2224,8 +2225,8 @@ namespace NLGUI
else else
{ {
// FIXME: Optimize reverse UTF iteration // FIXME: Optimize reverse UTF iteration
u32string uctext = CUtfStringView(_Text).toUtf32(); ::u32string uctext = CUtfStringView(_Text).toUtf32();
u32string ucStrLetter = u32string(1, (u32char)' '); ::u32string ucStrLetter = u32string(1, (u32char)' ');
for (sint i = (sint)uctext.size() - 1; i >= 0; --i) for (sint i = (sint)uctext.size() - 1; i >= 0; --i)
{ {
ucStrLetter[0] = uctext[i]; ucStrLetter[0] = uctext[i];
@ -2358,7 +2359,7 @@ namespace NLGUI
charIndex += currLine.getNumChars() + currLine.getEndSpaces() + (currLine.getLF() ? 1 : 0); charIndex += currLine.getNumChars() + currLine.getEndSpaces() + (currLine.getLF() ? 1 : 0);
} }
// skip all spaces at start of line (unless there are only spaces in the line) // skip all spaces at start of line (unless there are only spaces in the line)
std::string::size_type nextPos = _Text.find_first_not_of((ucchar) ' ', charIndex); std::string::size_type nextPos = _Text.find_first_not_of(' ', charIndex);
if (nextPos != std::string::npos) if (nextPos != std::string::npos)
{ {
if (getLineFromIndex(charIndex) == (sint) line) if (getLineFromIndex(charIndex) == (sint) line)
@ -2567,7 +2568,7 @@ namespace NLGUI
float px = 0.f; float px = 0.f;
UTextContext::CStringInfo si; UTextContext::CStringInfo si;
u32string singleChar(1, ' '); ::u32string singleChar(1, ' ');
uint i = 0; uint i = 0;
NLMISC::CUtfStringView sv(textValue); NLMISC::CUtfStringView sv(textValue);
for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++i) for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++i)
@ -3405,7 +3406,7 @@ namespace NLGUI
while(textIndex<formatTag.Index) while(textIndex<formatTag.Index)
{ {
if(tempText[textIndex] == ucchar(' ')) if(tempText[textIndex] == ' ')
spacesNb++; spacesNb++;
textIndex++; textIndex++;

@ -459,6 +459,9 @@ namespace NLMISC
{ {
return handleWMCopyData(hwnd, (COPYDATASTRUCT *) lParam); return handleWMCopyData(hwnd, (COPYDATASTRUCT *) lParam);
} }
// https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-unichar
if (uMsg == WM_UNICHAR)
return (wParam == UNICODE_NOCHAR);
return DefWindowProc(hwnd, uMsg, wParam, lParam); return DefWindowProc(hwnd, uMsg, wParam, lParam);
} }

@ -102,13 +102,13 @@ ucstring CUtfStringView::toUtf16(bool reEncode) const
return res; return res;
} }
u32string CUtfStringView::toUtf32() const ::u32string CUtfStringView::toUtf32() const
{ {
// Decode any UTF // Decode any UTF
// This implementation makes no attempt at fixing bad encoding // This implementation makes no attempt at fixing bad encoding
if (m_Iterator == utf32Iterator) if (m_Iterator == utf32Iterator)
return u32string((const u32char *)m_Str, (const u32char *)((ptrdiff_t)m_Str + m_Size)); return ::u32string((const u32char *)m_Str, (const u32char *)((ptrdiff_t)m_Str + m_Size));
u32string res; ::u32string res;
res.reserve(m_Size << 2); res.reserve(m_Size << 2);
for (iterator it(begin()), end(this->end()); it != end; ++it) for (iterator it(begin()), end(this->end()); it != end; ++it)
res += *it; res += *it;

@ -162,6 +162,14 @@ bool CWinEventEmitter::processMessage (HWND hWnd, uint32 msg, WPARAM wParam, LPA
server->postEvent (new CEventKeyUp ((NLMISC::TKey)wParam, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this)); server->postEvent (new CEventKeyUp ((NLMISC::TKey)wParam, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this));
} }
break; break;
case WM_UNICHAR:
if (wParam != UNICODE_NOCHAR && _KeyboardEventsEnabled)
{
//if (wParam < KeyCount)
//nlinfo("WM_UNICHAR with %u", wParam);
server->postEvent (new CEventChar ((u32char)wParam, getKeyButton(_AltButton, _ShiftButton, _CtrlButton), this));
}
break;
case WM_CHAR: case WM_CHAR:
if (_KeyboardEventsEnabled) if (_KeyboardEventsEnabled)
{ {

@ -499,9 +499,9 @@ void CCombo::init (NLMISC::TKey key, NLMISC::TKeyButton keyButtons)
} }
// *************************************************************************** // ***************************************************************************
ucstring CCombo::toUCString() const string CCombo::toString() const
{ {
ucstring ret; string ret;
if ((KeyButtons & shiftKeyButton) && (Key != 0x10)) if ((KeyButtons & shiftKeyButton) && (Key != 0x10))
ret += CI18N::get("uiKeySHIFT") + "+"; ret += CI18N::get("uiKeySHIFT") + "+";
if ((KeyButtons & ctrlKeyButton) && (Key != 0x11)) if ((KeyButtons & ctrlKeyButton) && (Key != 0x11))

@ -66,7 +66,7 @@ public:
void init (NLMISC::TKey key, NLMISC::TKeyButton keyButtons); void init (NLMISC::TKey key, NLMISC::TKeyButton keyButtons);
/// Get the combo in human readable form /// Get the combo in human readable form
ucstring toUCString() const; std::string toString() const;
// For maps // For maps
bool operator<(const CCombo &other) const bool operator<(const CCombo &other) const

@ -70,7 +70,7 @@ static inline uint getCharacterCategory(u32char c)
/** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed) /** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed)
* It returns the new index * It returns the new index
*/ */
static uint skipUCCharsRight(uint startPos, const u32string &str) static uint skipUCCharsRight(uint startPos, const ::u32string &str)
{ {
uint pos = startPos; uint pos = startPos;
uint endIndex = (uint)str.length(); uint endIndex = (uint)str.length();
@ -87,7 +87,7 @@ static uint skipUCCharsRight(uint startPos, const u32string &str)
/** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed) /** skip a block of character in a string, (same behaviour than when Ctrl-arrow is pressed)
* It returns the new index * It returns the new index
*/ */
static uint skipUCCharsLeft(uint startPos, const u32string &str) static uint skipUCCharsLeft(uint startPos, const ::u32string &str)
{ {
uint pos = startPos; uint pos = startPos;
-- pos; -- pos;
@ -363,7 +363,7 @@ class CAHEditPreviousLine : public CAHEdit
if (_GroupEdit->getMaxHistoric() && (! _GroupEdit->getViewText()->getMultiLine())) if (_GroupEdit->getMaxHistoric() && (! _GroupEdit->getViewText()->getMultiLine()))
{ {
// Get the start of the string. // Get the start of the string.
u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos()); ::u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
// Search all historic string that match startStr. // Search all historic string that match startStr.
for(sint i=_GroupEdit->getCurrentHistoricIndex()+1;i<(sint)_GroupEdit->getNumHistoric();i++) for(sint i=_GroupEdit->getCurrentHistoricIndex()+1;i<(sint)_GroupEdit->getNumHistoric();i++)
@ -435,7 +435,7 @@ class CAHEditNextLine : public CAHEdit
if( (! _GroupEdit->getViewText()->getMultiLine()) && _GroupEdit->getMaxHistoric() && _GroupEdit->getCurrentHistoricIndex()>0) if( (! _GroupEdit->getViewText()->getMultiLine()) && _GroupEdit->getMaxHistoric() && _GroupEdit->getCurrentHistoricIndex()>0)
{ {
// Get the start of the string. // Get the start of the string.
u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos()); ::u32string startStr= _GroupEdit->getInputStringRef().substr(0, _GroupEdit->getCursorPos());
// Search all historic string that match startStr. // Search all historic string that match startStr.
for(sint i=_GroupEdit->getCurrentHistoricIndex()-1;i>=0;i--) for(sint i=_GroupEdit->getCurrentHistoricIndex()-1;i>=0;i--)
@ -521,8 +521,8 @@ protected:
// else cut forwards // else cut forwards
else if(_GroupEdit->getCursorPos() < (sint32) _GroupEdit->getInputStringRef().length()) else if(_GroupEdit->getCursorPos() < (sint32) _GroupEdit->getInputStringRef().length())
{ {
u32string inputString = _GroupEdit->getInputStringRef(); ::u32string inputString = _GroupEdit->getInputStringRef();
u32string::iterator it = inputString.begin() + _GroupEdit->getCursorPos(); ::u32string::iterator it = inputString.begin() + _GroupEdit->getCursorPos();
inputString.erase(it); inputString.erase(it);
_GroupEdit->setInputStringRef (inputString); _GroupEdit->setInputStringRef (inputString);
if (!_GroupEdit->getAHOnChange().empty()) if (!_GroupEdit->getAHOnChange().empty())
@ -660,7 +660,7 @@ class CAHEditExpandOrCycleTell : public CAHEdit
else else
{ {
// it is not a filtered chat, display 'tell' (must be ingame) // it is not a filtered chat, display 'tell' (must be ingame)
_GroupEdit->setCommand(ucstring("tell ") + *lastTellPeople + (ucchar) ' ', false); _GroupEdit->setCommand("tell " + (*lastTellPeople).toUtf8() + ' ', false);
} }
} }
}; };

@ -349,13 +349,13 @@ void CChatWindow::enableBlink(uint numBlinks)
void CChatWindow::setCommand(const std::string &command, bool execute) void CChatWindow::setCommand(const std::string &command, bool execute)
{ {
if (!_EB) return; if (!_EB) return;
_EB->setCommand(ucstring(command), execute); _EB->setCommand(command, execute);
} }
void CChatWindow::setCommand(const ucstring &command,bool execute) void CChatWindow::setCommand(const ucstring &command,bool execute)
{ {
if (!_EB) return; if (!_EB) return;
_EB->setCommand(command, execute); _EB->setCommand(command.toUtf8(), execute);
} }

@ -3398,7 +3398,7 @@ void CDBCtrlSheet::getContextHelp(std::string &help) const
if (macroName.empty()) if (macroName.empty())
macroName = CI18N::get("uiNotAssigned"); macroName = CI18N::get("uiNotAssigned");
ucstring assignedTo = macro->Combo.toUCString(); ucstring assignedTo = macro->Combo.toString();
if (assignedTo.empty()) if (assignedTo.empty())
assignedTo = CI18N::get("uiNotAssigned"); assignedTo = CI18N::get("uiNotAssigned");

@ -89,7 +89,7 @@ bool CGroupModalGetKey::handleEvent (const NLGUI::CEventDescriptor &event)
// Setup the text ! // Setup the text !
CInterfaceManager *pIM = CInterfaceManager::getInstance(); CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewText *pVT= dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId( VIEW_TEXT_KEY )); CViewText *pVT= dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId( VIEW_TEXT_KEY ));
if (pVT != NULL) pVT->setText(Combo.toUCString().toUtf8()); if (pVT != NULL) pVT->setText(Combo.toString());
// Check if in use // Check if in use
CActionsManager *pCurAM = NULL; CActionsManager *pCurAM = NULL;

@ -244,7 +244,7 @@ void CGroupQuickHelp::beginElement(CHtmlElement &elm)
CActionsManager::TActionComboMap::const_iterator ite = actionCombo.find (CAction::CName (elm.getAttribute("z_action_shortcut").c_str(), params.c_str())); CActionsManager::TActionComboMap::const_iterator ite = actionCombo.find (CAction::CName (elm.getAttribute("z_action_shortcut").c_str(), params.c_str()));
if (ite != actionCombo.end()) if (ite != actionCombo.end())
{ {
addString (ite->second.toUCString()); addString (ite->second.toString());
} }
} }
} }

@ -665,7 +665,7 @@ static DECLARE_INTERFACE_USER_FCT(getKey)
CActionsManager::TActionComboMap::const_iterator it = acmap.find(CAction::CName(name.c_str(),param.c_str())); CActionsManager::TActionComboMap::const_iterator it = acmap.find(CAction::CName(name.c_str(),param.c_str()));
if (it != acmap.end()) if (it != acmap.end())
{ {
result.setString (it->second.toUCString().toUtf8()); result.setString (it->second.toString());
} }
else else
{ {

@ -208,7 +208,7 @@ void getAllComboAction(uint8 nAM, CGroupList *pList, const map<ucstring, CComboA
if(remapIT->second.Combo.Key==KeyCount) if(remapIT->second.Combo.Key==KeyCount)
keyName= CI18N::get("uiNotAssigned"); keyName= CI18N::get("uiNotAssigned");
else else
keyName= remapIT->second.Combo.toUCString(); keyName= remapIT->second.Combo.toString();
const CBaseAction *baseAction = pAM->getBaseAction(remapIT->second.ActionName); const CBaseAction *baseAction = pAM->getBaseAction(remapIT->second.ActionName);
if (baseAction) if (baseAction)
{ {
@ -711,7 +711,7 @@ void CModalContainerEditCmd::activateFrom (const std::string &cmdName, const std
CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_TEXT_KEY)); CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_TEXT_KEY));
if (pVT != NULL) pVT->setActive(true); if (pVT != NULL) pVT->setActive(true);
// setup the text of the key // setup the text of the key
pVT->setText(it->second.toUCString().toUtf8()); pVT->setText(it->second.toString());
// There is already a shortcut so we can display ok button // There is already a shortcut so we can display ok button
pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK)); pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
@ -887,7 +887,7 @@ void CModalContainerEditCmd::validCurrentCommand()
{ {
CurrentEditCmdLine.Combo = it->second; CurrentEditCmdLine.Combo = it->second;
// Yes ok let setup the text of the key // Yes ok let setup the text of the key
pVT->setText(it->second.toUCString().toUtf8()); pVT->setText(it->second.toString());
// There is already a shortcut so we can display ok button // There is already a shortcut so we can display ok button
CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK)); CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
if (pCB != NULL) pCB->setFrozen (false); if (pCB != NULL) pCB->setFrozen (false);
@ -1353,7 +1353,7 @@ public:
pMCM->NewKey->CurrentEditCmdLine.Combo = pGetKey->Combo; pMCM->NewKey->CurrentEditCmdLine.Combo = pGetKey->Combo;
CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+VIEW_EDITCMD_TEXT_KEY)); CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+VIEW_EDITCMD_TEXT_KEY));
if (pVT != NULL) pVT->setText(pMCM->NewKey->CurrentEditCmdLine.Combo.toUCString().toUtf8()); if (pVT != NULL) pVT->setText(pMCM->NewKey->CurrentEditCmdLine.Combo.toString());
CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+CTRL_EDITCMD_BUTTON_OK)); CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+CTRL_EDITCMD_BUTTON_OK));
if (pCB != NULL) pCB->setFrozen (false); if (pCB != NULL) pCB->setFrozen (false);
@ -1365,7 +1365,7 @@ public:
pMCM->EditCmd->CurrentEditCmdLine.Combo = pGetKey->Combo; pMCM->EditCmd->CurrentEditCmdLine.Combo = pGetKey->Combo;
pMCM->CurrentEditMacro.Combo = pMCM->EditCmd->CurrentEditCmdLine.Combo; pMCM->CurrentEditMacro.Combo = pMCM->EditCmd->CurrentEditCmdLine.Combo;
CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(VIEW_NEWMACRO_KEY)); CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(VIEW_NEWMACRO_KEY));
if (pVT != NULL) pVT->setText(pMCM->EditCmd->CurrentEditCmdLine.Combo.toUCString().toUtf8()); if (pVT != NULL) pVT->setText(pMCM->EditCmd->CurrentEditCmdLine.Combo.toString());
} }
} }
}; };

@ -897,7 +897,7 @@ public:
if (pMCM->CurrentEditMacro.Combo.Key == KeyCount) if (pMCM->CurrentEditMacro.Combo.Key == KeyCount)
pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT)); pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
else else
pVT->setText(pMCM->CurrentEditMacro.Combo.toUCString().toUtf8()); pVT->setText(pMCM->CurrentEditMacro.Combo.toString());
} }
pList->clearGroups(); pList->clearGroups();
@ -1003,7 +1003,7 @@ void addMacroLine (CGroupList *pParent, uint macNb, const CMacroCmd &macro)
if (pVT != NULL) if (pVT != NULL)
{ {
if (macro.Combo.Key != KeyCount) if (macro.Combo.Key != KeyCount)
pVT->setText(macro.Combo.toUCString().toUtf8()); pVT->setText(macro.Combo.toString());
else else
pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT)); pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
} }

@ -180,7 +180,7 @@ public:
if (pVT != NULL) if (pVT != NULL)
{ {
if (it != acmap.end()) if (it != acmap.end())
pVT->setText(it->second.toUCString().toUtf8()); pVT->setText(it->second.toString());
else else
pVT->setText(CI18N::get("uiNotAssigned")); pVT->setText(CI18N::get("uiNotAssigned"));
} }

@ -714,7 +714,7 @@ static std::string getActionKey(const char* name, const char* param = "")
CActionsManager::TActionComboMap::const_iterator ite = acmap.find(CAction::CName(name, param)); CActionsManager::TActionComboMap::const_iterator ite = acmap.find(CAction::CName(name, param));
if (ite != acmap.end()) if (ite != acmap.end())
return ite->second.toUCString().toString(); return ite->second.toString();
return CI18N::get("uiNotAssigned"); return CI18N::get("uiNotAssigned");
} }

Loading…
Cancel
Save