2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2004 Chris Schoeneman
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "platform/OSXClipboardTextConverter.h"
|
|
|
|
|
|
|
|
|
|
#include "base/Unicode.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// OSXClipboardTextConverter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
OSXClipboardTextConverter::OSXClipboardTextConverter()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
OSXClipboardTextConverter::~OSXClipboardTextConverter()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
CFStringRef OSXClipboardTextConverter::getOSXFormat() const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return CFSTR("public.plain-text");
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardTextConverter::convertString(
|
|
|
|
|
const std::string &data, CFStringEncoding fromEncoding, CFStringEncoding toEncoding
|
|
|
|
|
)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
CFStringRef stringRef = CFStringCreateWithCString(kCFAllocatorDefault, data.c_str(), fromEncoding);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
if (stringRef == NULL) {
|
2025-01-06 00:55:07 +00:00
|
|
|
return std::string();
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CFIndex buffSize;
|
|
|
|
|
CFRange entireString = CFRangeMake(0, CFStringGetLength(stringRef));
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, NULL, 0, &buffSize);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
char *buffer = new char[buffSize];
|
|
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
2016-12-28 11:50:32 +00:00
|
|
|
CFRelease(stringRef);
|
2025-01-06 00:55:07 +00:00
|
|
|
return std::string();
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
CFStringGetBytes(stringRef, entireString, toEncoding, 0, false, (UInt8 *)buffer, buffSize, NULL);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string result(buffer, buffSize);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
delete[] buffer;
|
|
|
|
|
CFRelease(stringRef);
|
|
|
|
|
|
|
|
|
|
return result;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardTextConverter::doFromIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
return convertString(data, kCFStringEncodingUTF8, CFStringGetSystemEncoding());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string OSXClipboardTextConverter::doToIClipboard(const std::string &data) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
return convertString(data, CFStringGetSystemEncoding(), kCFStringEncodingUTF8);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|