Commit 1e05248e authored by mercury233's avatar mercury233

fix linux paste

parent e44c6720
......@@ -1360,6 +1360,15 @@ typedef string<c8> stringc;
//! Typedef for wide character strings
typedef string<wchar_t> stringw;
//! wrap of mbstowcs
static inline wchar_t* toWideChar(const char* p)
{
size_t lenOld = strlen(p);
wchar_t* ws = new wchar_t[lenOld + 1];
size_t lenNew = mbstowcs(ws, p, lenOld);
ws[lenNew] = 0;
return ws;
}
} // end namespace core
} // end namespace irr
......
......@@ -9,6 +9,7 @@
#include <windows.h>
#endif
#else
#include <locale.h>
#include <string.h>
#include <unistd.h>
#ifndef _IRR_SOLARIS_PLATFORM_
......@@ -124,10 +125,12 @@ const c16* COSOperator::getTextFromClipboard() const
if ( IrrDeviceLinux )
{
const c8 * p = IrrDeviceLinux->getTextFromClipboard();
size_t lenOld = strlen(p);
wchar_t *ws = new wchar_t[lenOld + 1];
size_t lenNew = mbstowcs(ws,p,lenOld);
ws[lenNew] = 0;
char* oldLocale = setlocale(LC_CTYPE, NULL);
setlocale(LC_CTYPE, "");
wchar_t* ws = core::toWideChar(p);
setlocale(LC_CTYPE, oldLocale);
return ws;
}
return 0;
......
......@@ -602,14 +602,7 @@ void CIrrDeviceMacOSX::processKeyEvent()
void CIrrDeviceMacOSX::handleInputEvent(const char *cStr)
{
SEvent ievent;
// TODO: we should have such a function in core::string
size_t lenOld = strlen(cStr);
wchar_t *ws = new wchar_t[lenOld + 1];
size_t len = mbstowcs(ws,cStr,lenOld);
ws[len] = 0;
irr::core::stringw widep(ws);
delete[] ws;
irr::core::stringw widep(irr::core::toWideChar(cStr));
ievent.EventType = irr::EET_KEY_INPUT_EVENT;
ievent.KeyInput.Key = (irr::EKEY_CODE)0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment