Merge branch 'develop' into ryzomclassic-develop

ryzomclassic-develop
kaetemi 4 years ago
commit 2295769ad5

@ -262,10 +262,10 @@ public:
virtual NLMISC::IEventEmitter *getEventEmitter() = 0; virtual NLMISC::IEventEmitter *getEventEmitter() = 0;
/// Copy a string to system clipboard. /// 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. /// 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; virtual uint8 getBitPerPixel() = 0;

@ -558,10 +558,10 @@ public:
// @} // @}
// Copy a string to system clipboard. // 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. // Paste a string from system clipboard.
virtual bool pasteTextFromClipboard(ucstring &text); virtual bool pasteTextFromClipboard(std::string &text);
virtual uint64 getSwapBufferCounter(); virtual uint64 getSwapBufferCounter();

@ -835,10 +835,10 @@ public:
/// \name Clipboard management /// \name Clipboard management
// @{ // @{
// Copy a string to system clipboard. // 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. // Paste a string from system clipboard.
virtual bool pasteTextFromClipboard(ucstring &text) =0; virtual bool pasteTextFromClipboard(std::string &text) =0;
// @} // @}
public: public:

@ -60,7 +60,7 @@ public:
keydown = 0, // a key has been press down. The key value is stored as a TKey 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 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 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 unknown, // uninitialized event
}; };
CEventDescriptorKey() : _KeyEvent(unknown), _CtrlState(false), _ShiftState(false), _AltState(false), _Char(0) CEventDescriptorKey() : _KeyEvent(unknown), _CtrlState(false), _ShiftState(false), _AltState(false), _Char(0)

@ -248,13 +248,6 @@ namespace NLGUI
// Get the header color draw. NB: depends if grayed, and if active. // Get the header color draw. NB: depends if grayed, and if active.
NLMISC::CRGBA getDrawnHeaderColor () const; NLMISC::CRGBA getDrawnHeaderColor () const;
std::string getTitleRaw () const;
void setTitleRaw (const std::string &title);
std::string getTitleOpenedRaw () const;
void setTitleOpenedRaw (const std::string &title);
std::string getTitleClosedRaw () const;
void setTitleClosedRaw (const std::string &title);
ucstring getUCTitleOpened () const; ucstring getUCTitleOpened () const;
void setUCTitleOpened (const ucstring &title); void setUCTitleOpened (const ucstring &title);
ucstring getUCTitleClosed () const; ucstring getUCTitleClosed () const;
@ -295,10 +288,6 @@ namespace NLGUI
REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened); REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened);
REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed); REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed);
REFLECT_STRING("title_raw", getTitleRaw, setTitleRaw);
REFLECT_STRING("title_opened_raw", getTitleOpenedRaw, setTitleOpenedRaw);
REFLECT_STRING("title_closed_raw", getTitleClosedRaw, setTitleClosedRaw);
REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // FIXME: Lua UTF-8 REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // FIXME: Lua UTF-8
REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // FIXME: Lua UTF-8 REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // FIXME: Lua UTF-8
REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // FIXME: Lua UTF-8 REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // FIXME: Lua UTF-8
@ -315,6 +304,8 @@ namespace NLGUI
REFLECT_BOOL("lockable", isLockable, setLockable); REFLECT_BOOL("lockable", isLockable, setLockable);
REFLECT_BOOL("locked", isLocked, setLocked); REFLECT_BOOL("locked", isLocked, setLocked);
REFLECT_BOOL("localize", isLocalize, setLocalize);
REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive); REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive);
REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled); REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled);
REFLECT_EXPORT_END REFLECT_EXPORT_END
@ -377,7 +368,7 @@ namespace NLGUI
bool isActiveSavable() const { return _ActiveSavable; } bool isActiveSavable() const { return _ActiveSavable; }
bool isLocalize() const { return _Localize; } bool isLocalize() const { return _Localize; }
void setLocalize(bool localize) { _Localize = localize; } void setLocalize(bool localize);
void setPopupX(sint32 x) { _PopupX = x; } void setPopupX(sint32 x) { _PopupX = x; }
void setPopupY(sint32 y) { _PopupY = y; } void setPopupY(sint32 y) { _PopupY = y; }
@ -649,6 +640,9 @@ namespace NLGUI
TTileClass convertTitleClass(const char *ptr); TTileClass convertTitleClass(const char *ptr);
void setTitledOpenedViewText();
void setTitledClosedViewText();
static COptionsContainerMove *getMoveOptions(); static COptionsContainerMove *getMoveOptions();
COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used

