text copy - get unicode text to clipboard.

This commit is contained in:
Laurens Voerman 2018-01-19 11:20:34 +01:00
parent ee7e7a7019
commit 9ef68841c0

View File

@ -566,18 +566,21 @@ bool Input::keyDown(int key, int mask, const WindowManager*)
if (selectionMax - selectionMin > 0)
{
std::string data;
std::copy(s.begin() + selectionMin, s.begin() + selectionMax, std::inserter(data, data.begin()));
osgText::String selection;
std::copy(s.begin() + selectionMin, s.begin() + selectionMax, std::back_inserter(selection));
data = selection.createUTF8EncodedString();
// Data to clipboard
#ifdef WIN32
if(::OpenClipboard(NULL))
{
::EmptyClipboard();
HGLOBAL clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, data.length()+1);
char* buffer = (char*)::GlobalLock(clipbuffer);
strcpy(buffer, data.c_str());
int wchar_count = MultiByteToWideChar(CP_UTF8, 0, data.c_str(), -1, NULL, 0);
HGLOBAL clipbuffer = ::GlobalAlloc(GMEM_MOVEABLE, wchar_count * sizeof(wchar_t));
wchar_t* buffer = (wchar_t*)::GlobalLock(clipbuffer);
MultiByteToWideChar(CP_UTF8, 0, data.c_str(), -1, buffer, wchar_count);
::GlobalUnlock(clipbuffer);
::SetClipboardData(CF_TEXT,clipbuffer);
::SetClipboardData(CF_UNICODETEXT,clipbuffer);
::CloseClipboard();
}
#endif