kaetemi 4 years ago
parent ac799e444d
commit 376dd2aff1

@ -38,7 +38,7 @@ namespace NLGUI
private:
// stylesheet currently parsed
ucstring _Style;
std::string _Style;
// keep track of current position in _Style
size_t _Position;
@ -70,49 +70,49 @@ namespace NLGUI
void preprocess();
// 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
void parseRule(const ucstring &selectorString, const ucstring &styleString);
void parseRule(const std::string &selectorString, const std::string &styleString);
inline bool is_eof() const
{
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') ||
(ch >= (ucchar)'a' && ch <= (ucchar)'f') ||
(ch >= (ucchar)'A' && ch <= (ucchar)'F'));
return ((ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'f') ||
(ch >= 'A' && ch <= 'F'));
}
inline bool maybe_escape() const
{
// 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)'}') ||
(open == '[' && ch == (ucchar)']') ||
(open == '(' && ch == (ucchar)')'));
return ((open == '{' && ch == (char)'}') ||
(open == '[' && ch == (char)']') ||
(open == '(' && ch == (char)')'));
}
inline bool is_comment_open() const
@ -120,25 +120,25 @@ namespace NLGUI
if (_Position+1 > _Style.size())
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*/;
}
inline bool is_alpha(ucchar ch) const
inline bool is_alpha(char ch) const
{
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';
}
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
return ch == '_' || ch == '-' || is_alpha(ch) || is_digit(ch) || is_nonascii(ch) || ch == '\\'/*is_escape(ch)*/;

@ -82,13 +82,13 @@ public:
return _Key;
}
// 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);
return _Char;
}
// 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);
return _String;
@ -141,9 +141,9 @@ private:
union
{
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.
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;
void setUCTitleOpened (const ucstring &title);
ucstring getUCTitleClosed () const;
@ -287,9 +294,15 @@ namespace NLGUI
REFLECT_STRING("title", getTitle, setTitle);
REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened);
REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed);
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened);
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed);
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle);
REFLECT_STRING("title_raw", getTitleRaw, setTitleRaw);
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_SINT32("pop_min_h", getPopupMinH, setPopupMinH);
REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH);

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

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

@ -222,7 +222,7 @@ namespace NLGUI
int luaSetLineMaxW(CLuaState &ls);
REFLECT_EXPORT_START(CViewText, CViewBase)
REFLECT_STRING("text", getText, setText);
REFLECT_STRING("text_raw", getText, setText);
REFLECT_STRING("hardtext", getHardText, setHardText);
// REFLECT_UCSTRING("uc_text", getTextAsUtf16, setTextAsUtf16); // Deprecate uc_ functions
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 '_')
float _FontWidth;
// strings to use when computing font size
ucstring _FontSizingChars;
ucstring _FontSizingFallback;
::u32string _FontSizingChars;
::u32string _FontSizingFallback;
// height of the font in pixel.
// use getFontHeight
float _FontHeight;

@ -320,11 +320,11 @@ public:
class CEventChar : public CEventKey
{
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;
}
ucchar Char;
u32char Char;
virtual CEvent *clone() const {return new CEventChar(*this);}
void setRaw( bool raw ) { _Raw = raw; }
@ -341,11 +341,11 @@ private:
class CEventString : public CEventKey
{
public:
CEventString (const ucstring &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId)
CEventString (const std::string &str, IEventEmitter* emitter) : CEventKey (noKeyButton, emitter, EventStringId)
{
String = str;
}
ucstring String;
std::string String;
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 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
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::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;
}
// 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);
}

@ -183,6 +183,10 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
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);
}

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

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

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