@ -140,7 +140,7 @@ namespace NLGUI
// Paste the selection into buffer // Paste the selection into buffer
void paste(); void paste();
// Write the string into buffer // Write the string into buffer
void writeString(const ucstring &str, bool replace = true, bool atEnd = true); // UTF-16 because of Clipboard implementation 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) // Expand the expression (true if there was a '/' at the start of the line)
bool expand(); bool expand();
@ -299,9 +299,9 @@ namespace NLGUI
void handleEventString(const NLGUI::CEventDescriptorKey &event); void handleEventString(const NLGUI::CEventDescriptorKey &event);
void setup(); void setup();
void triggerOnChangeAH(); void triggerOnChangeAH();
void appendStringFromClipboard(const ucstring &str); // UTF-16 because of Clipboard implementation void appendStringFromClipboard(const std::string &str);
ucstring getSelection(); // UTF-16 because of Clipboard implementation std::string getSelection();
static CGroupEditBox *_MenuFather; static CGroupEditBox *_MenuFather;

@ -352,7 +352,7 @@ namespace NLGUI
// Set the title // Set the title
void setTitle (const std::string &title); void setTitle (const std::string &title);
std::string getTitle() const; std::string getTitle() const;
void setTitleRaw (const std::string &title); void setContainerTitle (const std::string &title);
// Lookup a url in local file system // Lookup a url in local file system
bool lookupLocalFile (std::string &result, const char *url, bool isUrl); bool lookupLocalFile (std::string &result, const char *url, bool isUrl);

@ -21,7 +21,6 @@
#define STRING_CASE_H #define STRING_CASE_H
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#include "nel/misc/ucstring.h"
namespace NLGUI namespace NLGUI
{ {

@ -84,7 +84,7 @@ namespace NLGUI
/// Set /// Set
void setText(const std::string &text); void setText(const std::string &text); //< Not localized. Use setHardText to localize strings starting with "ui". TODO: Add a Localize flag, like title in group container. HardText then simply sets localize to true.
void setTextAsUtf16 (const ucstring &text); void setTextAsUtf16 (const ucstring &text);
void setFontName (const std::string &name); void setFontName (const std::string &name);
void setFontSize (sint nFontSize, bool coef = true); void setFontSize (sint nFontSize, bool coef = true);
@ -178,7 +178,7 @@ namespace NLGUI
void getLineEndIndex(uint line, sint &index, bool &endOfPreviousLine) const; void getLineEndIndex(uint line, sint &index, bool &endOfPreviousLine) const;
std::string getHardText() const { return _HardText.empty() ? _Text : _HardText; } std::string getHardText() const { return _HardText.empty() ? _Text : _HardText; }
void setHardText (const std::string &ht); void setHardText (const std::string &ht); //< Localizes strings starting with "ui"
void setHardTextAsUtf16(const ucstring &ht); void setHardTextAsUtf16(const ucstring &ht);
std::string getColorAsString() const; std::string getColorAsString() const;
@ -262,8 +262,8 @@ namespace NLGUI
// width of the font in pixel. Just a Hint for tabing format (computed with '_') // width of the font in pixel. Just a Hint for tabing format (computed with '_')
float _FontWidth; float _FontWidth;
// strings to use when computing font size // strings to use when computing font size
::u32string _FontSizingChars; std::string _FontSizingChars;
::u32string _FontSizingFallback; std::string _FontSizingFallback;
// height of the font in pixel. // height of the font in pixel.
// use getFontHeight // use getFontHeight
float _FontHeight; float _FontHeight;

@ -48,8 +48,8 @@ public:
/// From IEventEmitter. This call submitEvents on all the emitters /// From IEventEmitter. This call submitEvents on all the emitters
virtual void submitEvents(CEventServer &server, bool allWindows); virtual void submitEvents(CEventServer &server, bool allWindows);
virtual bool copyTextToClipboard(const ucstring &text); virtual bool copyTextToClipboard(const std::string &text);
virtual bool pasteTextFromClipboard(ucstring &text); virtual bool pasteTextFromClipboard(std::string &text);
private: private:
typedef std::vector<std::pair<IEventEmitter *, bool> > TEmitterCont; typedef std::vector<std::pair<IEventEmitter *, bool> > TEmitterCont;

@ -49,10 +49,10 @@ public:
static bool updateProgressBar(uint value, uint total); static bool updateProgressBar(uint value, uint total);
/// Copy a string to system clipboard. /// 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. /// Paste a string from system clipboard.
static bool pasteTextFromClipboard(ucstring &text); static bool pasteTextFromClipboard(std::string &text);
/// Check if system supports unicode. /// Check if system supports unicode.
static bool supportUnicode(); static bool supportUnicode();

@ -4018,12 +4018,12 @@ void CDriverD3D::findNearestFullscreenVideoMode()
} }
} }
} }
bool CDriverD3D::copyTextToClipboard(const ucstring &text) bool CDriverD3D::copyTextToClipboard(const std::string &text)
{ {
return _EventEmitter.copyTextToClipboard(text); return _EventEmitter.copyTextToClipboard(text);
} }
bool CDriverD3D::pasteTextFromClipboard(ucstring &text) bool CDriverD3D::pasteTextFromClipboard(std::string &text)
{ {
return _EventEmitter.pasteTextFromClipboard(text); return _EventEmitter.pasteTextFromClipboard(text);
} }

