allow copsing unicode in wesnoth

this completes a previous commit which enabled pasting unicode.
This commit is contained in:
gfgtdf 2014-10-18 19:12:21 +02:00
parent d3017c45a7
commit 321166b869

View file

@ -436,15 +436,18 @@ void copy_to_clipboard(const std::string& text, const bool)
++last;
}
const HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE, (str.size() + 1) * sizeof(TCHAR));
utf16::string ustring = unicode_cast<utf16::string>(str);
std::wstring wstr(ustring.begin(), ustring.end());
const HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE, (wstr.size() + 1) * sizeof(wchar_t));
if(hglb == NULL) {
CloseClipboard();
return;
}
char* const buffer = reinterpret_cast<char* const>(GlobalLock(hglb));
strcpy(buffer, str.c_str());
wchar_t* const buffer = reinterpret_cast<wchar_t* const>(GlobalLock(hglb));
wcscpy(buffer, wstr.c_str());
GlobalUnlock(hglb);
SetClipboardData(CF_TEXT, hglb);
SetClipboardData(CF_UNICODETEXT, hglb);
CloseClipboard();
}