diff --git a/nel/include/nel/3d/driver.h b/nel/include/nel/3d/driver.h index 75472df37..0fdae7a58 100644 --- a/nel/include/nel/3d/driver.h +++ b/nel/include/nel/3d/driver.h @@ -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..862921f8f 100644 --- a/nel/include/nel/3d/driver_user.h +++ b/nel/include/nel/3d/driver_user.h @@ -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/u_driver.h b/nel/include/nel/3d/u_driver.h index f4f78e2cb..ca8a98e02 100644 --- a/nel/include/nel/3d/u_driver.h +++ b/nel/include/nel/3d/u_driver.h @@ -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/gui/event_descriptor.h b/nel/include/nel/gui/event_descriptor.h index dd2ae19c4..baa9414fd 100644 --- a/nel/include/nel/gui/event_descriptor.h +++ b/nel/include/nel/gui/event_descriptor.h @@ -60,7 +60,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) diff --git a/nel/include/nel/gui/group_editbox.h b/nel/include/nel/gui/group_editbox.h index 9b2998be0..3263837c1 100644 --- a/nel/include/nel/gui/group_editbox.h +++ b/nel/include/nel/gui/group_editbox.h @@ -140,7 +140,7 @@ namespace NLGUI // Paste the selection into buffer void paste(); // Write the string into buffer - void writeString(const ucstring &str, bool replace = true, bool atEnd = true); // 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) bool expand(); @@ -299,9 +299,9 @@ namespace NLGUI void handleEventString(const NLGUI::CEventDescriptorKey &event); void setup(); 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; diff --git a/nel/include/nel/misc/event_emitter_multi.h b/nel/include/nel/misc/event_emitter_multi.h index e41ee2055..9b8d25c64 100644 --- a/nel/include/nel/misc/event_emitter_multi.h +++ b/nel/include/nel/misc/event_emitter_multi.h @@ -48,8 +48,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/system_utils.h b/nel/include/nel/misc/system_utils.h index 426e38b73..9093eb90d 100644 --- a/nel/include/nel/misc/system_utils.h +++ b/nel/include/nel/misc/system_utils.h @@ -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/src/3d/driver/direct3d/driver_direct3d.cpp b/nel/src/3d/driver/direct3d/driver_direct3d.cpp index f26a37afb..6263de0f8 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -4018,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..bc7911df2 100644 --- a/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -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/opengl/driver_opengl.h b/nel/src/3d/driver/opengl/driver_opengl.h index e1ee968a5..e85d2da05 100644 --- a/nel/src/3d/driver/opengl/driver_opengl.h +++ b/nel/src/3d/driver/opengl/driver_opengl.h @@ -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_window.cpp b/nel/src/3d/driver/opengl/driver_opengl_window.cpp index a987b7425..c60ec602e 100644 --- a/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -3020,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 fcb00b20e..594d60183 100644 --- a/nel/src/3d/driver/opengl/unix_event_emitter.cpp +++ b/nel/src/3d/driver/opengl/unix_event_emitter.cpp @@ -547,6 +547,7 @@ 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 ((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) { 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 { @@ -710,6 +710,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) else if (target == XA_STRING) { // FIXME: Convert local to UTF-8 + // text = NLMISC::CUtfStringView(text).toAscii(); } else { @@ -767,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; @@ -786,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..68dc81a48 100644 --- a/nel/src/3d/driver/opengl/unix_event_emitter.h +++ b/nel/src/3d/driver/opengl/unix_event_emitter.h @@ -66,12 +66,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 +105,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..02e9c4b27 100644 --- a/nel/src/3d/driver_user.cpp +++ b/nel/src/3d/driver_user.cpp @@ -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/gui/action_handler.cpp b/nel/src/gui/action_handler.cpp index 2b8bf890b..b80ce2f5f 100644 --- a/nel/src/gui/action_handler.cpp +++ b/nel/src/gui/action_handler.cpp @@ -751,9 +751,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/group_editbox.cpp b/nel/src/gui/group_editbox.cpp index 47a36d0a1..dc7e34e16 100644 --- a/nel/src/gui/group_editbox.cpp +++ b/nel/src/gui/group_editbox.cpp @@ -805,7 +805,7 @@ namespace NLGUI cutSelection(); } - ucstring sString; + string 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(); 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(); 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 maxPos= max(_CursorPos, _SelectCursorPos); // get the selection - return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf16(); + return CUtfStringView(_InputString.substr(minPos, maxPos-minPos)).toUtf8(); } diff --git a/nel/src/misc/event_emitter_multi.cpp b/nel/src/misc/event_emitter_multi.cpp index 45559ebc4..a7d133f3c 100644 --- a/nel/src/misc/event_emitter_multi.cpp +++ b/nel/src/misc/event_emitter_multi.cpp @@ -98,13 +98,13 @@ const IEventEmitter *CEventEmitterMulti::getEmitter(uint index) const 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 return CSystemUtils::copyTextToClipboard(text); } -bool CEventEmitterMulti::pasteTextFromClipboard(ucstring &text) +bool CEventEmitterMulti::pasteTextFromClipboard(std::string &text) { // Naush: wrapped to old API to avoid duplicate code return CSystemUtils::pasteTextFromClipboard(text); diff --git a/nel/src/misc/system_utils.cpp b/nel/src/misc/system_utils.cpp index 63eecbf0d..ba15d5363 100644 --- a/nel/src/misc/system_utils.cpp +++ b/nel/src/misc/system_utils.cpp @@ -19,6 +19,7 @@ #include "stdmisc.h" #include "nel/misc/system_utils.h" +#include "nel/misc/utf_string_view.h" #ifdef NL_OS_WINDOWS #define INITGUID @@ -154,7 +155,7 @@ bool CSystemUtils::updateProgressBar(uint value, uint total) return true; } -bool CSystemUtils::copyTextToClipboard(const ucstring &text) +bool CSystemUtils::copyTextToClipboard(const std::string &text) { if (text.empty()) return false; @@ -167,10 +168,23 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) bool isUnicode = (IsClipboardFormatAvailable(CF_UNICODETEXT) == TRUE); // allocates a buffer to copy text in global memory - std::string textLocal; - if (!isUnicode) textLocal = NLMISC::wideToMbcs((const wchar_t *)text.c_str(), text.size()); - if (text.size() && !textLocal.size()) textLocal = text.toString(); - HGLOBAL mem = GlobalAlloc(GHND | GMEM_DDESHARE, isUnicode ? ((text.size() + 1) * sizeof(wchar_t)) : textLocal.size()); + std::string textMbcs; + std::wstring textWide; + if (!isUnicode) + { + 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) { @@ -180,9 +194,9 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) { // copy text to this buffer if (isUnicode) - wcscpy((wchar_t *)hLock, (const wchar_t *)text.c_str()); + wcscpy((wchar_t *)hLock, textWide.c_str()); else - strcpy((char *)hLock, textLocal.c_str()); + strcpy((char *)hLock, textMbcs.c_str()); // unlock buffer GlobalUnlock(mem); @@ -204,7 +218,7 @@ bool CSystemUtils::copyTextToClipboard(const ucstring &text) return res; } -bool CSystemUtils::pasteTextFromClipboard(ucstring &text) +bool CSystemUtils::pasteTextFromClipboard(std::string &text) { bool res = false; @@ -228,13 +242,21 @@ bool CSystemUtils::pasteTextFromClipboard(ucstring &text) // retrieve clipboard data 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 { - reinterpret_cast(text) = NLMISC::mbcsToWide((const char *)hLock); - if (!text.size() && ((const char *)hLock)[0]) - text = (const char *)hLock; + const char *str = (const char *)hLock; + text = NLMISC::mbcsToUtf8(str); // Prefer system for API + 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 diff --git a/nel/src/misc/utf_string_view.cpp b/nel/src/misc/utf_string_view.cpp index 070745202..d1239ae43 100644 --- a/nel/src/misc/utf_string_view.cpp +++ b/nel/src/misc/utf_string_view.cpp @@ -125,7 +125,7 @@ std::string CUtfStringView::toAscii() const if (c < 0x80) res += c; else - res += '_'; + res += '?'; } return res; }