diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-05-03 10:53:06 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-07-01 11:18:27 +0200 |
commit | 615d16bd5ba11e89262cc5cfe94a35b6d6e7a628 (patch) | |
tree | c520bd561b0e44f005cc2fbc118b8e36f439bfcb /win/rfb_win32/Clipboard.cxx | |
parent | 56fa7821560a60db39195e8c81d16b46e8f972c2 (diff) | |
download | tigervnc-615d16bd5ba11e89262cc5cfe94a35b6d6e7a628.tar.gz tigervnc-615d16bd5ba11e89262cc5cfe94a35b6d6e7a628.zip |
Improved clipboard API
Change the internal clipboard API to use a request based model in
order to be prepared for more advanced clipboard transfers.
Diffstat (limited to 'win/rfb_win32/Clipboard.cxx')
-rw-r--r-- | win/rfb_win32/Clipboard.cxx | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/win/rfb_win32/Clipboard.cxx b/win/rfb_win32/Clipboard.cxx index 49526956..306cfbad 100644 --- a/win/rfb_win32/Clipboard.cxx +++ b/win/rfb_win32/Clipboard.cxx @@ -103,32 +103,10 @@ Clipboard::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { } else { vlog.debug("local clipboard changed by %p", owner); - // Open the clipboard - if (OpenClipboard(getHandle())) { - // Get the clipboard data - HGLOBAL cliphandle = GetClipboardData(CF_TEXT); - if (cliphandle) { - char* clipdata = (char*) GlobalLock(cliphandle); - - // Notify clients - if (notifier) { - if (!clipdata) { - notifier->notifyClipboardChanged(0); - } else { - CharArray unix_text(convertLF(clipdata, strlen(clipdata))); - removeNonISOLatin1Chars(unix_text.buf); - notifier->notifyClipboardChanged(unix_text.buf); - } - } else { - vlog.debug("no clipboard notifier registered"); - } - - // Release the buffer and close the clipboard - GlobalUnlock(cliphandle); - } - - CloseClipboard(); - } + if (notifier == NULL) + vlog.debug("no clipboard notifier registered"); + else + notifier->notifyClipboardChanged(IsClipboardFormatAvailable(CF_TEXT)); } } if (next_window) @@ -139,6 +117,40 @@ Clipboard::processMessage(UINT msg, WPARAM wParam, LPARAM lParam) { return MsgWindow::processMessage(msg, wParam, lParam); }; +char* +Clipboard::getClipText() { + HGLOBAL cliphandle; + char* clipdata; + char* filtered; + + // Open the clipboard + if (!OpenClipboard(getHandle())) + return NULL; + + // Get the clipboard data + cliphandle = GetClipboardData(CF_TEXT); + if (!cliphandle) { + CloseClipboard(); + return NULL; + } + + clipdata = (char*) GlobalLock(cliphandle); + if (!clipdata) { + CloseClipboard(); + return NULL; + } + + // Filter out anything unwanted + filtered = convertLF(clipdata, strlen(clipdata)); + removeNonISOLatin1Chars(filtered); + + // Release the buffer and close the clipboard + GlobalUnlock(cliphandle); + CloseClipboard(); + + return filtered; +} + void Clipboard::setClipText(const char* text) { HANDLE clip_handle = 0; |