@ -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); 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 copyTextToClipboard(const std::string &text);
virtual bool pasteTextFromClipboard(ucstring &text); virtual bool pasteTextFromClipboard(std::string &text);
public: public:
#ifdef NL_DEBUG #ifdef NL_DEBUG

@ -354,8 +354,8 @@ public:
return _win; return _win;
} }
virtual bool copyTextToClipboard(const ucstring &text); virtual bool copyTextToClipboard(const std::string &text);
virtual bool pasteTextFromClipboard(ucstring &text); virtual bool pasteTextFromClipboard(std::string &text);
virtual uint32 getAvailableVertexAGPMemory (); virtual uint32 getAvailableVertexAGPMemory ();
virtual uint32 getAvailableVertexVRAMMemory (); virtual uint32 getAvailableVertexVRAMMemory ();

@ -3020,12 +3020,12 @@ void CDriverGL::setupApplicationMenu()
} }
#endif #endif
bool CDriverGL::copyTextToClipboard(const ucstring &text) bool CDriverGL::copyTextToClipboard(const std::string &text)
{ {
return _EventEmitter.copyTextToClipboard(text); return _EventEmitter.copyTextToClipboard(text);
} }
bool CDriverGL::pasteTextFromClipboard(ucstring &text) bool CDriverGL::pasteTextFromClipboard(std::string &text)
{ {
return _EventEmitter.pasteTextFromClipboard(text); return _EventEmitter.pasteTextFromClipboard(text);
} }

