1 /* 2 * barrier -- mouse and keyboard sharing utility 3 * Copyright (C) 2012-2016 Symless Ltd. 4 * Copyright (C) 2002 Chris Schoeneman 5 * 6 * This package is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * found in the file LICENSE that should have accompanied this file. 9 * 10 * This package is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #include "barrier/Clipboard.h" 20 21 // 22 // Clipboard 23 // 24 Clipboard()25Clipboard::Clipboard() : 26 m_open(false), 27 m_owner(false) 28 { 29 open(0); 30 empty(); 31 close(); 32 } 33 ~Clipboard()34Clipboard::~Clipboard() 35 { 36 // do nothing 37 } 38 39 bool empty()40Clipboard::empty() 41 { 42 assert(m_open); 43 44 // clear all data 45 for (SInt32 index = 0; index < kNumFormats; ++index) { 46 m_data[index] = ""; 47 m_added[index] = false; 48 } 49 50 // save time 51 m_timeOwned = m_time; 52 53 // we're the owner now 54 m_owner = true; 55 56 return true; 57 } 58 59 void add(EFormat format,const String & data)60Clipboard::add(EFormat format, const String& data) 61 { 62 assert(m_open); 63 assert(m_owner); 64 65 m_data[format] = data; 66 m_added[format] = true; 67 } 68 69 bool open(Time time) const70Clipboard::open(Time time) const 71 { 72 assert(!m_open); 73 74 m_open = true; 75 m_time = time; 76 77 return true; 78 } 79 80 void close() const81Clipboard::close() const 82 { 83 assert(m_open); 84 85 m_open = false; 86 } 87 88 Clipboard::Time getTime() const89Clipboard::getTime() const 90 { 91 return m_timeOwned; 92 } 93 94 bool has(EFormat format) const95Clipboard::has(EFormat format) const 96 { 97 assert(m_open); 98 return m_added[format]; 99 } 100 101 String get(EFormat format) const102Clipboard::get(EFormat format) const 103 { 104 assert(m_open); 105 return m_data[format]; 106 } 107 108 void unmarshall(const String & data,Time time)109Clipboard::unmarshall(const String& data, Time time) 110 { 111 IClipboard::unmarshall(this, data, time); 112 } 113 114 String marshall() const115Clipboard::marshall() const 116 { 117 return IClipboard::marshall(this); 118 } 119