///////////////////////////////////////////////////////
| 77 | |
| 78 | //////////////////////////////////////////////////////////// |
| 79 | void ClipboardImpl::setString(const String& text) |
| 80 | { |
| 81 | if (!OpenClipboard(nullptr)) |
| 82 | { |
| 83 | err() << "Failed to open the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl; |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if (!EmptyClipboard()) |
| 88 | { |
| 89 | err() << "Failed to empty the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl; |
| 90 | CloseClipboard(); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | // Create a Win32-compatible string |
| 95 | const auto string = text.toUtf16(); |
| 96 | const std::size_t stringSize = (string.size() + 1) * sizeof(char16_t); |
| 97 | if (const HANDLE stringHandle = GlobalAlloc(GMEM_MOVEABLE, stringSize)) |
| 98 | { |
| 99 | std::memcpy(GlobalLock(stringHandle), string.data(), stringSize); |
| 100 | GlobalUnlock(stringHandle); |
| 101 | SetClipboardData(CF_UNICODETEXT, stringHandle); |
| 102 | } |
| 103 | |
| 104 | CloseClipboard(); |
| 105 | } |
| 106 | |
| 107 | } // namespace sf::priv |
nothing calls this directly
no test coverage detected