@ -96,7 +96,7 @@ namespace NLGUI
_ViewTextDeltaX(0)
{
_Prompt = u32string(1, (u32char)'>');
_Prompt = ::u32string(1, (u32char)'>');
_BackSelectColor= CRGBA::White;
_TextSelectColor= CRGBA::Black;
}
@ -264,9 +264,9 @@ namespace NLGUI
std::string s;
s.reserve( _NegativeFilter.size() );
std::vector< char >::const_iterator itr;
for( itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr )
s.push_back( *itr );
std::vector< u32char >::const_iterator itr;
for (itr = _NegativeFilter.begin(); itr != _NegativeFilter.end(); ++itr)
CUtfStringView::append(s, *itr);
return s;
}
@ -450,10 +450,10 @@ namespace NLGUI
if( name == "negative_filter" )
{
_NegativeFilter.clear();
std::string::size_type i;
for( i = 0; i < value.size(); i++ )
_NegativeFilter.push_back( value[ i ] );
::u32string::size_type i;
::u32string ustr = CUtfStringView(value).toUtf32();
for( i = 0; i < ustr.size(); i++ )
_NegativeFilter.push_back(ustr[i]);
}
else
CInterfaceGroup::setProperty( name, value );
@ -539,9 +539,9 @@ namespace NLGUI
std::string s;
s.reserve( _NegativeFilter.size() );
std::vector< char >::const_iterator itr;
std::vector< u32char >::const_iterator 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() );
@ -657,9 +657,11 @@ namespace NLGUI
prop = (char*) xmlGetProp( cur, (xmlChar*)"negative_filter" );
if (prop)
{
uint length = (uint)strlen(prop);
_NegativeFilter.resize(length);
std::copy((const char *) prop, (const char *) prop + length, _NegativeFilter.begin());
_NegativeFilter.clear();
::u32string::size_type i;
::u32string ustr = CUtfStringView(prop).toUtf32();
for( i = 0; i < ustr.size(); i++ )
_NegativeFilter.push_back(ustr[i]);
}
return true;
@ -829,10 +831,10 @@ namespace NLGUI
// ----------------------------------------------------------------------------
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();
u32string toAppend;
::u32string toAppend;
// filter character depending on the entry type
switch (_EntryType)
{
@ -854,7 +856,7 @@ namespace NLGUI
}
}
// 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;
@ -965,7 +967,7 @@ namespace NLGUI
{
length = _MaxNumChar - (sint)_InputString.length();
}
u32string toAdd = toAppend.substr(0, length);
::u32string toAdd = toAppend.substr(0, length);
sint32 minPos;
sint32 maxPos;
if (_CurrSelection == this)
@ -1015,7 +1017,7 @@ namespace NLGUI
_CursorAtPreviousLineEnd = false;
if (_ClearOnEscape)
{
setInputStringAsUtf32(u32string());
setInputStringAsUtf32(::u32string());
triggerOnChangeAH();
}
CWidgetManager::getInstance()->setCaptureKeyboard(NULL);
@ -1077,7 +1079,7 @@ namespace NLGUI
cutSelection();
}
ucchar c = isKeyRETURN ? '\n' : rEDK.getChar();
u32char c = isKeyRETURN ? '\n' : rEDK.getChar();
if (isFiltered(c)) return;
switch(_EntryType)
{
@ -1124,8 +1126,8 @@ namespace NLGUI
if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX))
{
// estimate new string
u32string copyStr= _InputString;
u32string::iterator it = copyStr.begin() + _CursorPos;
::u32string copyStr= _InputString;
::u32string::iterator it = copyStr.begin() + _CursorPos;
copyStr.insert(it, c);
sint32 value;
fromString(CUtfStringView(copyStr).toUtf8(), value);
@ -1137,8 +1139,8 @@ namespace NLGUI
if(_EntryType==PositiveInteger && (_PositiveIntegerMinValue!=0 || _PositiveIntegerMaxValue!=UINT_MAX))
{
// estimate new string
u32string copyStr= _InputString;
u32string::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;
@ -1151,7 +1153,7 @@ namespace NLGUI
if ((uint) _InputString.length() < _MaxNumChar)
{
makeTopWindow();
u32string::iterator it = _InputString.begin() + _CursorPos;
::u32string::iterator it = _InputString.begin() + _CursorPos;
_InputString.insert(it, c);
++ _CursorPos;
triggerOnChangeAH();
@ -1263,7 +1265,7 @@ namespace NLGUI
// else delete last character
else if(_InputString.size () > 0 && _CursorPos != 0)
{
u32string::iterator it = _InputString.begin() + (_CursorPos - 1);
::u32string::iterator it = _InputString.begin() + (_CursorPos - 1);
_InputString.erase(it);
-- _CursorPos;
_CursorAtPreviousLineEnd = false;
@ -1436,7 +1438,7 @@ namespace NLGUI
std::string usTmp;
if (_EntryType == Password)
{
usTmp = CUtfStringView(_Prompt + u32string(_InputString.size(), 0x2022)).toUtf8();
usTmp = CUtfStringView(_Prompt + ::u32string(_InputString.size(), 0x2022)).toUtf8();
}
else
{
@ -1634,7 +1636,7 @@ namespace NLGUI
{
setInputStringAsUtf32(CUtfStringView(str).toUtf32());
}
void CGroupEditBox::setInputStringAsUtf32(const u32string &str)
void CGroupEditBox::setInputStringAsUtf32(const ::u32string &str)
{
_InputString = str;
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;
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
if(_Frozen)
return;
// set the string and maybe execute
setInputStringAsUtf16((ucchar) '/' + command);
setInputString('/' + command);
if (execute)
{
// stop selection
@ -1878,7 +1880,7 @@ namespace NLGUI
void CGroupEditBox::onQuit()
{
// clear the text and restore backup pos before final save
setInputStringAsUtf32(u32string());
setInputStringAsUtf32(::u32string());
_CurrSelection = NULL;
}
@ -1886,7 +1888,7 @@ namespace NLGUI
void CGroupEditBox::onLoadConfig()
{
// config is not saved when there's an empty string, so restore that default state.
setInputStringAsUtf32(u32string());
setInputStringAsUtf32(::u32string());
_CurrSelection = NULL;
_PrevNumLine = 1;
}
@ -1901,7 +1903,7 @@ namespace NLGUI
if (_DefaultInputString)
{
_DefaultInputString= false;
setInputStringAsUtf32(u32string());
setInputStringAsUtf32(::u32string());
}
_CanRedo = 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)
{
@ -1042,44 +1042,43 @@ namespace NLGUI
return;
// Build a UTF8 string
string inputString(buf, buf+len);
if (_ParsingLua && _TrustedDomain)
{
// we are parsing a lua script
_LuaScript += inputString;
_LuaScript += string(buf, buf + len);
// no more to do
return;
}
// Build a unicode string
ucstring inputUCString;
inputUCString.fromUtf8(inputString);
CUtfStringView inputStringView(buf, len);
// Build the final unicode string
ucstring tmp;
string tmp;
tmp.reserve(len);
uint ucLen = (uint)inputUCString.size();
for (uint i=0; i<ucLen; i++)
u32char lastChar = 0;
u32char inputStringView0 = *inputStringView.begin();
for (CUtfStringView::iterator it(inputStringView.begin()), end(inputStringView.end()); it != end; ++it)
{
ucchar output;
u32char output;
bool keep;
// 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
output = inputUCString[i];
output = *it;
keep = true;
}
else
{
// 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)
{
tmp.push_back(output);
CUtfStringView::append(tmp, output);
lastChar = output;
}
}
@ -1293,7 +1292,7 @@ namespace NLGUI
pos++;
}
token = content.substr(start, pos - start);
addString(ucstring::makeFromUtf8(token));
addString(token);
// skip closing quote
pos++;
@ -1376,7 +1375,7 @@ namespace NLGUI
if (elm.hasAttribute(token))
{
addString(ucstring::makeFromUtf8(elm.getAttribute(token)));
addString(elm.getAttribute(token));
}
}
else
@ -1562,7 +1561,7 @@ namespace NLGUI
else
if( name == "title_prefix" )
{
return _TitlePrefix.toString();
return _TitlePrefix;
}
else
if( name == "background_color" )
@ -2224,7 +2223,7 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "type", BAD_CAST "html" );
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 "error_color", BAD_CAST toString( ErrorColor ).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 ?
bool keep = true;
@ -2691,13 +2690,13 @@ namespace NLGUI
else
{
// Get the last char
ucchar lastChar = lastCharParam;
u32char lastChar = lastCharParam;
if (lastChar == 0)
lastChar = getLastChar();
keep = ((lastChar != (ucchar)' ') &&
keep = ((lastChar != (u32char)' ') &&
(lastChar != 0)) || getPRE() || (_CurrentViewImage && (lastChar == 0));
if(!getPRE())
input = ' ';
input = (u32char)' ';
}
}
break;
@ -2710,11 +2709,11 @@ namespace NLGUI
else
{
// Get the last char
ucchar lastChar = lastCharParam;
u32char lastChar = lastCharParam;
if (lastChar == 0)
lastChar = getLastChar();
keep = ((lastChar != (ucchar)' ') &&
(lastChar != (ucchar)'\n') &&
keep = ((lastChar != (u32char)' ') &&
(lastChar != (u32char)'\n') &&
(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)
{
@ -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 ?
if (!_Paragraph)
@ -3024,7 +3023,7 @@ namespace NLGUI
CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb"));
if (eb)
{
eb->setInputString(CUtfStringView(decodeHTMLEntities(content)).toUtf8());
eb->setInputString(decodeHTMLEntities(content));
if (style.hasStyle("background-color"))
{
CViewBitmap *bg = dynamic_cast<CViewBitmap*>(eb->getView("bg"));
@ -3310,7 +3309,7 @@ namespace NLGUI
{
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())
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();
if (parent)
@ -3412,7 +3411,7 @@ namespace NLGUI
CGroupContainer *container = dynamic_cast<CGroupContainer*>(parent);
if (container)
{
container->setUCTitle (title);
container->setTitleRaw (title);
}
}
}
@ -3420,21 +3419,18 @@ namespace NLGUI
void CGroupHTML::setTitle(const std::string &title)
{
ucstring uctitle;
uctitle.fromUtf8(title);
_TitleString.clear();
if(!_TitlePrefix.empty())
{
_TitleString = _TitlePrefix + " - ";
}
_TitleString += uctitle;
_TitleString += title;
setTitle(_TitleString);
setTitleRaw(_TitleString);
}
std::string CGroupHTML::getTitle() const {
return _TitleString.toUtf8();
return _TitleString;
};
// ***************************************************************************
@ -4685,9 +4681,7 @@ namespace NLGUI
CLuaIHM::checkArgType(ls, funcName, 3, LUA_TBOOLEAN);
string name = ls.toString(1);
ucstring text;
text.fromUtf8(ls.toString(2));
string text = ls.toString(2);
if (!_Forms.empty())
{
@ -4717,7 +4711,7 @@ namespace NLGUI
const char *funcName = "addString";
CLuaIHM::checkArgCount(ls, funcName, 1);
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
addString(ucstring::makeFromUtf8(ls.toString(1)));
addString(ls.toString(1));
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 (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>='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;
for (uint i=0; i<str.length(); ++i)
@ -5002,13 +4997,13 @@ namespace NLGUI
continue;
}
ucchar c = 0;
u32char c = 0;
// 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
result += c;
CUtfStringView::append(result, c);
// move 'i' forward to point at the ';' .. the for(...) will increment i to point to next char
i = last;
@ -5017,10 +5012,10 @@ namespace NLGUI
}
// special xml characters
if (str.substr(i+1,5)==ucstring("quot;")) { i+=5; result+='\"'; continue; }
if (str.substr(i+1,4)==ucstring("amp;")) { i+=4; result+='&'; continue; }
if (str.substr(i+1,3)==ucstring("lt;")) { i+=3; result+='<'; continue; }
if (str.substr(i+1,3)==ucstring("gt;")) { i+=3; result+='>'; continue; }
if (str.substr(i+1,5)=="quot;") { i+=5; result+='\"'; continue; }
if (str.substr(i+1,4)=="amp;") { i+=4; result+='&'; continue; }
if (str.substr(i+1,3)=="lt;") { 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
@ -5563,8 +5558,7 @@ namespace NLGUI
{
if (!_Paragraph || _Paragraph->getNumChildren() == 0)
{
ucstring tmp("\n");
addString(tmp);
addString("\n");
}
else
{
@ -6086,8 +6080,7 @@ namespace NLGUI
{
// Get the string name
string name = elm.getAttribute("name");
ucstring ucValue;
ucValue.fromUtf8(elm.getAttribute("value"));
string ucValue = elm.getAttribute("value");
uint size = 20;
uint maxlength = 1024;
@ -6121,12 +6114,12 @@ namespace NLGUI
string normal = elm.getAttribute("src");
string pushed;
string over;
ucstring ucValue = ucstring("on");
string ucValue = "on";
bool checked = elm.hasAttribute("checked");
// TODO: unknown if empty attribute should override or not
if (elm.hasNonEmptyAttribute("value"))
ucValue.fromUtf8(elm.getAttribute("value"));
ucValue = elm.getAttribute("value");
if (type == "radio")
{
@ -6191,8 +6184,7 @@ namespace NLGUI
string name = elm.getAttribute("name");
// Get the value
ucstring ucValue;
ucValue.fromUtf8(elm.getAttribute("value"));
string ucValue = elm.getAttribute("value");
// Add an entry
CGroupHTML::CForm::CEntry entry;
@ -6224,8 +6216,7 @@ namespace NLGUI
if (elm.hasNonEmptyAttribute("value"))
fromString(elm.getAttribute("value"), _UL.back().Value);
ucstring str;
str.fromUtf8(_UL.back().getListMarkerText());
string str = _UL.back().getListMarkerText();
addString (str);
// list-style-type: outside
@ -6429,7 +6420,7 @@ namespace NLGUI
// use option text as 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
@ -6437,7 +6428,7 @@ namespace NLGUI
if (cb)
{
uint lineIndex = cb->getNumTexts();
cb->addText(_SelectOptionStr.toUtf8());
cb->addText(_SelectOptionStr);
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{
cb->setGrayed(lineIndex, true);
@ -6449,7 +6440,7 @@ namespace NLGUI
if (sb)
{
uint lineIndex = sb->getNumLine();
sb->addLine(_SelectOptionStr.toUtf8(), "", "");
sb->addLine(_SelectOptionStr, "", "");
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{

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

@ -459,6 +459,9 @@ namespace NLMISC
{
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);
}

@ -102,13 +102,13 @@ ucstring CUtfStringView::toUtf16(bool reEncode) const
return res;
}
u32string CUtfStringView::toUtf32() const
::u32string CUtfStringView::toUtf32() const
{
// Decode any UTF
// This implementation makes no attempt at fixing bad encoding
if (m_Iterator == utf32Iterator)
return u32string((const u32char *)m_Str, (const u32char *)((ptrdiff_t)m_Str + m_Size));
u32string res;
return ::u32string((const u32char *)m_Str, (const u32char *)((ptrdiff_t)m_Str + m_Size));
::u32string res;
res.reserve(m_Size << 2);
for (iterator it(begin()), end(this->end()); it != end; ++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));
}
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:
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))
ret += CI18N::get("uiKeySHIFT") + "+";
if ((KeyButtons & ctrlKeyButton) && (Key != 0x11))

@ -66,7 +66,7 @@ public:
void init (NLMISC::TKey key, NLMISC::TKeyButton keyButtons);
/// Get the combo in human readable form
ucstring toUCString() const;
std::string toString() const;
// For maps
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)
* 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 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)
* It returns the new index
*/
static uint skipUCCharsLeft(uint startPos, const u32string &str)
static uint skipUCCharsLeft(uint startPos, const ::u32string &str)
{
uint pos = startPos;
-- pos;
@ -363,7 +363,7 @@ class CAHEditPreviousLine : public CAHEdit
if (_GroupEdit->getMaxHistoric() && (! _GroupEdit->getViewText()->getMultiLine()))
{
// 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.
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)
{
// 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.
for(sint i=_GroupEdit->getCurrentHistoricIndex()-1;i>=0;i--)
@ -521,8 +521,8 @@ protected:
// else cut forwards
else if(_GroupEdit->getCursorPos() < (sint32) _GroupEdit->getInputStringRef().length())
{
u32string inputString = _GroupEdit->getInputStringRef();
u32string::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())
@ -660,7 +660,7 @@ class CAHEditExpandOrCycleTell : public CAHEdit
else
{
// 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)
{
if (!_EB) return;
_EB->setCommand(ucstring(command), execute);
_EB->setCommand(command, execute);
}
void CChatWindow::setCommand(const ucstring &command,bool execute)
{
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())
macroName = CI18N::get("uiNotAssigned");
ucstring assignedTo = macro->Combo.toUCString();
ucstring assignedTo = macro->Combo.toString();
if (assignedTo.empty())
assignedTo = CI18N::get("uiNotAssigned");

@ -89,7 +89,7 @@ bool CGroupModalGetKey::handleEvent (const NLGUI::CEventDescriptor &event)
// Setup the text !
CInterfaceManager *pIM = CInterfaceManager::getInstance();
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
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()));
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()));
if (it != acmap.end())
{
result.setString (it->second.toUCString().toUtf8());
result.setString (it->second.toString());
}
else
{

@ -208,7 +208,7 @@ void getAllComboAction(uint8 nAM, CGroupList *pList, const map<ucstring, CComboA
if(remapIT->second.Combo.Key==KeyCount)
keyName= CI18N::get("uiNotAssigned");
else
keyName= remapIT->second.Combo.toUCString();
keyName= remapIT->second.Combo.toString();
const CBaseAction *baseAction = pAM->getBaseAction(remapIT->second.ActionName);
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));
if (pVT != NULL) pVT->setActive(true);
// 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
pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
@ -887,7 +887,7 @@ void CModalContainerEditCmd::validCurrentCommand()
{
CurrentEditCmdLine.Combo = it->second;
// 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
CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
if (pCB != NULL) pCB->setFrozen (false);
@ -1353,7 +1353,7 @@ public:
pMCM->NewKey->CurrentEditCmdLine.Combo = pGetKey->Combo;
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));
if (pCB != NULL) pCB->setFrozen (false);
@ -1365,7 +1365,7 @@ public:
pMCM->EditCmd->CurrentEditCmdLine.Combo = pGetKey->Combo;
pMCM->CurrentEditMacro.Combo = pMCM->EditCmd->CurrentEditCmdLine.Combo;
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)
pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
else
pVT->setText(pMCM->CurrentEditMacro.Combo.toUCString().toUtf8());
pVT->setText(pMCM->CurrentEditMacro.Combo.toString());
}
pList->clearGroups();
@ -1003,7 +1003,7 @@ void addMacroLine (CGroupList *pParent, uint macNb, const CMacroCmd &macro)
if (pVT != NULL)
{
if (macro.Combo.Key != KeyCount)
pVT->setText(macro.Combo.toUCString().toUtf8());
pVT->setText(macro.Combo.toString());
else
pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
}

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

Loading…
Cancel
Save