Commit 1e05248e authored by mercury233's avatar mercury233

fix linux paste

parent e44c6720
...@@ -1360,6 +1360,15 @@ typedef string<c8> stringc; ...@@ -1360,6 +1360,15 @@ typedef string<c8> stringc;
//! Typedef for wide character strings //! Typedef for wide character strings
typedef string<wchar_t> stringw; 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 core
} // end namespace irr } // end namespace irr
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#else #else
#include <locale.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifndef _IRR_SOLARIS_PLATFORM_ #ifndef _IRR_SOLARIS_PLATFORM_
...@@ -124,10 +125,12 @@ const c16* COSOperator::getTextFromClipboard() const ...@@ -124,10 +125,12 @@ const c16* COSOperator::getTextFromClipboard() const
if ( IrrDeviceLinux ) if ( IrrDeviceLinux )
{ {
const c8 * p = IrrDeviceLinux->getTextFromClipboard(); const c8 * p = IrrDeviceLinux->getTextFromClipboard();
size_t lenOld = strlen(p);
wchar_t *ws = new wchar_t[lenOld + 1]; char* oldLocale = setlocale(LC_CTYPE, NULL);
size_t lenNew = mbstowcs(ws,p,lenOld); setlocale(LC_CTYPE, "");
ws[lenNew] = 0; wchar_t* ws = core::toWideChar(p);
setlocale(LC_CTYPE, oldLocale);
return ws; return ws;
} }
return 0; return 0;
......
...@@ -602,14 +602,7 @@ void CIrrDeviceMacOSX::processKeyEvent() ...@@ -602,14 +602,7 @@ void CIrrDeviceMacOSX::processKeyEvent()
void CIrrDeviceMacOSX::handleInputEvent(const char *cStr) void CIrrDeviceMacOSX::handleInputEvent(const char *cStr)
{ {
SEvent ievent; SEvent ievent;
irr::core::stringw widep(irr::core::toWideChar(cStr));
// 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;
ievent.EventType = irr::EET_KEY_INPUT_EVENT; ievent.EventType = irr::EET_KEY_INPUT_EVENT;
ievent.KeyInput.Key = (irr::EKEY_CODE)0; 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