Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

COSXClipboardTextConverter.cpp

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

Generated on Fri Nov 6 00:21:14 2009 for synergy-plus by  doxygen 1.3.9.1