2014-05-13 12:31:05 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2014-2016 Symless Ltd.
|
2014-05-13 12:31:05 +00:00
|
|
|
* Patch by Ryan Chapman
|
|
|
|
|
*
|
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2014-05-13 12:31:05 +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 "platform/OSXClipboardHTMLConverter.h"
|
|
|
|
|
|
|
|
|
|
#include "base/Unicode.h"
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
OSXClipboardHTMLConverter::OSXClipboardHTMLConverter() {
|
|
|
|
|
// do nothing
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
OSXClipboardHTMLConverter::~OSXClipboardHTMLConverter() {
|
|
|
|
|
// do nothing
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
IClipboard::EFormat OSXClipboardHTMLConverter::getFormat() const {
|
|
|
|
|
return IClipboard::kHTML;
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
CFStringRef OSXClipboardHTMLConverter::getOSXFormat() const {
|
|
|
|
|
return CFSTR("public.html");
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
String OSXClipboardHTMLConverter::convertString(const String &data,
|
|
|
|
|
CFStringEncoding fromEncoding,
|
|
|
|
|
CFStringEncoding toEncoding) {
|
|
|
|
|
CFStringRef stringRef = CFStringCreateWithCString(kCFAllocatorDefault,
|
|
|
|
|
data.c_str(), fromEncoding);
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (stringRef == NULL) {
|
|
|
|
|
return String();
|
|
|
|
|
}
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
CFIndex buffSize;
|
|
|
|
|
CFRange entireString = CFRangeMake(0, CFStringGetLength(stringRef));
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, NULL, 0,
|
|
|
|
|
&buffSize);
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
char *buffer = new char[buffSize];
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (buffer == NULL) {
|
|
|
|
|
CFRelease(stringRef);
|
|
|
|
|
return String();
|
|
|
|
|
}
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
CFStringGetBytes(stringRef, entireString, toEncoding, 0, false,
|
|
|
|
|
(UInt8 *)buffer, buffSize, NULL);
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
String result(buffer, buffSize);
|
|
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
CFRelease(stringRef);
|
2014-05-13 12:31:05 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return result;
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
String OSXClipboardHTMLConverter::doFromIClipboard(const String &data) const {
|
|
|
|
|
return data;
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
String OSXClipboardHTMLConverter::doToIClipboard(const String &data) const {
|
|
|
|
|
if (Unicode::isUTF8(data)) {
|
|
|
|
|
return data;
|
|
|
|
|
} else {
|
|
|
|
|
return convertString(data, CFStringGetSystemEncoding(),
|
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
|
}
|
2014-05-13 12:31:05 +00:00
|
|
|
}
|