Skip to content

Commit

Permalink
allow copying unicode in wesnoth
Browse files Browse the repository at this point in the history
this completes a previous commit which enabled pasting unicode.
  • Loading branch information
gfgtdf authored and cbeck88 committed Oct 26, 2014
1 parent c9b9422 commit 67b2b88
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/clipboard.cpp
Expand Up @@ -433,15 +433,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();
}

Expand Down

0 comments on commit 67b2b88

Please sign in to comment.