@ -547,6 +547,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
server->postEvent (charEvent); server->postEvent (charEvent);
#else #else
// FIXME: Convert locale to UTF-32
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++)
{ {
CEventChar *charEvent = new CEventChar ((u32char)(unsigned char)Text[i], getKeyButton(event.xbutton.state), this); CEventChar *charEvent = new CEventChar ((u32char)(unsigned char)Text[i], getKeyButton(event.xbutton.state), this);
@ -610,14 +611,13 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
else if (req.target == XA_STRING) else if (req.target == XA_STRING)
{ {
respond.xselection.property = req.property; 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()); 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) else if (req.target == XA_UTF8_STRING)
{ {
respond.xselection.property = req.property; 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*)_CopiedString.c_str(), _CopiedString.length());
XChangeProperty(req.display, req.requestor, respond.xselection.property, XA_UTF8_STRING, 8, PropModeReplace, (const unsigned char*)str.c_str(), str.length());
} }
else else
{ {
@ -710,6 +710,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
else if (target == XA_STRING) else if (target == XA_STRING)
{ {
// FIXME: Convert local to UTF-8 // FIXME: Convert local to UTF-8
// text = NLMISC::CUtfStringView(text).toAscii();
} }
else else
{ {
@ -767,7 +768,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
return true; return true;
} }
bool CUnixEventEmitter::copyTextToClipboard(const ucstring &text) bool CUnixEventEmitter::copyTextToClipboard(const std::string &text)
{ {
_CopiedString = text; _CopiedString = text;
@ -786,7 +787,7 @@ bool CUnixEventEmitter::copyTextToClipboard(const ucstring &text)
return true; return true;
} }
bool CUnixEventEmitter::pasteTextFromClipboard(ucstring &text) bool CUnixEventEmitter::pasteTextFromClipboard(std::string &text)
{ {
// check if we own the selection // check if we own the selection
if (_SelectionOwned) if (_SelectionOwned)

@ -66,12 +66,12 @@ public:
/** /**
* Copy a string to system clipboard. * 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. * Paste a string from system clipboard.
*/ */
virtual bool pasteTextFromClipboard(ucstring &text); virtual bool pasteTextFromClipboard(std::string &text);
void createIM(); void createIM();
void closeIM(); void closeIM();
@ -105,7 +105,7 @@ private:
XIC _ic; XIC _ic;
NL3D::IDriver* _driver; NL3D::IDriver* _driver;
CUnixEventServer _InternalServer; CUnixEventServer _InternalServer;
ucstring _CopiedString; std::string _CopiedString;
bool _SelectionOwned; bool _SelectionOwned;
}; };

@ -1971,12 +1971,12 @@ bool CDriverUser::setRenderTarget(class UTexture & uTex, uint32 x, uint32 y, uin
return result; return result;
} }
bool CDriverUser::copyTextToClipboard(const ucstring &text) bool CDriverUser::copyTextToClipboard(const std::string &text)
{ {
return _Driver->copyTextToClipboard(text); return _Driver->copyTextToClipboard(text);
} }
bool CDriverUser::pasteTextFromClipboard(ucstring &text) bool CDriverUser::pasteTextFromClipboard(std::string &text)
{ {
return _Driver->pasteTextFromClipboard(text); return _Driver->pasteTextFromClipboard(text);
} }

@ -751,9 +751,7 @@ namespace NLGUI
{ {
virtual void execute (CCtrlBase *pCaller, const std::string &params) virtual void execute (CCtrlBase *pCaller, const std::string &params)
{ {
ucstring s; if (!CViewRenderer::getInstance()->getDriver()->copyTextToClipboard(params))
s.fromUtf8(params);
if (!CViewRenderer::getInstance()->getDriver()->copyTextToClipboard(s))
{ {
nlwarning("Copy to clipboard failed: '%s'", params.c_str()); nlwarning("Copy to clipboard failed: '%s'", params.c_str());
} }

@ -3744,7 +3744,7 @@ namespace NLGUI
_TitleOpened->setY (pLayer->getValSInt32 ("title_offset_y")); _TitleOpened->setY (pLayer->getValSInt32 ("title_offset_y"));
} }
_TitleOpened->setFontSize (pLayer->getValSInt32 ("title_font_size")); _TitleOpened->setFontSize (pLayer->getValSInt32 ("title_font_size"));
if (_TitleClass==TitleText) _TitleOpened->setText (_TitleTextOpened); if (_TitleClass == TitleText) setTitledOpenedViewText();
_TitleOpened->setActive (_Opened); _TitleOpened->setActive (_Opened);
// Title when the container is closed // Title when the container is closed
@ -3796,7 +3796,7 @@ namespace NLGUI
_TitleClosed->setY (pLayer->getValSInt32 ("title_offset_y")); _TitleClosed->setY (pLayer->getValSInt32 ("title_offset_y"));
} }
_TitleClosed->setFontSize (pLayer->getValSInt32 ("title_font_size")); _TitleClosed->setFontSize (pLayer->getValSInt32 ("title_font_size"));
if (_TitleClass==TitleText) _TitleClosed->setText (_TitleTextClosed); if (_TitleClass == TitleText) setTitledClosedViewText();
_TitleClosed->setActive(!_Opened); _TitleClosed->setActive(!_Opened);
@ -3946,6 +3946,15 @@ namespace NLGUI
} }
} }
// ***************************************************************************
void CGroupContainer::setLocalize(bool localize)
{
_Localize = localize;
setTitledOpenedViewText();
setTitledClosedViewText();
invalidateCoords();
}
// *************************************************************************** // ***************************************************************************
std::string CGroupContainer::getTitle () const std::string CGroupContainer::getTitle () const
{ {
@ -3955,8 +3964,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitle (const std::string &title) void CGroupContainer::setTitle (const std::string &title)
{ {
if (_Localize) setTitleRaw (CI18N::get(title)); setTitleOpened(title);
else setTitleRaw (title); setTitleClosed(title);
} }
// *************************************************************************** // ***************************************************************************
@ -3968,8 +3977,9 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitleOpened (const std::string &title) void CGroupContainer::setTitleOpened (const std::string &title)
{ {
if (_Localize) setTitleOpenedRaw (CI18N::get(title)); _TitleTextOpened = title;
else setTitleOpenedRaw (title); setTitledOpenedViewText();
invalidateCoords();
} }
// *************************************************************************** // ***************************************************************************
@ -3980,88 +3990,70 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitleClosed (const std::string &title) void CGroupContainer::setTitleClosed (const std::string &title)
{
if (_Localize) setTitleClosedRaw (CI18N::get(title));
else setTitleClosedRaw (title);
}
// ***************************************************************************
void CGroupContainer::setTitleOpenedRaw(const std::string &title)
{
_TitleTextOpened = title;
if (_TitleOpened != NULL)
_TitleOpened->setText (title);
invalidateCoords();
}
// ***************************************************************************
void CGroupContainer::setTitleClosedRaw(const std::string &title)
{ {
_TitleTextClosed = title; _TitleTextClosed = title;
if (_TitleClosed != NULL) setTitledClosedViewText();
_TitleClosed->setText (_TitleTextClosed);
invalidateCoords(); invalidateCoords();
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setTitleRaw(const std::string &title) void CGroupContainer::setTitledOpenedViewText()
{ {
setTitleOpenedRaw(title); if (_TitleOpened != NULL)
setTitleClosedRaw(title); {
} if (_Localize && NLMISC::startsWith(_TitleTextOpened, "ui"))
_TitleOpened->setHardText(_TitleTextOpened);
// *************************************************************************** else
std::string CGroupContainer::getTitleRaw () const _TitleOpened->setText(_TitleTextOpened);
{ }
return getTitleOpened();
}
// ***************************************************************************
std::string CGroupContainer::getTitleOpenedRaw () const
{
return _TitleTextOpened;
} }
// *************************************************************************** // ***************************************************************************
std::string CGroupContainer::getTitleClosedRaw () const void CGroupContainer::setTitledClosedViewText()
{ {
return _TitleTextClosed; if (_TitleClosed != NULL)
{
if (_Localize && NLMISC::startsWith(_TitleTextClosed, "ui"))
_TitleClosed->setHardText(_TitleTextClosed);
else
_TitleClosed->setText(_TitleTextClosed);
}
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitleOpened(const ucstring &title) void CGroupContainer::setUCTitleOpened(const ucstring &title)
{ {
setTitleOpenedRaw(title.toUtf8()); setTitleOpened(title.toUtf8());
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitleClosed(const ucstring &title) void CGroupContainer::setUCTitleClosed(const ucstring &title)
{ {
setTitleClosedRaw(title.toUtf8()); setTitleClosed(title.toUtf8());
} }
// *************************************************************************** // ***************************************************************************
void CGroupContainer::setUCTitle(const ucstring &title) void CGroupContainer::setUCTitle(const ucstring &title)
{ {
setTitleRaw(title.toUtf8()); setTitle(title.toUtf8());
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitle () const ucstring CGroupContainer::getUCTitle () const
{ {
return ucstring::makeFromUtf8(getTitleRaw()); return ucstring::makeFromUtf8(getTitle());
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitleOpened () const ucstring CGroupContainer::getUCTitleOpened () const
{ {
return ucstring::makeFromUtf8(getTitleOpenedRaw()); return ucstring::makeFromUtf8(getTitleOpened());
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupContainer::getUCTitleClosed () const ucstring CGroupContainer::getUCTitleClosed () const
{ {
return ucstring::makeFromUtf8(getTitleClosedRaw()); return ucstring::makeFromUtf8(getTitleClosed());
} }
// *************************************************************************** // ***************************************************************************

@ -805,7 +805,7 @@ namespace NLGUI
cutSelection(); cutSelection();
} }
ucstring sString; string sString;
if (CViewRenderer::getInstance()->getDriver()->pasteTextFromClipboard(sString)) if (CViewRenderer::getInstance()->getDriver()->pasteTextFromClipboard(sString))
{ {
@ -815,7 +815,7 @@ namespace NLGUI
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void CGroupEditBox::appendStringFromClipboard(const ucstring &str) void CGroupEditBox::appendStringFromClipboard(const std::string &str)
{ {
stopParentBlink(); stopParentBlink();
makeTopWindow(); makeTopWindow();
@ -829,7 +829,7 @@ namespace NLGUI
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void CGroupEditBox::writeString(const ucstring &str16, bool replace, bool atEnd) void CGroupEditBox::writeString(const std::string &str16, bool replace, bool atEnd)
{ {
::u32string str = CUtfStringView(str16).toUtf32(); ::u32string str = CUtfStringView(str16).toUtf32();
sint length = (sint)str.length(); sint length = (sint)str.length();
@ -1717,12 +1717,12 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
ucstring CGroupEditBox::getSelection() std::string CGroupEditBox::getSelection()
{ {
ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos); ptrdiff_t minPos= min(_CursorPos, _SelectCursorPos);
ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos); ptrdiff_t maxPos= max(_CursorPos, _SelectCursorPos);
// get the selection // get the selection
return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf16(); return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf8();
} }

@ -3401,7 +3401,7 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::setTitleRaw (const std::string &title) void CGroupHTML::setContainerTitle (const std::string &title)
{ {
CInterfaceElement *parent = getParent(); CInterfaceElement *parent = getParent();
if (parent) if (parent)
@ -3411,7 +3411,7 @@ namespace NLGUI
CGroupContainer *container = dynamic_cast<CGroupContainer*>(parent); CGroupContainer *container = dynamic_cast<CGroupContainer*>(parent);
if (container) if (container)
{ {
container->setTitleRaw (title); container->setTitle(title);
} }
} }
} }
@ -3426,7 +3426,7 @@ namespace NLGUI
} }
_TitleString += title; _TitleString += title;
setTitleRaw(_TitleString); setContainerTitle(_TitleString);
} }
std::string CGroupHTML::getTitle() const { std::string CGroupHTML::getTitle() const {

@ -119,11 +119,9 @@ namespace NLGUI
// - "_" that should be the character with the lowest part // - "_" that should be the character with the lowest part
// - A with an accent for the highest part // - A with an accent for the highest part
// https://www.compart.com/en/unicode/U+00C4 // https://www.compart.com/en/unicode/U+00C4
static const u32char chars[] = { (u32char)'_', 0x000000C4, 0 }; _FontSizingChars = "_\xC3\x84q";
_FontSizingChars = chars;
// fallback if SizingChars are not supported by font // fallback if SizingChars are not supported by font
static const u32char fallback[] = { (u32char)'|', 0 }; _FontSizingFallback = "|XO";
_FontSizingFallback = fallback;
computeFontSize (); computeFontSize ();
} }
@ -399,12 +397,12 @@ namespace NLGUI
else else
if ( name == "sizing_chars" ) if ( name == "sizing_chars" )
{ {
return CUtfStringView(_FontSizingChars).toUtf8(); return _FontSizingChars;
} }
else else
if ( name == "sizing_fallback" ) if ( name == "sizing_fallback" )
{ {
return CUtfStringView(_FontSizingFallback).toUtf8(); return _FontSizingFallback;
} }
else else
return ""; return "";
@ -691,13 +689,13 @@ namespace NLGUI
else else
if( name == "sizing_chars" ) if( name == "sizing_chars" )
{ {
_FontSizingChars = CUtfStringView(value).toUtf32(); _FontSizingChars = value;
return true; return true;
} }
else else
if( name == "sizing_fallback" ) if( name == "sizing_fallback" )
{ {
_FontSizingFallback = CUtfStringView(value).toUtf32(); _FontSizingFallback = value;
return true; return true;
} }
else else
@ -769,8 +767,8 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() ); xmlSetProp( node, BAD_CAST "clamp_right", BAD_CAST toString( _ClampRight ).c_str() );
xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() ); xmlSetProp( node, BAD_CAST "auto_clamp_offset", BAD_CAST toString( _AutoClampOffset ).c_str() );
xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() ); xmlSetProp( node, BAD_CAST "continuous_update", BAD_CAST toString( _ContinuousUpdate ).c_str() );
xmlSetProp( node, BAD_CAST "sizing_chars", BAD_CAST CUtfStringView(_FontSizingChars).toUtf8().c_str() ); xmlSetProp( node, BAD_CAST "sizing_chars", BAD_CAST _FontSizingChars.c_str() );
xmlSetProp( node, BAD_CAST "sizing_fallback", BAD_CAST CUtfStringView(_FontSizingFallback).toUtf8().c_str() ); xmlSetProp( node, BAD_CAST "sizing_fallback", BAD_CAST _FontSizingFallback.c_str() );
return true; return true;
} }
@ -956,18 +954,18 @@ namespace NLGUI
} }
// "_Ä" lowest/highest chars (underscore, A+diaeresis) // "_Ä" lowest/highest chars (underscore, A+diaeresis)
static const u32char chars[] = { (u32char)'_', 0x000000C4, 0 };
_FontSizingChars = chars;
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_chars" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_chars" );
if (prop) if (prop)
_FontSizingChars = CUtfStringView((const char*)prop).toUtf32(); _FontSizingChars = (const char*)prop;
else
_FontSizingChars = "_\xC3\x84q";
// fallback if SizingChars are not supported by font // fallback if SizingChars are not supported by font
static const u32char fallback[] = { (u32char)'|', 0 };
_FontSizingFallback = fallback;
prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_fallback" ); prop = (char*) xmlGetProp( cur, (xmlChar*)"sizing_fallback" );
if (prop) if (prop)
_FontSizingFallback = CUtfStringView((const char*)prop).toUtf32(); _FontSizingFallback = (const char *)prop;
else
_FontSizingFallback = "|XO";
computeFontSize (); computeFontSize ();
} }
@ -1472,10 +1470,8 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CViewText::setFontSizing(const std::string &chars, const std::string &fallback) void CViewText::setFontSizing(const std::string &chars, const std::string &fallback)
{ {
_FontSizingChars.clear(); _FontSizingChars = chars;
_FontSizingChars = CUtfStringView(chars).toUtf32(); _FontSizingFallback = fallback;
_FontSizingFallback.clear();
_FontSizingFallback = CUtfStringView(fallback).toUtf32();
} }
// *************************************************************************** // ***************************************************************************
@ -3046,6 +3042,44 @@ namespace NLGUI
TextContext->setEmbolden (_Embolden); TextContext->setEmbolden (_Embolden);
TextContext->setOblique (_Oblique); TextContext->setOblique (_Oblique);
#if 1
UTextContext::CStringInfo si = TextContext->getStringInfo("XO");
float xoHeight = si.StringHeight;
si = TextContext->getStringInfo("XO\xC3\x81\xC3\x83");
float upHeight = si.StringHeight;
si = TextContext->getStringInfo("XOgq");
float downHeight = si.StringHeight;
float legHeight = si.StringLine;
nlassert(upHeight >= xoHeight);
nlassert(downHeight >= xoHeight);
float diff;
if (downHeight > upHeight)
{
diff = downHeight - xoHeight;
}
else
{
diff = upHeight - xoHeight;
legHeight += upHeight - downHeight;
}
_FontHeight = xoHeight + diff + diff;
_FontLegHeight = legHeight;
// Space width
si = TextContext->getStringInfo(" ");
_SpaceWidth = si.StringWidth;
// Font Width (used for <tab>)
si = TextContext->getStringInfo("O");
_FontWidth = si.StringWidth;
#else
// Letter size // Letter size
UTextContext::CStringInfo si = TextContext->getStringInfo(_FontSizingChars); UTextContext::CStringInfo si = TextContext->getStringInfo(_FontSizingChars);
@ -3066,6 +3100,8 @@ namespace NLGUI
// Font Width (used for <tab>) // Font Width (used for <tab>)
si = TextContext->getStringInfo("_"); si = TextContext->getStringInfo("_");
_FontWidth = si.StringWidth; _FontWidth = si.StringWidth;
#endif
} }

