deskflow/src/lib/synergy/Clipboard.cpp

119 lines
2 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
2012-06-10 16:50:54 +00:00
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
2012-06-10 16:50:54 +00:00
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "synergy/Clipboard.h"
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
// Clipboard
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
Clipboard::Clipboard() :
m_open(false),
m_owner(false)
2012-06-10 16:50:54 +00:00
{
open(0);
empty();
close();
2012-06-10 16:50:54 +00:00
}
2014-11-11 13:51:47 +00:00
Clipboard::~Clipboard()
2012-06-10 16:50:54 +00:00
{
// do nothing
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Clipboard::empty()
2012-06-10 16:50:54 +00:00
{
assert(m_open);
2012-06-10 16:50:54 +00:00
// clear all data
for (SInt32 index = 0; index < kNumFormats; ++index) {
m_data[index] = "";
m_added[index] = false;
}
2012-06-10 16:50:54 +00:00
// save time
m_timeOwned = m_time;
2012-06-10 16:50:54 +00:00
// we're the owner now
m_owner = true;
2012-06-10 16:50:54 +00:00
return true;
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Clipboard::add(EFormat format, const String& data)
2012-06-10 16:50:54 +00:00
{
assert(m_open);
assert(m_owner);
2012-06-10 16:50:54 +00:00
m_data[format] = data;
m_added[format] = true;
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Clipboard::open(Time time) const
2012-06-10 16:50:54 +00:00
{
assert(!m_open);
2012-06-10 16:50:54 +00:00
m_open = true;
m_time = time;
2012-06-10 16:50:54 +00:00
return true;
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Clipboard::close() const
2012-06-10 16:50:54 +00:00
{
assert(m_open);
2012-06-10 16:50:54 +00:00
m_open = false;
2012-06-10 16:50:54 +00:00
}
2014-11-11 13:51:47 +00:00
Clipboard::Time
Clipboard::getTime() const
2012-06-10 16:50:54 +00:00
{
return m_timeOwned;
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Clipboard::has(EFormat format) const
2012-06-10 16:50:54 +00:00
{
assert(m_open);
return m_added[format];
2012-06-10 16:50:54 +00:00
}
2014-11-11 13:51:47 +00:00
String
Clipboard::get(EFormat format) const
2012-06-10 16:50:54 +00:00
{
assert(m_open);
return m_data[format];
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Clipboard::unmarshall(const String& data, Time time)
2012-06-10 16:50:54 +00:00
{
IClipboard::unmarshall(this, data, time);
2012-06-10 16:50:54 +00:00
}
2014-11-11 13:51:47 +00:00
String
Clipboard::marshall() const
2012-06-10 16:50:54 +00:00
{
return IClipboard::marshall(this);
2012-06-10 16:50:54 +00:00
}