Fix bug getting ANSI clipboard text on Windows

Sometimes the clipboard content is in CF_TEXT format and there is
no implicit CF_UNICODETEXT conversion.
This commit is contained in:
David Capello 2015-05-07 22:56:02 -03:00
parent bea61fab88
commit dab8c96fa8

View File

@ -42,9 +42,9 @@ std::string ClipboardWin32::getText(DisplayHandle hwnd)
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
if (open_clipboard((HWND)hwnd)) {
HGLOBAL hglobal = GetClipboardData(CF_UNICODETEXT);
if (hglobal != NULL) {
if (hglobal) {
LPWSTR lpstr = static_cast<LPWSTR>(GlobalLock(hglobal));
if (lpstr != NULL) {
if (lpstr) {
text = base::to_utf8(lpstr).c_str();
GlobalUnlock(hglobal);
}
@ -52,6 +52,19 @@ std::string ClipboardWin32::getText(DisplayHandle hwnd)
CloseClipboard();
}
}
else if (IsClipboardFormatAvailable(CF_TEXT)) {
if (open_clipboard((HWND)hwnd)) {
HGLOBAL hglobal = GetClipboardData(CF_TEXT);
if (hglobal) {
LPSTR lpstr = static_cast<LPSTR>(GlobalLock(hglobal));
if (lpstr) {
text = lpstr;
GlobalUnlock(hglobal);
}
}
CloseClipboard();
}
}
return text;
}