Make clipboard UTF-8 on Windows too

This commit is contained in:
sfan5 2021-08-30 21:51:24 +02:00
parent 9c4b6f25ab
commit 34f1f8d089
2 changed files with 21 additions and 9 deletions

@ -70,16 +70,20 @@ void COSOperator::copyToClipboard(const c8 *text) const
EmptyClipboard();
core::stringw tempbuffer;
core::multibyteToWString(tempbuffer, text);
const u32 size = (tempbuffer.size() + 1) * sizeof(wchar_t);
HGLOBAL clipbuffer;
char * buffer;
void * buffer;
clipbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
buffer = (char*)GlobalLock(clipbuffer);
clipbuffer = GlobalAlloc(GMEM_MOVEABLE, size);
buffer = GlobalLock(clipbuffer);
strcpy(buffer, text);
memcpy(buffer, tempbuffer.c_str(), size);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT, clipbuffer);
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
@ -113,13 +117,17 @@ const c8* COSOperator::getTextFromClipboard() const
if (!OpenClipboard(NULL))
return 0;
char * buffer = 0;
wchar_t * buffer = 0;
HANDLE hData = GetClipboardData( CF_UNICODETEXT );
buffer = (wchar_t*) GlobalLock( hData );
core::wStringToMultibyte(ClipboardBuf, buffer);
HANDLE hData = GetClipboardData( CF_TEXT );
buffer = (char*)GlobalLock( hData );
GlobalUnlock( hData );
CloseClipboard();
return buffer;
return ClipboardBuf.c_str();
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
NSString* str = nil;

@ -48,6 +48,10 @@ private:
CIrrDeviceLinux * IrrDeviceLinux;
#endif
#ifdef _IRR_WINDOWS_API_
mutable core::stringc ClipboardBuf;
#endif
};
} // end namespace