diff --git a/synergy/CMSWindowsClipboard.cpp b/synergy/CMSWindowsClipboard.cpp index 006ebc75..8503574c 100644 --- a/synergy/CMSWindowsClipboard.cpp +++ b/synergy/CMSWindowsClipboard.cpp @@ -18,44 +18,23 @@ CMSWindowsClipboard::~CMSWindowsClipboard() // do nothing } -bool CMSWindowsClipboard::open(Time time) +bool CMSWindowsClipboard::empty() { - log((CLOG_DEBUG "open clipboard")); + log((CLOG_DEBUG "empty clipboard")); - if (!OpenClipboard(m_window)) { - log((CLOG_WARN "failed to open clipboard")); + if (!EmptyClipboard()) { + log((CLOG_DEBUG "failed to grab clipboard")); return false; } - if (EmptyClipboard()) { - log((CLOG_DEBUG "grabbed clipboard")); - } - else { - log((CLOG_WARN "failed to grab clipboard")); - CloseClipboard(); - return false; - } - - m_time = time; return true; } -void CMSWindowsClipboard::close() -{ - log((CLOG_DEBUG "close clipboard")); - CloseClipboard(); -} - void CMSWindowsClipboard::add( EFormat format, const CString& data) { log((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); - if (!OpenClipboard(m_window)) { - log((CLOG_WARN "failed to open clipboard")); - return; - } - // convert data to win32 required form const UINT win32Format = convertFormatToWin32(format); HANDLE win32Data; @@ -73,8 +52,25 @@ void CMSWindowsClipboard::add( if (win32Data != NULL) { SetClipboardData(win32Format, win32Data); } +} - // done with clipboard +bool CMSWindowsClipboard::open(Time time) const +{ + log((CLOG_DEBUG "open clipboard")); + + if (!OpenClipboard(m_window)) { + log((CLOG_WARN "failed to open clipboard")); + return false; + } + + m_time = time; + + return true; +} + +void CMSWindowsClipboard::close() const +{ + log((CLOG_DEBUG "close clipboard")); CloseClipboard(); } @@ -96,11 +92,6 @@ CString CMSWindowsClipboard::get(EFormat format) const if (win32Format == 0) return CString(); - if (!OpenClipboard(m_window)) { - log((CLOG_WARN "failed to open clipboard")); - return CString(); - } - // get a handle to the clipboard data and convert it HANDLE win32Data = GetClipboardData(win32Format); CString data; @@ -112,9 +103,6 @@ CString CMSWindowsClipboard::get(EFormat format) const } } - // close the clipboard - CloseClipboard(); - return data; } diff --git a/synergy/CMSWindowsClipboard.h b/synergy/CMSWindowsClipboard.h index 0010af57..7d7d0225 100644 --- a/synergy/CMSWindowsClipboard.h +++ b/synergy/CMSWindowsClipboard.h @@ -10,9 +10,10 @@ public: virtual ~CMSWindowsClipboard(); // IClipboard overrides - virtual bool open(Time); - virtual void close(); + virtual bool empty(); virtual void add(EFormat, const CString& data); + virtual bool open(Time) const; + virtual void close() const; virtual Time getTime() const; virtual bool has(EFormat) const; virtual CString get(EFormat) const; @@ -24,7 +25,7 @@ private: private: HWND m_window; - Time m_time; + mutable Time m_time; }; #endif