• Main Page
  • Classes
  • Files
  • File List

COSXClipboardTextConverter.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2004 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include "COSXClipboardTextConverter.h"
00020 #include "CUnicode.h"
00021 
00022 //
00023 // COSXClipboardTextConverter
00024 //
00025 
00026 COSXClipboardTextConverter::COSXClipboardTextConverter() 
00027 {
00028     // do nothing
00029 }
00030 
00031 COSXClipboardTextConverter::~COSXClipboardTextConverter()
00032 {
00033     // do nothing
00034 }
00035 
00036 CFStringRef
00037 COSXClipboardTextConverter::getOSXFormat() const
00038 {
00039     return CFSTR("public.plain-text");
00040 }
00041 
00042 CString 
00043 COSXClipboardTextConverter::convertString(
00044                 const CString& data, 
00045                 CFStringEncoding fromEncoding,
00046                 CFStringEncoding toEncoding)
00047 {
00048     CFStringRef stringRef =
00049         CFStringCreateWithCString(kCFAllocatorDefault,
00050                             data.c_str(), fromEncoding);
00051 
00052     if (stringRef == NULL) {
00053         return CString();
00054     }
00055 
00056     CFIndex buffSize;
00057     CFRange entireString = CFRangeMake(0, CFStringGetLength(stringRef));
00058 
00059     CFStringGetBytes(stringRef, entireString, toEncoding,
00060                             0, false, NULL, 0, &buffSize);
00061 
00062     char* buffer = new char[buffSize];
00063     
00064     if (buffer == NULL) {
00065         CFRelease(stringRef);
00066         return CString();
00067     }
00068     
00069     CFStringGetBytes(stringRef, entireString, toEncoding,
00070                             0, false, (UInt8*)buffer, buffSize, NULL);
00071 
00072     CString result(buffer, buffSize);
00073 
00074     delete[] buffer;
00075     CFRelease(stringRef);
00076     
00077     return result;
00078 }
00079 
00080 CString
00081 COSXClipboardTextConverter::doFromIClipboard(const CString& data) const
00082 {
00083     return convertString(data, kCFStringEncodingUTF8,
00084                             CFStringGetSystemEncoding());
00085 }
00086 
00087 CString
00088 COSXClipboardTextConverter::doToIClipboard(const CString& data) const
00089 {
00090     return convertString(data, CFStringGetSystemEncoding(),
00091                             kCFStringEncodingUTF8);
00092 }

Generated on Sun May 19 2013 00:00:05 for Synergy by  doxygen 1.7.1