develop
kaetemi 4 years ago
parent 7c028d7a83
commit 8dc777495a

@ -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)

@ -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;

@ -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());
} }

@ -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();
} }

@ -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