CXWindowsClipboardTextConverter.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2002 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 "CXWindowsClipboardTextConverter.h"
00016 #include "CUnicode.h"
00017 
00018 //
00019 // CXWindowsClipboardTextConverter
00020 //
00021 
00022 CXWindowsClipboardTextConverter::CXWindowsClipboardTextConverter(
00023                 Display* display, const char* name) :
00024     m_atom(XInternAtom(display, name, False))
00025 {
00026     // do nothing
00027 }
00028 
00029 CXWindowsClipboardTextConverter::~CXWindowsClipboardTextConverter()
00030 {
00031     // do nothing
00032 }
00033 
00034 IClipboard::EFormat
00035 CXWindowsClipboardTextConverter::getFormat() const
00036 {
00037     return IClipboard::kText;
00038 }
00039 
00040 Atom
00041 CXWindowsClipboardTextConverter::getAtom() const
00042 {
00043     return m_atom;
00044 }
00045 
00046 int
00047 CXWindowsClipboardTextConverter::getDataSize() const
00048 {
00049     return 8;
00050 }
00051 
00052 CString
00053 CXWindowsClipboardTextConverter::fromIClipboard(const CString& data) const
00054 {
00055     return CUnicode::UTF8ToText(data);
00056 }
00057 
00058 CString
00059 CXWindowsClipboardTextConverter::toIClipboard(const CString& data) const
00060 {
00061     // convert to UTF-8
00062     bool errors;
00063     CString utf8 = CUnicode::textToUTF8(data, &errors);
00064 
00065     // if there were decoding errors then, to support old applications
00066     // that don't understand UTF-8 but can report the exact binary
00067     // UTF-8 representation, see if the data appears to be UTF-8.  if
00068     // so then use it as is.
00069     if (errors && CUnicode::isUTF8(data)) {
00070         return data;
00071     }
00072 
00073     return utf8;
00074 }

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7