@ -98,13 +98,13 @@ const IEventEmitter *CEventEmitterMulti::getEmitter(uint index) const
return _Emitters[index].first; return _Emitters[index].first;
} }
bool CEventEmitterMulti::copyTextToClipboard(const ucstring &text) bool CEventEmitterMulti::copyTextToClipboard(const std::string &text)
{ {
// Naush: wrapped to old API to avoid duplicate code // Naush: wrapped to old API to avoid duplicate code
return CSystemUtils::copyTextToClipboard(text); return CSystemUtils::copyTextToClipboard(text);
} }
bool CEventEmitterMulti::pasteTextFromClipboard(ucstring &text) bool CEventEmitterMulti::pasteTextFromClipboard(std::string &text)
{ {
// Naush: wrapped to old API to avoid duplicate code // Naush: wrapped to old API to avoid duplicate code
return CSystemUtils::pasteTextFromClipboard(text); return CSystemUtils::pasteTextFromClipboard(text);

@ -19,6 +19,7 @@
#include "stdmisc.h" #include "stdmisc.h"
#include "nel/misc/system_utils.h" #include "nel/misc/system_utils.h"
#include "nel/misc/utf_string_view.h"
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
#define INITGUID #define INITGUID
@ -154,7 +155,7 @@ bool CSystemUtils::updateProgressBar(uint value, uint total)
return true; return true;
} }
bool CSystemUtils::copyTextToClipboard(const ucstring &text) bool CSystemUtils::copyTextToClipboard(const std::string &text)
{ {
if (text.empty()) return false; if (text.empty()) return false;
@ -167,10 +168,23 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text)
bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE); bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE);
// allocates a buffer to copy text in global memory // allocates a buffer to copy text in global memory
std::string textLocal; std::string textMbcs;
if (!isUnicode) textLocal = NLMISC::wideToMbcs((const wchar_t *)text.c_str(), text.size()); std::wstring textWide;
if (text.size() && !textLocal.size()) textLocal = text.toString(); if (!isUnicode)
HGLOBAL mem = GlobalAlloc(GHND | GMEM_DDESHARE, isUnicode ? ((text.size() + 1) * sizeof(wchar_t)) : textLocal.size()); {
textMbcs = NLMISC::utf8ToMbcs(text); // Prefer system for API
if (text.size() && !textMbcs.size())
textMbcs = CUtfStringView(text).toAscii(); // Fallback to 7-bit ASCII
}
else
{
textWide = NLMISC::utf8ToWide(text); // Prefer system for API
if (text.size() && !textWide.size())
textWide = CUtfStringView(text).toWide();
}
HGLOBAL mem = GlobalAlloc(GHND | GMEM_DDESHARE, isUnicode
? ((textWide.size() + 1) * sizeof(wchar_t))
: (textMbcs.size() + 1));
if (mem) if (mem)
{ {
@ -180,9 +194,9 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text)
{ {
// copy text to this buffer // copy text to this buffer
if (isUnicode) if (isUnicode)
wcscpy((wchar_t *)hLock, (const wchar_t *)text.c_str()); wcscpy((wchar_t *)hLock, textWide.c_str());
else else
strcpy((char *)hLock, textLocal.c_str()); strcpy((char *)hLock, textMbcs.c_str());
// unlock buffer // unlock buffer
GlobalUnlock(mem); GlobalUnlock(mem);
@ -204,7 +218,7 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text)
return res; return res;
} }
bool CSystemUtils::pasteTextFromClipboard(ucstring &text) bool CSystemUtils::pasteTextFromClipboard(std::string &text)
{ {
bool res = false; bool res = false;
@ -228,13 +242,21 @@ bool CSystemUtils::pasteTextFromClipboard(ucstring &text)
// retrieve clipboard data // retrieve clipboard data
if (isUnicode) if (isUnicode)
{ {
text = (const ucchar *)hLock; const wchar_t *str = (const wchar_t *)hLock;
text = NLMISC::wideToUtf8(str); // Prefer system for API
if (!text.size() && str[0])
text = CUtfStringView(str).toUtf8();
else
text = CUtfStringView(text).toUtf8(true); // Sanitize UTF-8 user input
} }
else else
{ {
reinterpret_cast<std::wstring &>(text) = NLMISC::mbcsToWide((const char *)hLock); const char *str = (const char *)hLock;
if (!text.size() && ((const char *)hLock)[0]) text = NLMISC::mbcsToUtf8(str); // Prefer system for API
text = (const char *)hLock; if (!text.size() && str[0])
text = CUtfStringView(str).toAscii(); // Fallback to 7-bit ASCII
else
text = CUtfStringView(text).toUtf8(true); // Sanitize UTF-8 user input
} }
// unlock data // unlock data

@ -125,7 +125,7 @@ std::string CUtfStringView::toAscii() const
if (c < 0x80) if (c < 0x80)
res += c; res += c;
else else
res += '_'; res += '?';
} }
return res; return res;
} }

Loading…
Cancel
Save