updated win32 clipboard to match new model.

This commit is contained in:
crs 2002-05-27 18:55:51 +00:00
parent f5a6d2738a
commit 8cb0302665
2 changed files with 26 additions and 37 deletions

View File

@ -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;
}

View File

@ -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