Merge pull request #452 from LaurensVoerman/submit_input_copyWchar

text copy - get unicode text to clipboard.
This commit is contained in:
OpenSceneGraph git repository 2018-01-20 12:35:30 +00:00 committed by GitHub
commit 9cc2bab737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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