diff --git a/CMakeLists.txt b/CMakeLists.txt index 96efcd0e8..bb3e1352e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,20 @@ IF(WITH_STATIC) IF(LIBLZMA_LIBRARIES) SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${LIBLZMA_LIBRARIES}) ENDIF() + + # under Linux and OS X, recent libxml2 versions are linked against libicu + # FIND_PACKAGE(Icu) + FIND_LIBRARY(ICU_LIBRARY icuuc) + IF(ICU_LIBRARY) + FIND_LIBRARY(ICU_DATA_LIBRARY icudata) + IF(ICU_LIBRARY) + MESSAGE(STATUS "ICU UC was found: ${ICU_LIBRARY}") + ELSE() + MESSAGE(STATUS "ICU UC was NOT found") + ENDIF() + SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${ICU_DATA_LIBRARY} ${ICU_LIBRARY}) + ENDIF() + ENDIF() ENDIF() diff --git a/nel/include/nel/3d/async_file_manager_3d.h b/nel/include/nel/3d/async_file_manager_3d.h index 4e86f10b1..3f43a01e3 100644 --- a/nel/include/nel/3d/async_file_manager_3d.h +++ b/nel/include/nel/3d/async_file_manager_3d.h @@ -40,7 +40,7 @@ class CTextureFile; class CAsyncFileManager3D { - NLMISC_SAFE_SINGLETON_DECL(CAsyncFileManager3D); + NLMISC_SAFE_RELEASABLE_SINGLETON_DECL(CAsyncFileManager3D); CAsyncFileManager3D(); public: diff --git a/nel/include/nel/3d/computed_string.h b/nel/include/nel/3d/computed_string.h index 3f27a2879..c0ae90578 100644 --- a/nel/include/nel/3d/computed_string.h +++ b/nel/include/nel/3d/computed_string.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -181,7 +181,8 @@ public: CVertexBuffer Vertices; CMaterial *Material; CRGBA Color; - ucstring Text; + std::string Text; + size_t Length; uint32 CacheVersion; diff --git a/nel/include/nel/3d/driver.h b/nel/include/nel/3d/driver.h index 75472df37..1892aace0 100644 --- a/nel/include/nel/3d/driver.h +++ b/nel/include/nel/3d/driver.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -262,10 +262,10 @@ public: virtual NLMISC::IEventEmitter *getEventEmitter() = 0; /// Copy a string to system clipboard. - virtual bool copyTextToClipboard(const ucstring &text) = 0; + virtual bool copyTextToClipboard(const std::string &text) = 0; /// Paste a string from system clipboard. - virtual bool pasteTextFromClipboard(ucstring &text) = 0;/// Return the depth of the driver after init(). + virtual bool pasteTextFromClipboard(std::string &text) = 0;/// Return the depth of the driver after init(). virtual uint8 getBitPerPixel() = 0; diff --git a/nel/include/nel/3d/driver_user.h b/nel/include/nel/3d/driver_user.h index c3564975f..a59d167a4 100644 --- a/nel/include/nel/3d/driver_user.h +++ b/nel/include/nel/3d/driver_user.h @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Matt RAYKOWSKI (sfb) // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -558,10 +558,10 @@ public: // @} // Copy a string to system clipboard. - virtual bool copyTextToClipboard(const ucstring &text); + virtual bool copyTextToClipboard(const std::string &text); // Paste a string from system clipboard. - virtual bool pasteTextFromClipboard(ucstring &text); + virtual bool pasteTextFromClipboard(std::string &text); virtual uint64 getSwapBufferCounter(); diff --git a/nel/include/nel/3d/font_generator.h b/nel/include/nel/3d/font_generator.h index b69249d58..f79b3c109 100644 --- a/nel/include/nel/3d/font_generator.h +++ b/nel/include/nel/3d/font_generator.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -33,7 +36,7 @@ typedef struct FT_FaceRec_* FT_Face; #include "nel/misc/types_nl.h" #include - +#include namespace NL3D { @@ -64,17 +67,17 @@ public: * \param height height of the generated bitmap, this value is set by this function * \param pitch pitch of the generated bitmap (+ or - the number of bytes per row), this value is set by this function */ - uint8 *getBitmap (ucchar c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex); + uint8 *getBitmap (u32char c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex); /** returns the width and height of a character using a specific size and * * \warning this function is not very fast (but faster than getBitmap()) because it has to load the char before. */ - void getSizes (ucchar c, uint32 size, uint32 &width, uint32 &height); + void getSizes (u32char c, uint32 size, uint32 &width, uint32 &height); - void getKerning (ucchar left, ucchar right, sint32 &kernx); + void getKerning (u32char left, u32char right, sint32 &kernx); - uint32 getCharIndex (ucchar c); + uint32 getCharIndex (u32char c); uint32 getUID() { return _UID; } @@ -85,6 +88,7 @@ private: static uint32 _FontGeneratorCounterUID; uint32 _UID; std::string _FontFileName; + std::vector _FontFileNames; #ifndef NL_DONT_USE_EXTERNAL_CODE const char *getFT2Error(FT_Error fte); @@ -92,7 +96,7 @@ private: static FT_Library _Library; static uint _LibraryInit; - FT_Face _Face; + std::vector _Faces; #else // NL_DONT_USE_EXTERNAL_CODE #endif // NL_DONT_USE_EXTERNAL_CODE diff --git a/nel/include/nel/3d/font_manager.h b/nel/include/nel/3d/font_manager.h index 663e9d23a..620b2164f 100644 --- a/nel/include/nel/3d/font_manager.h +++ b/nel/include/nel/3d/font_manager.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -19,6 +22,7 @@ #include "nel/misc/types_nl.h" #include "nel/misc/smart_ptr.h" +#include "nel/misc/utf_string_view.h" #include "nel/3d/texture.h" #include "nel/3d/material.h" #include "nel/3d/texture_font.h" @@ -111,6 +115,7 @@ public: * \param output computed string * \param keep800x600Ratio true if you want that CFontManager look at Driver window size, and resize fontSize so it keeps same size... */ + /* void computeString (const std::string& s, CFontGenerator *fontGen, const NLMISC::CRGBA &color, @@ -120,11 +125,12 @@ public: IDriver *driver, CComputedString& output, bool keep800x600Ratio= true); + */ /** * Same as computeString but works with a unicode string (ucstring) */ - void computeString (const ucstring &s, + void computeString (NLMISC::CUtfStringView sv, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, @@ -137,7 +143,21 @@ public: /** * Same as computeString but do not make vertex buffers and primitives */ - void computeStringInfo (const ucstring &s, + void computeStringInfo (NLMISC::CUtfStringView sv, + size_t len, + CFontGenerator *fontGen, + const NLMISC::CRGBA &color, + uint32 fontSize, + bool embolden, + bool oblique, + IDriver *driver, + CComputedString &output, + bool keep800x600Ratio= true); + + /** + * Same as computeString but do not make vertex buffers and primitives + */ + void computeStringInfo (NLMISC::CUtfStringView sv, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, diff --git a/nel/include/nel/3d/landscape.h b/nel/include/nel/3d/landscape.h index f6e1a5861..cf05f6c9a 100644 --- a/nel/include/nel/3d/landscape.h +++ b/nel/include/nel/3d/landscape.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/include/nel/3d/text_context.h b/nel/include/nel/3d/text_context.h index 1eb256855..a8d4188a8 100644 --- a/nel/include/nel/3d/text_context.h +++ b/nel/include/nel/3d/text_context.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -134,7 +134,7 @@ public: uint32 textPush (const char *format, ...); /// computes an ucstring and adds the result to the cache (return the index) - uint32 textPush (const ucstring &str); + uint32 textPush (NLMISC::CUtfStringView sv); /// remove a string from the cache void erase (uint32 index); @@ -262,12 +262,12 @@ public: } /// Directly print a string - void printAt (float x, float z, const ucstring &ucstr) + void printAt (float x, float z, NLMISC::CUtfStringView sv) { nlassert(_FontGen); // compute the string just one time - _FontManager->computeString (ucstr, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, _TempString, _Keep800x600Ratio); + _FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, _TempString, _Keep800x600Ratio); // draw shaded if (_Shaded) @@ -372,14 +372,19 @@ public: * \param an ucstring * \param the computed string */ - void computeString (const ucstring& s, CComputedString& output) + void computeString (NLMISC::CUtfStringView sv, CComputedString& output) { - _FontManager->computeString (s, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio); + _FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio); + } + + void computeStringInfo (NLMISC::CUtfStringView sv, CComputedString& output) + { + _FontManager->computeStringInfo (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio); } - void computeStringInfo (const ucstring& s, CComputedString& output) + void computeStringInfo (NLMISC::CUtfStringView sv, CComputedString& output, size_t len) { - _FontManager->computeStringInfo (s, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio); + _FontManager->computeStringInfo (sv, len, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, output, _Keep800x600Ratio); } /// Debug : write to the disk the texture cache diff --git a/nel/include/nel/3d/text_context_user.h b/nel/include/nel/3d/text_context_user.h index 2a167b2e9..b673bfa8f 100644 --- a/nel/include/nel/3d/text_context_user.h +++ b/nel/include/nel/3d/text_context_user.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -97,13 +97,14 @@ public: */ // @{ uint32 textPush(const char *format, ...) ; - uint32 textPush(const ucstring &str) ; + uint32 textPush(NLMISC::CUtfStringView sv) ; void setStringColor(uint32 i, CRGBA newCol); void setStringSelection(uint32 i, uint32 selectStart, uint32 selectSize); void resetStringSelection(uint32 i); void erase(uint32 i) ; virtual CStringInfo getStringInfo (uint32 i); - virtual CStringInfo getStringInfo (const ucstring &ucstr); + virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv); + virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len); void clear() ; void printAt(float x, float y, uint32 i) ; @@ -111,10 +112,10 @@ public: void printClipAtUnProjected(URenderStringBuffer &renderBuffer, class NL3D::CFrustum &frustum, const NLMISC::CMatrix &scaleMatrix, float x, float y, float depth, uint32 i, float xmin, float ymin, float xmax, float ymax); void printClipAtOld (float x, float y, uint32 i, float xmin, float ymin, float xmax, float ymax); - void printAt(float x, float y, const ucstring &ucstr) ; + void printAt(float x, float y, NLMISC::CUtfStringView sv) ; void printfAt(float x, float y, const char * format, ...) ; - void render3D(const CMatrix &mat, const ucstring &ucstr) ; + void render3D(const CMatrix &mat, NLMISC::CUtfStringView sv) ; void render3D(const CMatrix &mat, const char *format, ...) ; float getLastXBound() const ; diff --git a/nel/include/nel/3d/texture.h b/nel/include/nel/3d/texture.h index f74af29d9..6016917d2 100644 --- a/nel/include/nel/3d/texture.h +++ b/nel/include/nel/3d/texture.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2019 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/include/nel/3d/texture_font.h b/nel/include/nel/3d/texture_font.h index 865615b63..b250fecd8 100644 --- a/nel/include/nel/3d/texture_font.h +++ b/nel/include/nel/3d/texture_font.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -69,7 +72,7 @@ public: // Holds info for glyphs displayed on screen struct SLetterInfo { - ucchar Char; + u32char Char; sint Size; bool Embolden; bool Oblique; @@ -94,7 +97,7 @@ public: struct SLetterKey { - ucchar Char; + u32char Char; sint Size; bool Embolden; bool Oblique; diff --git a/nel/include/nel/3d/u_driver.h b/nel/include/nel/3d/u_driver.h index f4f78e2cb..24e3d6482 100644 --- a/nel/include/nel/3d/u_driver.h +++ b/nel/include/nel/3d/u_driver.h @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Matt RAYKOWSKI (sfb) // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -835,10 +835,10 @@ public: /// \name Clipboard management // @{ // Copy a string to system clipboard. - virtual bool copyTextToClipboard(const ucstring &text) =0; + virtual bool copyTextToClipboard(const std::string &text) =0; // Paste a string from system clipboard. - virtual bool pasteTextFromClipboard(ucstring &text) =0; + virtual bool pasteTextFromClipboard(std::string &text) =0; // @} public: diff --git a/nel/include/nel/3d/u_text_context.h b/nel/include/nel/3d/u_text_context.h index cdde02f82..f7f833c47 100644 --- a/nel/include/nel/3d/u_text_context.h +++ b/nel/include/nel/3d/u_text_context.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -24,7 +24,7 @@ #include "nel/misc/rgba.h" #include "nel/misc/ucstring.h" #include "nel/misc/matrix.h" - +#include "nel/misc/utf_string_view.h" namespace NL3D { @@ -104,8 +104,11 @@ public: */ float StringLine; - CStringInfo() {StringWidth= StringHeight= StringLine= 0;} - CStringInfo(float w, float h, float l) {StringWidth= w; StringHeight= h; StringLine = l;} + /// The length in characters + size_t StringLength; + + CStringInfo() { StringWidth = StringHeight = StringLine = 0; StringLength = 0; } + CStringInfo(float w, float h, float l, size_t len) { StringWidth = w; StringHeight = h; StringLine = l; StringLength = len; } /** * Get the string's origin @@ -248,7 +251,7 @@ public: * \param an ucstring * \return the index where computed string has been inserted */ - virtual uint32 textPush (const ucstring &str) = 0; + virtual uint32 textPush (NLMISC::CUtfStringView sv) = 0; /** * set the color of a string. */ @@ -274,7 +277,12 @@ public: * Get a string information from the ucstring * The returned string info is in pixel size per default. */ - virtual CStringInfo getStringInfo (const ucstring &ucstr) = 0; + virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv) = 0; + /** + * Get a string information from the ucstring + * The returned string info is in pixel size per default. + */ + virtual CStringInfo getStringInfo (NLMISC::CUtfStringView sv, size_t len) = 0; /** * empty the map */ @@ -299,7 +307,7 @@ public: /** * compute and print a ucstring at the location (2D method) x/y E [0,1] */ - virtual void printAt (float x, float y, const ucstring &ucstr) = 0; + virtual void printAt (float x, float y, NLMISC::CUtfStringView sv) = 0; /** * compute and print a string at the location (2D method) x/y E [0,1] */ @@ -309,7 +317,7 @@ public: * compute and render a ucstring at the location (3D method) * render3D() use UDriver Matrix context for Frustum/ViewMatrix, but use its own modelmatrix (mat). */ - virtual void render3D (const NLMISC::CMatrix &mat, const ucstring &ucstr) = 0; + virtual void render3D (const NLMISC::CMatrix &mat, NLMISC::CUtfStringView sv) = 0; /** * compute and render a string at the location (3D method) * render3D() use UDriver Matrix context for Frustum/ViewMatrix, but use its own modelmatrix (mat). diff --git a/nel/include/nel/georges/form.h b/nel/include/nel/georges/form.h index 9b21c4c49..732a45840 100644 --- a/nel/include/nel/georges/form.h +++ b/nel/include/nel/georges/form.h @@ -22,6 +22,7 @@ #include "nel/misc/types_nl.h" #include "nel/georges/u_form.h" +#include "form_dfn.h" #include "form_elm.h" #include "header.h" @@ -124,6 +125,10 @@ private: // The form filename std::string _Filename; + + // The dfn + NLMISC::CSmartPtr _Dfn; + }; } // NLGEORGES diff --git a/nel/include/nel/georges/form_elm.h b/nel/include/nel/georges/form_elm.h index bf9b3ef62..f94d9842c 100644 --- a/nel/include/nel/georges/form_elm.h +++ b/nel/include/nel/georges/form_elm.h @@ -282,6 +282,10 @@ public: { Element = NULL; } + ~CFormElmStructElm() + { + nlassert(!Element); + } std::string Name; CFormElm* Element; @@ -400,6 +404,10 @@ public: { Element = NULL; } + ~CElement () + { + nlassert(!Element); + } std::string Name; CFormElm* Element; @@ -631,7 +639,7 @@ inline bool CFormElm::convertValue (bool &result, const std::string &value) cons } else { - std::string temp = NLMISC::toLower(value); + std::string temp = NLMISC::toLowerAscii(value); if (strcmp (temp.c_str (), "true") == 0) { result = true; diff --git a/nel/include/nel/gui/action_handler.h b/nel/include/nel/gui/action_handler.h index 7288c9529..5bdad89ba 100644 --- a/nel/include/nel/gui/action_handler.h +++ b/nel/include/nel/gui/action_handler.h @@ -69,7 +69,7 @@ namespace NLGUI static CAHManager* getInstance() { - if (_GlobalInstance == NULL) + if (_GlobalInstance == NULL && !s_Deleted) _GlobalInstance = new CAHManager; return _GlobalInstance; } @@ -134,6 +134,19 @@ namespace NLGUI static CAHManager *_GlobalInstance; static bool editorMode; + class CDeleter + { + public: + ~CDeleter() + { + delete _GlobalInstance; + _GlobalInstance = NULL; + s_Deleted = true; + } + }; + static CDeleter s_Deleter; + static bool s_Deleted; + }; /// Ah name must all be lower case diff --git a/nel/include/nel/gui/css_parser.h b/nel/include/nel/gui/css_parser.h index a6dc92022..c3a426ee7 100644 --- a/nel/include/nel/gui/css_parser.h +++ b/nel/include/nel/gui/css_parser.h @@ -1,6 +1,9 @@ // Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -38,7 +41,7 @@ namespace NLGUI private: // stylesheet currently parsed - ucstring _Style; + std::string _Style; // keep track of current position in _Style size_t _Position; @@ -70,49 +73,49 @@ namespace NLGUI void preprocess(); // parse selectors + combinators - std::vector parse_selector(const ucstring &sel, std::string &pseudoElement) const; + std::vector 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 +123,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)*/; diff --git a/nel/include/nel/gui/ctrl_base.h b/nel/include/nel/gui/ctrl_base.h index a8bdef85f..55983bfbb 100644 --- a/nel/include/nel/gui/ctrl_base.h +++ b/nel/include/nel/gui/ctrl_base.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -85,9 +86,12 @@ namespace NLGUI /// Get the ContextHelp for this control. Default is to return _ContextHelp - virtual void getContextHelp(ucstring &help) const {help= _ContextHelp;} + virtual void getContextHelp(std::string &help) const {help= _ContextHelp;} +#ifdef RYZOM_LUA_UCSTRING + virtual void getContextHelpAsUtf16(ucstring &help) const {help.fromUtf8(_ContextHelp);} // Compatibility +#endif /// Get the ContextHelp for this control, with tooltip specific code. Default behaviour is identical to getContextHelp. - virtual void getContextHelpToolTip(ucstring &help) const { getContextHelp(help); } + virtual void getContextHelpToolTip(std::string &help) const { getContextHelp(help); } // Get the name of the context help window. Default to "context_help" virtual std::string getContextHelpWindowName() const; /// Get the ContextHelp ActionHandler. If "", noop @@ -123,8 +127,12 @@ namespace NLGUI void setToolTipPosRef(THotSpot pos) { _ToolTipPosRef = pos;} /// replace the default contextHelp - ucstring getDefaultContextHelp() const {return _ContextHelp;} - void setDefaultContextHelp(const ucstring &help) {_ContextHelp= help;} + std::string getDefaultContextHelp() const {return _ContextHelp;} + void setDefaultContextHelp(const std::string &help) {_ContextHelp= help;} +#ifdef RYZOM_LUA_UCSTRING + ucstring getDefaultContextHelpAsUtf16() const {return ucstring::makeFromUtf8(_ContextHelp);} // Compatibility + void setDefaultContextHelpAsUtf16(const ucstring &help) {_ContextHelp= help.toUtf8();} // Compatibility +#endif void setOnContextHelp(const std::string &help) {_OnContextHelp= help;} void setOnContextHelpAHParams(const std::string &p) {_OnContextHelpParams= p;} @@ -154,12 +162,18 @@ namespace NLGUI // called when keyboard capture has been lost virtual void onKeyboardCaptureLost() {} +#ifdef RYZOM_LUA_UCSTRING // 'tooltip' property expects string to be ucstring or latin1 which is not possible from html page - int luaSetTooltipUtf8(CLuaState &ls); + int luaSetTooltipUtf8(CLuaState &ls); // Compatibility +#endif REFLECT_EXPORT_START(CCtrlBase, CViewBase) - REFLECT_UCSTRING("tooltip", getDefaultContextHelp, setDefaultContextHelp); - REFLECT_LUA_METHOD("setTooltipUtf8", luaSetTooltipUtf8); +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING("tooltip", getDefaultContextHelpAsUtf16, setDefaultContextHelpAsUtf16); // Compatibility + REFLECT_LUA_METHOD("setTooltipUtf8", luaSetTooltipUtf8); // Compatibility +#else + REFLECT_STRING("tooltip", getDefaultContextHelp, setDefaultContextHelp); +#endif REFLECT_EXPORT_END // special for mouse over : return true and fill the name of the cursor to display @@ -171,7 +185,7 @@ namespace NLGUI protected: // This is the ContextHelp filled by default in parse() - ucstring _ContextHelp; + std::string _ContextHelp; CStringShared _OnContextHelp; CStringShared _OnContextHelpParams; CStringShared _ToolTipSpecialParent; diff --git a/nel/include/nel/gui/ctrl_scroll.h b/nel/include/nel/gui/ctrl_scroll.h index 76827dd29..4052e6cea 100644 --- a/nel/include/nel/gui/ctrl_scroll.h +++ b/nel/include/nel/gui/ctrl_scroll.h @@ -177,6 +177,7 @@ namespace NLGUI bool _MouseDown : 1; bool _CallingAH : 1; bool _Cancelable : 1; // true if the slider may be cancelled when pressed on the mouse right button + bool _Keyboard : 1; bool _Frozen : 1; bool _Scale : 1; diff --git a/nel/include/nel/gui/ctrl_text_button.h b/nel/include/nel/gui/ctrl_text_button.h index 25fc9eeac..98223a802 100644 --- a/nel/include/nel/gui/ctrl_text_button.h +++ b/nel/include/nel/gui/ctrl_text_button.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -96,8 +97,14 @@ namespace NLGUI bool getTextModulateGlobalColorOver() const {return _TextModulateGlobalColorOver;} void setTextModulateGlobalColorOver(bool v) {_TextModulateGlobalColorOver= v;} // Set text (noop if text id) - void setText (const ucstring &text); - ucstring getText () const; + void setText (const std::string &text); + std::string getText () const; +#ifdef RYZOM_LUA_UCSTRING + void setTextAsUtf16 (const ucstring &text); // Compatibility + ucstring getTextAsUtf16 () const; // Compatibility +#endif + void setLocalize (bool localize); + bool isLocalized () const; void setHardText (const std::string &text); std::string getHardText () const; @@ -130,8 +137,12 @@ namespace NLGUI int luaGetViewText(CLuaState &ls); REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton) - REFLECT_UCSTRING("uc_hardtext", getText, setText); +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING("uc_hardtext", getTextAsUtf16, setTextAsUtf16); // Compatibility +#endif + REFLECT_BOOL("localize", isLocalized, setLocalize); REFLECT_STRING("hardtext", getHardText, setHardText); + REFLECT_STRING("text", getText, setText); REFLECT_SINT32("text_x", getTextX, setTextX) REFLECT_SINT32("wmargin", getWMargin, setWMargin) REFLECT_SINT32("wmin", getWMin, setWMin) diff --git a/nel/include/nel/gui/dbgroup_combo_box.h b/nel/include/nel/gui/dbgroup_combo_box.h index 6f42572bb..3826bf00f 100644 --- a/nel/include/nel/gui/dbgroup_combo_box.h +++ b/nel/include/nel/gui/dbgroup_combo_box.h @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2015 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -60,13 +60,19 @@ namespace NLGUI // Combo Texts void resetTexts(); - void addText(const ucstring &text); - void setText(uint i, const ucstring &text); - void insertText(uint i, const ucstring &text); - const ucstring &getText(uint i) const; + void addText(const std::string &text); + void setText(uint i, const std::string &text); + void insertText(uint i, const std::string &text); + const std::string &getText(uint i) const; +#ifdef RYZOM_LUA_UCSTRING + ucstring getTextAsUtf16(uint i) const; // Compatibility +#endif uint getTextId(uint i) const; uint getTextPos(uint nId) const; - const ucstring &getTexture(uint i) const; + const std::string &getTexture(uint i) const; +#ifdef RYZOM_LUA_UCSTRING + ucstring getTextureAsUtf16(uint i) const; // Compatibility +#endif void setGrayed(uint i, bool g); bool getGrayed(uint i) const; void removeText(uint nPos); @@ -87,11 +93,15 @@ namespace NLGUI std::string getSelectionText() const; // view text - void setViewText(const ucstring & text); - ucstring getViewText() const; + void setViewText(const std::string & text); + std::string getViewText() const; +#ifdef RYZOM_LUA_UCSTRING + void setViewTextAsUtf16(const ucstring &text) { setViewText(text.toUtf8()); } // Compatibility + ucstring getViewTextAsUtf16() const; // Compatibility +#endif CViewText *getViewText(); - void setTexture(uint i, const ucstring &texture); + void setTexture(uint i, const std::string &texture); sint32 evalContentWidth() const; @@ -122,7 +132,11 @@ namespace NLGUI REFLECT_LUA_METHOD("resetTexts", luaResetTexts) REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb) REFLECT_STRING ("selection_text", getSelectionText, setSelectionText) - REFLECT_UCSTRING ("view_text", getViewText, setViewText) +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING ("view_text", getViewTextAsUtf16, setViewTextAsUtf16) // Compatibility +#else + REFLECT_STRING ("view_text", getViewText, setViewText) +#endif REFLECT_EXPORT_END @@ -137,8 +151,8 @@ namespace NLGUI // sint32 CInterfaceProperty _Selection; sint32 _NotLinkedToDBSelection; - std::vector > _Texts; - std::vector _Textures; + std::vector > _Texts; + std::vector _Textures; std::vector _Grayed; // Action Handler called on combo click @@ -155,7 +169,7 @@ namespace NLGUI CCtrlBaseButton *_SelectButton; bool _IsExternViewText; - ucstring _ExternViewText; + std::string _ExternViewText; private: diff --git a/nel/include/nel/gui/dbview_quantity.h b/nel/include/nel/gui/dbview_quantity.h index 16a11f5a0..e172624d7 100644 --- a/nel/include/nel/gui/dbview_quantity.h +++ b/nel/include/nel/gui/dbview_quantity.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -57,7 +58,7 @@ namespace NLGUI CInterfaceProperty _NumberMax; sint32 _Cache; sint32 _CacheMax; - ucstring _EmptyText; + std::string _EmptyText; void buildTextFromCache(); }; diff --git a/nel/include/nel/gui/event_descriptor.h b/nel/include/nel/gui/event_descriptor.h index 95bdad212..69c90ff5d 100644 --- a/nel/include/nel/gui/event_descriptor.h +++ b/nel/include/nel/gui/event_descriptor.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -60,7 +61,7 @@ public: keydown = 0, // a key has been press down. The key value is stored as a TKey keyup, // a key has been released. The key value is stored as a TKey keychar, // a key has been stroke. The key is a ucchar - keystring, // a string has been sent. The string is a ucstring + keystring, // a string has been sent. The string is a utf-8 string unknown, // uninitialized event }; CEventDescriptorKey() : _KeyEvent(unknown), _CtrlState(false), _ShiftState(false), _AltState(false), _Char(0) @@ -82,13 +83,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 +142,9 @@ private: union { NLMISC::TKey _Key; - ucchar _Char; + u32char _Char; }; - ucstring _String; + std::string _String; }; // ---------------------------------------------------------------------------- diff --git a/nel/include/nel/gui/group_container.h b/nel/include/nel/gui/group_container.h index 742dfcfb2..5157c22b1 100644 --- a/nel/include/nel/gui/group_container.h +++ b/nel/include/nel/gui/group_container.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -248,12 +249,14 @@ namespace NLGUI // Get the header color draw. NB: depends if grayed, and if active. NLMISC::CRGBA getDrawnHeaderColor () const; - ucstring getUCTitleOpened () const; - void setUCTitleOpened (const ucstring &title); - ucstring getUCTitleClosed () const; - void setUCTitleClosed (const ucstring &title); - ucstring getUCTitle () const; - void setUCTitle (const ucstring &title); +#ifdef RYZOM_LUA_UCSTRING + ucstring getUCTitleOpened () const; // Compatibility + void setUCTitleOpened (const ucstring &title); // Compatibility + ucstring getUCTitleClosed () const; // Compatibility + void setUCTitleClosed (const ucstring &title); // Compatibility + ucstring getUCTitle () const; // Compatibility + void setUCTitle (const ucstring &title); // Compatibility +#endif void setPopable(bool popable) { _Popable = popable; } bool isPopable() const { return _Popable; } @@ -287,9 +290,13 @@ 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); + +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // Compatibility + REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // Compatibility + REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // Compatibility +#endif + REFLECT_STRING("title_color", getTitleColorAsString, setTitleColorAsString); REFLECT_SINT32("pop_min_h", getPopupMinH, setPopupMinH); REFLECT_SINT32("pop_max_h", getPopupMaxH, setPopupMaxH); @@ -302,6 +309,8 @@ namespace NLGUI REFLECT_BOOL("lockable", isLockable, setLockable); REFLECT_BOOL("locked", isLocked, setLocked); + REFLECT_BOOL("localize", isLocalize, setLocalize); + REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive); REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled); REFLECT_EXPORT_END @@ -364,7 +373,7 @@ namespace NLGUI bool isActiveSavable() const { return _ActiveSavable; } bool isLocalize() const { return _Localize; } - void setLocalize(bool localize) { _Localize = localize; } + void setLocalize(bool localize); void setPopupX(sint32 x) { _PopupX = x; } void setPopupY(sint32 y) { _PopupY = y; } @@ -477,8 +486,8 @@ namespace NLGUI float _CurrentRolloverAlphaContainer; float _CurrentRolloverAlphaContent; sint32 _LayerSetup; - ucstring _TitleTextOpened; - ucstring _TitleTextClosed; + std::string _TitleTextOpened; + std::string _TitleTextClosed; CViewText *_TitleOpened; CViewText *_TitleClosed; sint32 _TitleDeltaMaxW; @@ -636,6 +645,9 @@ namespace NLGUI TTileClass convertTitleClass(const char *ptr); + void setTitledOpenedViewText(); + void setTitledClosedViewText(); + static COptionsContainerMove *getMoveOptions(); COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used diff --git a/nel/include/nel/gui/group_editbox.h b/nel/include/nel/gui/group_editbox.h index 096f3daa0..ebd9aeeaf 100644 --- a/nel/include/nel/gui/group_editbox.h +++ b/nel/include/nel/gui/group_editbox.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -63,26 +64,29 @@ namespace NLGUI virtual bool handleEvent (const NLGUI::CEventDescriptor& eventDesc); /// Accessors - ucstring getInputString() const { return _InputString; } - const ucstring &getInputStringRef() const { return _InputString; } - const ucstring &getPrompt() const { return _Prompt; } + std::string getInputString() const; + std::string getPrompt() const; + 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 ucstring &s) { _Prompt = s; } - void setInputString(const ucstring &str); - void setInputStringRef(const ucstring &str) {_InputString = str; }; + void setPrompt(const std::string &s); + void setInputString(const std::string &str); + void setInputStringRef(const ::u32string &str); void setInputStringAsInt(sint32 val); sint32 getInputStringAsInt() const; void setInputStringAsInt64(sint64 val); sint64 getInputStringAsInt64() const; void setInputStringAsFloat(float val); float getInputStringAsFloat() const; - void setInputStringAsStdString(const std::string &str); - std::string getInputStringAsStdString() const; - void setInputStringAsUtf8(const std::string &str); - std::string getInputStringAsUtf8() const; +#ifdef RYZOM_LUA_UCSTRING + void setInputStringAsUtf16(const ucstring &str); // Compatibility + ucstring getInputStringAsUtf16() const; // Compatibility + void setInputStringAsUtf32(const ::u32string &str) { setInputStringRef(str); } // Compatibility + ::u32string getInputStringAsUtf32() const { return _InputString; } // Compatibility +#endif void setColor(NLMISC::CRGBA col); @@ -97,7 +101,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(); } @@ -121,7 +125,7 @@ namespace NLGUI sint32 getMaxHistoric() const {return _MaxHistoric;} sint32 getCurrentHistoricIndex () const {return _CurrentHistoricIndex;} void setCurrentHistoricIndex (sint32 index) {_CurrentHistoricIndex=index;} - const ucstring &getHistoric(uint32 index) const {return _Historic[index];} + const ::u32string &getHistoric(uint32 index) const {return _Historic[index];} uint32 getNumHistoric() const {return (uint32)_Historic.size ();} // Get on change action handler @@ -139,7 +143,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 std::string &str, bool replace = true, bool atEnd = true); // Expand the expression (true if there was a '/' at the start of the line) bool expand(); @@ -170,7 +174,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;} @@ -189,8 +193,10 @@ namespace NLGUI REFLECT_LUA_METHOD("setSelectionAll", luaSetSelectionAll); REFLECT_LUA_METHOD("setFocusOnText", luaSetFocusOnText); REFLECT_LUA_METHOD("cancelFocusOnText", luaCancelFocusOnText); - REFLECT_STRING("input_string", getInputStringAsStdString, setInputStringAsStdString); - REFLECT_UCSTRING("uc_input_string", getInputString, setInputString); + REFLECT_STRING("input_string", getInputString, setInputString); +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING("uc_input_string", getInputStringAsUtf16, setInputStringAsUtf16); // Compatibility +#endif REFLECT_EXPORT_END /** Restore the original value of the edit box. @@ -215,6 +221,7 @@ namespace NLGUI float _BlinkTime; sint32 _CursorPos; uint32 _MaxNumChar; + uint32 _MaxNumBytes; uint32 _MaxNumReturn; uint32 _MaxFloatPrec; // used in setInputStringAsFloat() only sint32 _MaxCharsSize; @@ -228,17 +235,17 @@ namespace NLGUI NLMISC::CRGBA _BackSelectColor; // Text info - ucstring _Prompt; - ucstring _InputString; + ::u32string _Prompt; + ::u32string _InputString; CViewText *_ViewText; // undo / redo - ucstring _StartInputString; // value of the input string when focus was acuired first - ucstring _ModifiedInputString; + ::u32string _StartInputString; // value of the input string when focus was acuired first + ::u32string _ModifiedInputString; // Historic info - typedef std::deque THistoric; + typedef std::deque<::u32string> THistoric; THistoric _Historic; uint32 _MaxHistoric; sint32 _CurrentHistoricIndex; @@ -275,7 +282,7 @@ namespace NLGUI bool _CanRedo : 1; bool _CanUndo : 1; - std::vector _NegativeFilter; + std::vector _NegativeFilter; sint _CursorTexID; sint32 _CursorWidth; @@ -298,13 +305,13 @@ namespace NLGUI void handleEventString(const NLGUI::CEventDescriptorKey &event); void setup(); void triggerOnChangeAH(); - void appendStringFromClipboard(const ucstring &str); + void appendStringFromClipboard(const std::string &str); - ucstring getSelection(); + std::string getSelection(); static CGroupEditBox *_MenuFather; - static bool isValidAlphaNumSpace(ucchar c) + static bool isValidAlphaNumSpace(u32char c) { if (c > 255) return false; char ac = (char) c; @@ -314,7 +321,7 @@ namespace NLGUI ac==' '; } - static bool isValidAlphaNum(ucchar c) + static bool isValidAlphaNum(u32char c) { if (c > 255) return false; char ac = (char) c; @@ -323,7 +330,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; @@ -331,13 +338,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 == '/' || @@ -351,12 +358,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; } diff --git a/nel/include/nel/gui/group_html.h b/nel/include/nel/gui/group_html.h index 590c43a89..a96f0180a 100644 --- a/nel/include/nel/gui/group_html.h +++ b/nel/include/nel/gui/group_html.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2019-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -320,16 +321,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 +351,9 @@ namespace NLGUI void flushString(); // Set the title - void setTitle (const ucstring &title); void setTitle (const std::string &title); std::string getTitle() const; + void setContainerTitle (const std::string &title); // Lookup a url in local file system bool lookupLocalFile (std::string &result, const char *url, bool isUrl); @@ -392,10 +393,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 +645,7 @@ namespace NLGUI std::string Name; // Variable value - ucstring Value; + std::string Value; // Text area group CInterfaceGroup *TextArea; @@ -747,7 +748,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 +756,7 @@ namespace NLGUI // current mode is in select option bool _SelectOption; - ucstring _SelectOptionStr; + std::string _SelectOptionStr; // Current node is a object std::string _ObjectType; @@ -765,7 +766,7 @@ namespace NLGUI std::string _TextAreaScript; // Get last char - ucchar getLastChar() const; + u32char getLastChar() const; // Current link view class CViewLink *_CurrentViewLink; @@ -826,7 +827,7 @@ namespace NLGUI void spliceFragment(std::list::iterator src); // decode all HTML entities - static ucstring decodeHTMLEntities(const ucstring &str); + static std::string decodeHTMLEntities(const std::string &str); struct CDataImageDownload { diff --git a/nel/include/nel/gui/group_list.h b/nel/include/nel/gui/group_list.h index 58af530b5..e7fda6eb3 100644 --- a/nel/include/nel/gui/group_list.h +++ b/nel/include/nel/gui/group_list.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -67,13 +68,13 @@ namespace NLGUI * \param line : text to be added * \param color : text color */ - void addTextChild (const ucstring& line,const NLMISC::CRGBA &textColor, bool multiLine = true); + void addTextChild (const std::string& line,const NLMISC::CRGBA &textColor, bool multiLine = true); /** * add a text child element to the group, using the text template * \param line : text to be added */ - void addTextChild (const ucstring& line, bool multiLine = true); + void addTextChild (const std::string& line, bool multiLine = true); /// Same as adding a text child but the text will be taken from the string manager void addTextChildID (uint32 id, bool multiLine = true); diff --git a/nel/include/nel/gui/group_menu.h b/nel/include/nel/gui/group_menu.h index 21a740d84..fb5f9af88 100644 --- a/nel/include/nel/gui/group_menu.h +++ b/nel/include/nel/gui/group_menu.h @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -122,12 +122,12 @@ namespace NLGUI // retrieve the index of a line from its id (-1 if not found) sint getLineFromId(const std::string &id); - CViewTextMenu* addLine (const ucstring &name, const std::string &ah, + CViewTextMenu* addLine (const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id="", const std::string &cond = std::string(), const std::string &texture="", bool checkable = false, bool checked = false, bool formatted = false ); - CViewTextMenu* addLineAtIndex(uint index, const ucstring &name, const std::string &ah, + CViewTextMenu* addLineAtIndex(uint index, const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id="", const std::string &cond = std::string(), const std::string &texture="", bool checkable = false, bool checked = false, bool formatted = false @@ -332,12 +332,7 @@ namespace NLGUI virtual void setActive (bool state); virtual bool isWindowUnder (sint32 x, sint32 y); - - // add line with a string, for backward compatibility - void addLine (const std::string &name, const std::string &ah, const std::string ¶ms, - const std::string &id = std::string(), - const std::string &cond = std::string(), const std::string &texture="", - bool checkable = false, bool checked = false); + uint getNumLine() const; void deleteLine(uint index); const std::string getActionHandler(uint lineIndex) const; @@ -350,12 +345,12 @@ namespace NLGUI void setRightClickHandler(uint lineIndex, const std::string &ah = ""); void setRightClickHandlerParam(uint lineIndex, const std::string ¶ms = ""); - void addLine (const ucstring &name, const std::string &ah = "", const std::string ¶ms = "", + void addLine (const std::string &name, const std::string &ah = "", const std::string ¶ms = "", const std::string &id = std::string(), const std::string &cond = std::string(), const std::string &texture="", bool checkable = false, bool checked = false ); - void addLineAtIndex (uint index, const ucstring &name, const std::string &ah = "", const std::string ¶ms = "", + void addLineAtIndex (uint index, const std::string &name, const std::string &ah = "", const std::string ¶ms = "", const std::string &id = std::string(), const std::string &cond = std::string(), const std::string &texture="", bool checkable = false, bool checked = false diff --git a/nel/include/nel/gui/group_paragraph.h b/nel/include/nel/gui/group_paragraph.h index 6142bc33b..20bc50585 100644 --- a/nel/include/nel/gui/group_paragraph.h +++ b/nel/include/nel/gui/group_paragraph.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -84,13 +85,13 @@ namespace NLGUI * \param line : text to be added * \param color : text color */ - void addTextChild (const ucstring& line,const NLMISC::CRGBA &textColor, bool multiLine = true); + void addTextChild (const std::string& line,const NLMISC::CRGBA &textColor, bool multiLine = true); /** * add a text child element to the group, using the text template * \param line : text to be added */ - void addTextChild (const ucstring& line, bool multiLine = true); + void addTextChild (const std::string& line, bool multiLine = true); /// Same as adding a text child but the text will be taken from the string manager void addTextChildID (uint32 id, bool multiLine = true); diff --git a/nel/include/nel/gui/group_tree.h b/nel/include/nel/gui/group_tree.h index 266e7e23f..7a39ccfea 100644 --- a/nel/include/nel/gui/group_tree.h +++ b/nel/include/nel/gui/group_tree.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -60,7 +61,7 @@ namespace NLGUI bool Show; // If false, the node is not displayed (true default, Root ignored) sint32 YDecal; // Text - ucstring Text; // Internationalized displayed text + std::string Text; // Internationalized displayed text sint32 FontSize; // If -1 (default), then take the groupTree one NLMISC::CRGBA Color; // Template @@ -112,8 +113,12 @@ namespace NLGUI std::string getBitmap() const { return Bitmap; } void setOpened(bool opened) { Opened = opened; } bool getOpened() const { return Opened; } - void setText(const ucstring &text) { Text = text; } - const ucstring& getText() const { return Text; } + void setText(const std::string &text) { Text = text; } + const std::string& getText() const { return Text; } +#ifdef RYZOM_LUA_UCSTRING + void setTextAsUtf16(const ucstring &text) { Text = text.toUtf8(); } // Compatibility + ucstring getTextAsUtf16() const { return ucstring::makeFromUtf8(Text); } // Compatibility +#endif sint32 getFontSize() const { return FontSize; } void setFontSize(sint32 value) { FontSize = value; } sint32 getYDecal() const { return YDecal; } @@ -181,7 +186,11 @@ namespace NLGUI REFLECT_STRING("AHParamsClose", getAHParamsClose, setAHParamsClose); REFLECT_BOOL("Opened", getOpened, setOpened); REFLECT_BOOL("Show", getShow, setShow); - REFLECT_UCSTRING_REF("Text", getText, setText); +#ifdef RYZOM_LUA_UCSTRING + REFLECT_UCSTRING("Text", getTextAsUtf16, setTextAsUtf16); // Compatibility +#else + REFLECT_STRING_REF("Text", getText, setText); +#endif // lua REFLECT_LUA_METHOD("getNumChildren", luaGetNumChildren); REFLECT_LUA_METHOD("getChild", luaGetChild); diff --git a/nel/include/nel/gui/interface_element.h b/nel/include/nel/gui/interface_element.h index 47025f155..ab2b6a4e3 100644 --- a/nel/include/nel/gui/interface_element.h +++ b/nel/include/nel/gui/interface_element.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2019 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -382,7 +383,6 @@ namespace NLGUI void dummySet(const std::string &value); public: - // export some properties REFLECT_EXPORT_START(CInterfaceElement, CReflectable) REFLECT_BOOL ("active", getActive, setActive); @@ -397,6 +397,7 @@ namespace NLGUI REFLECT_SINT32 ("h_real", getHReal, dummySet); REFLECT_STRING ("id", getIdByValue, dummySet); REFLECT_STRING ("sizeref", getSizeRefAsString, setSizeRef); + REFLECT_STRING ("posparent", getPosParent, setPosParent); REFLECT_LUA_METHOD("updateCoords", luaUpdateCoords); REFLECT_LUA_METHOD("invalidateCoords", luaInvalidateCoords); REFLECT_LUA_METHOD("invalidateContent", luaInvalidateContent); @@ -523,6 +524,8 @@ namespace NLGUI void parseSizeParent( const std::string &id ); void setSizeParent( const std::string &id ); void getSizeParent( std::string &id ) const; + + std::string getPosParent() const; void setSerializable( bool b ){ serializable = b; } bool IsSerializable() const{ return serializable; } diff --git a/nel/include/nel/gui/interface_expr.h b/nel/include/nel/gui/interface_expr.h index b967ef7ab..b4474ac22 100644 --- a/nel/include/nel/gui/interface_expr.h +++ b/nel/include/nel/gui/interface_expr.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -59,16 +60,15 @@ namespace NLGUI bool getBool() const; sint64 getInteger() const; double getDouble() const; - std::string getString() const; + const std::string &getString() const; NLMISC::CRGBA getRGBA() const; - const ucstring &getUCString() const; CInterfaceExprUserType *getUserType() const; // set void setBool(bool value) { clean(); _Type = Boolean; _BoolValue = value; } void setInteger(sint64 value) { clean(); _Type = Integer; _IntegerValue = value; } void setDouble(double value) { clean(); _Type = Double; _DoubleValue = value; } void setString(const std::string &value) { clean(); _Type = String; _StringValue = value; } - void setUCString(const ucstring &value) { clean(); _Type = String; _StringValue = value; } + void setString(const char *value) { clean(); _Type = String; _StringValue = value; } void setRGBA(NLMISC::CRGBA value) { clean(); _Type = RGBA; _RGBAValue = (uint32)(value.R+(value.G<<8)+(value.B<<16)+(value.A<<24)); } void setUserType(CInterfaceExprUserType *value); // reset this object to initial state (no type) @@ -99,7 +99,7 @@ namespace NLGUI CInterfaceExprUserType *_UserTypeValue; uint32 _RGBAValue; }; - ucstring _StringValue; // well, can't fit in union, unless we do some horrible hack.. + std::string _StringValue; // well, can't fit in union, unless we do some horrible hack.. private: const char *evalBoolean(const char *expr); const char *evalNumber(const char *expr); diff --git a/nel/include/nel/gui/interface_group.h b/nel/include/nel/gui/interface_group.h index 9f1e5562b..672e52e6a 100644 --- a/nel/include/nel/gui/interface_group.h +++ b/nel/include/nel/gui/interface_group.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2019 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/include/nel/gui/lua_helper.h b/nel/include/nel/gui/lua_helper.h index da5c33e6a..fa941f79a 100644 --- a/nel/include/nel/gui/lua_helper.h +++ b/nel/include/nel/gui/lua_helper.h @@ -2,8 +2,8 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013 Jan BOON (Kaetemi) // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -379,6 +379,10 @@ namespace NLGUI TSmallScriptCache _SmallScriptCache; static const char * _NELSmallScriptTableName; +#ifdef _WIN32 + HMODULE m_LuaSocket; +#endif + private: // this object isn't intended to be copied CLuaState(const CLuaState &/* other */):NLMISC::CRefCount() { nlassert(0); } diff --git a/nel/include/nel/gui/lua_helper_inline.h b/nel/include/nel/gui/lua_helper_inline.h index 0d380bbf1..d50455880 100644 --- a/nel/include/nel/gui/lua_helper_inline.h +++ b/nel/include/nel/gui/lua_helper_inline.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -263,8 +263,8 @@ inline lua_Integer CLuaState::toInteger(int index) if (!isnum) { lua_Number d = lua_tonumber(_State, index); - nlwarning("Lua: Unable to convert Lua number %lf to integer", d); res = (lua_Integer)d; + nlwarning("Lua: Converting lua_Number %lf to lua_Integer %i", d, (int)res); } return res; #else diff --git a/nel/include/nel/gui/lua_ihm.h b/nel/include/nel/gui/lua_ihm.h index cc1051e62..ec047e69a 100644 --- a/nel/include/nel/gui/lua_ihm.h +++ b/nel/include/nel/gui/lua_ihm.h @@ -86,10 +86,12 @@ namespace NLGUI // ucstring +#ifdef RYZOM_LUA_UCSTRING static bool pop(CLuaState &ls, ucstring &dest); static void push(CLuaState &ls, const ucstring &value); static bool isUCStringOnStack(CLuaState &ls, sint index); static bool getUCStringOnStack(CLuaState &ls, sint index, ucstring &dest); +#endif // RGBA @@ -108,7 +110,9 @@ namespace NLGUI static void check(CLuaState &ls, bool ok, const std::string &failReason); static void checkArgType(CLuaState &ls, const char *funcName, uint index, int argType); static void checkArgTypeRGBA(CLuaState &ls, const char *funcName, uint index); +#ifdef RYZOM_LUA_UCSTRING static void checkArgTypeUCString(CLuaState &ls, const char *funcName, uint index); +#endif /** throw a lua expection (inside a C function called from lua) with the given reason, and the current call stack * The various check... function call this function when their test fails */ @@ -154,10 +158,12 @@ namespace NLGUI static uint32 getLocalTime(); static double getPreciseLocalTime(); static std::string findReplaceAll(const std::string &str, const std::string &search, const std::string &replace); +#ifdef RYZOM_LUA_UCSTRING static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const ucstring &replace); static ucstring findReplaceAll(const ucstring &str, const std::string &search, const std::string &replace); static ucstring findReplaceAll(const ucstring &str, const std::string &search, const ucstring &replace); static ucstring findReplaceAll(const ucstring &str, const ucstring &search, const std::string &replace); +#endif ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -183,8 +189,10 @@ namespace NLGUI static int runExpr(CLuaState &ls); // params: "expr". return: any of: nil,bool,string,number, RGBA, UCString static int runFct(CLuaState &ls); // params: "expr", param1, param2.... return: any of: nil,bool,string,number, RGBA, UCString static int runCommand(CLuaState &ls); // params: "command name", param1, param2 ... return true or false +#ifdef RYZOM_LUA_UCSTRING static int isUCString(CLuaState &ls); static int concatUCString(CLuaState &ls); // workaround for + operator that don't work in luabind for ucstrings ... +#endif static int concatString(CLuaState &ls); // speedup concatenation of several strings static int tableToString(CLuaState &ls); // concat element of a table to build a string static int getPathContent(CLuaState &ls); diff --git a/nel/include/nel/gui/reflect.h b/nel/include/nel/gui/reflect.h index 8bd3b4781..3f0b936a9 100644 --- a/nel/include/nel/gui/reflect.h +++ b/nel/include/nel/gui/reflect.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2019 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -41,9 +42,13 @@ namespace NLGUI UInt32, Float, String, +#ifdef RYZOM_LUA_UCSTRING UCString, +#endif StringRef, +#ifdef RYZOM_LUA_UCSTRING UCStringRef, +#endif RGBA, LuaMethod }; // other types will be added when needed @@ -78,9 +83,13 @@ namespace NLGUI TGetUInt32 GetUInt32; TGetFloat GetFloat; TGetString GetString; +#ifdef RYZOM_LUA_UCSTRING TGetUCString GetUCString; +#endif TGetStringRef GetStringRef; +#ifdef RYZOM_LUA_UCSTRING TGetUCStringRef GetUCStringRef; +#endif TGetRGBA GetRGBA; TLuaMethod GetLuaMethod; // lua method can only be obtained, not written ... } GetMethod; @@ -91,7 +100,9 @@ namespace NLGUI TSetUInt32 SetUInt32; TSetFloat SetFloat; TSetString SetString; +#ifdef RYZOM_LUA_UCSTRING TSetUCString SetUCString; +#endif TSetRGBA SetRGBA; } SetMethod; // name of the property @@ -297,6 +308,7 @@ namespace NLGUI props.push_back(prop); \ } +#ifdef RYZOM_LUA_UCSTRING // export a unicode string value, by giving the name of the get and the set method #define REFLECT_UCSTRING(exportName, getMethod, setMethod) \ { \ @@ -307,6 +319,7 @@ namespace NLGUI prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast(&A::setMethod); \ props.push_back(prop); \ } +#endif // export a string value, by giving the name of the get and the set method #define REFLECT_STRING_REF(exportName, getMethod, setMethod) \ @@ -319,6 +332,7 @@ namespace NLGUI props.push_back(prop); \ } +#ifdef RYZOM_LUA_UCSTRING // export a unicode string value, by giving the name of the get and the set method #define REFLECT_UCSTRING_REF(exportName, getMethod, setMethod) \ { \ @@ -329,7 +343,7 @@ namespace NLGUI prop.SetMethod.SetUCString = (CReflectedProperty::TSetUCString) static_cast(&A::setMethod); \ props.push_back(prop); \ } - +#endif // export a color value, by giving the name of the get and the set method #define REFLECT_RGBA(exportName, getMethod, setMethod) \ diff --git a/nel/include/nel/gui/string_case.h b/nel/include/nel/gui/string_case.h index ec8fa2925..44e38651f 100644 --- a/nel/include/nel/gui/string_case.h +++ b/nel/include/nel/gui/string_case.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -21,11 +22,9 @@ #define STRING_CASE_H #include "nel/misc/types_nl.h" -#include "nel/misc/ucstring.h" namespace NLGUI { - enum TCaseMode { CaseNormal = 0, // Nothing done @@ -37,10 +36,7 @@ namespace NLGUI CaseCount }; - - void setCase( ucstring &str, TCaseMode mode ); - - + void setCase( std::string &str, TCaseMode mode ); } #endif diff --git a/nel/include/nel/gui/view_pointer.h b/nel/include/nel/gui/view_pointer.h index cb550e44a..db7355465 100644 --- a/nel/include/nel/gui/view_pointer.h +++ b/nel/include/nel/gui/view_pointer.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -55,13 +56,16 @@ namespace NLGUI bool getStringMode() const {return _StringMode;} // Set cursor string - void setString (const ucstring &str); + void setString (const std::string &str); // TEMP PATCH void setCursor (const std::string &name) { - _TxDefault = name; - _TxIdDefault = -2; + if (_TxDefault != name) + { + _TxDefault = name; + _TxIdDefault = -2; + } } // TEMP PATCH @@ -126,14 +130,14 @@ namespace NLGUI bool _ForceStringMode; CInterfaceGroup *_StringCursor; CInterfaceGroup *_StringCursorHardware; - ucstring _ContextString; + std::string _ContextString; // draw current cursor with the given texture, or, if in hardware mode, change the hardware cursor shape void drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot); private: // set the string into frame for software or hardware version - void setString (const ucstring &str, CInterfaceGroup *target); + void setString(const std::string &str, CInterfaceGroup *target); static bool hwMouse; diff --git a/nel/include/nel/gui/view_text.h b/nel/include/nel/gui/view_text.h index 57ab6a096..3fb92f88c 100644 --- a/nel/include/nel/gui/view_text.h +++ b/nel/include/nel/gui/view_text.h @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -84,7 +84,12 @@ namespace NLGUI /// Set - void setText (const ucstring &text); + void setText(const std::string &text); + void setTextLocalized(const std::string &text, bool localized); +#ifdef RYZOM_LUA_UCSTRING + void setTextAsUtf16 (const ucstring &text); // Compatibility +#endif + void setLocalized(bool localized); void setFontName (const std::string &name); void setFontSize (sint nFontSize, bool coef = true); void setEmbolden (bool nEmbolden); @@ -95,7 +100,10 @@ namespace NLGUI void setShadowColor (const NLMISC::CRGBA &color); void setShadowOffset (sint x, sint y); void setLineMaxW (sint nMaxW, bool invalidate=true); - void setOverflowText(const ucstring &text) { _OverflowText = text; } + void setOverflowText(const std::string &text) { _OverflowText = text; } +#ifdef RYZOM_LUA_UCSTRING + void setOverflowTextAsUtf16(const ucstring &text) { _OverflowText = text.toUtf8(); } // Compatibility +#endif void setMultiLine (bool bMultiLine); void setMultiLineSpace (sint nMultiLineSpace); void setMultiLineMaxWOnly (bool state); @@ -112,8 +120,12 @@ namespace NLGUI void disableStringSelection(); /// Get - - ucstring getText() const { return _Text; } + std::string getText() const { return _HardText.empty() ? _Text : _HardText; } +#ifdef RYZOM_LUA_UCSTRING + ucstring getTextAsUtf16() const; // Compatibility + ucstring getHardTextAsUtf16() const; // Compatibility +#endif + bool isLocalized() const { return _Localized; } sint getFontSize() const; std::string getFontName() const { return _FontName; } bool getEmbolden() { return _Embolden; } @@ -124,7 +136,9 @@ namespace NLGUI NLMISC::CRGBA getShadowColor() { return _ShadowColor; } void getShadowOffset(sint &x, sint &y) { x = _ShadowX; y = _ShadowY; } sint getLineMaxW() const { return _LineMaxW; } - ucstring getOverflowText() const { return _OverflowText; } +#ifdef RYZOM_LUA_UCSTRING + ucstring getOverflowTextAsUtf16() const { return _OverflowText; } // Compatibility +#endif bool getMultiLine() const { return _MultiLine; } sint getMultiLineSpace() const { return _MultiLineSpace; } bool getMultiLineMaxWOnly() const { return _MultiLineMaxWOnly; } @@ -174,8 +188,11 @@ namespace NLGUI /// From a line number, get the character at which it ends (not including any '\n' ), or -1 if invalid void getLineEndIndex(uint line, sint &index, bool &endOfPreviousLine) const; - std::string getHardText() const { std::string result; _Text.toString (result); return result; } - void setHardText (const std::string &ht); + std::string getHardText() const { return _HardText.empty() ? _Text : _HardText; } + void setHardText (const std::string &ht); //< Localizes strings starting with "ui" +#ifdef RYZOM_LUA_UCSTRING + void setHardTextAsUtf16(const ucstring &ht); // Compatibility +#endif std::string getColorAsString() const; void setColorAsString(const std::string &ht); @@ -188,9 +205,15 @@ namespace NLGUI /** Setup a Text with Format Tags. Text is store without color/format tags, and special array is allocated for Format association */ - void setTextFormatTaged(const ucstring &text); + void setTextFormatTaged(const std::string &text); +#ifdef RYZOM_LUA_UCSTRING + void setTextFormatTagedAsUtf16(const ucstring &text); // Compatibility +#endif - void setSingleLineTextFormatTaged(const ucstring &text); + void setSingleLineTextFormatTaged(const std::string &text); +#ifdef RYZOM_LUA_UCSTRING + void setSingleLineTextFormatTagedAsUtf16(const ucstring &text); // Compatibility +#endif // Remove end space void removeEndSpaces(); @@ -216,10 +239,17 @@ namespace NLGUI int luaSetLineMaxW(CLuaState &ls); REFLECT_EXPORT_START(CViewText, CViewBase) - REFLECT_STRING("hardtext", getHardText, setHardText); - REFLECT_UCSTRING("uc_hardtext", getText, setText); - REFLECT_UCSTRING("uc_hardtext_format", getText, setTextFormatTaged); - REFLECT_UCSTRING("uc_hardtext_single_line_format", getText, setSingleLineTextFormatTaged); + REFLECT_BOOL("localize", isLocalized, setLocalized); + REFLECT_STRING("hardtext", getHardText, setHardText); // Same as text, but localize is implicitly set true + REFLECT_STRING("text", getText, setText); + REFLECT_STRING("text_format", getText, setTextFormatTaged); + REFLECT_STRING("text_single_line_format", getText, setSingleLineTextFormatTaged); +#ifdef RYZOM_LUA_UCSTRING + // REFLECT_UCSTRING("uc_text", getTextAsUtf16, setTextAsUtf16); // Deprecate uc_ functions + REFLECT_UCSTRING("uc_hardtext", getHardTextAsUtf16, setHardTextAsUtf16); // Compatibility + REFLECT_UCSTRING("uc_hardtext_format", getTextAsUtf16, setTextFormatTagedAsUtf16); // Compatibility + REFLECT_UCSTRING("uc_hardtext_single_line_format", getTextAsUtf16, setSingleLineTextFormatTagedAsUtf16); // Compatibility +#endif REFLECT_STRING ("color", getColorAsString, setColorAsString); REFLECT_RGBA ("color_rgba", getColorRGBA, setColorRGBA); REFLECT_SINT32 ("alpha", getAlpha, setAlpha); @@ -228,7 +258,6 @@ namespace NLGUI REFLECT_LUA_METHOD("setLineMaxW", luaSetLineMaxW); REFLECT_EXPORT_END - virtual void serial(NLMISC::IStream &f); // Sets the parent element @@ -236,9 +265,12 @@ namespace NLGUI void setParentElm( CInterfaceElement *parent ){ _ParentElm = parent; } protected: - std::string _HardtextFormat; /// Text to display. - ucstring _Text; + std::string _HardTextFormat; + std::string _HardText; + std::string _Text; + mutable sint _TextLength; + bool _Localized; /// index of the computed String associated to this text control uint _Index; /// info on the computed String associated to this text control @@ -253,8 +285,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; + std::string _FontSizingChars; + std::string _FontSizingFallback; // height of the font in pixel. // use getFontHeight float _FontHeight; @@ -278,7 +310,7 @@ namespace NLGUI sint32 _LineMaxW; /// For single line, true if the text is clamped (ie displayed with "...") bool _SingleLineTextClamped; - ucstring _OverflowText; + std::string _OverflowText; /// Multiple lines handling bool _MultiLine; @@ -339,7 +371,7 @@ namespace NLGUI public: // default ctor CWord(uint numSpaces = 0) : Index(0), NumSpaces(numSpaces) {} - ucstring Text; + std::string Text; uint Index; // index of the info for this word NL3D::UTextContext::CStringInfo Info; uint NumSpaces; // number of spaces before this word @@ -347,7 +379,7 @@ namespace NLGUI CFormatInfo Format; public: // build from a string, using the current text context - void build(const ucstring &text, NL3D::UTextContext &textContext, uint numSpaces= 0); + void build(const std::string &text, NL3D::UTextContext &textContext, uint numSpaces= 0); }; typedef std::vector TWordVect; @@ -360,7 +392,7 @@ namespace NLGUI // Clear the line & remove text contexts void clear(NL3D::UTextContext &textContext); // Add a new word (and its context) in the line + a number of spaces to append at the end of the line - void addWord(const ucstring &word, uint numSpaces, const CFormatInfo &wordFormat, float fontWidth, NL3D::UTextContext &textContext); + void addWord(const std::string &word, uint numSpaces, const CFormatInfo &wordFormat, float fontWidth, NL3D::UTextContext &textContext); void addWord(const CWord &word, float fontWidth); uint getNumWords() const { return (uint)_Words.size(); } CWord &getWord(uint index) { return _Words[index]; } @@ -434,15 +466,17 @@ namespace NLGUI void setup (); void setupDefault (); - void setStringSelectionSkipingSpace(uint stringId, const ucstring &text, sint charStart, sint charEnd); + void setTextLocalized(const std::string &text); + + void setStringSelectionSkipingSpace(uint stringId, const std::string &text, sint charStart, sint charEnd); - // void pushString(const ucstring &str, bool deleteSpaceAtStart = false); + // void pushString(const ucstring &str, bool deleteSpaceAtStart = false); // OLD /// \from CInterfaceElement void onInvalidateContent(); // may append a new line, and append a word to the last line (no spaces) - void flushWordInLine(ucstring &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat); + void flushWordInLine(std::string &ucCurrentWord, bool &linePushed, const CFormatInfo &wordFormat); // Clear all the lines and free their datas void clearLines(); // Update in the case of a multiline text @@ -456,7 +490,7 @@ namespace NLGUI void addDontClipWordLine(std::vector &currLine); // FormatTag build. - static void buildFormatTagText(const ucstring &text, ucstring &textBuild, std::vector &formatTags, std::vector &tooltips); + static void buildFormatTagText(const std::string &text, std::string &textBuild, std::vector &formatTags, std::vector &tooltips); // FormatTag parsing. bool isFormatTagChange(uint textIndex, uint ctIndex) const; void getFormatTagChange(uint textIndex, uint &ctIndex, CFormatInfo &wordFormat) const; diff --git a/nel/include/nel/gui/view_text_formated.h b/nel/include/nel/gui/view_text_formated.h index 43a7eb9a8..1b7146b8b 100644 --- a/nel/include/nel/gui/view_text_formated.h +++ b/nel/include/nel/gui/view_text_formated.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -45,7 +46,7 @@ namespace NLGUI { public: virtual ~IViewTextFormatter(){} - virtual ucstring formatString( const ucstring &inputString, const ucstring ¶mString ) = 0; + virtual std::string formatString( const std::string &inputString, const std::string ¶mString ) = 0; }; CViewTextFormated (const TCtorParam ¶m) : CViewText(param) @@ -55,15 +56,15 @@ namespace NLGUI xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); virtual void checkCoords(); - const ucstring &getFormatString() const { return _FormatString; } - void setFormatString(const ucstring &format); + const std::string &getFormatString() const { return _FormatString; } + void setFormatString(const std::string &format); - static ucstring formatString(const ucstring &inputString, const ucstring ¶mString); + static std::string formatString(const std::string &inputString, const std::string ¶mString); static void setFormatter( IViewTextFormatter *formatter ){ textFormatter = formatter; } private: - ucstring _FormatString; + std::string _FormatString; static IViewTextFormatter *textFormatter; }; diff --git a/nel/include/nel/gui/view_text_id.h b/nel/include/nel/gui/view_text_id.h index 1e46de062..5f8ccb14f 100644 --- a/nel/include/nel/gui/view_text_id.h +++ b/nel/include/nel/gui/view_text_id.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -38,7 +39,7 @@ namespace NLGUI public: virtual ~IOnReceiveTextId() {} // the deriver may change the input text - virtual void onReceiveTextId(ucstring &str) =0; + virtual void onReceiveTextId(std::string &str) =0; }; // *************************************************************************** @@ -58,8 +59,8 @@ namespace NLGUI { public: virtual ~IViewTextProvider(){} - virtual bool getString( uint32 stringId, ucstring &result ) = 0; - virtual bool getDynString( uint32 dynStringId, ucstring &result ) = 0; + virtual bool getString(uint32 stringId, std::string &result) = 0; + virtual bool getDynString(uint32 dynStringId, std::string &result) = 0; }; CViewTextID(const TCtorParam ¶m) : CViewText(param) @@ -144,7 +145,7 @@ namespace NLGUI // If true, setTextFormatted() is used instead of setText() bool _IsTextFormatTaged; - // Optional ucstring modifier + // Optional utf-8 string modifier IOnReceiveTextId *_StringModifier; std::string _DBPath; static IViewTextProvider* getTextProvider(){ return textProvider; } diff --git a/nel/include/nel/gui/view_text_id_formated.h b/nel/include/nel/gui/view_text_id_formated.h index cbc494dc1..428bca035 100644 --- a/nel/include/nel/gui/view_text_id_formated.h +++ b/nel/include/nel/gui/view_text_id_formated.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -49,10 +50,10 @@ namespace NLGUI xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); virtual void checkCoords(); - const ucstring &getFormatString() const { return _FormatString; } - void setFormatString(const ucstring &format); + const std::string &getFormatString() const { return _FormatString; } + void setFormatString(const std::string &format); private: - ucstring _FormatString; + std::string _FormatString; }; } diff --git a/nel/include/nel/gui/widget_manager.h b/nel/include/nel/gui/widget_manager.h index d0c65356b..2dc78eb73 100644 --- a/nel/include/nel/gui/widget_manager.h +++ b/nel/include/nel/gui/widget_manager.h @@ -2,8 +2,8 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013 Jan BOON (Kaetemi) // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -333,8 +333,8 @@ namespace NLGUI void updateTooltipCoords(CCtrlBase *newCtrl); /// for ContextHelp action handler only: set the result name - void setContextHelpText( const ucstring &text ){ _ContextHelpText = text; } - ucstring& getContextHelpText(){ return _ContextHelpText; } + void setContextHelpText( const std::string &text ){ _ContextHelpText = text; } + std::string& getContextHelpText(){ return _ContextHelpText; } /// force disable the context help void disableContextHelp(); @@ -626,7 +626,7 @@ namespace NLGUI SInterfaceTimes interfaceTimes; - ucstring _ContextHelpText; + std::string _ContextHelpText; bool _ContextHelpActive; bool inGame; diff --git a/nel/include/nel/misc/common.h b/nel/include/nel/misc/common.h index a5d1b2f27..d9edc8e14 100644 --- a/nel/include/nel/misc/common.h +++ b/nel/include/nel/misc/common.h @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Matt RAYKOWSKI (sfb) // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2015-2019 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -227,18 +227,62 @@ inline double isValidDouble (double v) * \param str a string to transform to lower case */ -std::string toLower ( const char *str ); -std::string toLower ( const std::string &str ); -void toLower ( char *str ); +std::string toLower ( const char *str ); // UTF-8 +std::string toLower ( const std::string &str ); // UTF-8 +void toLower ( char *str ); // Ascii only char toLower ( const char ch ); // convert only one character /** Convert a string in upper case. * \param a string to transform to upper case */ -std::string toUpper ( const std::string &str); -void toUpper ( char *str); +std::string toUpper ( const char *str ); // UTF-8 +std::string toUpper ( const std::string &str); // UTF-8 +void toUpper ( char *str); // Ascii only +/** Convert a single character in UTF-8 to upper or lowercase. +* \param res Character is appended in UTF-8 into this string. +* \param src Character is sourced from this UTF-8 string. +* \param i Index in `str`, incremented by the number of bytes read. +*/ +void appendToLower(std::string &res, const char *str, ptrdiff_t &i); +void appendToLower(std::string &res, const std::string &str, ptrdiff_t &i); +void appendToUpper(std::string &res, const char *str, ptrdiff_t &i); +void appendToUpper(std::string &res, const std::string &str, ptrdiff_t &i); +void appendToTitle(std::string &res, const char *str, ptrdiff_t &i); +void appendToTitle(std::string &res, const std::string &str, ptrdiff_t &i); + +/** UTF-8 case insensitive compare */ +int compareCaseInsensitive(const char *a, const char *b); +int compareCaseInsensitive(const char *a, size_t lenA, const char *b, size_t lenB); +inline int compareCaseInsensitive(const std::string &a, const std::string &b) { return compareCaseInsensitive(&a[0], a.size(), &b[0], b.size()); } +inline bool ltCaseInsensitive(const std::string &a, const std::string &b) { return compareCaseInsensitive(&a[0], a.size(), &b[0], b.size()) < 0; } +std::string toCaseInsensitive(const char *str); // UTF-8, case-insensitive toLower +std::string toCaseInsensitive(const std::string &str); // UTF-8, case-insensitive toLower + +/** ASCII to lowercase. Useful for internal identifiers. +* Characters outside of the 7-bit ASCII space, and control characters, are replaced. +*/ +std::string toLowerAscii(const std::string &str, char replacement); +void toLowerAscii(char *str, char replacement); + +/** ASCII to uppercase. Useful for internal identifiers. +* Characters outside of the 7-bit ASCII space, and control characters, are replaced. +*/ +std::string toUpperAscii(const std::string &str, char replacement); +void toUpperAscii(char *str, char replacement); + +/** ASCII to lowercase. Useful for internal identifiers. +* Characters outside of the 7-bit ASCII space are not affected. +*/ +std::string toLowerAscii(const std::string &str); +void toLowerAscii(char *str); + +/** ASCII to uppercase. Useful for internal identifiers. +* Characters outside of the 7-bit ASCII space are not affected. +*/ +std::string toUpperAscii(const std::string &str); +void toUpperAscii(char *str); /** * Convert to an hexadecimal std::string diff --git a/nel/include/nel/misc/debug.h b/nel/include/nel/misc/debug.h index 1d533c149..9b6e48376 100644 --- a/nel/include/nel/misc/debug.h +++ b/nel/include/nel/misc/debug.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2015 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/include/nel/misc/deep_ptr.h b/nel/include/nel/misc/deep_ptr.h new file mode 100644 index 000000000..76493c6e4 --- /dev/null +++ b/nel/include/nel/misc/deep_ptr.h @@ -0,0 +1,83 @@ +// NeL - MMORPG Framework +// Copyright (C) 2020 Jan BOON (Kaetemi) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NLMISC_DEEP_PTR_H +#define NLMISC_DEEP_PTR_H + +#include + +namespace NLMISC { + +/// Pointer template with deep copy and move semantics +template +class CDeepPtr +{ +public: + NL_FORCE_INLINE CDeepPtr() : m(NULL) { } //< Null + NL_FORCE_INLINE ~CDeepPtr() { delete m; } + + NL_FORCE_INLINE CDeepPtr(const CDeepPtr &p) : m(p.m ? new T(*p) : NULL) { } //< Copy operator + NL_FORCE_INLINE CDeepPtr &operator=(const CDeepPtr &p) { if (p.m) { if (!m) m = new T(*p); else *m = *p; } else { delete m; m = NULL; } return *this; } //< Copy operator + +#ifdef NL_CPP14 + NL_FORCE_INLINE CDeepPtr(CDeepPtr &&p) noexcept : m(p.m) { p.m = NULL; } //< Move operator + NL_FORCE_INLINE CDeepPtr &operator=(CDeepPtr &&p) noexcept { delete m; m = p.m; p.m = NULL; return *this; } //< Move operator +#endif + + NL_FORCE_INLINE CDeepPtr(T *p) : m(p) { } //< Initializer + NL_FORCE_INLINE CDeepPtr &operator=(T *p) { delete m; m = p; return *this; } //< Initializer + + NL_FORCE_INLINE bool operator==(const CDeepPtr &p) const { return /* (m == p.m) || */ (m && p.m && *m == *p); } + NL_FORCE_INLINE bool operator!=(const CDeepPtr &p) const { return !(*this == p); } + + NL_FORCE_INLINE bool operator==(const T *p) const { return (m == p) || (m && p && *m == *p); } + NL_FORCE_INLINE bool operator!=(const T *p) const { return !(*this == p); } + + NL_FORCE_INLINE bool operator==(const T &p) const { return (m == &p) || (m && *m == p); } + NL_FORCE_INLINE bool operator!=(const T &p) const { return !(*this == p); } + + NL_FORCE_INLINE bool operator==(long int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == NULL + NL_FORCE_INLINE bool operator!=(long int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != NULL + + NL_FORCE_INLINE bool operator==(int p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == 0 + NL_FORCE_INLINE bool operator!=(int p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != 0 + +#ifdef NL_CPP14 + NL_FORCE_INLINE bool operator==(nullptr_t p) const { return (*this == (const T *)(ptrdiff_t)p); } //< == nullptr + NL_FORCE_INLINE bool operator!=(nullptr_t p) const { return (*this != (const T *)(ptrdiff_t)p); } //< != nullptr +#endif + + NL_FORCE_INLINE T &operator*() { return *m; } + NL_FORCE_INLINE const T &operator*() const { return *m; } + NL_FORCE_INLINE T *operator->() { return m; } + NL_FORCE_INLINE const T *operator->() const { return m; } + + NL_FORCE_INLINE operator bool() const { return m; } + NL_FORCE_INLINE bool operator!() const { return !m; } + + NL_FORCE_INLINE T *ptr() { return m; } + NL_FORCE_INLINE const T *ptr() const { return m; } + +private: + T *m; + +}; + +} /* namespace NLMISC */ + +#endif /* #ifndef NLMISC_DEEP_PTR_H */ + +/* end of file */ diff --git a/nel/include/nel/misc/event_emitter_multi.h b/nel/include/nel/misc/event_emitter_multi.h index e41ee2055..cb41d023f 100644 --- a/nel/include/nel/misc/event_emitter_multi.h +++ b/nel/include/nel/misc/event_emitter_multi.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -48,8 +51,8 @@ public: /// From IEventEmitter. This call submitEvents on all the emitters virtual void submitEvents(CEventServer &server, bool allWindows); - virtual bool copyTextToClipboard(const ucstring &text); - virtual bool pasteTextFromClipboard(ucstring &text); + virtual bool copyTextToClipboard(const std::string &text); + virtual bool pasteTextFromClipboard(std::string &text); private: typedef std::vector > TEmitterCont; diff --git a/nel/include/nel/misc/events.h b/nel/include/nel/misc/events.h index c783a85eb..b75d72ca2 100644 --- a/nel/include/nel/misc/events.h +++ b/nel/include/nel/misc/events.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -320,11 +323,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 +344,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);} }; diff --git a/nel/include/nel/misc/factory.h b/nel/include/nel/misc/factory.h index 4455cfa64..dce0f4221 100644 --- a/nel/include/nel/misc/factory.h +++ b/nel/include/nel/misc/factory.h @@ -58,12 +58,8 @@ public: static CFactory &instance() { // Singleton instance pointer. - static CFactory *instance = NULL; - if (!instance) - { - instance = new CFactory(); - } - return *instance; + static CFactory instance; + return instance; } /** Register a factorable object in the factory. @@ -182,12 +178,8 @@ public: /// Get the singleton instance reference. static CFactoryIndirect &instance() { - static CFactoryIndirect *instance = NULL; - if (!instance) - { - instance = new CFactoryIndirect(); - } - return *instance; + static CFactoryIndirect instance; + return instance; } void registerClass(const KeyType &key, IFactoryIndirectRegister *factoryRegister) diff --git a/nel/include/nel/misc/file.h b/nel/include/nel/misc/file.h index f634f4378..6f0584dd7 100644 --- a/nel/include/nel/misc/file.h +++ b/nel/include/nel/misc/file.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/include/nel/misc/fixed_size_allocator.h b/nel/include/nel/misc/fixed_size_allocator.h index e00809344..1f49dfa68 100644 --- a/nel/include/nel/misc/fixed_size_allocator.h +++ b/nel/include/nel/misc/fixed_size_allocator.h @@ -107,6 +107,7 @@ private: uint _NumBlockPerChunk; // uint _NumAlloc; + uint8 *_SpareMem; }; } // NLMISC diff --git a/nel/include/nel/misc/i18n.h b/nel/include/nel/misc/i18n.h index e8b00385b..86499eae5 100644 --- a/nel/include/nel/misc/i18n.h +++ b/nel/include/nel/misc/i18n.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -99,7 +100,7 @@ public: /// Return a vector with all language available. The vector contains the name of the language. /// The index in the vector is used in \c load() function - static const std::vector &getLanguageNames(); + static const std::vector &getLanguageNames(); /** Return a vector with all language code available. * Code are ISO 639-2 compliant. @@ -122,7 +123,7 @@ public: static void loadFromFilename (const std::string &filename, bool reload); /// Returns the name of the language in the language name (English, Francais, ...) - static ucstring getCurrentLanguageName (); + static std::string getCurrentLanguageName (); /// Returns the code of the language ("fr", "en", ...) static std::string getCurrentLanguageCode (); @@ -134,7 +135,10 @@ public: static bool setSystemLanguageCode (const std::string &languageCode); /// Find a string in the selected language and return his association. - static const ucstring &get (const std::string &label); + static const ucstring &getAsUtf16 (const std::string &label); + + /// Find a string in the selected language and return his association. + static const std::string &get (const std::string &label); // Test if a string has a translation in the selected language. // NB : The empty string is considered to have a translation @@ -219,24 +223,28 @@ public: private: - typedef std::map StrMapContainer; + typedef std::map StrMapContainer; + typedef std::map StrMapContainer16; static ILoadProxy *_LoadProxy; static StrMapContainer _StrMap; + static StrMapContainer16 _StrMap16; static bool _StrMapLoaded; // the alternative language that will be used if the sentence is not found in the original language static StrMapContainer _StrMapFallback; + static StrMapContainer16 _StrMapFallback16; static std::vector _LanguageCodes; - static std::vector _LanguageNames; + static std::vector _LanguageNames; static std::string _SystemLanguageCode; static bool _LanguagesNamesLoaded; static std::string _SelectedLanguageCode; - static const ucstring _NotTranslatedValue; + static const ucstring _NotTranslatedValue16; + static const std::string _NotTranslatedValue; /** Structure to hold contextual info during * read of preprocessed file @@ -256,7 +264,7 @@ private: /// Init _LanguageCodes and _LanguageNames static void initLanguages(); - static bool loadFileIntoMap(const std::string &filename, StrMapContainer &dest); + static bool loadFileIntoMap(const std::string &filename, StrMapContainer &dest, StrMapContainer16 &dest16); /// The internal read function, it does the real job of readTextFile static void _readTextFile(const std::string &filename, diff --git a/nel/include/nel/misc/sha1.h b/nel/include/nel/misc/sha1.h index d458c6f8f..8c046fca1 100644 --- a/nel/include/nel/misc/sha1.h +++ b/nel/include/nel/misc/sha1.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2019 Jan BOON (Kaetemi) +// Copyright (C) 2019-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/include/nel/misc/sheet_id.h b/nel/include/nel/misc/sheet_id.h index 856dbf330..c1fc7070f 100644 --- a/nel/include/nel/misc/sheet_id.h +++ b/nel/include/nel/misc/sheet_id.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2012 Jan BOON (Kaetemi) +// Copyright (C) 2012-2019 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/include/nel/misc/stream.h b/nel/include/nel/misc/stream.h index 89db78a1c..9b18d575c 100644 --- a/nel/include/nel/misc/stream.h +++ b/nel/include/nel/misc/stream.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/include/nel/misc/string_common.h b/nel/include/nel/misc/string_common.h index 9f6d59aae..71ab05a30 100644 --- a/nel/include/nel/misc/string_common.h +++ b/nel/include/nel/misc/string_common.h @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2016-2019 Jan BOON (Kaetemi) +// Copyright (C) 2016-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -193,6 +193,10 @@ inline std::string toString(const sint32 &val) { return toString("%d", val); } inline std::string toString(const uint64 &val) { return toString("%" NL_I64 "u", val); } inline std::string toString(const sint64 &val) { return toString("%" NL_I64 "d", val); } +#ifdef NL_OS_WINDOWS +inline std::string toString(const wchar_t &val) { return toString(reinterpret_cast(val)); } +#endif + #ifdef NL_COMP_GCC # if GCC_VERSION == 40102 @@ -246,9 +250,14 @@ inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf( inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; } inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; } -// Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, anything else is undefined. -// (str[0] == '1' || (str[0] & 0xD2) == 0x50) -// - Kaetemi +#ifdef NL_OS_WINDOWS +inline bool fromString(const std::string &str, wchar_t &val) { return fromString(str, reinterpret_cast(val)); } +#endif + +/// Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, and empty strings, anything else is undefined. +/// - Kaetemi +inline bool toBool(const char *str) { return str[0] == '1' || (str[0] & 0xD2) == 0x50; } +inline bool toBool(const std::string &str) { return toBool(str.c_str()); } // Safe because first byte may be null bool fromString(const std::string &str, bool &val); diff --git a/nel/include/nel/misc/string_view.h b/nel/include/nel/misc/string_view.h new file mode 100644 index 000000000..9d1a96308 --- /dev/null +++ b/nel/include/nel/misc/string_view.h @@ -0,0 +1,131 @@ +// NeL - MMORPG Framework +// Copyright (C) 2020 Jan BOON (Kaetemi) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NLMISC_STRING_VIEW_H +#define NLMISC_STRING_VIEW_H + +#include +#include + +#ifdef NL_CPP14 +using namespace std::string_literals; +#ifdef NL_CPP17 +#include +using namespace std::string_view_literals; +#endif +#endif + +#ifdef NL_CPP14 +/// Obtain an std::string from a string literal. +#define nlstr(strLit) (strLit##s) +#else +/// Obtain an std::string from a string literal. +#define nlstr(strLit) (std::string(strLit)) +#endif + +#ifdef NL_CPP17 +/// Obtain a string view from a string literal. +#define nlsv(strLit) (strLit##sv) +/// Obtain an std::string from a string view. +#define nlsvs(strView) (std::string(strView)) +#else +/// Obtain a string view from a string literal. +#define nlsv(strLit) (CStringView(strLit, ::strlen(strLit))) +/// Obtain an std::string from a string view. +#define nlsvs(strView) (std::string(strView.data(), strView.size())) +#endif + +/// Obtain a temporary C-string from a string view. Use directly in argument, do not store. +#define nlsvc(strView) ((strView.data()[strView.size()]) ? nlsvs(strView).c_str() : strView.data()) + +namespace NLMISC { + +/// String view literals allow bypassing allocation and strlen calls. +/// CStringView is a 100% drop-in replacement for (const char *str, size_t len) tuples. It's a non-owning reference. +/// Always use `CStringView` where previously `const std::string &` would have been used. It avoids accidental copy. +/// Gotcha: CStringView doesn't need to end with \0, so there's no guarantee with functions that expect \0 terminated strings, +/// use the `nlsvc` macro to get a temporary C-string from a CStringView. +/// Use the `nlsv` macro to get a CStringView from a string literal. +/// Use the `nlstr` macro to get an std::string from a string literal. +/// Use the `nlsvs` macro to get an std::string from a CStringView. +#ifdef NL_CPP17 +typedef std::string_view CStringView; +#else +class CStringView +{ +public: + CStringView(const std::string &str) : m_Str(&str[0]), m_Len(str.size()) {} + CStringView(const char *const str, const size_t len) : m_Str(str), m_Len(len) {} + CStringView(const char *const str) : m_Str(str), m_Len(sizeof(str)) {} + + inline const char *data() const { return m_Str; } + inline size_t length() const { return m_Len; } + inline size_t size() const { return m_Len; } + + inline CStringView substr(const size_t offset, const size_t count = -1) { return CStringView(m_Str + offset, std::min(m_Len - offset, count)); } + + inline bool operator==(const CStringView o) { if (m_Len != o.m_Len) return false; return memcmp(m_Str, o.m_Str, m_Len) == 0; } + inline bool operator!=(const CStringView o) { if (m_Len != o.m_Len) return true; return memcmp(m_Str, o.m_Str, m_Len) != 0; } + + struct const_iterator + { + public: + const_iterator() : m_Addr(NULL) { } + + inline void operator++() + { + ++m_Addr; + } + inline void operator+=(ptrdiff_t v) + { + m_Addr += v; + } + inline void operator--() + { + --m_Addr; + } + inline void operator-=(ptrdiff_t v) + { + m_Addr -= v; + } + inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; } + inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; } + inline const char &operator*() const { return *m_Addr; } + + private: + friend class CStringView; + inline const_iterator(const char *addr) : m_Addr(addr) {} + const char *m_Addr; + + }; + + typedef const_iterator iterator; + + iterator begin() const { return iterator(m_Str); } + inline iterator end() const { return iterator(m_Str + m_Len); } + +private: + const char *m_Str; + size_t m_Len; + +}; +#endif + +} + +#endif /* #ifndef NLMISC_STRING_VIEW_H */ + +/* end of file */ diff --git a/nel/include/nel/misc/system_utils.h b/nel/include/nel/misc/system_utils.h index 426e38b73..5cec22af2 100644 --- a/nel/include/nel/misc/system_utils.h +++ b/nel/include/nel/misc/system_utils.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2015-2019 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -49,10 +49,10 @@ public: static bool updateProgressBar(uint value, uint total); /// Copy a string to system clipboard. - static bool copyTextToClipboard(const ucstring &text); + static bool copyTextToClipboard(const std::string &text); /// Paste a string from system clipboard. - static bool pasteTextFromClipboard(ucstring &text); + static bool pasteTextFromClipboard(std::string &text); /// Check if system supports unicode. static bool supportUnicode(); diff --git a/nel/include/nel/misc/types_nl.h b/nel/include/nel/misc/types_nl.h index 445882c34..a257eb293 100644 --- a/nel/include/nel/misc/types_nl.h +++ b/nel/include/nel/misc/types_nl.h @@ -2,7 +2,7 @@ // Copyright (C) 2010-2011 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014-2019 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -548,6 +548,14 @@ template<> struct hash */ typedef uint16 ucchar; +#ifdef NL_CPP14 +typedef char32_t u32char; +typedef std::u32string u32string; +#else +typedef uint32 u32char; +typedef std::basic_string u32string; +#endif + #ifndef NL_OVERRIDE #define NL_OVERRIDE override #endif diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index b3dc1294f..5b95c33c2 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2015 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -35,113 +35,111 @@ typedef std::basic_string ucstringbase; class ucstring : public ucstringbase { public: + ucstring() { } - ucstring () {} + ucstring(const ucstringbase &str) + : ucstringbase(str) + { + } - ucstring (const ucstringbase &str) : ucstringbase (str) {} + ucstring(const ucchar *begin, const ucchar *end) + : ucstringbase(begin, end) + { + } - ucstring (const std::string &str) : ucstringbase () + ucstring(const std::string &str) + : ucstringbase() { - rawCopy(str); + fromUtf8(str); } - ~ucstring () {} + ~ucstring() { } - ucstring &operator= (ucchar c) + ucstring &operator=(ucchar c) { - resize (1); + resize(1); operator[](0) = c; return *this; } - ucstring &operator= (const char *str) + ucstring &operator=(const char *str) { - resize (strlen (str)); - for (uint i = 0; i < strlen (str); i++) + resize(strlen(str)); + for (uint i = 0; i < strlen(str); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const std::string &str) + ucstring &operator=(const std::string &str) { - resize (str.size ()); - for (uint i = 0; i < str.size (); i++) + resize(str.size()); + for (uint i = 0; i < str.size(); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const ucstringbase &str) + ucstring &operator=(const ucstringbase &str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring& operator= (const ucchar *str) + ucstring &operator=(const ucchar *str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring &operator+= (ucchar c) + ucstring &operator+=(ucchar c) { - resize (size() + 1); - operator[](size()-1) = c; + resize(size() + 1); + operator[](size() - 1) = c; return *this; } - ucstring &operator+= (const char *str) + ucstring &operator+=(const char *str) { size_t s = size(); - resize (s + strlen(str)); + resize(s + strlen(str)); for (uint i = 0; i < strlen(str); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const std::string &str) + ucstring &operator+=(const std::string &str) { size_t s = size(); - resize (s + str.size()); + resize(s + str.size()); for (uint i = 0; i < str.size(); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const ucstringbase &str) + ucstring &operator+=(const ucstringbase &str) { - ucstringbase::operator +=(str); + ucstringbase::operator+=(str); return *this; } const ucchar *c_str() const { const ucchar *tmp = ucstringbase::c_str(); - const_cast(tmp)[size()] = 0; + const_cast(tmp)[size()] = 0; return tmp; } /// Converts the controlled ucstring to a string str - void toString (std::string &str) const - { - str.resize (size ()); - for (uint i = 0; i < str.size (); i++) - { - if (operator[](i) > 255) - str[i] = '?'; - else - str[i] = (char) operator[](i); - } - } + void toString(std::string &str) const; /// Converts the controlled ucstring and returns the resulting string - std::string toString () const + std::string toString() const { std::string str; toString(str); @@ -149,43 +147,7 @@ public: } /// Convert this ucstring (16bits char) into a utf8 string - std::string toUtf8() const - { - std::string res; - ucstring::const_iterator first(begin()), last(end()); - for (; first != last; ++first) - { - //ucchar c = *first; - uint nbLoop = 0; - if (*first < 0x80) - res += char(*first); - else if (*first < 0x800) - { - ucchar c = *first; - c = c >> 6; - c = c & 0x1F; - res += char(c) | 0xC0; - nbLoop = 1; - } - else /*if (*first < 0x10000)*/ - { - ucchar c = *first; - c = c >> 12; - c = c & 0x0F; - res += char(c) | 0xE0; - nbLoop = 2; - } - - for (uint i=0; i> ((nbLoop - i - 1) * 6); - c = c & 0x3F; - res += char(c) | 0x80; - } - } - return res; - } + std::string toUtf8() const; ucstring substr(size_type pos = 0, size_type n = npos) const { @@ -199,86 +161,7 @@ public: } /// Convert the utf8 string into this ucstring (16 bits char) - void fromUtf8(const std::string &stringUtf8) - { - // clear the string - erase(); - - uint8 c; - ucchar code; - sint iterations = 0; - - std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end()); - for (; first != last; ) - { - c = *first++; - code = c; - - if ((code & 0xFE) == 0xFC) - { - code &= 0x01; - iterations = 5; - } - else if ((code & 0xFC) == 0xF8) - { - code &= 0x03; - iterations = 4; - } - else if ((code & 0xF8) == 0xF0) - { - code &= 0x07; - iterations = 3; - } - else if ((code & 0xF0) == 0xE0) - { - code &= 0x0F; - iterations = 2; - } - else if ((code & 0xE0) == 0xC0) - { - code &= 0x1F; - iterations = 1; - } - else if ((code & 0x80) == 0x80) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - else - { - push_back(code); - iterations = 0; - } - - if (iterations) - { - for (sint i = 0; i < iterations; i++) - { - if (first == last) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - - uint8 ch; - ch = *first ++; - - if ((ch & 0xC0) != 0x80) - { - // If it's not a valid UTF8 string, just copy the line without utf8 conversion - rawCopy(stringUtf8); - return; - } - - code <<= 6; - code |= (ucchar)(ch & 0x3F); - } - push_back(code); - } - } - } + void fromUtf8(const std::string &stringUtf8); static ucstring makeFromUtf8(const std::string &stringUtf8) { @@ -288,83 +171,72 @@ public: return ret; } -private: - - void rawCopy(const std::string &str) - { - // We need to convert the char into 8bits unsigned int before promotion to 16 bits - // otherwise, as char are signed on some compiler (MSCV for ex), the sign bit is extended to 16 bits. - resize(str.size()); - std::string::const_iterator first(str.begin()), last(str.end()); - iterator dest(begin()); - for (;first != last; ++first, ++dest) - { - *dest = uint8(*first); - } - } }; inline ucstring operator+(const ucstringbase &ucstr, ucchar c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const char *c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const std::string &c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(ucchar c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const char *c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const std::string &c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } -namespace NLMISC -{ +namespace NLMISC { // Traits for hash_map using CEntityId struct CUCStringHashMapTraits { - enum { bucket_size = 4, min_buckets = 8 }; + enum + { + bucket_size = 4, + min_buckets = 8 + }; CUCStringHashMapTraits() { } - size_t operator() (const ucstring &id ) const + size_t operator()(const ucstring &id) const { return id.size(); } - bool operator() (const ucstring &id1, const ucstring &id2) const + bool operator()(const ucstring &id1, const ucstring &id2) const { return id1 < id2; } @@ -375,18 +247,18 @@ struct CUCStringHashMapTraits * \param a string or a char to transform to lower case */ -ucstring toLower (const ucstring &str); -void toLower (ucchar *str); -ucchar toLower (ucchar c); +ucstring toLower(const ucstring &str); +void toLower(ucchar *str); +ucchar toLower(ucchar c); /** Convert an unicode string in upper case. * Characters with accent are converted in a uppercase character without accent * \param a string or a char to transform to upper case */ -ucstring toUpper (const ucstring &str); -void toUpper (ucchar *str); -ucchar toUpper (ucchar c); +ucstring toUpper(const ucstring &str); +void toUpper(ucchar *str); +ucchar toUpper(ucchar c); }; diff --git a/nel/include/nel/misc/utf_string_view.h b/nel/include/nel/misc/utf_string_view.h new file mode 100644 index 000000000..6264f425e --- /dev/null +++ b/nel/include/nel/misc/utf_string_view.h @@ -0,0 +1,178 @@ +// NeL - MMORPG Framework +// Copyright (C) 2020 Jan BOON (Kaetemi) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NLMISC_UTF_STRING_VIEW_H +#define NLMISC_UTF_STRING_VIEW_H + +#include + +#include + +#include +#include + +namespace NLMISC { + +class IStream; + +/// String view for UTF-8 and UTF-32 iteration as 32-bit codepoints. +/// This string view keeps the string as a reference, it does not make a copy. +/// Only use this for iterating a string's codepoints. +/// String must be NUL terminated, but its size may specify a substring. +class CUtfStringView +{ +public: + inline CUtfStringView() : m_Str(NULL), m_Size(0), m_Iterator(utf32Iterator) {} + + inline CUtfStringView(const std::string &utf8Str) : m_Str(utf8Str.c_str()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {} + inline CUtfStringView(const char *utf8Str) : m_Str(utf8Str), m_Size(strlen(utf8Str)), m_Iterator(utf8Iterator) {} + inline CUtfStringView(const char *utf8Str, size_t len): m_Str(utf8Str), m_Size(len), m_Iterator(utf8Iterator) + { + nlassert(len <= strlen(utf8Str)); + } + + inline CUtfStringView(CStringView utf8Str) : m_Str(utf8Str.data()), m_Size(utf8Str.size()), m_Iterator(utf8Iterator) {} + +#if defined(NL_OS_WINDOWS) + inline CUtfStringView(const wchar_t *utf16Str) : m_Str(utf16Str), m_Size(wcslen(utf16Str)), m_Iterator(utf16Iterator) {} + inline CUtfStringView(const wchar_t *utf16Str, size_t len): m_Str(utf16Str), m_Size(len), m_Iterator(utf16Iterator) + { + nlassert(len <= wcslen(utf16Str)); + } +#else + inline CUtfStringView(const wchar_t *utf32Str) : m_Str(utf32Str), m_Size(wcslen(utf32Str)), m_Iterator(utf32Iterator) {} + inline CUtfStringView(const wchar_t *utf32Str, size_t len): m_Str(utf32Str), m_Size(len), m_Iterator(utf32Iterator) + { + nlassert(len <= wcslen(utf32Str)); + } +#endif + + 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) {} + + 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 + + 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. + + inline bool isUtf8() const { return m_Iterator == utf8Iterator; } + inline bool isUtf16() const { return m_Iterator == utf16Iterator; } + inline bool isUtf32() const { return m_Iterator == utf32Iterator; } + + struct const_iterator + { + public: + inline void operator++() + { + if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size)) + m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size); + m_Addr = m_Next; + m_Char = m_View.m_Iterator(&m_Next); + } + inline void operator+=(ptrdiff_t a) + { + while ((ptrdiff_t)m_Addr < ((ptrdiff_t)m_View.m_Str + m_View.m_Size)) + { + ++(*this); + } + } + inline bool operator!=(const const_iterator &o) const { return m_Addr != o.m_Addr; } + inline bool operator==(const const_iterator &o) const { return m_Addr == o.m_Addr; } + inline const u32char &operator*() const { return m_Char; } + const_iterator() : m_View(*(CUtfStringView *)NULL), m_Addr(NULL), m_Char(0) { } + + const_iterator &operator=(const const_iterator &other) + { + if (this == &other) return *this; + this->~const_iterator(); + return *new(this) const_iterator(other); + } + + const void *ptr() const { return m_Addr; } + private: + friend class CUtfStringView; + inline const_iterator(const CUtfStringView &view, const void *addr) : m_View(view), m_Addr(addr), m_Next(addr), m_Char(view.m_Iterator(&m_Next)) + { + if ((ptrdiff_t)m_Next > ((ptrdiff_t)m_View.m_Str + m_View.m_Size)) + m_Next = (void *)((ptrdiff_t)m_View.m_Str + m_View.m_Size); + } + inline const_iterator(const CUtfStringView &view) : m_View(view), m_Addr((char *)view.m_Str + view.m_Size), m_Next((char *)view.m_Str + view.m_Size + 1), m_Char(0) { } + const CUtfStringView &m_View; + const void *m_Addr; // Current address + const void *m_Next; // Next address + u32char m_Char; + }; + + typedef const_iterator iterator; + + iterator begin() const { return iterator(*this, m_Str); } + inline iterator end() const { return iterator(*this); } + + /// Largest possible number of characters in this string. + /// Number of actual characters may be less or equal. + inline size_t largestSize() const { return m_Size; } + + inline bool empty() const { return !m_Size; } + const void *ptr() const { return m_Str; } + + size_t count() const; //< Slow count of UTF-32 codepoints + ptrdiff_t offset(ptrdiff_t i); const //< Get byte offset by utf-32 codepoint index + + inline CUtfStringView substr(const iterator &begin, const iterator &end) const + { + return CUtfStringView(begin.m_Addr, (ptrdiff_t)end.m_Addr - (ptrdiff_t)begin.m_Addr, m_Iterator); + } + + inline bool endsWith(char c) { nlassert(c < 0x80); return *((char *)m_Str + m_Size - 1) == c; } + + CUtfStringView &operator=(const CUtfStringView &other) + { + if(this == &other) return *this; + this->~CUtfStringView(); + return *new(this) CUtfStringView(other); + } + + static void append(std::string &str, u32char c); + + /// Encode or decode a single UTF-8 character in a stream (also useful for packing unsigned 20-bit integers) + static void append(IStream &s, u32char c); + static u32char get(IStream &s); + + /// Get an UTF-8 string from an undefined ASCII-based codepage, without attempting to convert non-7-bit characters + static std::string fromAscii(const std::string &str); + +private: + typedef u32char (*TIterator)(const void **addr); + static u32char utf8Iterator(const void **addr); + static u32char utf16Iterator(const void **addr); + static u32char utf32Iterator(const void **addr); + + inline CUtfStringView(const void *str, size_t len, TIterator it) : m_Str(str), m_Size(len), m_Iterator(it) { } + + const void *const m_Str; // String + const size_t m_Size; // Size in bytes + const TIterator m_Iterator; + +}; /* class CUtfStringView */ + +} /* namespace NLMISC */ + +#endif /* #ifndef NLMISC_UTF_STRING_VIEW_H */ + +/* end of file */ diff --git a/nel/include/nel/misc/win_event_emitter.h b/nel/include/nel/misc/win_event_emitter.h index d23d9d040..ee709ec04 100644 --- a/nel/include/nel/misc/win_event_emitter.h +++ b/nel/include/nel/misc/win_event_emitter.h @@ -36,7 +36,7 @@ namespace NLMISC { class CWinEventEmitter : public IEventEmitter { public: - CWinEventEmitter () : _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true) + CWinEventEmitter () : _Utf16Pair(0), _MouseEventsEnabled(true), _KeyboardEventsEnabled(true), _IMEEventsEnabled(true) { _HWnd=NULL; resetButtonFlagState (); @@ -106,6 +106,7 @@ public: private: CWinEventServer _InternalServer; HWND _HWnd; + wchar_t _Utf16Pair; public: // private: may need to be in sync with direct input flags however... bool _CtrlButton; diff --git a/nel/include/nel/net/unified_network.h b/nel/include/nel/net/unified_network.h index df735a740..094ff7390 100644 --- a/nel/include/nel/net/unified_network.h +++ b/nel/include/nel/net/unified_network.h @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/include/nel/sound/music_channel_fader.h b/nel/include/nel/sound/music_channel_fader.h index 577d23949..bacbbe837 100644 --- a/nel/include/nel/sound/music_channel_fader.h +++ b/nel/include/nel/sound/music_channel_fader.h @@ -7,7 +7,7 @@ */ // NeL - MMORPG Framework -// Copyright (C) 2008-2012 Jan BOON (Kaetemi) +// Copyright (C) 2008-2020 Jan BOON (Kaetemi) // // This source file has been modified by the following contributors: // Copyright (C) 2010 Winch Gate Property Limited diff --git a/nel/include/nel/sound/stream_file_source.h b/nel/include/nel/sound/stream_file_source.h index c8cf91cf5..1ade68572 100644 --- a/nel/include/nel/sound/stream_file_source.h +++ b/nel/include/nel/sound/stream_file_source.h @@ -7,7 +7,7 @@ */ // NeL - MMORPG Framework -// Copyright (C) 2012 Jan BOON (Kaetemi) +// Copyright (C) 2012-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/include/nel/web/http_client_curl.h b/nel/include/nel/web/http_client_curl.h index e130cd768..cfb1ac38a 100644 --- a/nel/include/nel/web/http_client_curl.h +++ b/nel/include/nel/web/http_client_curl.h @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2019 Jan BOON (Kaetemi) +// Copyright (C) 2019-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/samples/misc/i18n/main.cpp b/nel/samples/misc/i18n/main.cpp index 1c8ddabb9..5b1c73123 100644 --- a/nel/samples/misc/i18n/main.cpp +++ b/nel/samples/misc/i18n/main.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -44,9 +47,9 @@ int main (int argc, char **argv) // load the language CI18N::load(langName); - InfoLog->displayRawNL(CI18N::get("Hi").toString().c_str()); - InfoLog->displayRawNL(CI18N::get("PresentI18N").toString().c_str(), "Nevrax"); - InfoLog->displayRawNL(CI18N::get("ExitStr").toString().c_str()); + InfoLog->displayRawNL(CI18N::get("Hi").c_str()); + InfoLog->displayRawNL(CI18N::get("PresentI18N").c_str(), "Nevrax"); + InfoLog->displayRawNL(CI18N::get("ExitStr").c_str()); getchar(); return EXIT_SUCCESS; diff --git a/nel/src/3d/animation_set.cpp b/nel/src/3d/animation_set.cpp index 0b4c096c0..462587b09 100644 --- a/nel/src/3d/animation_set.cpp +++ b/nel/src/3d/animation_set.cpp @@ -289,7 +289,7 @@ void CAnimationSet::preloadSSSShapes(IDriver &drv, CShapeBank &shapeBank) std::set::iterator it; for(it=_SSSShapes.begin();it!=_SSSShapes.end();it++) { - string fileName= toLower(*it); + string fileName= toLowerAscii(*it); // link the shape to the shapeCache shapeBank.linkShapeToShapeCache(fileName, shapeCacheName); diff --git a/nel/src/3d/async_texture_manager.cpp b/nel/src/3d/async_texture_manager.cpp index a962c9991..22c4969ea 100644 --- a/nel/src/3d/async_texture_manager.cpp +++ b/nel/src/3d/async_texture_manager.cpp @@ -151,7 +151,7 @@ uint CAsyncTextureManager::addTextureRef(const string &textNameNotLwr, CMeshBa uint ret; // lower case name - string textName = toLower(textNameNotLwr); + string textName = toLowerAscii(textNameNotLwr); // find the texture in map ItTextureEntryMap it; diff --git a/nel/src/3d/coarse_mesh_build.cpp b/nel/src/3d/coarse_mesh_build.cpp index 966f389b4..e89c8da8d 100644 --- a/nel/src/3d/coarse_mesh_build.cpp +++ b/nel/src/3d/coarse_mesh_build.cpp @@ -117,7 +117,7 @@ bool CCoarseMeshBuild::buildBitmap (const std::vector& coarseMe if (texture->supportSharing()) { // Get sharing name - name+=toLower(texture->getShareName()); + name+=toLowerAscii(texture->getShareName()); } else { @@ -477,7 +477,7 @@ void CCoarseMeshBuild::remapCoordinates (const std::vector& coa if (texture->supportSharing()) { // Get sharing name - name+=toLower(texture->getShareName()); + name+=toLowerAscii(texture->getShareName()); } else { diff --git a/nel/src/3d/driver.cpp b/nel/src/3d/driver.cpp index 32cd19a89..71600d3c9 100644 --- a/nel/src/3d/driver.cpp +++ b/nel/src/3d/driver.cpp @@ -291,7 +291,7 @@ bool IDriver::invalidateShareTexture (ITexture &texture) void IDriver::getTextureShareName (const ITexture& tex, string &output) { // Create the shared Name. - output= toLower(tex.getShareName()); + output= toLowerAscii(tex.getShareName()); // append format Id of the texture. static char fmt[256]; @@ -372,7 +372,7 @@ void IDriver::profileTextureUsage(std::vector &result) // get the shareName string shareName; if(text->supportSharing()) - shareName= toLower(text->getShareName()); + shareName= toLowerAscii(text->getShareName()); else shareName= "Not Shared"; diff --git a/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 3a4f67aee..f8a678957 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2019 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // Copyright (C) 2014 Matthew LAGOE (Botanic) // // This program is free software: you can redistribute it and/or modify @@ -1173,7 +1173,7 @@ void D3DWndProc(CDriverD3D *driver, HWND hWnd, UINT message, WPARAM wParam, LPAR } } - if (driver->_EventEmitter.getNumEmitters() > 0) + if (driver && driver->_EventEmitter.getNumEmitters() > 0) { CWinEventEmitter *we = NLMISC::safe_cast(driver->_EventEmitter.getEmitter(0)); // Process the message by the emitter @@ -1225,12 +1225,29 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l D3DWndProc (pDriver, hWnd, message, wParam, lParam); } + if (message == WM_SYSCOMMAND) + { + switch (wParam) + { #ifdef NL_DISABLE_MENU - // disable menu (F10, ALT and ALT+SPACE key doesn't freeze or open the menu) - if(message == WM_SYSCOMMAND && wParam == SC_KEYMENU) - return 0; + // disable menu (F10, ALT and ALT+SPACE key doesn't freeze or open the menu) + case SC_KEYMENU: #endif // NL_DISABLE_MENU + // Screensaver Trying To Start? + case SC_SCREENSAVE: + + // Monitor Trying To Enter Powersave? + case SC_MONITORPOWER: + + // Prevent From Happening + return 0; + + default: + break; + } + } + // ace: if we receive close, exit now or it'll assert after if(message == WM_CLOSE) { @@ -1248,6 +1265,12 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l return 0; } +#ifdef WM_UNICHAR + // https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-unichar + if (message == WM_UNICHAR) + return (wParam == UNICODE_NOCHAR); +#endif + return DefWindowProcW(hWnd, message, wParam, lParam); } @@ -3995,12 +4018,12 @@ void CDriverD3D::findNearestFullscreenVideoMode() } } } -bool CDriverD3D::copyTextToClipboard(const ucstring &text) +bool CDriverD3D::copyTextToClipboard(const std::string &text) { return _EventEmitter.copyTextToClipboard(text); } -bool CDriverD3D::pasteTextFromClipboard(ucstring &text) +bool CDriverD3D::pasteTextFromClipboard(std::string &text) { return _EventEmitter.pasteTextFromClipboard(text); } diff --git a/nel/src/3d/driver/direct3d/driver_direct3d.h b/nel/src/3d/driver/direct3d/driver_direct3d.h index c021f052d..9a434cab2 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2019 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -2748,8 +2748,8 @@ public: bool convertBitmapToIcon(const NLMISC::CBitmap &bitmap, HICON &icon, uint iconWidth, uint iconHeight, uint iconDepth, const NLMISC::CRGBA &col = NLMISC::CRGBA::White, sint hotSpotX = 0, sint hotSpotY = 0, bool cursor = false); - virtual bool copyTextToClipboard(const ucstring &text); - virtual bool pasteTextFromClipboard(ucstring &text); + virtual bool copyTextToClipboard(const std::string &text); + virtual bool pasteTextFromClipboard(std::string &text); public: #ifdef NL_DEBUG diff --git a/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp b/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp index 2285688d4..1436e5aa4 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp b/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp index 15dcb7768..71af20f00 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2012-2014 Jan BOON (Kaetemi) +// Copyright (C) 2012-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/src/3d/driver/opengl/driver_opengl.cpp b/nel/src/3d/driver/opengl/driver_opengl.cpp index 90b17958f..6fe9ae7c4 100644 --- a/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -2583,7 +2583,7 @@ void CDriverGL::retrieveATIDriverVersion() result = RegQueryValueExA(subKey, "DriverDesc", NULL, &valueType, (unsigned char *) driverDesc, &driverDescBufSize); if (result == ERROR_SUCCESS && valueType == REG_SZ) { - toLower(driverDesc); + toLowerAscii(driverDesc); if (strstr(driverDesc, "radeon")) // is it a radeon card ? { char driverVersion[256]; diff --git a/nel/src/3d/driver/opengl/driver_opengl.h b/nel/src/3d/driver/opengl/driver_opengl.h index e1ee968a5..5be157403 100644 --- a/nel/src/3d/driver/opengl/driver_opengl.h +++ b/nel/src/3d/driver/opengl/driver_opengl.h @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) // Copyright (C) 2010 Thibaut GIRKA (ThibG) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -354,8 +354,8 @@ public: return _win; } - virtual bool copyTextToClipboard(const ucstring &text); - virtual bool pasteTextFromClipboard(ucstring &text); + virtual bool copyTextToClipboard(const std::string &text); + virtual bool pasteTextFromClipboard(std::string &text); virtual uint32 getAvailableVertexAGPMemory (); virtual uint32 getAvailableVertexVRAMMemory (); diff --git a/nel/src/3d/driver/opengl/driver_opengl_extension.cpp b/nel/src/3d/driver/opengl/driver_opengl_extension.cpp index 0b8c4a458..ff5252c61 100644 --- a/nel/src/3d/driver/opengl/driver_opengl_extension.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl_extension.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp b/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp index 689c37ba5..8c86f4c7e 100644 --- a/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl_vertex_buffer_hard.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -1373,10 +1373,11 @@ CVertexBufferHardARB::~CVertexBufferHardARB() } } #ifdef NL_DEBUG - if (_VertexPtr) - { - _VertexArrayRange->_MappedVBList.erase(_IteratorInMappedVBList); - } + if (_VertexPtr) + { + nlassert(_VertexArrayRange); + _VertexArrayRange->_MappedVBList.erase(_IteratorInMappedVBList); + } #endif #ifdef USE_OPENGLES diff --git a/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/nel/src/3d/driver/opengl/driver_opengl_window.cpp index f04ad304e..163f64843 100644 --- a/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2019 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -183,6 +183,12 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l return 0; } +#ifdef WM_UNICHAR + // https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-unichar + if (message == WM_UNICHAR) + return (wParam == UNICODE_NOCHAR); +#endif + return trapMessage ? 0 : DefWindowProcW(hWnd, message, wParam, lParam); } @@ -3014,12 +3020,12 @@ void CDriverGL::setupApplicationMenu() } #endif -bool CDriverGL::copyTextToClipboard(const ucstring &text) +bool CDriverGL::copyTextToClipboard(const std::string &text) { return _EventEmitter.copyTextToClipboard(text); } -bool CDriverGL::pasteTextFromClipboard(ucstring &text) +bool CDriverGL::pasteTextFromClipboard(std::string &text) { return _EventEmitter.pasteTextFromClipboard(text); } diff --git a/nel/src/3d/driver/opengl/unix_event_emitter.cpp b/nel/src/3d/driver/opengl/unix_event_emitter.cpp index d4153dde5..e8e8ae99f 100644 --- a/nel/src/3d/driver/opengl/unix_event_emitter.cpp +++ b/nel/src/3d/driver/opengl/unix_event_emitter.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -29,6 +29,7 @@ #include #include #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); @@ -547,9 +547,10 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) server->postEvent (charEvent); #else + // FIXME: Convert locale to UTF-32 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); @@ -610,14 +611,13 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) else if (req.target == XA_STRING) { respond.xselection.property = req.property; - std::string str = _CopiedString.toString(); + std::string str = _CopiedString; // NLMISC::CUtfStringView(_CopiedString).toAscii(); // FIXME: Convert UTF-8 to local XChangeProperty(req.display, req.requestor, req.property, XA_STRING, 8, PropModeReplace, (const unsigned char*)str.c_str(), str.length()); } else if (req.target == XA_UTF8_STRING) { respond.xselection.property = req.property; - std::string str = _CopiedString.toUtf8(); - XChangeProperty(req.display, req.requestor, respond.xselection.property, XA_UTF8_STRING, 8, PropModeReplace, (const unsigned char*)str.c_str(), str.length()); + XChangeProperty(req.display, req.requestor, respond.xselection.property, XA_UTF8_STRING, 8, PropModeReplace, (const unsigned char*)_CopiedString.c_str(), _CopiedString.length()); } else { @@ -699,22 +699,22 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) if (XGetWindowProperty(_dpy, _win, XA_NEL_SEL, 0, XMaxRequestSize(_dpy), False, AnyPropertyType, &actualType, &actualFormat, &nitems, &bytesLeft, (unsigned char**)&data) != Success) return false; - ucstring text; - std::string tmpData = (const char*)data; + std::string text = (const char*)data; XFree(data); // convert buffer to ucstring if (target == XA_UTF8_STRING) { - text = ucstring::makeFromUtf8(tmpData); + // OK } else if (target == XA_STRING) { - text = tmpData; + // FIXME: Convert local to UTF-8 + // text = NLMISC::CUtfStringView(text).toAscii(); } else { - nlwarning("Unknow format %u", (uint)target); + nlwarning("Unknown format %u", (uint)target); } // sent string event to event server @@ -768,7 +768,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) return true; } -bool CUnixEventEmitter::copyTextToClipboard(const ucstring &text) +bool CUnixEventEmitter::copyTextToClipboard(const std::string &text) { _CopiedString = text; @@ -787,7 +787,7 @@ bool CUnixEventEmitter::copyTextToClipboard(const ucstring &text) return true; } -bool CUnixEventEmitter::pasteTextFromClipboard(ucstring &text) +bool CUnixEventEmitter::pasteTextFromClipboard(std::string &text) { // check if we own the selection if (_SelectionOwned) diff --git a/nel/src/3d/driver/opengl/unix_event_emitter.h b/nel/src/3d/driver/opengl/unix_event_emitter.h index bbee65e5e..297fdcb5a 100644 --- a/nel/src/3d/driver/opengl/unix_event_emitter.h +++ b/nel/src/3d/driver/opengl/unix_event_emitter.h @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2010 Robert TIMM (rti) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -66,12 +67,12 @@ public: /** * Copy a string to system clipboard. */ - virtual bool copyTextToClipboard(const ucstring &text); + virtual bool copyTextToClipboard(const std::string &text); /* * Paste a string from system clipboard. */ - virtual bool pasteTextFromClipboard(ucstring &text); + virtual bool pasteTextFromClipboard(std::string &text); void createIM(); void closeIM(); @@ -105,7 +106,7 @@ private: XIC _ic; NL3D::IDriver* _driver; CUnixEventServer _InternalServer; - ucstring _CopiedString; + std::string _CopiedString; bool _SelectionOwned; }; diff --git a/nel/src/3d/driver_user.cpp b/nel/src/3d/driver_user.cpp index b44a64737..a7bd7a332 100644 --- a/nel/src/3d/driver_user.cpp +++ b/nel/src/3d/driver_user.cpp @@ -4,7 +4,7 @@ // This source file has been modified by the following contributors: // Copyright (C) 2010 Matt RAYKOWSKI (sfb) // Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // Copyright (C) 2015 Laszlo KIS-ADAM (dfighter) // // This program is free software: you can redistribute it and/or modify @@ -1971,12 +1971,12 @@ bool CDriverUser::setRenderTarget(class UTexture & uTex, uint32 x, uint32 y, uin return result; } -bool CDriverUser::copyTextToClipboard(const ucstring &text) +bool CDriverUser::copyTextToClipboard(const std::string &text) { return _Driver->copyTextToClipboard(text); } -bool CDriverUser::pasteTextFromClipboard(ucstring &text) +bool CDriverUser::pasteTextFromClipboard(std::string &text) { return _Driver->pasteTextFromClipboard(text); } diff --git a/nel/src/3d/font_generator.cpp b/nel/src/3d/font_generator.cpp index 44d8f5ab0..8cc24c4b6 100644 --- a/nel/src/3d/font_generator.cpp +++ b/nel/src/3d/font_generator.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2015 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -26,6 +26,7 @@ #include "nel/misc/common.h" #include "nel/misc/path.h" #include "nel/misc/file.h" +#include "nel/misc/i18n.h" #include "nel/3d/font_generator.h" @@ -190,6 +191,20 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri _FontGeneratorCounterUID++; _FontFileName = fontFileName; + if (NLMISC::startsWith(fontFileName, "ui")) + { + std::string nameList = CI18N::get(fontFileName); + NLMISC::explode(nameList, string("\n"), _FontFileNames, true); + for (std::vector::iterator it(_FontFileNames.begin()), end(_FontFileNames.end()); it != end; ++it) + { + *it = CPath::lookup(*it); + } + } + else + { + _FontFileNames.push_back(fontFileName); + } + FT_Error error; if (!_LibraryInit) @@ -202,49 +217,66 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri } ++_LibraryInit; - FT_Open_Args args; - - if (!createFreetypeStream(fontFileName, args)) + for (std::vector::iterator it(_FontFileNames.begin()), end(_FontFileNames.end()); it != end; ++it) { - nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str()); - } + FT_Open_Args args; + const std::string &fileName = *it; - error = FT_Open_Face(_Library, &args, 0, &_Face); - if (error) - { - nlerror ("FT_New_Face() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(error)); - } + if (!createFreetypeStream(fileName, args)) + { + nlerror("createFreetypeStream failed with file '%s'", fileName.c_str()); + } - string fontEx = fontExFileName; - if (fontEx.empty()) - { - // try to see if the ex filename exists based on the fontExFileName - fontEx = CPath::lookup(CFile::getFilenameWithoutExtension (fontFileName)+".afm", false, false); - } + FT_Face face; + error = FT_Open_Face(_Library, &args, 0, &face); + if (error) + { + nlerror("FT_New_Face() failed with file '%s': %s", fileName.c_str(), getFT2Error(error)); + } - if (!fontEx.empty()) - { - if (!createFreetypeStream(fontEx, args)) + string fontEx = fontExFileName; + if (fontEx.empty()) + { + // try to see if the ex filename exists based on the fontExFileName + fontEx = CPath::lookup(CFile::getFilenameWithoutExtension(fileName) + ".afm", false, false); + } + + if (!fontEx.empty()) { - nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str()); + if (!createFreetypeStream(fontEx, args)) + { + nlerror("createFreetypeStream failed with file '%s'", fileName.c_str()); + FT_Done_Face(face); + continue; + } + + error = FT_Attach_Stream(face, &args); + if (error) + { + nlwarning("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error)); + FT_Done_Face(face); + continue; + } } - error = FT_Attach_Stream(_Face, &args); + error = FT_Select_Charmap(face, ft_encoding_unicode); if (error) { - nlwarning ("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error)); + nlerror("FT_Select_Charmap() failed with file '%s': %s", fileName.c_str(), getFT2Error(error)); + FT_Done_Face(face); + continue; } - } - error = FT_Select_Charmap (_Face, ft_encoding_unicode); - if (error) - { - nlerror ("FT_Select_Charmap() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(error)); + _Faces.push_back(face); } } CFontGenerator::~CFontGenerator () { + for (std::vector::iterator it(_Faces.begin()), end(_Faces.end()); it != end; ++it) + FT_Done_Face(*it); + _Faces.clear(); + // important: destroying and creating your last font generator // will also reload the freetype library nlassert(_LibraryInit); @@ -256,33 +288,44 @@ CFontGenerator::~CFontGenerator () } } -void CFontGenerator::getSizes (ucchar c, uint32 size, uint32 &width, uint32 &height) +void CFontGenerator::getSizes (u32char c, uint32 size, uint32 &width, uint32 &height) { FT_Error error; + FT_Face face; + FT_UInt glyph_index = 0; - error = FT_Set_Pixel_Sizes (_Face, size, size); - if (error) + if (!_Faces.size()) { - nlerror ("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error)); + nlerror("No faces loaded"); + return; } - // retrieve glyph index from character code - FT_UInt glyph_index = FT_Get_Char_Index (_Face, c); - - if (glyph_index == 0) + for (std::vector::iterator it(_Faces.begin()), end(_Faces.end()); it != end; ++it) { - // no glyph available, replace with a dot - glyph_index = FT_Get_Char_Index (_Face, ucchar('.')); + face = *it; + error = FT_Set_Pixel_Sizes(face, size, size); + if (error) + { + nlerror("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error)); + continue; + } + + // retrieve glyph index from character code + glyph_index = FT_Get_Char_Index(face, c); + + // found glyph + if (glyph_index) + break; } // load glyph image into the slot (erase previous one) - error = FT_Load_Glyph (_Face, glyph_index, FT_LOAD_DEFAULT); + error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); if (error) { // use fallback for glyph/character errors (composite char limit for example) nlwarning ("FT_Load_Glyph() failed: %s", getFT2Error(error)); - error = FT_Load_Glyph (_Face, 0, FT_LOAD_DEFAULT); + error = FT_Load_Glyph(face, 0, FT_LOAD_DEFAULT); if (error) { nlerror("FT_Load_Glyph() fallback failed: %s", getFT2Error(error)); @@ -290,37 +333,48 @@ void CFontGenerator::getSizes (ucchar c, uint32 size, uint32 &width, uint32 &hei } // convert 24.6 fixed point into integer - width = _Face->glyph->metrics.width >> 6; - height = _Face->glyph->metrics.height >> 6; + width = face->glyph->metrics.width >> 6; + height = face->glyph->metrics.height >> 6; } -uint8 *CFontGenerator::getBitmap (ucchar c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex) +uint8 *CFontGenerator::getBitmap (u32char c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex) { FT_Error error; + FT_Face face; + FT_UInt glyph_index = 0; - error = FT_Set_Pixel_Sizes (_Face, size, size); - if (error) + if (!_Faces.size()) { - nlerror ("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error)); + nlerror("No faces loaded"); + return NULL; } - // retrieve glyph index from character code - FT_UInt glyph_index = FT_Get_Char_Index (_Face, c); - - if (glyph_index == 0) + for (std::vector::iterator it(_Faces.begin()), end(_Faces.end()); it != end; ++it) { - // no glyph available, replace with a dot - glyph_index = FT_Get_Char_Index (_Face, ucchar('.')); + face = *it; + error = FT_Set_Pixel_Sizes(face, size, size); + if (error) + { + nlerror("FT_Set_Pixel_Sizes() failed: %s", getFT2Error(error)); + continue; + } + + // retrieve glyph index from character code + glyph_index = FT_Get_Char_Index(face, c); + + // found glyph + if (glyph_index) + break; } // load glyph image into the slot (erase previous one) - error = FT_Load_Glyph (_Face, glyph_index, FT_LOAD_DEFAULT); + error = FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT); if (error) { // use fallback for glyph/character errors (composite char limit for example) nlwarning ("FT_Load_Glyph() failed: %s", getFT2Error(error)); - error = FT_Load_Glyph (_Face, 0, FT_LOAD_DEFAULT); + error = FT_Load_Glyph (face, 0, FT_LOAD_DEFAULT); if (error) { nlerror("FT_Load_Glyph() fallback failed: %s", getFT2Error(error)); @@ -341,47 +395,49 @@ uint8 *CFontGenerator::getBitmap (ucchar c, uint32 size, bool embolden, bool obl if (embolden) { - FT_GlyphSlot_Embolden(_Face->glyph); + FT_GlyphSlot_Embolden(face->glyph); } if (oblique) { - FT_GlyphSlot_Oblique(_Face->glyph); + FT_GlyphSlot_Oblique(face->glyph); } // convert to an anti-aliased bitmap - error = FT_Render_Glyph (_Face->glyph, ft_render_mode_normal); + error = FT_Render_Glyph (face->glyph, ft_render_mode_normal); if (error) { nlerror ("FT_Render_Glyph() failed: %s", getFT2Error(error)); } - width = _Face->glyph->bitmap.width; - height = _Face->glyph->bitmap.rows; - pitch = _Face->glyph->bitmap.pitch; + width = face->glyph->bitmap.width; + height = face->glyph->bitmap.rows; + pitch = face->glyph->bitmap.pitch; - left = _Face->glyph->bitmap_left; - top = _Face->glyph->bitmap_top; + left = face->glyph->bitmap_left; + top = face->glyph->bitmap_top; - advx = _Face->glyph->advance.x >> 6; + advx = face->glyph->advance.x >> 6; glyphIndex = glyph_index; - return (uint8 *) _Face->glyph->bitmap.buffer; + return (uint8 *) face->glyph->bitmap.buffer; } -void CFontGenerator::getKerning (ucchar left, ucchar right, sint32 &kernx) +void CFontGenerator::getKerning (u32char left, u32char right, sint32 &kernx) { - if (!FT_HAS_KERNING(_Face)) + if (!FT_HAS_KERNING(_Faces[0])) { kernx = 0; } else { + // This is currently not used... + FT_Vector kerning; - FT_Error error = FT_Get_Kerning (_Face, left, right, ft_kerning_default, &kerning); + FT_Error error = FT_Get_Kerning (_Faces[0], left, right, ft_kerning_default, &kerning); if (error) { nlerror ("FT_Get_Kerning() failed: %s", getFT2Error(error)); @@ -392,14 +448,16 @@ void CFontGenerator::getKerning (ucchar left, ucchar right, sint32 &kernx) -uint32 CFontGenerator::getCharIndex (ucchar c) +uint32 CFontGenerator::getCharIndex (u32char c) { - uint32 ret = FT_Get_Char_Index(_Face, c); + // This is currently not used... + + uint32 ret = FT_Get_Char_Index(_Faces[0], c); if (ret == 0) { // no glyph available, replace with a dot - ret = FT_Get_Char_Index (_Face, ucchar('.')); + ret = FT_Get_Char_Index (_Faces[0], u32char('.')); } return ret; @@ -473,14 +531,14 @@ CFontGenerator::~CFontGenerator () DeleteDC (hdcDib); } -void CFontGenerator::getSizes (ucchar c, uint32 size, uint32 &width, uint32 &height) +void CFontGenerator::getSizes (u32char c, uint32 size, uint32 &width, uint32 &height) { } HFONT hFont = NULL; uint32 CurrentFontSize = 0; -uint8 *CFontGenerator::getBitmap (ucchar c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex) +uint8 *CFontGenerator::getBitmap (u32char c, uint32 size, bool embolden, bool oblique, uint32 &width, uint32 &height, uint32 &pitch, sint32 &left, sint32 &top, sint32 &advx, uint32 &glyphIndex) { if (size == 0) { @@ -527,7 +585,7 @@ uint8 *CFontGenerator::getBitmap (ucchar c, uint32 size, bool embolden, bool obl SelectObject (hdcDib, hFont); SelectObject (hdcDib, Dib); - const ucchar cc = /*(char)*/ c; + const u32char cc = /*(char)*/ c; // prevent outputing white glyph if char is not available in font DWORD glyphIndex; @@ -637,13 +695,13 @@ uint8 *CFontGenerator::getBitmap (ucchar c, uint32 size, bool embolden, bool obl -void CFontGenerator::getKerning (ucchar left, ucchar right, sint32 &kernx) +void CFontGenerator::getKerning (u32char left, u32char right, sint32 &kernx) { } -uint32 CFontGenerator::getCharIndex (ucchar c) +uint32 CFontGenerator::getCharIndex (u32char c) { return 0; } diff --git a/nel/src/3d/font_manager.cpp b/nel/src/3d/font_manager.cpp index d00ebb8f5..3d468f987 100644 --- a/nel/src/3d/font_manager.cpp +++ b/nel/src/3d/font_manager.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -63,27 +66,8 @@ CMaterial* CFontManager::getFontMaterial() return _MatFont; } - -// *************************************************************************** -void CFontManager::computeString (const std::string &s, - CFontGenerator *fontGen, - const NLMISC::CRGBA &color, - uint32 fontSize, - bool embolden, - bool oblique, - IDriver *driver, - CComputedString &output, - bool keep800x600Ratio) -{ - // static to avoid reallocation - static ucstring ucs; - ucs= s; - computeString(ucs, fontGen, color, fontSize, embolden, oblique, driver, output, keep800x600Ratio); -} - - // *************************************************************************** -void CFontManager::computeString (const ucstring &s, +void CFontManager::computeString (NLMISC::CUtfStringView sv, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, @@ -109,7 +93,7 @@ void CFontManager::computeString (const ucstring &s, } // Setting vertices format - output.Vertices.setNumVertices (4 * (uint32)s.size()); + output.Vertices.setNumVertices (4 * (uint32)sv.largestSize()); // 1 character <-> 1 quad sint32 penx = 0, dx; @@ -144,10 +128,12 @@ void CFontManager::computeString (const ucstring &s, output.StringHeight = 0; // save string info for later rebuild as needed - output.Text = s; + if (sv.ptr() != output.Text.c_str()) // don't resave if rebuilding + output.Text = sv.toUtf8(); output.CacheVersion = getCacheVersion(); uint j = 0; + size_t idx = 0; { CVertexBufferReadWrite vba; output.Vertices.lock (vba); @@ -156,10 +142,14 @@ void CFontManager::computeString (const ucstring &s, hlfPixScrH = 0.f; // For all chars - for (uint i = 0; i < s.size(); i++) + for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end; ++it, ++idx) { // Creating font - k.Char = s[i]; + k.Char = *it; + if (k.Char < 0x20) // Control Characters + k.Char += 0x2400; + if (k.Char == 0x7F) // DEL + k.Char = 0x2421; k.FontGenerator = fontGen; k.Size = fontSize; k.Embolden = embolden; @@ -228,6 +218,8 @@ void CFontManager::computeString (const ucstring &s, } } output.Vertices.setNumVertices (j); + output.Length = idx; + nlassert(output.Length == NLMISC::CUtfStringView(output.Text).count()); // compile string info output.StringWidth = (float)penx; @@ -245,7 +237,23 @@ void CFontManager::computeString (const ucstring &s, // *************************************************************************** -void CFontManager::computeStringInfo ( const ucstring &s, +void CFontManager::computeStringInfo ( NLMISC::CUtfStringView sv, + CFontGenerator *fontGen, + const NLMISC::CRGBA &color, + uint32 fontSize, + bool embolden, + bool oblique, + IDriver *driver, + CComputedString &output, + bool keep800x600Ratio ) +{ + computeStringInfo(sv, sv.largestSize(), fontGen, color, fontSize, embolden, oblique, driver, output, keep800x600Ratio); +} + + +// *************************************************************************** +void CFontManager::computeStringInfo ( NLMISC::CUtfStringView sv, + size_t len, CFontGenerator *fontGen, const NLMISC::CRGBA &color, uint32 fontSize, @@ -258,10 +266,11 @@ void CFontManager::computeStringInfo ( const ucstring &s, output.Color = color; // save string info for later rebuild as needed - output.Text = s; + if (sv.ptr() != output.Text.c_str()) // don't resave if rebuilding + output.Text = sv.toUtf8(); output.CacheVersion = 0; - if (s.empty()) + if (sv.empty()) { output.StringWidth = 0.f; output.StringHeight = 0; @@ -290,10 +299,13 @@ void CFontManager::computeStringInfo ( const ucstring &s, CTextureFont::SLetterKey k; CTextureFont::SLetterInfo *pLI; - for (uint i = 0; i < s.size(); i++) + size_t idx = 0; + for (NLMISC::CUtfStringView::iterator it(sv.begin()), end(sv.end()); it != end && idx < len; ++it, ++idx) { // Creating font - k.Char = s[i]; + k.Char = *it; + if (k.Char < 0x20) + k.Char += 0x2400; k.FontGenerator = fontGen; k.Size = fontSize; k.Embolden = embolden; @@ -313,6 +325,8 @@ void CFontManager::computeStringInfo ( const ucstring &s, penx += pLI->AdvX; } } + output.Length = idx; + nlassert(output.Length == std::min(len, NLMISC::CUtfStringView(output.Text).count())); // compile string info output.StringWidth = (float)penx; diff --git a/nel/src/3d/fxaa.cpp b/nel/src/3d/fxaa.cpp index 6478abf8e..2dfd58d37 100644 --- a/nel/src/3d/fxaa.cpp +++ b/nel/src/3d/fxaa.cpp @@ -7,7 +7,7 @@ */ // NeL - MMORPG Framework -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/src/3d/hls_texture_bank.cpp b/nel/src/3d/hls_texture_bank.cpp index b741ec387..9077f1638 100644 --- a/nel/src/3d/hls_texture_bank.cpp +++ b/nel/src/3d/hls_texture_bank.cpp @@ -59,7 +59,7 @@ uint32 CHLSTextureBank::addColorTexture(const CHLSColorTexture &tex) // *************************************************************************** void CHLSTextureBank::addTextureInstance(const std::string &name, uint32 colorTextureId, const vector &cols) { - string nameLwr= toLower(name); + string nameLwr= toLowerAscii(name); // checks nlassert(colorTextureId<_ColorTextures.size()); diff --git a/nel/src/3d/hls_texture_manager.cpp b/nel/src/3d/hls_texture_manager.cpp index 586ec53ce..3f585eb6b 100644 --- a/nel/src/3d/hls_texture_manager.cpp +++ b/nel/src/3d/hls_texture_manager.cpp @@ -76,7 +76,7 @@ sint CHLSTextureManager::findTexture(const std::string &name) const return -1; // Build a valid key. - string nameLwr= toLower(name); + string nameLwr= toLowerAscii(name); CHLSTextureBank::CTextureInstance textKey; CHLSTextureBank::CTextureInstanceHandle textKeyHandle; textKey.buildAsKey(nameLwr.c_str()); diff --git a/nel/src/3d/instance_lighter.cpp b/nel/src/3d/instance_lighter.cpp index 87e0deb45..a08a0a38f 100644 --- a/nel/src/3d/instance_lighter.cpp +++ b/nel/src/3d/instance_lighter.cpp @@ -415,7 +415,7 @@ void CInstanceLighter::light (const CInstanceGroup &igIn, CInstanceGroup &igOut, string name= _Instances[i].Name; bool shapeFound= true; - if (toLower (CFile::getExtension (name)) == "pacs_prim") + if (toLowerAscii (CFile::getExtension (name)) == "pacs_prim") { nlwarning("EXPORT BUG: Can't read %s (not a shape), should not be part of .ig!", name.c_str()); continue; diff --git a/nel/src/3d/landscapeig_manager.cpp b/nel/src/3d/landscapeig_manager.cpp index 10eab0f60..78154deda 100644 --- a/nel/src/3d/landscapeig_manager.cpp +++ b/nel/src/3d/landscapeig_manager.cpp @@ -115,7 +115,7 @@ void CLandscapeIGManager::initIG(UScene *scene, const std::string &igDesc, UDriv if (ig) { // add it to the map. - string tokId= toUpper(string(token)); + string tokId= toUpperAscii(string(token)); _ZoneInstanceGroupMap[tokId]= CInstanceGroupElement(ig, token); // Add a reference on the shapes @@ -129,7 +129,7 @@ void CLandscapeIGManager::initIG(UScene *scene, const std::string &igDesc, UDriv _ig.getShapeName(i, shapeName); if (!shapeName.empty ()) { - if (toLower(CFile::getExtension(shapeName)) != "pacs_prim") + if (toLowerAscii(CFile::getExtension(shapeName)) != "pacs_prim") { // Insert a new shape ? if (_ShapeAdded.find(shapeName) == _ShapeAdded.end()) @@ -295,7 +295,7 @@ UInstanceGroup *CLandscapeIGManager::getIG(const std::string &name) const std::string CLandscapeIGManager::translateName(const std::string &name) const { std::string ret; - ret= toUpper(name + ".ig"); + ret= toUpperAscii(name + ".ig"); return ret; } @@ -364,7 +364,7 @@ void CLandscapeIGManager::reloadAllIgs() const char *token= bkupIgFileNameList[i].c_str(); UInstanceGroup *ig = UInstanceGroup::createInstanceGroup(token); // add it to the map. - string tokId= toUpper(token); + string tokId= toUpperAscii(token); _ZoneInstanceGroupMap[tokId]= CInstanceGroupElement(ig, token); // If was addedToScene before, re-add to scene now. diff --git a/nel/src/3d/lod_character_manager.cpp b/nel/src/3d/lod_character_manager.cpp index f5d6a23c5..8e062bf07 100644 --- a/nel/src/3d/lod_character_manager.cpp +++ b/nel/src/3d/lod_character_manager.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/src/3d/packed_zone.cpp b/nel/src/3d/packed_zone.cpp index 72866ea78..fc8fa9a8a 100644 --- a/nel/src/3d/packed_zone.cpp +++ b/nel/src/3d/packed_zone.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -662,7 +665,7 @@ void CPackedZone32::build(std::vector &leaves, { CMatrix instanceMatrix; igs[k]->getInstanceMatrix(l, instanceMatrix); - if (NLMISC::toLower(NLMISC::CFile::getExtension(igs[k]->getShapeName(l))) == "pacs_prim") continue; + if (NLMISC::toLowerAscii(NLMISC::CFile::getExtension(igs[k]->getShapeName(l))) == "pacs_prim") continue; std::string stdShapeName = standardizeShapeName(igs[k]->getShapeName(l)); TShapeCache::const_iterator it = shapeCache.find(stdShapeName); if (it != shapeCache.end()) diff --git a/nel/src/3d/render_trav.cpp b/nel/src/3d/render_trav.cpp index 0a071303f..1b7e8e84e 100644 --- a/nel/src/3d/render_trav.cpp +++ b/nel/src/3d/render_trav.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2012-2014 Jan BOON (Kaetemi) +// Copyright (C) 2012-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -921,7 +921,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], color); } - + nlassert(_VPNumLights < MaxVPLight); if (i != _VPNumLights) { color= _VPLightDiffuse[i] * matDiff; diff --git a/nel/src/3d/scene.cpp b/nel/src/3d/scene.cpp index 7f1263ea1..651837e2c 100644 --- a/nel/src/3d/scene.cpp +++ b/nel/src/3d/scene.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013-2014 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -775,9 +775,9 @@ CTransformShape *CScene::createInstance(const string &shapeName) // Look if this instance get lightmap information #if defined(__GNUC__) && __GNUC__ < 3 - CMeshBase *pMB = (CMeshBase*)((IShape*)(pTShp->Shape)); + CMeshBase *pMB = pTShp ? (CMeshBase*)((IShape*)(pTShp->Shape)) : NULL; #else // not GNUC - CMeshBase *pMB = dynamic_cast((IShape*)(pTShp->Shape)); + CMeshBase *pMB = pTShp ? dynamic_cast((IShape*)(pTShp->Shape)) : NULL; #endif // not GNUC CMeshBaseInstance *pMBI = dynamic_cast( pTShp ); if( ( pMB != NULL ) && ( pMBI != NULL ) ) @@ -793,7 +793,7 @@ CTransformShape *CScene::createInstance(const string &shapeName) if (pMB->getAutoAnim()) { - std::string animName = toLower(CFile::getFilenameWithoutExtension(shapeName)); + std::string animName = toLowerAscii(CFile::getFilenameWithoutExtension(shapeName)); uint animID = _AutomaticAnimationSet->getAnimationIdByName(animName); if (animID != CAnimationSet::NotFound) { @@ -833,7 +833,7 @@ void CScene::createInstanceAsync(const string &shapeName, CTransformShape **pIns if (_ShapeBank->getPresentState( shapeName ) != CShapeBank::Present) { // Load it from file asynchronously - _ShapeBank->loadAsync( toLower(shapeName), getDriver(), position, NULL, selectedTexture); + _ShapeBank->loadAsync( toLowerAscii(shapeName), getDriver(), position, NULL, selectedTexture); } } diff --git a/nel/src/3d/scene_group.cpp b/nel/src/3d/scene_group.cpp index dc5dd9f73..131f5feaf 100644 --- a/nel/src/3d/scene_group.cpp +++ b/nel/src/3d/scene_group.cpp @@ -607,7 +607,7 @@ void CInstanceGroup::getShapeName (uint instanceIndex, std::string &shapeName) c shapeName = _TransformName->transformName (instanceIndex, rInstanceInfo.InstanceName, rInstanceInfo.Name); } - toLower(shapeName); + toLowerAscii(shapeName); if (!shapeName.empty() && shapeName.find('.') == std::string::npos) shapeName += ".shape"; } @@ -860,7 +860,7 @@ bool CInstanceGroup::addToSceneAsync (CScene& scene, IDriver *driver, uint selec shapeName = _TransformName->transformName (i, rInstanceInfo.InstanceName, rInstanceInfo.Name); } - toLower(shapeName); + toLowerAscii(shapeName); if (!shapeName.empty() && shapeName.find('.') == std::string::npos) shapeName += ".shape"; @@ -920,7 +920,7 @@ void CInstanceGroup::stopAddToSceneAsync () shapeName = rInstanceInfo.Name; } - toLower(shapeName); + toLowerAscii(shapeName); _AddToSceneTempScene->getShapeBank()->cancelLoadAsync (shapeName); } } diff --git a/nel/src/3d/shadow_map_manager.cpp b/nel/src/3d/shadow_map_manager.cpp index a8400ce0b..174ecd580 100644 --- a/nel/src/3d/shadow_map_manager.cpp +++ b/nel/src/3d/shadow_map_manager.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2013 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -256,14 +256,14 @@ void CShadowMapManager::renderGenerate(CScene *scene) garbageShadowTextures(scene); IDriver *driverForShadowGeneration= scene->getRenderTrav().getAuxDriver(); + nlassert(driverForShadowGeneration); CSmartPtr previousRenderTarget = driverForShadowGeneration->getRenderTarget(); // Init // ******** uint32 wndW= _BlurTextureW, wndH= _BlurTextureH; // get some text/screen size. - if(driverForShadowGeneration) - driverForShadowGeneration->getWindowSize(wndW, wndH); + driverForShadowGeneration->getWindowSize(wndW, wndH); uint baseTextureSize= scene->getShadowMapTextureSize(); // Minimize the Dest Texture size, so the blurTexture don't get too heavy in VRAM. uint32 textDestW= min(wndW, (uint32)NL3D_SMM_MAX_TEXTDEST_SIZE); diff --git a/nel/src/3d/shape_bank.cpp b/nel/src/3d/shape_bank.cpp index 61a65c423..cb6ea8c21 100644 --- a/nel/src/3d/shape_bank.cpp +++ b/nel/src/3d/shape_bank.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -53,7 +56,7 @@ CShapeBank::~CShapeBank() IShape*CShapeBank::addRef(const string &shapeNameNotLwr) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); // get the shape info (must succeed) TShapeInfoMap::iterator scfpmIt = ShapePtrToShapeInfo.find( getShapePtrFromShapeName( shapeName ) ); @@ -431,7 +434,7 @@ bool CShapeBank::processWSUploadTexture (CWaitingShape &rWS, uint32 &nTotalUploa CShapeBank::TShapeState CShapeBank::getPresentState (const string &shapeNameNotLwr) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); // Is the shape is found in the shape map so return Present TShapeMap::iterator smIt = ShapeMap.find (shapeName); @@ -447,7 +450,7 @@ CShapeBank::TShapeState CShapeBank::getPresentState (const string &shapeNameNotL // *************************************************************************** IShape *CShapeBank::getShape (const std::string &shapeNameNotLwr) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); // Is the shape is found in the shape map so return Present TShapeMap::iterator smIt = ShapeMap.find (shapeName); @@ -461,7 +464,7 @@ IShape *CShapeBank::getShape (const std::string &shapeNameNotLwr) void CShapeBank::load (const string &shapeNameNotLwr) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); TShapeMap::iterator smIt = ShapeMap.find(shapeName); if( smIt == ShapeMap.end() ) @@ -495,7 +498,7 @@ void CShapeBank::load (const string &shapeNameNotLwr) void CShapeBank::loadAsync (const std::string &shapeNameNotLwr, IDriver *pDriver, const CVector &position, bool *bSignal, uint selectedTexture) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); TShapeMap::iterator smIt = ShapeMap.find(shapeName); if (smIt != ShapeMap.end()) @@ -527,7 +530,7 @@ void CShapeBank::loadAsync (const std::string &shapeNameNotLwr, IDriver *pDriver void CShapeBank::cancelLoadAsync (const std::string &shapeNameNotLwr) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); TWaitingShapesMap::iterator wsmmIt = WaitingShapes.find(shapeName); if (wsmmIt != WaitingShapes.end()) @@ -597,7 +600,7 @@ bool CShapeBank::isShapeWaiting () void CShapeBank::add (const string &shapeNameNotLwr, IShape* pShp) { nlassert(pShp); - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); // request a system mem geometry copy? if(pShp && _ShapeNeedingSystemGeometryCopy.find(shapeName)!=_ShapeNeedingSystemGeometryCopy.end()) @@ -683,8 +686,7 @@ void CShapeBank::reset() while( scmIt != ShapeCacheNameToShapeCache.end() ) { CShapeCache *pShpCache = getShapeCachePtrFromShapeCacheName( scmIt->first ); - if( pShpCache == NULL ) - nlstop; // Should never happen + nlassert(pShpCache); pShpCache->MaxSize = 0; checkShapeCache( pShpCache ); @@ -722,7 +724,7 @@ sint CShapeBank::getShapeCacheFreeSpace(const std::string &shapeCacheName) const void CShapeBank::linkShapeToShapeCache(const string &shapeNameNotLwr, const string &shapeCacheName) { - string shapeName= toLower(shapeNameNotLwr); + string shapeName= toLowerAscii(shapeNameNotLwr); for(;;) { @@ -855,7 +857,7 @@ void CShapeBank::preLoadShapes(const std::string &shapeCacheName, return; // lower case - string wildCard= toLower(wildCardNotLwr); + string wildCard= toLowerAscii(wildCardNotLwr); // For all files for(uint i=0;iprogress ((float)i/(float)listFile.size ()); - string fileName= toLower(CFile::getFilename(listFile[i])); + string fileName= toLowerAscii(CFile::getFilename(listFile[i])); // if the file is ok for the wildCard, process it if( testWildCard(fileName.c_str(), wildCard.c_str()) ) { @@ -906,7 +908,7 @@ void CShapeBank::preLoadShapes(const std::string &shapeCacheName, // *************************************************************************** void CShapeBank::buildSystemGeometryForshape(const std::string &shapeName) { - _ShapeNeedingSystemGeometryCopy.insert(toLower(shapeName)); + _ShapeNeedingSystemGeometryCopy.insert(toLowerAscii(shapeName)); } diff --git a/nel/src/3d/shape_info.cpp b/nel/src/3d/shape_info.cpp index d3a8a4df3..4385b044e 100644 --- a/nel/src/3d/shape_info.cpp +++ b/nel/src/3d/shape_info.cpp @@ -229,7 +229,7 @@ void CShapeInfo::build(const CMeshBase &meshBase, const CMeshMRMGeom &meshGeom) // *************************************************************************** std::string standardizeShapeName(const std::string &name) { - std::string result = NLMISC::toLower(name); + std::string result = NLMISC::toLowerAscii(name); if (CFile::getExtension(result).empty()) { result += ".shape"; diff --git a/nel/src/3d/surface_light_grid.cpp b/nel/src/3d/surface_light_grid.cpp index deec090a4..d85422869 100644 --- a/nel/src/3d/surface_light_grid.cpp +++ b/nel/src/3d/surface_light_grid.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -121,17 +124,20 @@ void CSurfaceLightGrid::getStaticLightSetup(NLMISC::CRGBA sunAmbient, const CVe CLightInfluenceInterpolator::CCorner &corner= interp.Corners[y*2 + x]; // For all lights uint lid; - for(lid= 0; lid leave color and alpha To 0. - if(cellCorner.LocalAmbientId!=0xFF) + if(igPointLights && cellCorner.LocalAmbientId!=0xFF) { CPointLight &pl= igPointLights[cellCorner.LocalAmbientId]; // take current ambient from pointLight diff --git a/nel/src/3d/tessellation.cpp b/nel/src/3d/tessellation.cpp index 451e1013b..88c0fa26e 100644 --- a/nel/src/3d/tessellation.cpp +++ b/nel/src/3d/tessellation.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -2678,6 +2681,8 @@ void CTessFace::updateBindAndSplit() } else { + nlassert(f0); + nlassert(f1); // multipatch face case are detected when face->Patch==NULL !!! if(f0->FLeft && f0->FLeft->Patch==NULL) { @@ -2710,6 +2715,8 @@ void CTessFace::updateBindAndSplit() } else { + nlassert(f0); + nlassert(f1); if(f0->FLeft) { while(f0->FLeft->isLeaf()) @@ -2781,6 +2788,8 @@ void CTessFace::updateBindAndSplit() { CTessFace *f; sint i; + nlassert(f0); + nlassert(f1); // Same reasoning for rectangular patchs, as above. for(i=0;i<2;i++) diff --git a/nel/src/3d/text_context.cpp b/nel/src/3d/text_context.cpp index 1ccb920e4..4549622da 100644 --- a/nel/src/3d/text_context.cpp +++ b/nel/src/3d/text_context.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -77,13 +77,11 @@ uint32 CTextContext::textPush (const char *format, ...) char *str; NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); - ucstring uc; - uc.fromUtf8((const char *)str); - return textPush(uc); + return textPush(NLMISC::CUtfStringView(str)); } // ------------------------------------------------------------------------------------------------ -uint32 CTextContext::textPush (const ucstring &str) +uint32 CTextContext::textPush (NLMISC::CUtfStringView sv) { nlassert(_FontGen); @@ -103,7 +101,7 @@ uint32 CTextContext::textPush (const ucstring &str) nlassert (index < _CacheStrings.size()); CComputedString &strToFill = _CacheStrings[index]; - _FontManager->computeString (str, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, strToFill, _Keep800x600Ratio); + _FontManager->computeString (sv, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, strToFill, _Keep800x600Ratio); // just compute letters, glyphs are rendered on demand before first draw //_FontManager->computeStringInfo(str, _FontGen, _Color, _FontSize, _Embolden, _Oblique, _Driver, strToFill, _Keep800x600Ratio); diff --git a/nel/src/3d/text_context_user.cpp b/nel/src/3d/text_context_user.cpp index 0430eae1a..01bfe21df 100644 --- a/nel/src/3d/text_context_user.cpp +++ b/nel/src/3d/text_context_user.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -229,13 +229,13 @@ uint32 CTextContextUser::textPush(const char *format, ...) char *str; NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); - return _TextContext.textPush(ucstring(str)) ; + return _TextContext.textPush(str) ; } -uint32 CTextContextUser::textPush(const ucstring &str) +uint32 CTextContextUser::textPush(NLMISC::CUtfStringView sv) { H_AUTO2; - return _TextContext.textPush(str) ; + return _TextContext.textPush(sv) ; } void CTextContextUser::setStringColor(uint32 i, CRGBA newCol) { @@ -275,16 +275,23 @@ UTextContext::CStringInfo CTextContextUser::getStringInfo(uint32 i) CComputedString *cstr= _TextContext.getComputedString(i); if(!cstr) - return CStringInfo(0, 0, 0); + return CStringInfo(0, 0, 0, 0); else - return CStringInfo(cstr->StringWidth, cstr->StringHeight, cstr->StringLine); + return CStringInfo(cstr->StringWidth, cstr->StringHeight, cstr->StringLine, cstr->Length); +} +UTextContext::CStringInfo CTextContextUser::getStringInfo(NLMISC::CUtfStringView sv) +{ + H_AUTO2; + + _TextContext.computeStringInfo(sv, _CacheString); + return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine, _CacheString.Length); } -UTextContext::CStringInfo CTextContextUser::getStringInfo(const ucstring &str) +UTextContext::CStringInfo CTextContextUser::getStringInfo(NLMISC::CUtfStringView sv, size_t len) { H_AUTO2; - _TextContext.computeStringInfo(str, _CacheString); - return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine); + _TextContext.computeStringInfo(sv, _CacheString, len); + return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine, _CacheString.Length); } void CTextContextUser::clear() { @@ -319,11 +326,11 @@ void CTextContextUser::printClipAtOld (float x, float y, uint32 i, float xmin, f printClipAt(rdrBuffer, x, y ,i, xmin, ymin, xmax, ymax); flushRenderBuffer(&rdrBuffer); } -void CTextContextUser::printAt(float x, float y, const ucstring &ucstr) +void CTextContextUser::printAt(float x, float y, NLMISC::CUtfStringView sv) { H_AUTO2; - _TextContext.printAt(x, y, ucstr); + _TextContext.printAt(x, y, sv); _DriverUser->restoreMatrixContext(); } void CTextContextUser::printfAt(float x, float y, const char * format, ...) @@ -333,16 +340,16 @@ void CTextContextUser::printfAt(float x, float y, const char * format, ...) char *str; NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); - _TextContext.printAt(x, y, ucstring(str)) ; + _TextContext.printAt(x, y, str) ; _DriverUser->restoreMatrixContext(); } -void CTextContextUser::render3D(const CMatrix &mat, const ucstring &ucstr) +void CTextContextUser::render3D(const CMatrix &mat, NLMISC::CUtfStringView sv) { NL3D_HAUTO_RENDER_3D_TEXTCONTEXT; CComputedString computedStr; - _TextContext.computeString(ucstr,computedStr); + _TextContext.computeString(sv,computedStr); computedStr.render3D(*_Driver,mat); @@ -355,7 +362,7 @@ void CTextContextUser::render3D(const CMatrix &mat, const char *format, ...) char *str; NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); - render3D(mat, ucstring(str)); + render3D(mat, str); _DriverUser->restoreMatrixContext(); } diff --git a/nel/src/3d/texture_bump.cpp b/nel/src/3d/texture_bump.cpp index 7705a58fa..fc1fe4139 100644 --- a/nel/src/3d/texture_bump.cpp +++ b/nel/src/3d/texture_bump.cpp @@ -1,6 +1,9 @@ // NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the diff --git a/nel/src/3d/texture_file.cpp b/nel/src/3d/texture_file.cpp index 0e343ec8e..58f2f333f 100644 --- a/nel/src/3d/texture_file.cpp +++ b/nel/src/3d/texture_file.cpp @@ -311,7 +311,7 @@ void CTextureFile::setMipMapSkipAtLoad(uint8 level) // *************************************************************************** std::string CTextureFile::getShareName() const { - return toLower(_FileName); + return toLowerAscii(_FileName); } diff --git a/nel/src/3d/tile_bank.cpp b/nel/src/3d/tile_bank.cpp index a22a797f4..9ba3ca756 100644 --- a/nel/src/3d/tile_bank.cpp +++ b/nel/src/3d/tile_bank.cpp @@ -275,7 +275,7 @@ sint CTileBank::getNumBitmap (CTile::TBitmap bitmap) const { std::vector vect (str.length()+1); memcpy (&*vect.begin(), str.c_str(), str.length()+1); - toLower(&*vect.begin()); + toLowerAscii(&*vect.begin()); setString.insert (std::string (&*vect.begin())); } } @@ -600,7 +600,7 @@ void CTileBank::removeDisplacementMap (uint mapId) uint CTileBank::getDisplacementMap (const string &fileName) { // Lower string - string lower=toLower(fileName); + string lower=toLowerAscii(fileName); // Look for this texture filename uint noiseTile; diff --git a/nel/src/georges/form.cpp b/nel/src/georges/form.cpp index c3fea6e0a..63e4ee2ed 100644 --- a/nel/src/georges/form.cpp +++ b/nel/src/georges/form.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -191,6 +191,9 @@ void CForm::read (xmlNodePtr node, CFormLoader &loader, CFormDfn *dfn, const std // Reset form clean (); + // Save the dfn + _Dfn = dfn; + // Check node name if ( ((const char*)node->name == NULL) || (strcmp ((const char*)node->name, "FORM") != 0) ) { @@ -371,7 +374,7 @@ void CForm::warning (bool exception, const std::string &function, const char *fo void CForm::getDependencies (std::set &dependencies) const { // Add me - if (dependencies.insert (toLower(CFile::getFilename (_Filename))).second) + if (dependencies.insert (toLowerAscii(CFile::getFilename (_Filename))).second) { // Add parents uint i; diff --git a/nel/src/georges/form_dfn.cpp b/nel/src/georges/form_dfn.cpp index d9c52c1b4..628077579 100644 --- a/nel/src/georges/form_dfn.cpp +++ b/nel/src/georges/form_dfn.cpp @@ -882,7 +882,7 @@ void CFormDfn::warning (bool exception, const std::string &function, const char void CFormDfn::getDependencies (std::set &dependencies) const { // Scan only if not already inserted - if (dependencies.insert (toLower(CFile::getFilename (_Filename))).second) + if (dependencies.insert (toLowerAscii(CFile::getFilename (_Filename))).second) { // Add parents uint i; @@ -898,7 +898,7 @@ void CFormDfn::getDependencies (std::set &dependencies) const Entries[i].getDfnPtr ()->getDependencies (dependencies); if (Entries[i].getTypePtr ()) { - dependencies.insert (toLower(CFile::getFilename (Entries[i].getFilename()))); + dependencies.insert (toLowerAscii(CFile::getFilename (Entries[i].getFilename()))); } } } diff --git a/nel/src/georges/form_elm.cpp b/nel/src/georges/form_elm.cpp index af87a2e0a..358b45f65 100644 --- a/nel/src/georges/form_elm.cpp +++ b/nel/src/georges/form_elm.cpp @@ -1707,6 +1707,7 @@ CFormElmStruct::CFormElmStruct (CForm *form, CFormElm *parentNode, const CFormDf CFormElmStruct::~CFormElmStruct () { // Job done in clean() + clean(); } // *************************************************************************** @@ -1717,10 +1718,10 @@ void CFormElmStruct::clean () uint elm; for (elm =0; elm dfn = loadFormDfn (name, false); if (dfn) { // Open the file diff --git a/nel/src/georges/type.cpp b/nel/src/georges/type.cpp index 1055313dd..9c65acae7 100644 --- a/nel/src/georges/type.cpp +++ b/nel/src/georges/type.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2010 Winch Gate Property Limited // // This source file has been modified by the following contributors: -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as diff --git a/nel/src/gui/CMakeLists.txt b/nel/src/gui/CMakeLists.txt index bb5a0b7f2..4dd53e857 100644 --- a/nel/src/gui/CMakeLists.txt +++ b/nel/src/gui/CMakeLists.txt @@ -1,8 +1,7 @@ FILE(GLOB SRC *.cpp *.h) FILE(GLOB HEADERS ../../include/nel/gui/*.h) -SOURCE_GROUP("include" FILES ${HEADERS}) -SOURCE_GROUP("src" FILES ${SRC}) +SOURCE_GROUP("" FILES ${HEADERS} ${SRC}) NL_TARGET_LIB(nelgui ${SRC} ${HEADERS}) diff --git a/nel/src/gui/action_handler.cpp b/nel/src/gui/action_handler.cpp index 2b8bf890b..601175361 100644 --- a/nel/src/gui/action_handler.cpp +++ b/nel/src/gui/action_handler.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -41,6 +42,8 @@ namespace NLGUI // ------------------------------------------------------------------------------------------------ CAHManager *CAHManager::_GlobalInstance = NULL; bool CAHManager::editorMode = false; + CAHManager::CDeleter CAHManager::s_Deleter; + bool CAHManager::s_Deleted = false; // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ @@ -72,13 +75,13 @@ namespace NLGUI { string allparam = Params; skipBlankAtStart (allparam); - string param = toLower (ParamName); + string param = toLowerAscii (ParamName); while (!allparam.empty()) { std::string::size_type e = allparam.find('='); if (e == std::string::npos || e == 0) break; std::string::size_type p = allparam.find('|'); - string tmp = NLMISC::toLower(allparam.substr(0,e)); + string tmp = NLMISC::toLowerAscii(allparam.substr(0,e)); skipBlankAtEnd(tmp); if (tmp == param) { @@ -104,7 +107,7 @@ namespace NLGUI std::string::size_type e = allparam.find('='); if (e == std::string::npos || e == 0) break; std::string::size_type p = allparam.find('|'); - string tmp = NLMISC::toLower(allparam.substr(0,e)); + string tmp = NLMISC::toLowerAscii(allparam.substr(0,e)); skipBlankAtEnd(tmp); string tmp2 = allparam.substr(e+1,p-e-1); @@ -751,9 +754,7 @@ namespace NLGUI { virtual void execute (CCtrlBase *pCaller, const std::string ¶ms) { - ucstring s; - s.fromUtf8(params); - if (!CViewRenderer::getInstance()->getDriver()->copyTextToClipboard(s)) + if (!CViewRenderer::getInstance()->getDriver()->copyTextToClipboard(params)) { nlwarning("Copy to clipboard failed: '%s'", params.c_str()); } diff --git a/nel/src/gui/css_parser.cpp b/nel/src/gui/css_parser.cpp index e59cf832b..ab9f6edb7 100644 --- a/nel/src/gui/css_parser.cpp +++ b/nel/src/gui/css_parser.cpp @@ -1,6 +1,9 @@ // Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // +// This source file has been modified by the following contributors: +// Copyright (C) 2020 Jan BOON (Kaetemi) +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the @@ -47,7 +50,7 @@ namespace NLGUI pos = elements[i].find_first_of(':'); if (pos != std::string::npos) { - std::string key = trim(toLower(elements[i].substr(0, pos))); + std::string key = trim(toLowerAscii(elements[i].substr(0, pos))); std::string value = trim(elements[i].substr(pos+1)); styles.push_back(TStylePair(key, value)); } @@ -65,7 +68,7 @@ namespace NLGUI _Rules.clear(); _Style.clear(); - _Style.fromUtf8(cssString); + _Style = cssString; preprocess(); _Position = 0; @@ -73,7 +76,7 @@ namespace NLGUI { skipWhitespace(); - if (_Style[_Position] == (ucchar)'@') + if (_Style[_Position] == '@') readAtRule(); else readRule(); @@ -89,13 +92,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 selectors; - NLMISC::explode(selectorString, ucstring(","), selectors); + std::vector 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 +132,7 @@ namespace NLGUI skipIdentifier(); // skip at-rule statement - while(!is_eof() && _Style[_Position] != (ucchar)';') + while(!is_eof() && _Style[_Position] != ';') { if (maybe_escape()) { @@ -174,9 +177,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 +187,7 @@ namespace NLGUI if (!is_eof()) { - ucstring selector; + std::string selector; selector.append(_Style, start, _Position - start); skipWhitespace(); @@ -194,7 +197,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 +218,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 +249,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 +288,7 @@ namespace NLGUI // @internal void CCssParser::skipBlock() { - ucchar startChar = _Style[_Position]; + char startChar = _Style[_Position]; // block start _Position++; @@ -311,7 +314,7 @@ namespace NLGUI // @internal void CCssParser::skipString() { - ucchar endChar = _Style[_Position]; + char endChar = _Style[_Position]; // quote start _Position++; @@ -338,7 +341,7 @@ namespace NLGUI // *************************************************************************** // parse selector list // @internal - std::vector CCssParser::parse_selector(const ucstring &sel, std::string &pseudoElement) const + std::vector CCssParser::parse_selector(const std::string &sel, std::string &pseudoElement) const { std::vector result; CCssSelector current; @@ -346,10 +349,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 +361,7 @@ namespace NLGUI while(pos < sel.size() && is_nmchar(sel[pos])) pos++; - current.Element = toLower(sel.substr(start, pos - start).toUtf8()); + current.Element = toLowerAscii(sel.substr(start, pos - start)); start = pos; continue; } @@ -371,7 +374,7 @@ namespace NLGUI while(pos < sel.size() && is_nmchar(sel[pos])) pos++; - current.Id = toLower(sel.substr(start, pos - start).toUtf8()); + current.Id = toLowerAscii(sel.substr(start, pos - start)); start = pos; } else if (sel[pos] == '.') @@ -383,7 +386,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(toLowerAscii(sel.substr(start, pos - start))); start = pos; } else if (sel[pos] == '[') @@ -399,9 +402,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 +423,7 @@ namespace NLGUI if (sel[pos] == ']') { - current.addAttribute(key.toUtf8()); + current.addAttribute(key); } else { @@ -496,14 +499,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 +552,7 @@ namespace NLGUI } } - std::string key = toLower(sel.substr(start, pos - start).toUtf8()); + std::string key = toLowerAscii(sel.substr(start, pos - start)); if (key.empty()) { failed = true; @@ -647,7 +650,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,14 +663,15 @@ 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) { // Unicode replacement character - _Style[_Position] = 0xFFFD; + // _Style[_Position] = 0xFFFD; + _Style.replace(_Position, 1, "\xEF\xBF\xBD"); } else { @@ -686,12 +690,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 diff --git a/nel/src/gui/css_selector.cpp b/nel/src/gui/css_selector.cpp index 2c9d94559..18d0375b0 100644 --- a/nel/src/gui/css_selector.cpp +++ b/nel/src/gui/css_selector.cpp @@ -59,7 +59,7 @@ namespace NLGUI void CCssSelector::setClass(const std::string &cls) { std::vector parts; - NLMISC::splitString(toLower(cls), ".", parts); + NLMISC::splitString(toLowerAscii(cls), ".", parts); for(uint i = 0; i< parts.size(); i++) { @@ -80,7 +80,7 @@ namespace NLGUI } else { - Attr.push_back(SAttribute(key, toLower(val), op, cs)); + Attr.push_back(SAttribute(key, toLowerAscii(val), op, cs)); } } @@ -146,7 +146,7 @@ namespace NLGUI // case-insensitive compare, Attr.value is already lowercased if (!Attr[i].caseSensitive) { - value = toLower(value); + value = toLowerAscii(value); } switch(Attr[i].op) @@ -255,7 +255,7 @@ namespace NLGUI if (start == std::string::npos) return; - std::string expr = toLower(pseudo.substr(start, end - start)); + std::string expr = toLowerAscii(pseudo.substr(start, end - start)); if (expr.empty()) return; diff --git a/nel/src/gui/css_style.cpp b/nel/src/gui/css_style.cpp index 396bff062..ac36da726 100644 --- a/nel/src/gui/css_style.cpp +++ b/nel/src/gui/css_style.cpp @@ -676,7 +676,7 @@ namespace NLGUI else if (it->first == "text-decoration" || it->first == "text-decoration-line") { - std::string prop(toLower(it->second)); + std::string prop(toLowerAscii(it->second)); style.Underlined = (prop.find("underline") != std::string::npos); style.StrikeThrough = (prop.find("line-through") != std::string::npos); } @@ -924,7 +924,7 @@ namespace NLGUI { // normalize std::string image = trim(it->second); - if (toLower(image.substr(0, 4)) == "url(") + if (toLowerAscii(image.substr(0, 4)) == "url(") { image = image.substr(4, image.size()-5); } @@ -934,7 +934,7 @@ namespace NLGUI if (it->first == "background-repeat") { // normalize - std::string val = toLower(trim(it->second)); + std::string val = toLowerAscii(trim(it->second)); std::vector parts; splitParams(val, ' ', parts); // check for "repeat repeat" @@ -947,7 +947,7 @@ namespace NLGUI if (it->first == "background-size") { // normalize - std::string val = toLower(trim(it->second)); + std::string val = toLowerAscii(trim(it->second)); std::vector parts; splitParams(val, ' ', parts); if (parts.size() == 2 && parts[0] == parts[1]) @@ -999,7 +999,7 @@ namespace NLGUI uint index = 0; while(!failed && index < parts.size()) { - std::string val = toLower(parts[index]); + std::string val = toLowerAscii(parts[index]); bool matches = false; for(uint i = 0; i < nbProps; i++) { @@ -1028,7 +1028,7 @@ namespace NLGUI // second loop -> false && break loop = !loop; - val = toLower(parts[next]); + val = toLowerAscii(parts[next]); if (val == "center") { if (bgPositionX.empty()) bgPositionX = "center"; @@ -1082,7 +1082,7 @@ namespace NLGUI uint next = index + 1; if (next < parts.size()) { - val = toLower(parts[next]); + val = toLowerAscii(parts[next]); if (val == "cover" || val == "contain") { matches = true; @@ -1106,7 +1106,7 @@ namespace NLGUI next++; if (next < parts.size()) { - val = toLower(parts[next]); + val = toLowerAscii(parts[next]); if (val == "auto") v = "auto"; else if (getCssLength(fval, unit, val)) @@ -1160,7 +1160,7 @@ namespace NLGUI uint next = index + 1; if (next < parts.size()) { - val = toLower(parts[next]); + val = toLowerAscii(parts[next]); if (val == "repeat" || val == "space" || val == "round" || val == "no-repeat") { vert = val; @@ -1334,7 +1334,7 @@ namespace NLGUI bool CCssStyle::tryBorderWidthShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; - splitParams(toLower(value), ' ', parts); + splitParams(toLowerAscii(value), ' ', parts); float tmpf; std::string unit; @@ -1371,7 +1371,7 @@ namespace NLGUI bool CCssStyle::tryBorderStyleShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; - splitParams(toLower(value), ' ', parts); + splitParams(toLowerAscii(value), ' ', parts); // verify that parts are valid uint8 maxSize = (prop == "border" || prop == "border-style") ? 4 : 1; @@ -1420,7 +1420,7 @@ namespace NLGUI bool CCssStyle::tryBorderColorShorthand(const std::string &prop, const std::string &value, TStyle &style) const { std::vector parts; - splitParams(toLower(value), ' ', parts); + splitParams(toLowerAscii(value), ' ', parts); CRGBA color; // verify that parts are valid @@ -1465,7 +1465,7 @@ namespace NLGUI TStyle borderStyle; std::vector parts; - splitParams(toLower(value), ' ', parts); + splitParams(toLowerAscii(value), ' ', parts); for(uint index = 0; index < parts.size(); ++index) { @@ -1530,7 +1530,7 @@ namespace NLGUI void CCssStyle::expandPaddingShorthand(const std::string &value, TStyle &style) const { std::vector parts; - splitParams(toLower(value), ' ', parts); + splitParams(toLowerAscii(value), ' ', parts); uint8 t, r, b, l; if (!getShorthandIndices(parts.size(), t, r, b, l)) diff --git a/nel/src/gui/ctrl_base.cpp b/nel/src/gui/ctrl_base.cpp index 737bacb68..fa790d9d4 100644 --- a/nel/src/gui/ctrl_base.cpp +++ b/nel/src/gui/ctrl_base.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -99,7 +100,7 @@ namespace NLGUI CCtrlBase::TToolTipParentType CCtrlBase::stringToToolTipParent( const std::string &str ) { - std::string s = toLower( str ); + std::string s = toLowerAscii( str ); if( s == "mouse" ) return TTMouse; @@ -122,32 +123,26 @@ namespace NLGUI CXMLAutoPtr prop; // get static toolTip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip" ); - if (prop) + prop = (char *)xmlGetProp(cur, (xmlChar *)"tooltip_i18n"); + if ((bool)prop && strlen((const char *)prop) > 0) { - const char *propPtr = prop; -#ifdef RYZOM_FORGE - if (strlen(propPtr) > 2 && propPtr[0] == 'u' && propPtr[1] == ':') - _ContextHelp = ucstring::makeFromUtf8(std::string(propPtr).substr(2)); + // Force I18N tooltip + if (!editorMode) + _ContextHelp = CI18N::get((const char *)prop); else -#endif - _ContextHelp = ucstring(propPtr); - - - if( !editorMode && ( strlen(propPtr) > 2 ) ) - { - if ((propPtr[0] == 'u') && (propPtr[1] == 'i')) - _ContextHelp = CI18N::get ((const char *) prop); - } + _ContextHelp = (const char *)prop; } - // Force I18N tooltip - prop = (char*) xmlGetProp( cur, (xmlChar*)"tooltip_i18n" ); - if ((bool)prop && strlen((const char*)prop)>0) + else { - if( !editorMode ) - _ContextHelp = CI18N::get ((const char *) prop); - else - _ContextHelp = (const char*)prop; + // get static toolTip + prop = (char *)xmlGetProp(cur, (xmlChar *)"tooltip"); + if (prop) + { + if (!editorMode && NLMISC::startsWith((const char *)prop, "ui")) + _ContextHelp = CI18N::get((const char *)prop); + else + _ContextHelp = (const char *)prop; + } } // get dynamic toolTip ActionHandler @@ -175,7 +170,7 @@ namespace NLGUI _ToolTipSpecialParent= CStringShared(); if(prop) { - _ToolTipSpecialParent= std::string((const char*)prop); + _ToolTipSpecialParent= (const char*)prop; } // Tooltip posref @@ -203,12 +198,12 @@ namespace NLGUI { if( name == "tooltip" ) { - return _ContextHelp.toString(); + return _ContextHelp; } else if( name == "tooltip_i18n" ) { - return _ContextHelp.toString(); + return _ContextHelp; } else if( name == "on_tooltip" ) @@ -264,13 +259,19 @@ namespace NLGUI { if( name == "tooltip" ) { - _ContextHelp = ucstring::makeFromUtf8(value); + if (!editorMode && NLMISC::startsWith(value, "ui")) + _ContextHelp = CI18N::get(value); + else + _ContextHelp = value; return; } else if( name == "tooltip_i18n" ) { - _ContextHelp = value; + if (!editorMode) + _ContextHelp = CI18N::get(value); + else + _ContextHelp = value; return; } else @@ -382,8 +383,8 @@ namespace NLGUI if( node == NULL ) return NULL; - xmlNewProp( node, BAD_CAST "tooltip", BAD_CAST _ContextHelp.toString().c_str() ); - xmlNewProp( node, BAD_CAST "tooltip_i18n", BAD_CAST _ContextHelp.toString().c_str() ); + xmlNewProp( node, BAD_CAST "tooltip", BAD_CAST _ContextHelp.c_str() ); + xmlNewProp( node, BAD_CAST "tooltip_i18n", BAD_CAST _ContextHelp.c_str() ); xmlNewProp( node, BAD_CAST "on_tooltip", BAD_CAST _OnContextHelp.toString().c_str() ); xmlNewProp( node, BAD_CAST "on_tooltip_params", BAD_CAST _OnContextHelpParams.toString().c_str() ); xmlNewProp( node, BAD_CAST "tooltip_parent", BAD_CAST tooltipParentToString( _ToolTipParent ).c_str() ); @@ -476,7 +477,7 @@ namespace NLGUI // *************************************************************************** bool CCtrlBase::emptyContextHelp() const { - ucstring help; + std::string help; getContextHelp(help); std::string sTmp = _OnContextHelp; return help.empty() && sTmp.empty(); @@ -494,12 +495,15 @@ namespace NLGUI void CCtrlBase::serial(NLMISC::IStream &f) { CViewBase::serial(f); + + uint version = f.serialVersion(1); + nlassert(version); + f.serial(_ContextHelp); f.serial(_OnContextHelp); f.serial(_OnContextHelpParams); f.serial(_ToolTipSpecialParent); f.serialEnum(_ToolTipParent); - // THotSpot tmpToolTipParentPosRef = _ToolTipParentPosRef; THotSpot tmpToolTipPosRef = _ToolTipPosRef; @@ -515,7 +519,7 @@ namespace NLGUI _ToolTipPosRef = tmpToolTipPosRef; _ToolTipParentPosRefAlt = tmpToolTipParentPosRefAlt; _ToolTipPosRefAlt = tmpToolTipPosRefAlt; - // + nlSerialBitBool(f, _ToolTipInstant); } @@ -569,6 +573,7 @@ namespace NLGUI return itr2->second; } +#ifdef RYZOM_LUA_UCSTRING // *************************************************************************** int CCtrlBase::luaSetTooltipUtf8(CLuaState &ls) { @@ -577,9 +582,10 @@ namespace NLGUI CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); std::string tooltip = ls.toString(1); - setDefaultContextHelp(ucstring::makeFromUtf8(tooltip)); + setDefaultContextHelp(tooltip); return 0; } +#endif } diff --git a/nel/src/gui/ctrl_base_button.cpp b/nel/src/gui/ctrl_base_button.cpp index dec715048..68aa19f15 100644 --- a/nel/src/gui/ctrl_base_button.cpp +++ b/nel/src/gui/ctrl_base_button.cpp @@ -584,18 +584,18 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"menu_l" ); if (prop) { - _ListMenuLeft = NLMISC::toLower(std::string((const char *) prop)); + _ListMenuLeft = NLMISC::toLowerAscii(std::string((const char *) prop)); } prop = (char*) xmlGetProp( cur, (xmlChar*)"menu_r" ); if (prop) { - _ListMenuRight = NLMISC::toLower(std::string((const char *) prop)); + _ListMenuRight = NLMISC::toLowerAscii(std::string((const char *) prop)); } // list menu on both clicks prop = (char*) xmlGetProp( cur, (xmlChar*)"menu_b" ); if (prop) { - setListMenuBoth(NLMISC::toLower(std::string((const char *) prop))); + setListMenuBoth(NLMISC::toLowerAscii(std::string((const char *) prop))); } prop= (char*) xmlGetProp (cur, (xmlChar*)"frozen"); diff --git a/nel/src/gui/ctrl_button.cpp b/nel/src/gui/ctrl_button.cpp index e27d8cfbd..cc38e50e4 100644 --- a/nel/src/gui/ctrl_button.cpp +++ b/nel/src/gui/ctrl_button.cpp @@ -210,21 +210,21 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_normal" ); if (prop) { - string TxName = NLMISC::toLower((const char *) prop); + string TxName = NLMISC::toLowerAscii((const char *) prop); _TextureIdNormal.setTexture(TxName.c_str()); } prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_pushed" ); if (prop) { - string TxName = NLMISC::toLower((const char *) prop); + string TxName = NLMISC::toLowerAscii((const char *) prop); _TextureIdPushed.setTexture(TxName.c_str()); } prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_over" ); if (prop) { - string TxName = NLMISC::toLower((const char *) prop); + string TxName = NLMISC::toLowerAscii((const char *) prop); _TextureIdOver.setTexture(TxName.c_str()); } diff --git a/nel/src/gui/ctrl_col_pick.cpp b/nel/src/gui/ctrl_col_pick.cpp index 411414de7..251c655c2 100644 --- a/nel/src/gui/ctrl_col_pick.cpp +++ b/nel/src/gui/ctrl_col_pick.cpp @@ -212,12 +212,12 @@ namespace NLGUI CViewRenderer &rVR = *CViewRenderer::getInstance(); if(prop) { - string sTmp = NLMISC::toLower((const char*)prop); + string sTmp = NLMISC::toLowerAscii((const char*)prop); _Texture = rVR.createTexture (sTmp, 0, 0, 256, 64, false, false); } prop = (char*) xmlGetProp( node, (xmlChar*)"onchange" ); - if (prop) _AHOnChange = NLMISC::toLower((const char*)prop); + if (prop) _AHOnChange = NLMISC::toLowerAscii((const char*)prop); prop = (char*) xmlGetProp( node, (xmlChar*)"onchange_params" ); if (prop) _AHOnChangeParams = string((const char*)prop); diff --git a/nel/src/gui/ctrl_scroll.cpp b/nel/src/gui/ctrl_scroll.cpp index 14caa75f4..00f089660 100644 --- a/nel/src/gui/ctrl_scroll.cpp +++ b/nel/src/gui/ctrl_scroll.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2015 Jan BOON (Kaetemi) +// Copyright (C) 2015-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -57,6 +57,7 @@ namespace NLGUI _MouseDown = false; _CallingAH = false; _Cancelable = false; + _Keyboard = false; _Target = NULL; _Inverted = false; _IsDBLink = false; @@ -225,6 +226,11 @@ namespace NLGUI return toString( _Cancelable ); } else + if( name == "keyboard" ) + { + return toString( _Keyboard ); + } + else if( name == "frozen" ) { return toString( _Frozen ); @@ -405,6 +411,14 @@ namespace NLGUI return; } else + if( name == "keyboard" ) + { + bool b; + if( fromString( value, b ) ) + _Keyboard = b; + return; + } + else if( name == "frozen" ) { bool b; @@ -474,6 +488,7 @@ namespace NLGUI xmlSetProp( node, BAD_CAST "target_stepy", BAD_CAST toString( _TargetStepY ).c_str() ); xmlSetProp( node, BAD_CAST "step_value", BAD_CAST toString( _StepValue ).c_str() ); xmlSetProp( node, BAD_CAST "cancelable", BAD_CAST toString( _Cancelable ).c_str() ); + xmlSetProp( node, BAD_CAST "keyboard", BAD_CAST toString( _Keyboard ).c_str() ); xmlSetProp( node, BAD_CAST "frozen", BAD_CAST toString( _Frozen ).c_str() ); return node; @@ -546,17 +561,17 @@ namespace NLGUI // Read Action handlers prop = (char*) xmlGetProp( node, (xmlChar*)"onscroll" ); - if (prop) _AHOnScroll = NLMISC::toLower(prop.str()); + if (prop) _AHOnScroll = NLMISC::toLowerAscii(prop.str()); prop = (char*) xmlGetProp( node, (xmlChar*)"params" ); if (prop) _AHOnScrollParams = string((const char*)prop); // prop = (char*) xmlGetProp( node, (xmlChar*)"onscrollend" ); - if (prop) _AHOnScrollEnd = NLMISC::toLower(prop.str()); + if (prop) _AHOnScrollEnd = NLMISC::toLowerAscii(prop.str()); prop = (char*) xmlGetProp( node, (xmlChar*)"end_params" ); if (prop) _AHOnScrollEndParams = string((const char*)prop); // prop = (char*) xmlGetProp( node, (xmlChar*)"onscrollcancel" ); - if (prop) _AHOnScrollCancel = NLMISC::toLower(prop.str()); + if (prop) _AHOnScrollCancel = NLMISC::toLowerAscii(prop.str()); prop = (char*) xmlGetProp( node, (xmlChar*)"cancel_params" ); if (prop) _AHOnScrollCancelParams = string((const char*)prop); @@ -589,6 +604,9 @@ namespace NLGUI prop = (char*) xmlGetProp( node, (xmlChar*)"cancelable" ); if (prop) _Cancelable = convertBool(prop); + prop = (char*) xmlGetProp( node, (xmlChar*)"keyboard" ); + if (prop) _Keyboard = convertBool(prop); + prop= (char*) xmlGetProp (node, (xmlChar*)"frozen"); _Frozen = false; if (prop) @@ -912,6 +930,30 @@ namespace NLGUI return true; } } + else if (event.getType() == NLGUI::CEventDescriptor::key) + { + const NLGUI::CEventDescriptorKey &eventDesc = (const NLGUI::CEventDescriptorKey &)event; + + if (eventDesc.getKeyEventType() == NLGUI::CEventDescriptorKey::keydown) + { + if (_Keyboard) + { + sint32 i = 0; + // direction + if (eventDesc.getKey() == KeyNEXT) i++; + else if (eventDesc.getKey() == KeyPRIOR) i--; + else + return false; + + if (_Vertical) + moveTrackY(-(i * _TargetStepY)); + else + moveTrackX(-(i * _TargetStepX)); + + return true; + } + } + } return false; } diff --git a/nel/src/gui/ctrl_text_button.cpp b/nel/src/gui/ctrl_text_button.cpp index de01174ed..8697fb212 100644 --- a/nel/src/gui/ctrl_text_button.cpp +++ b/nel/src/gui/ctrl_text_button.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -136,7 +137,7 @@ namespace NLGUI if( name == "hardtext" ) { if( _ViewText != NULL ) - return _ViewText->getText().toString(); + return _ViewText->getText(); else return std::string( "" ); } @@ -316,7 +317,7 @@ namespace NLGUI if( name == "hardtext" ) { if( _ViewText != NULL ) - _ViewText->setText( value ); + _ViewText->setHardText( value ); return; } else @@ -487,7 +488,7 @@ namespace NLGUI xmlNewProp( node, BAD_CAST "wmargin", BAD_CAST toString( _WMargin ).c_str() ); xmlNewProp( node, BAD_CAST "wmin", BAD_CAST toString( _WMin ).c_str() ); xmlNewProp( node, BAD_CAST "hmin", BAD_CAST toString( _HMin ).c_str() ); - xmlNewProp( node, BAD_CAST "hardtext", BAD_CAST _ViewText->getText().toString().c_str() ); + xmlNewProp( node, BAD_CAST "hardtext", BAD_CAST _ViewText->getText().c_str() ); xmlNewProp( node, BAD_CAST "text_y", BAD_CAST toString( _TextY ).c_str() ); xmlNewProp( node, BAD_CAST "text_x", BAD_CAST toString( _TextX ).c_str() ); xmlNewProp( node, BAD_CAST "text_underlined", BAD_CAST toString( _ViewText->getUnderlined() ).c_str() ); @@ -541,7 +542,7 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_normal" ); if (prop) { - string TxName = toLower(std::string((const char *) prop)); + string TxName = toLowerAscii(std::string((const char *) prop)); _TextureIdNormal[0].setTexture((TxName+"_l.tga").c_str()); _TextureIdNormal[1].setTexture((TxName+"_m.tga").c_str()); _TextureIdNormal[2].setTexture((TxName+"_r.tga").c_str()); @@ -550,7 +551,7 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_pushed" ); if (prop) { - string TxName = toLower(std::string((const char *) prop)); + string TxName = toLowerAscii(std::string((const char *) prop)); _TextureIdPushed[0].setTexture((TxName+"_l.tga").c_str()); _TextureIdPushed[1].setTexture((TxName+"_m.tga").c_str()); _TextureIdPushed[2].setTexture((TxName+"_r.tga").c_str()); @@ -559,7 +560,7 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"tx_over" ); if (prop) { - string TxName = toLower(std::string((const char *) prop)); + string TxName = toLowerAscii(std::string((const char *) prop)); _TextureIdOver[0].setTexture((TxName+"_l.tga").c_str()); _TextureIdOver[1].setTexture((TxName+"_m.tga").c_str()); _TextureIdOver[2].setTexture((TxName+"_r.tga").c_str()); @@ -596,10 +597,7 @@ namespace NLGUI if (prop) { const char *propPtr = prop; - ucstring text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - text = CI18N::get (propPtr); - _ViewText->setText(text); + _ViewText->setTextLocalized(propPtr, true); } } @@ -988,7 +986,7 @@ namespace NLGUI nlassert( v != NULL ); _ViewText = dynamic_cast< CViewText* >( v ); _ViewText->setId( _Id + "_text" ); - _ViewText->setText( ucstring( "text" ) ); + _ViewText->setText( "text" ); _ViewText->setSerializable( false ); } @@ -1039,19 +1037,49 @@ namespace NLGUI // *************************************************************************** - void CCtrlTextButton::setText (const ucstring &text) + void CCtrlTextButton::setText (const std::string &text) { if (_ViewText && !_IsViewTextId) _ViewText->setText(text); } // *************************************************************************** - ucstring CCtrlTextButton::getText () const + std::string CCtrlTextButton::getText () const { if (_ViewText && !_IsViewTextId) return _ViewText->getText(); + return std::string(); + } + + void CCtrlTextButton::setLocalize(bool localize) + { + if (_ViewText && !_IsViewTextId) + _ViewText->setLocalized(localize); + } + + bool CCtrlTextButton::isLocalized() const + { + if (_ViewText && !_IsViewTextId) + return _ViewText->isLocalized(); + return true; + } + +#ifdef RYZOM_LUA_UCSTRING + // *************************************************************************** + void CCtrlTextButton::setTextAsUtf16 (const ucstring &text) + { + if (_ViewText && !_IsViewTextId) + _ViewText->setText(text.toUtf8()); + } + + // *************************************************************************** + ucstring CCtrlTextButton::getTextAsUtf16 () const + { + if (_ViewText && !_IsViewTextId) + return CUtfStringView(_ViewText->getText()).toUtf16(); return ucstring(""); } +#endif // *************************************************************************** void CCtrlTextButton::setHardText (const std::string &text) diff --git a/nel/src/gui/dbgroup_combo_box.cpp b/nel/src/gui/dbgroup_combo_box.cpp index 834d2d5bf..b54d33e8f 100644 --- a/nel/src/gui/dbgroup_combo_box.cpp +++ b/nel/src/gui/dbgroup_combo_box.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2013-2015 Jan BOON (Kaetemi) +// Copyright (C) 2013-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -43,9 +43,10 @@ namespace NLGUI void force_link_dbgroup_combo_box_cpp() { } // Compare strings - static inline bool lt_text(const std::pair &s1, const std::pair &s2) + static inline bool lt_text(const std::pair &s1, const std::pair &s2) { - return toLower(s1.second) < toLower(s2.second); + // return toLower(s1.second) < toLower(s2.second); + return -NLMISC::compareCaseInsensitive(s1.second, s2.second); } std::string CDBGroupComboBox::measureMenu; @@ -183,10 +184,10 @@ namespace NLGUI if (name) { const char *propPtr = name; - ucstring Text = ucstring::makeFromUtf8(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - addText(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addText(CI18N::get(propPtr)); + else + addText(propPtr); } } child = child->next; @@ -236,7 +237,7 @@ namespace NLGUI // change selected text if(_CacheSelection<0 || _CacheSelection>=(sint32)_Texts.size() ) { - _ViewText->setText(ucstring()); + _ViewText->setText(std::string()); } else if(_IsExternViewText) { @@ -274,7 +275,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::addText(const ucstring &text) + void CDBGroupComboBox::addText(const std::string &text) { dirt(); _Texts.push_back(make_pair((uint)_Texts.size(), text)); @@ -283,7 +284,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::setText(uint i, const ucstring &text) + void CDBGroupComboBox::setText(uint i, const std::string &text) { dirt(); if(i<_Texts.size()) @@ -291,7 +292,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::insertText(uint i, const ucstring &text) + void CDBGroupComboBox::insertText(uint i, const std::string &text) { dirt(); if(i<_Texts.size()) @@ -313,7 +314,7 @@ namespace NLGUI } // *************************************************************************** - void CDBGroupComboBox::setTexture(uint i, const ucstring &texture) + void CDBGroupComboBox::setTexture(uint i, const std::string &texture) { dirt(); if(i<_Textures.size()) @@ -351,14 +352,22 @@ namespace NLGUI } // *************************************************************************** - const ucstring &CDBGroupComboBox::getText(uint i) const + const std::string &CDBGroupComboBox::getText(uint i) const { - static ucstring null; - if(i<_Texts.size()) + static const std::string empty; + if (i < _Texts.size()) return _Texts[i].second; else - return null; + return empty; + } + +#ifdef RYZOM_LUA_UCSTRING + // *************************************************************************** + ucstring CDBGroupComboBox::getTextAsUtf16(uint i) const + { + return ucstring::makeFromUtf8(getText(i)); } +#endif // *************************************************************************** uint CDBGroupComboBox::getTextId(uint i) const @@ -385,16 +394,24 @@ namespace NLGUI { sort(_Texts.begin(), _Texts.end(), lt_text); } - + // *************************************************************************** - const ucstring &CDBGroupComboBox::getTexture(uint i) const + const std::string &CDBGroupComboBox::getTexture(uint i) const { - static ucstring null; - if(i<_Textures.size()) + static const std::string empty; + if (i < _Textures.size()) return _Textures[i]; else - return null; + return empty; + } + +#ifdef RYZOM_LUA_UCSTRING + // *************************************************************************** + ucstring CDBGroupComboBox::getTextureAsUtf16(uint i) const + { + return ucstring::makeFromUtf8(getTexture(i)); } +#endif // *************************************************************************** void CDBGroupComboBox::setSelection(sint32 val) @@ -452,8 +469,7 @@ namespace NLGUI sint32 value; for(uint i=0; isetText(_ExternViewText); } // *************************************************************************** - ucstring CDBGroupComboBox::getViewText() const + std::string CDBGroupComboBox::getViewText() const + { + return _ViewText->getText(); + } + +#ifdef RYZOM_LUA_UCSTRING + // *************************************************************************** + ucstring CDBGroupComboBox::getViewTextAsUtf16() const { - return _ViewText->getText(); + return CUtfStringView(_ViewText->getText()).toUtf16(); } +#endif // *************************************************************************** CViewText *CDBGroupComboBox::getViewText() @@ -486,18 +510,14 @@ namespace NLGUI // *************************************************************************** std::string CDBGroupComboBox::getSelectionText() const { - ucstring text; if (_LinkedToDB) { - text = getText(_Selection.getSInt32()); + return getText(_Selection.getSInt32()); } else { - text = getText(_NotLinkedToDBSelection); + return getText(_NotLinkedToDBSelection); } - std::string texteS; - text.toString(texteS); - return texteS; } // *************************************************************************** @@ -538,8 +558,7 @@ namespace NLGUI sint32 value; for(uint i=0; iaddLine(getText(i), "combo_box_select_end", toString(i), - "", std::string(), getTexture(i).toString(), checkable); + "", std::string(), getTexture(i), checkable); groupMenu->setGrayedLine(i, getGrayed(i)); } diff --git a/nel/src/gui/dbview_number.cpp b/nel/src/gui/dbview_number.cpp index af768140c..c0c728f2b 100644 --- a/nel/src/gui/dbview_number.cpp +++ b/nel/src/gui/dbview_number.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -43,7 +44,7 @@ namespace NLGUI { _Positive = false; _Cache= 0; - setText(ucstring("0")); + setText(std::string("0")); _Divisor = 1; _Modulo = 0; } @@ -225,7 +226,7 @@ namespace NLGUI // init cache. _Cache= 0; - setText(ucstring("0")); + setText(std::string("0")); return true; } @@ -238,9 +239,9 @@ namespace NLGUI if (_Cache != val) { _Cache= val; - ucstring value = _Format ? NLMISC::formatThousands(toString(val)) : toString(val); - if (_Positive) setText(val >= 0 ? ( ucstring(_Prefix) + value + ucstring(_Suffix) ) : ucstring("?")); - else setText( ucstring(_Prefix) + value + ucstring(_Suffix) ); + std::string value = _Format ? NLMISC::formatThousands(toString(val)) : toString(val); + if (_Positive) setText(val >= 0 ? ( _Prefix.toString() + value + _Suffix.toString() ) : "?"); + else setText( _Prefix.toString() + value + _Suffix.toString() ); } } diff --git a/nel/src/gui/dbview_quantity.cpp b/nel/src/gui/dbview_quantity.cpp index cac772c96..84c214191 100644 --- a/nel/src/gui/dbview_quantity.cpp +++ b/nel/src/gui/dbview_quantity.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -63,7 +64,7 @@ namespace NLGUI else if( name == "emptytext" ) { - return _EmptyText.toString(); + return _EmptyText; } else return CViewText::getProperty( name ); @@ -112,7 +113,7 @@ namespace NLGUI else xmlSetProp( node, BAD_CAST "valuemax", BAD_CAST "" ); - xmlSetProp( node, BAD_CAST "emptytext", BAD_CAST _EmptyText.toString().c_str() ); + xmlSetProp( node, BAD_CAST "emptytext", BAD_CAST _EmptyText.c_str() ); return node; } @@ -147,9 +148,10 @@ namespace NLGUI if(ptr) { const char *propPtr = ptr; - _EmptyText = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - _EmptyText = CI18N::get (propPtr); + if (NLMISC::startsWith(propPtr, "ui")) + _EmptyText = CI18N::get(propPtr); + else + _EmptyText = propPtr; } // init cache. diff --git a/nel/src/gui/group_container.cpp b/nel/src/gui/group_container.cpp index 87fb59c38..9047fbfcb 100644 --- a/nel/src/gui/group_container.cpp +++ b/nel/src/gui/group_container.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -1338,19 +1338,19 @@ namespace NLGUI if( name == "title" ) { if( _TitleTextOpened == _TitleTextClosed ) - return _TitleTextOpened.toString(); + return _TitleTextOpened; else return ""; } else if( name == "title_opened" ) { - return _TitleTextOpened.toString(); + return _TitleTextOpened; } else if( name == "title_closed" ) { - return _TitleTextClosed.toString(); + return _TitleTextClosed; } else if( name == "header_active" ) @@ -1997,12 +1997,12 @@ namespace NLGUI xmlSetProp( node, BAD_CAST "content_y_offset", BAD_CAST toString( _ContentYOffset ).c_str() ); if( _TitleTextOpened == _TitleTextClosed ) - xmlSetProp( node, BAD_CAST "title", BAD_CAST _TitleTextOpened.toString().c_str() ); + xmlSetProp( node, BAD_CAST "title", BAD_CAST _TitleTextOpened.c_str() ); else xmlSetProp( node, BAD_CAST "title", BAD_CAST "" ); - xmlSetProp( node, BAD_CAST "title_opened", BAD_CAST _TitleTextOpened.toString().c_str() ); - xmlSetProp( node, BAD_CAST "title_closed", BAD_CAST _TitleTextClosed.toString().c_str() ); + xmlSetProp( node, BAD_CAST "title_opened", BAD_CAST _TitleTextOpened.c_str() ); + xmlSetProp( node, BAD_CAST "title_closed", BAD_CAST _TitleTextClosed.c_str() ); xmlSetProp( node, BAD_CAST "header_active", BAD_CAST toString( _HeaderActive ).c_str() ); if( _HeaderColor.getNodePtr() != NULL ) @@ -2144,24 +2144,20 @@ namespace NLGUI ptr = xmlGetProp (cur, (xmlChar*)"title"); if (ptr) { - if (_Localize) _TitleTextOpened = CI18N::get(string((const char*)ptr)); - else _TitleTextOpened = string((const char*)ptr); - if (_Localize) _TitleTextClosed = CI18N::get(string((const char*)ptr)); - else _TitleTextClosed = string((const char*)ptr); + _TitleTextOpened = (const char *)ptr; + _TitleTextClosed = (const char *)ptr; } ptr = xmlGetProp (cur, (xmlChar*)"title_opened"); if (ptr) { - if (_Localize) _TitleTextOpened = CI18N::get(string((const char*)ptr)); - else _TitleTextOpened = string((const char*)ptr); + _TitleTextOpened = (const char*)ptr; } ptr = xmlGetProp (cur, (xmlChar*)"title_closed"); if (ptr) { - if (_Localize) _TitleTextClosed = CI18N::get(string((const char*)ptr)); - else _TitleTextClosed = string((const char*)ptr); + _TitleTextClosed = (const char *)ptr; } ptr = xmlGetProp (cur, (xmlChar*)"header_active"); @@ -3712,7 +3708,7 @@ namespace NLGUI { CViewTextID *vti= new CViewTextID(CViewBase::TCtorParam()); // the title here is actually the DB path - vti->setDBTextID(_TitleTextOpened.toString()); + vti->setDBTextID(_TitleTextOpened); vti->setDynamicString(_TitleClass==TitleTextDynString); _TitleOpened = vti; } @@ -3744,7 +3740,7 @@ namespace NLGUI _TitleOpened->setY (pLayer->getValSInt32 ("title_offset_y")); } _TitleOpened->setFontSize (pLayer->getValSInt32 ("title_font_size")); - if (_TitleClass==TitleText) _TitleOpened->setText (_TitleTextOpened); + if (_TitleClass == TitleText) setTitledOpenedViewText(); _TitleOpened->setActive (_Opened); // Title when the container is closed @@ -3764,7 +3760,7 @@ namespace NLGUI { CViewTextID *vti= new CViewTextID(CViewBase::TCtorParam()); // the title here is actually the DB path - vti->setDBTextID(_TitleTextClosed.toString()); + vti->setDBTextID(_TitleTextClosed); vti->setDynamicString(_TitleClass==TitleTextDynString); _TitleClosed = vti; } @@ -3796,7 +3792,7 @@ namespace NLGUI _TitleClosed->setY (pLayer->getValSInt32 ("title_offset_y")); } _TitleClosed->setFontSize (pLayer->getValSInt32 ("title_font_size")); - if (_TitleClass==TitleText) _TitleClosed->setText (_TitleTextClosed); + if (_TitleClass == TitleText) setTitledClosedViewText(); _TitleClosed->setActive(!_Opened); @@ -3946,87 +3942,117 @@ namespace NLGUI } } + // *************************************************************************** + void CGroupContainer::setLocalize(bool localize) + { + _Localize = localize; + if (_TitleOpened) + { + _TitleOpened->setLocalized(localize); + } + if (_TitleClosed) + { + _TitleClosed->setLocalized(localize); + } + invalidateCoords(); + } + // *************************************************************************** std::string CGroupContainer::getTitle () const { - return _TitleTextOpened.toString(); + return _TitleTextOpened; } // *************************************************************************** void CGroupContainer::setTitle (const std::string &title) { - if (_Localize) setUCTitle (CI18N::get(title)); - else setUCTitle (title); + setTitleOpened(title); + setTitleClosed(title); } // *************************************************************************** std::string CGroupContainer::getTitleOpened () const { - return _TitleTextOpened.toString(); + return _TitleTextOpened; } // *************************************************************************** void CGroupContainer::setTitleOpened (const std::string &title) { - if (_Localize) setUCTitleOpened (CI18N::get(title)); - else setUCTitleOpened (title); + _TitleTextOpened = title; + setTitledOpenedViewText(); + invalidateCoords(); } // *************************************************************************** std::string CGroupContainer::getTitleClosed () const { - return _TitleTextClosed.toString(); + return _TitleTextClosed; } // *************************************************************************** void CGroupContainer::setTitleClosed (const std::string &title) { - if (_Localize) setUCTitleClosed (CI18N::get(title)); - else setUCTitleClosed (title); + _TitleTextClosed = title; + setTitledClosedViewText(); + invalidateCoords(); } // *************************************************************************** - void CGroupContainer::setUCTitleOpened(const ucstring &title) + void CGroupContainer::setTitledOpenedViewText() { - _TitleTextOpened = title; if (_TitleOpened != NULL) - _TitleOpened->setText (title); - invalidateCoords(); + { + _TitleOpened->setTextLocalized(_TitleTextOpened, _Localize); + } } // *************************************************************************** - void CGroupContainer::setUCTitleClosed(const ucstring &title) + void CGroupContainer::setTitledClosedViewText() { - _TitleTextClosed = title; if (_TitleClosed != NULL) - _TitleClosed->setText (_TitleTextClosed); - invalidateCoords(); + { + _TitleClosed->setTextLocalized(_TitleTextClosed, _Localize); + } + } + +#ifdef RYZOM_LUA_UCSTRING + // *************************************************************************** + void CGroupContainer::setUCTitleOpened(const ucstring &title) + { + setTitleOpened(title.toUtf8()); + } + + // *************************************************************************** + void CGroupContainer::setUCTitleClosed(const ucstring &title) + { + setTitleClosed(title.toUtf8()); } // *************************************************************************** void CGroupContainer::setUCTitle(const ucstring &title) { - setUCTitleOpened(title); - setUCTitleClosed(title); + setTitle(title.toUtf8()); } // *************************************************************************** ucstring CGroupContainer::getUCTitle () const { - return getUCTitleOpened(); + return ucstring::makeFromUtf8(getTitle()); } // *************************************************************************** ucstring CGroupContainer::getUCTitleOpened () const { - return _TitleTextOpened; + return ucstring::makeFromUtf8(getTitleOpened()); } // *************************************************************************** ucstring CGroupContainer::getUCTitleClosed () const { - return _TitleTextClosed; + return ucstring::makeFromUtf8(getTitleClosed()); } +#endif // *************************************************************************** void CGroupContainer::launch () diff --git a/nel/src/gui/group_editbox.cpp b/nel/src/gui/group_editbox.cpp index 136909f63..563a27312 100644 --- a/nel/src/gui/group_editbox.cpp +++ b/nel/src/gui/group_editbox.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -21,6 +22,7 @@ #include "stdpch.h" #include "nel/gui/group_editbox.h" #include "nel/misc/command.h" +#include "nel/misc/utf_string_view.h" #include "nel/gui/view_text.h" #include "nel/misc/xml_auto_ptr.h" #include "nel/gui/interface_options.h" @@ -52,6 +54,41 @@ namespace NLGUI CGroupEditBox *CGroupEditBox::_MenuFather = NULL; CGroupEditBox::IComboKeyHandler* CGroupEditBox::comboKeyHandler = NULL; + // For now, just trim unsupported codepoints to make emoji fallback to text form + static u32char supportedCodepoint(u32char c) + { + if (c >= 0xFE00 && c < 0xFE10) + return 0; // Variation Selectors, unsupported + else if (c >= 0xE0100 && c < 0xE01F0) + return 0; // Variation Selectors Supplement, unsupported + else if (c >= 0x200B && c < 0x2010) + return 0; // ZERO WIDTH JOINER, etcetera, unsupported + else if (c >= 0x2028 && c < 0x202F) + return 0; // PARAGRAPH SEPARATOR, etcetera, unsupported + else if (c >= 0x2060 && c < 0x2070) + return 0; // WORD JOINER, etcetera, unsupported + else if (c == 0xFEFF) + return 0; // BOM, unsupported + else if ((c & 0xFC00) == 0xD800) + return 0xFFFD; // UTF-16 surrogate, unmatched pair, invalid, set to replacement character + else if ((c & 0xFC00) == 0xDC00) + return 0xFFFD; // UTF-16 surrogate, unmatched pair, invalid, set to replacement character + return c; + } + + // For now, just trim unsupported codepoints to make emoji fallback to text form + static ::u32string trimUnsupported(const ::u32string str) + { + ::u32string res; + res.reserve(str.size()); + for (::u32string::const_iterator it(str.begin()), end(str.end()); it != end; ++it) + { + u32char c = supportedCodepoint(*it); + if (c) // This also trims NUL + res.push_back(c); + } + return res; + } // ---------------------------------------------------------------------------- NLMISC_REGISTER_OBJECT(CViewBase, CGroupEditBox, std::string, "edit_box"); @@ -61,6 +98,7 @@ namespace NLGUI _BlinkTime(0.f), _CursorPos(0), _MaxNumChar(std::numeric_limits::max()), + _MaxNumBytes(0), _MaxNumReturn(std::numeric_limits::max()), _MaxFloatPrec(20), _MaxCharsSize(32768), @@ -95,7 +133,7 @@ namespace NLGUI _ViewTextDeltaX(0) { - _Prompt = ">"; + _Prompt = ::u32string(1, (u32char)'>'); _BackSelectColor= CRGBA::White; _TextSelectColor= CRGBA::Black; } @@ -147,6 +185,11 @@ namespace NLGUI return toString( _MaxNumChar ); } else + if( name == "max_num_bytes" ) + { + return toString( _MaxNumBytes ); + } + else if( name == "max_num_return" ) { return toString( _MaxNumReturn ); @@ -169,7 +212,7 @@ namespace NLGUI else if( name == "prompt" ) { - return _Prompt.toString(); + return CUtfStringView(_Prompt).toUtf8(); } else if( name == "enter_type" ) @@ -263,9 +306,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; } @@ -319,6 +362,14 @@ namespace NLGUI return; } else + if( name == "max_num_bytes" ) + { + uint32 i; + if( fromString( value, i ) ) + _MaxNumBytes = i; + return; + } + else if( name == "max_num_return" ) { uint32 i; @@ -353,7 +404,7 @@ namespace NLGUI else if( name == "prompt" ) { - _Prompt = value; + _Prompt = CUtfStringView(value).toUtf32(); return; } else @@ -449,10 +500,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 ); @@ -472,11 +523,12 @@ namespace NLGUI xmlSetProp( node, BAD_CAST "on_focus", BAD_CAST _AHOnFocus.c_str() ); xmlSetProp( node, BAD_CAST "on_focus_params", BAD_CAST _AHOnFocusParams.c_str() ); xmlSetProp( node, BAD_CAST "max_num_chars", BAD_CAST toString( _MaxNumChar ).c_str() ); + xmlSetProp( node, BAD_CAST "max_num_bytes", BAD_CAST toString( _MaxNumBytes ).c_str() ); xmlSetProp( node, BAD_CAST "max_num_return", BAD_CAST toString( _MaxNumReturn ).c_str() ); xmlSetProp( node, BAD_CAST "max_chars_size", BAD_CAST toString( _MaxCharsSize ).c_str() ); xmlSetProp( node, BAD_CAST "enter_loose_focus", BAD_CAST toString( _LooseFocusOnEnter ).c_str() ); xmlSetProp( node, BAD_CAST "enter_recover_focus", BAD_CAST toString( _RecoverFocusOnEnter ).c_str() ); - xmlSetProp( node, BAD_CAST "prompt", BAD_CAST _Prompt.toString().c_str() ); + xmlSetProp( node, BAD_CAST "prompt", BAD_CAST CUtfStringView(_Prompt).toUtf8().c_str() ); std::string e; switch( _EntryType ) @@ -538,9 +590,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() ); @@ -589,6 +641,9 @@ namespace NLGUI prop = (char*) xmlGetProp( cur, (xmlChar*)"max_num_chars" ); if (prop) fromString((const char*)prop, _MaxNumChar); + prop = (char*) xmlGetProp( cur, (xmlChar*)"max_num_bytes" ); + if (prop) fromString((const char*)prop, _MaxNumBytes); + prop = (char*) xmlGetProp( cur, (xmlChar*)"max_num_return" ); if (prop) fromString((const char*)prop, _MaxNumReturn); @@ -605,7 +660,7 @@ namespace NLGUI if (prop) _ResetFocusOnHide = convertBool(prop); prop = (char*) xmlGetProp( cur, (xmlChar*)"prompt" ); - if (prop) _Prompt = (const char*)prop; + if (prop) _Prompt = CUtfStringView((const char*)prop).toUtf32(); prop = (char*) xmlGetProp( cur, (xmlChar*)"entry_type" ); _EntryType = Text; @@ -627,7 +682,7 @@ namespace NLGUI } prop = (char*) xmlGetProp( cur, (xmlChar*)"menu_r" ); - if (prop) _ListMenuRight = toLower((const char *) prop); + if (prop) _ListMenuRight = toLowerAscii((const char *) prop); prop = (char*) xmlGetProp( cur, (xmlChar*)"max_historic" ); if (prop) fromString((const char*)prop, _MaxHistoric); @@ -656,9 +711,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; @@ -802,7 +859,7 @@ namespace NLGUI cutSelection(); } - ucstring sString; + string sString; if (CViewRenderer::getInstance()->getDriver()->pasteTextFromClipboard(sString)) { @@ -812,7 +869,7 @@ namespace NLGUI } // ---------------------------------------------------------------------------- - void CGroupEditBox::appendStringFromClipboard(const ucstring &str) + void CGroupEditBox::appendStringFromClipboard(const std::string &str) { stopParentBlink(); makeTopWindow(); @@ -826,11 +883,13 @@ namespace NLGUI } // ---------------------------------------------------------------------------- - void CGroupEditBox::writeString(const ucstring &str, bool replace, bool atEnd) + void CGroupEditBox::writeString(const std::string &str16, bool replace, bool atEnd) { + // For now, just trim unsupported codepoints to make emoji fallback to text form + ::u32string str = trimUnsupported(CUtfStringView(str16).toUtf32()); sint length = (sint)str.length(); - ucstring toAppend; + ::u32string toAppend; // filter character depending on the entry type switch (_EntryType) { @@ -852,7 +911,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; @@ -963,7 +1022,18 @@ namespace NLGUI { length = _MaxNumChar - (sint)_InputString.length(); } - ucstring toAdd = toAppend.substr(0, length); + ::u32string toAdd = toAppend.substr(0, length); + if (_MaxNumBytes && length) + { + sint baseBytes = CUtfStringView(_InputString).toUtf8().length(); + sint bytes = baseBytes + CUtfStringView(toAdd).toUtf8().length(); + while (bytes > _MaxNumBytes) + { + length -= std::max((int)(bytes - _MaxNumBytes) >> 2, 1); + toAdd = toAdd.substr(0, length); + bytes = baseBytes + CUtfStringView(toAdd).toUtf8().length(); + } + } sint32 minPos; sint32 maxPos; if (_CurrSelection == this) @@ -1013,7 +1083,7 @@ namespace NLGUI _CursorAtPreviousLineEnd = false; if (_ClearOnEscape) { - setInputString(ucstring("")); + setInputStringRef(::u32string()); triggerOnChangeAH(); } CWidgetManager::getInstance()->setCaptureKeyboard(NULL); @@ -1059,8 +1129,9 @@ namespace NLGUI { if (isKeyRETURN) { - ucstring copyStr= _InputString; - if ((uint) std::count(copyStr.begin(), copyStr.end(), '\n') >= _MaxNumReturn) + //u32string copyStr= _InputString; + //if ((uint) std::count(copyStr.begin(), copyStr.end(), '\n') >= _MaxNumReturn) + if ((uint)std::count(_InputString.begin(), _InputString.end(), '\n') >= _MaxNumReturn) break; } @@ -1074,8 +1145,10 @@ namespace NLGUI cutSelection(); } - ucchar c = isKeyRETURN ? '\n' : rEDK.getChar(); + u32char c = isKeyRETURN ? '\n' : rEDK.getChar(); if (isFiltered(c)) return; + c = supportedCodepoint(c); + if (!c) return; // For now, just trim unsupported codepoints to make emoji fallback to text form switch(_EntryType) { case Integer: @@ -1121,11 +1194,11 @@ namespace NLGUI if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX)) { // estimate new string - ucstring copyStr= _InputString; - ucstring::iterator it = copyStr.begin() + _CursorPos; + ::u32string copyStr= _InputString; + ::u32string::iterator it = copyStr.begin() + _CursorPos; copyStr.insert(it, c); sint32 value; - fromString(copyStr.toString(), value); + fromString(CUtfStringView(copyStr).toUtf8(), value); // if out of bounds, abort char if(value<_IntegerMinValue || value>_IntegerMaxValue) return; @@ -1134,12 +1207,12 @@ namespace NLGUI if(_EntryType==PositiveInteger && (_PositiveIntegerMinValue!=0 || _PositiveIntegerMaxValue!=UINT_MAX)) { // estimate new string - ucstring copyStr= _InputString; - ucstring::iterator it = copyStr.begin() + _CursorPos; + ::u32string copyStr= _InputString; + ::u32string::iterator it = copyStr.begin() + _CursorPos; copyStr.insert(it, c); // \todo yoyo: this doesn't really work i think.... uint32 value; - fromString(copyStr.toString(), value); + fromString(CUtfStringView(copyStr).toUtf8(), value); // if out of bounds, abort char if(value<_PositiveIntegerMinValue || value>_PositiveIntegerMaxValue) return; @@ -1147,11 +1220,14 @@ namespace NLGUI // verify max num char if ((uint) _InputString.length() < _MaxNumChar) { - makeTopWindow(); - ucstring::iterator it = _InputString.begin() + _CursorPos; - _InputString.insert(it, c); - ++ _CursorPos; - triggerOnChangeAH(); + if (!_MaxNumBytes || CUtfStringView(_InputString + c).toUtf8().size() <= _MaxNumBytes) + { + makeTopWindow(); + ::u32string::iterator it = _InputString.begin() + _CursorPos; + _InputString.insert(it, c); + ++_CursorPos; + triggerOnChangeAH(); + } } if (isKeyRETURN) { @@ -1176,7 +1252,7 @@ namespace NLGUI if (CWidgetManager::getInstance()->getCaptureKeyboard() != this) return false; if (!_CanUndo) return false; _ModifiedInputString = _InputString; - setInputString(_StartInputString); + setInputStringRef(_StartInputString); _CanUndo = false; _CanRedo = true; setCursorPos((sint32)_InputString.length()); @@ -1189,7 +1265,7 @@ namespace NLGUI { if (CWidgetManager::getInstance()->getCaptureKeyboard() != this) return false; if (!_CanRedo) return false; - setInputString(_ModifiedInputString); + setInputStringRef(_ModifiedInputString); _CanUndo = true; _CanRedo = false; setCursorPos((sint32)_InputString.length()); @@ -1229,11 +1305,11 @@ namespace NLGUI { makeTopWindow(); // for french, deutsch and russian, be aware of unicode - std::string command = ucstring(_InputString.substr(1)).toUtf8(); + std::string command = CUtfStringView(_InputString.substr(1)).toUtf8(); ICommand::expand(command); - // then back to ucstring - _InputString.fromUtf8(command); - _InputString = '/' + _InputString; + // then back to u32string + _InputString = CUtfStringView('/' + command).toUtf32(); + _InputString = _InputString; _CursorPos = (sint32)_InputString.length(); _CursorAtPreviousLineEnd = false; triggerOnChangeAH(); @@ -1260,7 +1336,7 @@ namespace NLGUI // else delete last character else if(_InputString.size () > 0 && _CursorPos != 0) { - ucstring::iterator it = _InputString.begin() + (_CursorPos - 1); + ::u32string::iterator it = _InputString.begin() + (_CursorPos - 1); _InputString.erase(it); -- _CursorPos; _CursorAtPreviousLineEnd = false; @@ -1300,7 +1376,7 @@ namespace NLGUI default: break; } // update the text - setInputString(_InputString); + setInputStringRef(_InputString); // if event of type char or string, consider handle all of them if( rEDK.getKeyEventType()==NLGUI::CEventDescriptorKey::keychar || rEDK.getKeyEventType()==NLGUI::CEventDescriptorKey::keystring ) @@ -1430,16 +1506,14 @@ namespace NLGUI { if (_ViewText) { - ucstring usTmp; + std::string usTmp; if (_EntryType == Password) { - usTmp = _Prompt; - for (uint32 i = 0; i < _InputString.size(); ++i) - usTmp += "*"; + usTmp = CUtfStringView(_Prompt + ::u32string(_InputString.size(), 0x2022)).toUtf8(); } else { - usTmp = _Prompt + _InputString; + usTmp = CUtfStringView(_Prompt + _InputString).toUtf8(); } _ViewText->setText (usTmp); } @@ -1576,13 +1650,13 @@ namespace NLGUI _ViewText->setParent( this ); _ViewText->setIdRecurse( "edit_text" ); - _ViewText->setHardText( "" ); + _ViewText->setTextLocalized( "", false ); _ViewText->setPosRef( Hotspot_ML ); _ViewText->setParentPosRef( Hotspot_ML ); addView( _ViewText ); sint32 w,h; - w = std::max( sint32( _ViewText->getFontWidth() * _ViewText->getText().size() ), getW() ); + w = std::max( sint32( _ViewText->getFontWidth() * CUtfStringView(_ViewText->getText()).count() ), getW() ); h = std::max( sint32( _ViewText->getFontHeight() ), getH() ); setH( h ); @@ -1622,7 +1696,18 @@ namespace NLGUI // ---------------------------------------------------------------------------- - void CGroupEditBox::setInputString(const ucstring &str) + void CGroupEditBox::setPrompt(const std::string &s) + { + _Prompt = CUtfStringView(s).toUtf32(); + } + + + // ---------------------------------------------------------------------------- + void CGroupEditBox::setInputString(const std::string &str) + { + setInputStringRef(CUtfStringView(str).toUtf32()); + } + void CGroupEditBox::setInputStringRef(const ::u32string &str) { _InputString = str; if (_CursorPos > (sint32) str.length()) @@ -1638,18 +1723,17 @@ namespace NLGUI // *************************************************************************** - void CGroupEditBox::setDefaultInputString(const ucstring &str) + void CGroupEditBox::setDefaultInputString(const std::string &str) { _DefaultInputString= true; setInputString(str); } - // *************************************************************************** sint32 CGroupEditBox::getInputStringAsInt() const { sint32 value; - fromString(_InputString.toString(), value); + fromString(getInputString(), value); return value; } @@ -1663,7 +1747,7 @@ namespace NLGUI sint64 CGroupEditBox::getInputStringAsInt64() const { sint64 value; - fromString(_InputString.toString(), value); + fromString(getInputString(), value); return value; } @@ -1677,7 +1761,7 @@ namespace NLGUI float CGroupEditBox::getInputStringAsFloat() const { float value; - fromString(_InputString.toString(), value); + fromString(getInputString(), value); return value; } @@ -1691,8 +1775,8 @@ namespace NLGUI // *************************************************************************** void CGroupEditBox::cutSelection() { - sint32 minPos= min(_CursorPos, _SelectCursorPos); - sint32 maxPos= max(_CursorPos, _SelectCursorPos); + ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos); + ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos); // cut the selection if(!_InputString.empty()) { @@ -1704,12 +1788,12 @@ namespace NLGUI } // *************************************************************************** - ucstring CGroupEditBox::getSelection() + std::string CGroupEditBox::getSelection() { - sint32 minPos= min(_CursorPos, _SelectCursorPos); - sint32 maxPos= max(_CursorPos, _SelectCursorPos); + ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos); + ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos); // get the selection - return _InputString.substr(minPos, maxPos-minPos); + return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf8(); } @@ -1736,42 +1820,40 @@ namespace NLGUI } // *************************************************************************** - void CGroupEditBox::setInputStringAsStdString(const std::string &str) + std::string CGroupEditBox::getPrompt() const { - setInputString(ucstring(str)); + return NLMISC::CUtfStringView(_Prompt).toUtf8(); } // *************************************************************************** - std::string CGroupEditBox::getInputStringAsStdString() const + std::string CGroupEditBox::getInputString() const { - std::string result; - _InputString.toString(result); - return result; + return NLMISC::CUtfStringView(_InputString).toUtf8(); } +#ifdef RYZOM_LUA_UCSTRING // *************************************************************************** - void CGroupEditBox::setInputStringAsUtf8(const std::string &str) + void CGroupEditBox::setInputStringAsUtf16(const ucstring &str) { - ucstring tmp; - tmp.fromUtf8(str); - setInputString(tmp); + setInputStringAsUtf32(CUtfStringView(str).toUtf32()); } // *************************************************************************** - std::string CGroupEditBox::getInputStringAsUtf8() const + ucstring CGroupEditBox::getInputStringAsUtf16() const { - return _InputString.toUtf8(); + return CUtfStringView(_InputString).toUtf16(); } +#endif // *************************************************************************** - 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 - setInputString((ucchar) '/' + command); + setInputString('/' + command); if (execute) { // stop selection @@ -1826,18 +1908,35 @@ namespace NLGUI // *************************************************************************** void CGroupEditBox::serialConfig(NLMISC::IStream &f) { - f.serialVersion(0); + uint version = f.serialVersion(1); if(_DefaultInputString) // Don't want to save the default input { _DefaultInputString= false; _InputString.clear(); } - f.serial(_InputString); + if (version < 1) + { + ucstring str; // Compatibility + if (!f.isReading()) + str = CUtfStringView(_InputString).toUtf16(); + f.serial(str); + if (f.isReading()) + _InputString = CUtfStringView(str).toUtf32(); + } + else + { + std::string str; + if (!f.isReading()) + str = CUtfStringView(_InputString).toUtf8(); + f.serial(str); + if (f.isReading()) + _InputString = CUtfStringView(str).toUtf32(); + } f.serial(_CursorPos); f.serial(_PrevNumLine); if (f.isReading()) { - setInputString(_InputString); + setInputStringRef(_InputString); } // serial selection @@ -1854,7 +1953,7 @@ namespace NLGUI void CGroupEditBox::onQuit() { // clear the text and restore backup pos before final save - setInputString(ucstring("")); + setInputStringRef(::u32string()); _CurrSelection = NULL; } @@ -1862,7 +1961,7 @@ namespace NLGUI void CGroupEditBox::onLoadConfig() { // config is not saved when there's an empty string, so restore that default state. - setInputString(ucstring("")); + setInputStringRef(::u32string()); _CurrSelection = NULL; _PrevNumLine = 1; } @@ -1877,7 +1976,7 @@ namespace NLGUI if (_DefaultInputString) { _DefaultInputString= false; - setInputString(ucstring()); + setInputStringRef(::u32string()); } _CanRedo = false; _CanUndo = false; diff --git a/nel/src/gui/group_header.cpp b/nel/src/gui/group_header.cpp index 03d688921..2671c2a62 100644 --- a/nel/src/gui/group_header.cpp +++ b/nel/src/gui/group_header.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -161,8 +162,14 @@ namespace NLGUI // ... limitingParent = limitingParent->getParent(); } - - getParentContainer()->setW(totalWidth + getParentContainer()->getWReal() - limitingParent->getWReal()); + if (limitingParent) + { + getParentContainer()->setW(totalWidth + getParentContainer()->getWReal() - limitingParent->getWReal()); + } + else + { + nlwarning("No limiting parent for width"); + } } // resize H @@ -178,9 +185,14 @@ namespace NLGUI CInterfaceGroup *limitingParent = colEnclosing->getParent(); while (limitingParent && (limitingParent->getResizeFromChildH() || dynamic_cast(limitingParent))) limitingParent = limitingParent->getParent(); - - nlassert(limitingParent); - getParentContainer()->setH(col->getH() + getParentContainer()->getHReal() - limitingParent->getHReal()); + if (limitingParent) + { + getParentContainer()->setH(col->getH() + getParentContainer()->getHReal() - limitingParent->getHReal()); + } + else + { + nlwarning("No limiting parent for height"); + } } } } diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 50b381a3c..6694200bf 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2019 Jan BOON (Kaetemi) +// Copyright (C) 2019-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -27,6 +27,7 @@ #include "nel/misc/types_nl.h" #include "nel/misc/rgba.h" #include "nel/misc/algo.h" +#include "nel/misc/utf_string_view.h" #include "nel/gui/libwww.h" #include "nel/gui/group_html.h" #include "nel/gui/group_list.h" @@ -88,7 +89,7 @@ namespace NLGUI // Return URL with https is host is in HSTS list static std::string upgradeInsecureUrl(const std::string &url) { - if (toLower(url.substr(0, 7)) != "http://") { + if (toLowerAscii(url.substr(0, 7)) != "http://") { return url; } @@ -135,7 +136,7 @@ namespace NLGUI if (pos == std::string::npos) return; - std::string key = toLower(header.substr(0, pos)); + std::string key = toLowerAscii(header.substr(0, pos)); if (pos != std::string::npos) { HeadersRecv[key] = header.substr(pos + 2); @@ -184,7 +185,7 @@ namespace NLGUI bool hasHSTSHeader() { // ignore header if not secure connection - if (toLower(Url.substr(0, 8)) != "https://") + if (toLowerAscii(Url.substr(0, 8)) != "https://") { return false; } @@ -551,7 +552,7 @@ namespace NLGUI LOG_DL("curl easy handle %p created for '%s'", curl, download.url.c_str()); // https:// - if (toLower(download.url.substr(0, 8)) == "https://") + if (toLowerAscii(download.url.substr(0, 8)) == "https://") { // if supported, use custom SSL context function to load certificates NLWEB::CCurlCertificates::useCertificates(curl); @@ -1033,7 +1034,7 @@ namespace NLGUI // *************************************************************************** - void CGroupHTML::addText (const char * buf, int len) + void CGroupHTML::addText (const char *buf, int len) { if (_Browsing) { @@ -1041,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; igetText().empty() && *(_CurrentViewLink->getText().rbegin()) == (ucchar) '\n'; + bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n'; bool sameShadow = style.TextShadow.Enabled && _CurrentViewLink->getShadow(); if (sameShadow && style.TextShadow.Enabled) { @@ -2887,7 +2886,7 @@ namespace NLGUI ctrlButton->setModulateGlobalColorAll (false); // Translate the tooltip - ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(getLinkTitle())); + ctrlButton->setDefaultContextHelp(getLinkTitle()); ctrlButton->setText(tmpStr); // empty url / button disabled bool disabled = string(getLink()).empty(); @@ -2967,7 +2966,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) @@ -3233,7 +3232,7 @@ namespace NLGUI } else { - ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(tooltip)); + ctrlButton->setDefaultContextHelp(tooltip); //ctrlButton->setOnContextHelp(string(tooltip)); } @@ -3305,11 +3304,11 @@ namespace NLGUI // *************************************************************************** - ucchar CGroupHTML::getLastChar() const + u32char CGroupHTML::getLastChar() const { if (_CurrentViewLink) { - const ucstring &str = _CurrentViewLink->getText(); + ::u32string str = CUtfStringView(_CurrentViewLink->getText()).toUtf32(); // FIXME: Optimize reverse UTF iteration if (!str.empty()) return str[str.length()-1]; } @@ -3401,7 +3400,7 @@ namespace NLGUI // *************************************************************************** - void CGroupHTML::setTitle (const ucstring &title) + void CGroupHTML::setContainerTitle (const std::string &title) { CInterfaceElement *parent = getParent(); if (parent) @@ -3411,7 +3410,7 @@ namespace NLGUI CGroupContainer *container = dynamic_cast(parent); if (container) { - container->setUCTitle (title); + container->setTitle(title); } } } @@ -3419,21 +3418,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); + setContainerTitle(_TitleString); } std::string CGroupHTML::getTitle() const { - return _TitleString.toUtf8(); + return _TitleString; }; // *************************************************************************** @@ -3443,7 +3439,7 @@ namespace NLGUI result = url; string tmp; - if (toLower(result).find("file:") == 0 && result.size() > 5) + if (toLowerAscii(result).find("file:") == 0 && result.size() > 5) { result = result.substr(5, result.size()-5); } @@ -3464,7 +3460,7 @@ namespace NLGUI { // Normalize the path if (isUrl) - //result = "file:"+toLower(CPath::standardizePath (CPath::getFullPath (CFile::getPath(result)))+CFile::getFilename(result));*/ + //result = "file:"+toLowerAscii(CPath::standardizePath (CPath::getFullPath (CFile::getPath(result)))+CFile::getFilename(result));*/ result = "file:/"+tmp; else result = tmp; @@ -3698,7 +3694,7 @@ namespace NLGUI { // Text area ? bool addEntry = false; - ucstring entryData; + string entryData; if (form.Entries[i].TextArea) { // Get the edit box view @@ -3726,7 +3722,7 @@ namespace NLGUI else if (form.Entries[i].ComboBox) { CDBGroupComboBox *cb = form.Entries[i].ComboBox; - entryData.fromUtf8(form.Entries[i].SelectValues[cb->getSelection()]); + entryData = form.Entries[i].SelectValues[cb->getSelection()]; addEntry = true; } else if (form.Entries[i].SelectBox) @@ -3757,7 +3753,7 @@ namespace NLGUI // Add this entry if (addEntry) { - formfields.add(form.Entries[i].Name, CI18N::encodeUTF8(entryData)); + formfields.add(form.Entries[i].Name, entryData); } } @@ -3789,7 +3785,7 @@ namespace NLGUI updateRefreshButton(); std::string filename; - if (toLower(uri).find("file:/") == 0) + if (toLowerAscii(uri).find("file:/") == 0) { filename = uri.substr(6, uri.size() - 6); } @@ -3859,7 +3855,7 @@ namespace NLGUI } // https:// - if (toLower(url.substr(0, 8)) == "https://") + if (toLowerAscii(url.substr(0, 8)) == "https://") { // if supported, use custom SSL context function to load certificates NLWEB::CCurlCertificates::useCertificates(curl); @@ -4180,7 +4176,8 @@ namespace NLGUI } else { - renderHtmlString(content); + // Sanitize downloaded HTML UTF-8 encoding, and render + renderHtmlString(CUtfStringView(content).toUtf8(true)); } } @@ -4684,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()) { @@ -4716,7 +4711,7 @@ namespace NLGUI const char *funcName = "addString"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); - addString(ucstring(ls.toString(1))); + addString(ls.toString(1)); return 0; } @@ -4944,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; @@ -4954,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; @@ -4963,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; isetDefaultContextHelp(ucstring(tooltip)); + ctrlButton->setDefaultContextHelp(tooltip); } } - ctrlButton->setText(ucstring::makeFromUtf8(value)); + ctrlButton->setText(value); setTextButtonStyle(ctrlButton, _Style.Current); } @@ -5562,8 +5558,7 @@ namespace NLGUI { if (!_Paragraph || _Paragraph->getNumChildren() == 0) { - ucstring tmp("\n"); - addString(tmp); + addString("\n"); } else { @@ -5863,7 +5858,7 @@ namespace NLGUI // Build the form CGroupHTML::CForm form; // id check is case sensitive and auto id's are uppercase - form.id = toLower(trim(elm.getAttribute("id"))); + form.id = toLowerAscii(trim(elm.getAttribute("id"))); if (form.id.empty()) { form.id = toString("FORM%d", _Forms.size()); @@ -6085,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; @@ -6120,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") { @@ -6190,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; @@ -6223,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 @@ -6294,7 +6286,7 @@ namespace NLGUI { fromString(httpContent.substr(0, pos), _NextRefreshTime); - pos = toLower(httpContent).find("url="); + pos = toLowerAscii(httpContent).find("url="); if (pos != string::npos) _RefreshUrl = getAbsoluteUrl(httpContent.substr(pos + 4)); } @@ -6428,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 diff --git a/nel/src/gui/group_list.cpp b/nel/src/gui/group_list.cpp index b49eed7cc..b21784836 100644 --- a/nel/src/gui/group_list.cpp +++ b/nel/src/gui/group_list.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -518,11 +519,10 @@ namespace NLGUI { _HardText = std::string( (const char*)ptr ); const char *propPtr = ptr; - ucstring Text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - - addTextChild(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addTextChild(CI18N::get(propPtr)); + else + addTextChild(propPtr); } else { @@ -540,7 +540,7 @@ namespace NLGUI // ---------------------------------------------------------------------------- - void CGroupList::addTextChild(const ucstring& line, bool multiLine /*= true*/) + void CGroupList::addTextChild(const std::string& line, bool multiLine /*= true*/) { const string elid = _Id + ":el" + toString(_IdCounter); ++_IdCounter; CViewText *view= new CViewText (elid, string(""), _Templ.getFontSize(), _Templ.getColor(), _Templ.getShadow()); @@ -559,7 +559,7 @@ namespace NLGUI // ---------------------------------------------------------------------------- - void CGroupList::addTextChild(const ucstring& line, const CRGBA& textColor, bool multiLine /*= true*/) + void CGroupList::addTextChild(const std::string& line, const CRGBA& textColor, bool multiLine /*= true*/) { const string elid = _Id + ":el" + toString(_IdCounter); ++_IdCounter; CViewText *view= new CViewText (elid, string(""), _Templ.getFontSize(), _Templ.getColor(), _Templ.getShadow()); @@ -1286,12 +1286,18 @@ namespace NLGUI // ---------------------------------------------------------------------------- int CGroupList::luaAddTextChild(CLuaState &ls) { - CLuaIHM::checkArgCount(ls, "addTextChild", 1); - ucstring text; + const char *funcName = "addTextChild"; + CLuaIHM::checkArgCount(ls, funcName, 1); +#ifdef RYZOM_LUA_UCSTRING + ucstring text; // Compatibility if(CLuaIHM::pop(ls, text)) { - addTextChild(text); + addTextChild(text.toUtf8()); } +#else + CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); + addTextChild(ls.toString(1)); +#endif return 0; } @@ -1306,15 +1312,13 @@ namespace NLGUI CLuaIHM::checkArgType(ls, funcName, 4, LUA_TNUMBER); CLuaIHM::checkArgType(ls, funcName, 5, LUA_TNUMBER); string text = ls.toString(1); - ucstring ucText; - ucText.fromUtf8(text); uint r = (uint) ls.toInteger(2); uint g = (uint) ls.toInteger(3); uint b = (uint) ls.toInteger(4); uint a = (uint) ls.toInteger(5); - addTextChild(ucText, CRGBA(r, g, b, a)); + addTextChild(text, CRGBA(r, g, b, a)); return 0; } diff --git a/nel/src/gui/group_menu.cpp b/nel/src/gui/group_menu.cpp index 3fc8d0bbb..41c153c36 100644 --- a/nel/src/gui/group_menu.cpp +++ b/nel/src/gui/group_menu.cpp @@ -3,7 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2015 Jan BOON (Kaetemi) +// Copyright (C) 2014-2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -275,7 +275,7 @@ namespace NLGUI if (stricmp((char*)cur->name, "action") == 0) { string strId, strAh, strParams, strCond, strTexture; - ucstring ucstrName; + string ucstrName; if (id) strId = (const char*)id; CXMLAutoPtr name((const char*) xmlGetProp (cur, (xmlChar*)"name")); @@ -283,9 +283,10 @@ namespace NLGUI if (name) { const char *ptrName = (const char*)name; - ucstrName = ucstring(ptrName); - if ((strlen(ptrName)>2) && (ptrName[0] == 'u') && (ptrName[1] == 'i')) - ucstrName = CI18N::get (ptrName); + if (NLMISC::startsWith(ptrName, "ui")) + ucstrName = CI18N::get(ptrName); + else + ucstrName = ptrName; } CXMLAutoPtr ah((const char*) xmlGetProp (cur, (xmlChar*)"handler")); @@ -1214,7 +1215,7 @@ namespace NLGUI // ------------------------------------------------------------------------------------------------ - CViewTextMenu* CGroupSubMenu::addLine (const ucstring &name, const std::string &ah, + CViewTextMenu* CGroupSubMenu::addLine (const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id, const std::string &cond, const std::string &texture, bool checkable /*= false*/, bool checked /*= false*/, bool formatted /*= false */ @@ -1295,7 +1296,7 @@ namespace NLGUI return pV; } - CViewTextMenu* CGroupSubMenu::addLineAtIndex(uint index, const ucstring &name, const std::string &ah, + CViewTextMenu* CGroupSubMenu::addLineAtIndex(uint index, const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id /*=""*/, const std::string &cond /*=std::string()*/, const std::string &texture, bool checkable /*= false*/, bool checked /*= false*/, bool formatted /*= false */ @@ -1822,8 +1823,13 @@ namespace NLGUI const char *funcName = "getLineId"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); - std::string id = getLineId((uint) ls.toInteger(1)); +#ifdef RYZOM_LUA_UCSTRING + ucstring id = getLineId((uint) ls.toInteger(1)); // Compatibility CLuaIHM::push(ls, id); +#else + std::string id = getLineId((uint)ls.toInteger(1)); + ls.push(id); +#endif return 1; } @@ -1852,13 +1858,21 @@ namespace NLGUI { const char *funcName = "addLine"; CLuaIHM::checkArgCount(ls, funcName, 4); +#ifdef RYZOM_LUA_UCSTRING CLuaIHM::checkArgTypeUCString(ls, funcName, 1); +#else + CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); +#endif CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING); - ucstring arg1; +#ifdef RYZOM_LUA_UCSTRING + ucstring arg1; // Compatibility nlverify(CLuaIHM::getUCStringOnStack(ls, 1, arg1)); - addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4)); + addLine(arg1.toUtf8(), ls.toString(2), ls.toString(3), ls.toString(4)); +#else + addLine(ls.toString(1), ls.toString(2), ls.toString(3), ls.toString(4)); +#endif return 0; } @@ -1867,14 +1881,22 @@ namespace NLGUI { const char *funcName = "addIconLine"; CLuaIHM::checkArgCount(ls, funcName, 5); +#ifdef RYZOM_LUA_UCSTRING CLuaIHM::checkArgTypeUCString(ls, funcName, 1); +#else + CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); +#endif CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING); - ucstring arg1; +#ifdef RYZOM_LUA_UCSTRING + ucstring arg1; // Compatibility nlverify(CLuaIHM::getUCStringOnStack(ls, 1, arg1)); - addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4), string(), ls.toString(5)); + addLine(arg1.toUtf8(), ls.toString(2), ls.toString(3), ls.toString(4), string(), ls.toString(5)); +#else + addLine(ls.toString(1), ls.toString(2), ls.toString(3), ls.toString(4), string(), ls.toString(5)); +#endif return 0; } @@ -1884,13 +1906,21 @@ namespace NLGUI const char *funcName = "addLineAtIndex"; CLuaIHM::checkArgCount(ls, funcName, 5); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); +#ifdef RYZOM_LUA_UCSTRING CLuaIHM::checkArgTypeUCString(ls, funcName, 2); +#else + CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING); +#endif CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING); +#ifdef RYZOM_LUA_UCSTRING ucstring arg2; nlverify(CLuaIHM::getUCStringOnStack(ls, 2, arg2)); - addLineAtIndex((uint) ls.toInteger(1), arg2, ls.toString(3), ls.toString(4), ls.toString(5)); + addLineAtIndex((uint) ls.toInteger(1), arg2.toUtf8(), ls.toString(3), ls.toString(4), ls.toString(5)); +#else + addLineAtIndex((uint)ls.toInteger(1), ls.toString(2), ls.toString(3), ls.toString(4), ls.toString(5)); +#endif return 0; } @@ -2531,25 +2561,7 @@ namespace NLGUI } // ------------------------------------------------------------------------------------------------ - void CGroupMenu::addLine (const string &name, const string &ah, const string ¶ms, - const std::string &id/*=std::string()*/, - const std::string &cond /*= std::string()*/, const std::string &texture, - bool checkable /*= false*/, bool checked /*= false*/ - ) - { - if (_RootMenu == NULL) - { - _RootMenu = new CGroupSubMenu(CViewText::TCtorParam()); - _RootMenu->_GroupMenu = this; - _RootMenu->setSerializable( false ); - addGroup (_RootMenu); - } - - _RootMenu->addLine (name, ah, params, id, cond, texture, checkable, checked, _Formatted); - } - - // ------------------------------------------------------------------------------------------------ - void CGroupMenu::addLine(const ucstring &name, const std::string &ah, const std::string ¶ms, + void CGroupMenu::addLine(const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id /* = std::string()*/, const std::string &cond /*= std::string()*/, const std::string &texture, bool checkable /*= false*/, bool checked /*= false*/ @@ -2565,7 +2577,7 @@ namespace NLGUI _RootMenu->addLine (name, ah, params, id, cond, texture, checkable, checked, _Formatted); } // ------------------------------------------------------------------------------------------------ - void CGroupMenu::addLineAtIndex(uint index, const ucstring &name, const std::string &ah, + void CGroupMenu::addLineAtIndex(uint index, const std::string &name, const std::string &ah, const std::string ¶ms, const std::string &id /*=std::string()*/, const std::string &cond /*=std::string()*/, const std::string &texture, bool checkable /*=false*/, bool checked /*=false*/) diff --git a/nel/src/gui/group_paragraph.cpp b/nel/src/gui/group_paragraph.cpp index 9424c0218..4ca13c8ae 100644 --- a/nel/src/gui/group_paragraph.cpp +++ b/nel/src/gui/group_paragraph.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -476,11 +477,10 @@ namespace NLGUI { _HardText = std::string( (const char*)ptr ); const char *propPtr = ptr; - ucstring Text = ucstring(propPtr); - if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i')) - Text = CI18N::get (propPtr); - - addTextChild(Text); + if (NLMISC::startsWith(propPtr, "ui")) + addTextChild(CI18N::get(propPtr)); + else + addTextChild(propPtr); } else { @@ -496,7 +496,7 @@ namespace NLGUI } // ---------------------------------------------------------------------------- - void CGroupParagraph::addTextChild(const ucstring& line, bool multiLine /*= true*/) + void CGroupParagraph::addTextChild(const std::string& line, bool multiLine /*= true*/) { const string elid = _Id + ":el" + toString(_IdCounter); ++_IdCounter; CViewText *view= new CViewText (elid, string(""), _Templ.getFontSize(), _Templ.getColor(), _Templ.getShadow()); @@ -514,7 +514,7 @@ namespace NLGUI // ---------------------------------------------------------------------------- - void CGroupParagraph::addTextChild(const ucstring& line, const CRGBA& textColor, bool multiLine /*= true*/) + void CGroupParagraph::addTextChild(const std::string& line, const CRGBA& textColor, bool multiLine /*= true*/) { const string elid = _Id + ":el" + toString(_IdCounter); ++_IdCounter; CViewText *view= new CViewText (elid, string(""), _Templ.getFontSize(), _Templ.getColor(), _Templ.getShadow()); @@ -731,7 +731,7 @@ namespace NLGUI if (viewText) { changeLine = viewText->getNumLine() > 1; - if (!viewText->getText().empty() && *(viewText->getText().rbegin()) == (ucchar) '\n') + if (!viewText->getText().empty() && *(viewText->getText().rbegin()) == '\n') { changeLine = true; } diff --git a/nel/src/gui/group_tree.cpp b/nel/src/gui/group_tree.cpp index 83c080b5e..44636f1d6 100644 --- a/nel/src/gui/group_tree.cpp +++ b/nel/src/gui/group_tree.cpp @@ -3,6 +3,7 @@ // // This source file has been modified by the following contributors: // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) +// Copyright (C) 2020 Jan BOON (Kaetemi) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -306,9 +307,10 @@ namespace NLGUI if (name) { const char *ptrName = (const char*)name; - Text = ucstring(ptrName); - if ((strlen(ptrName)>2) && (ptrName[0] == 'u') && (ptrName[1] == 'i')) - Text = CI18N::get (ptrName); + if (NLMISC::startsWith(ptrName, "ui")) + Text = CI18N::get(ptrName); + else + Text = ptrName; } CXMLAutoPtr color((const char*) xmlGetProp (cur, (xmlChar*)"color")); diff --git a/nel/src/gui/html_parser.cpp b/nel/src/gui/html_parser.cpp index 3d7303706..de1a0e4d9 100644 --- a/nel/src/gui/html_parser.cpp +++ b/nel/src/gui/html_parser.cpp @@ -89,7 +89,7 @@ namespace NLGUI } } - parent.Children.push_back(CHtmlElement(CHtmlElement::ELEMENT_NODE, toLower((const char*)node->name))); + parent.Children.push_back(CHtmlElement(CHtmlElement::ELEMENT_NODE, toLowerAscii((const char*)node->name))); CHtmlElement &elm = parent.Children.back(); elm.ID = element_number; elm.parent = &parent; @@ -109,7 +109,7 @@ namespace NLGUI elm.Attributes.clear(); for (xmlAttr *cur_attr = node->properties; cur_attr; cur_attr = cur_attr->next) { - std::string key(toLower((const char *)(cur_attr->name))); + std::string key(toLowerAscii((const char *)(cur_attr->name))); std::string value; if (cur_attr->children) { @@ -124,7 +124,7 @@ namespace NLGUI NLMISC::splitString(elm.getAttribute("class"), " ", parts); for(uint i = 0; i for ingame browser @@ -154,7 +154,7 @@ namespace NLGUI bool useStyle = true; if (elm.hasAttribute("media")) { - std::string media = trim(toLower(elm.Attributes["media"])); + std::string media = trim(toLowerAscii(elm.Attributes["media"])); useStyle = media.empty() || media.find("all") != std::string::npos || media.find("screen") != std::string::npos; //