From bd7ad0cde084a3a75b83a6b254eb248a1ea42944 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 11 May 2015 11:26:37 -0300 Subject: [PATCH] Fix bug copying text on Windows clipboard We were asking if the clipboard format was equal to Unicode Text to copy Unicode text on it. --- src/she/win/clipboard.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/she/win/clipboard.cpp b/src/she/win/clipboard.cpp index 0e105cb61..b2e546060 100644 --- a/src/she/win/clipboard.cpp +++ b/src/she/win/clipboard.cpp @@ -71,25 +71,23 @@ std::string ClipboardWin32::getText(DisplayHandle hwnd) void ClipboardWin32::setText(DisplayHandle hwnd, const std::string& text) { - if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { - if (open_clipboard((HWND)hwnd)) { - EmptyClipboard(); + if (open_clipboard((HWND)hwnd)) { + EmptyClipboard(); - if (!text.empty()) { - std::wstring wstr = base::from_utf8(text); - int len = wstr.size(); + if (!text.empty()) { + std::wstring wstr = base::from_utf8(text); + int len = wstr.size(); - HGLOBAL hglobal = GlobalAlloc(GMEM_MOVEABLE | - GMEM_ZEROINIT, sizeof(WCHAR)*(len+1)); + HGLOBAL hglobal = GlobalAlloc(GMEM_MOVEABLE | + GMEM_ZEROINIT, sizeof(WCHAR)*(len+1)); - LPWSTR lpstr = static_cast(GlobalLock(hglobal)); - std::copy(wstr.begin(), wstr.end(), lpstr); - GlobalUnlock(hglobal); + LPWSTR lpstr = static_cast(GlobalLock(hglobal)); + std::copy(wstr.begin(), wstr.end(), lpstr); + GlobalUnlock(hglobal); - SetClipboardData(CF_UNICODETEXT, hglobal); - } - CloseClipboard(); + SetClipboardData(CF_UNICODETEXT, hglobal); } + CloseClipboard(); } }