1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_vcl.hxx" 24 25 #if OSL_DEBUG_LEVEL > 1 26 #include <stdio.h> 27 #endif 28 29 #include <X11_transferable.hxx> 30 #include <X11/Xatom.h> 31 #include <com/sun/star/io/IOException.hpp> 32 33 using namespace com::sun::star::datatransfer; 34 using namespace com::sun::star::lang; 35 using namespace com::sun::star::io; 36 using namespace com::sun::star::uno; 37 using namespace cppu; 38 using namespace osl; 39 using namespace rtl; 40 41 42 using namespace x11; 43 44 45 X11Transferable::X11Transferable( 46 SelectionManager& rManager, 47 const Reference< XInterface >& xCreator, 48 Atom selection 49 ) : 50 m_rManager( rManager ), 51 m_xCreator( xCreator ), 52 m_aSelection( selection ) 53 { 54 } 55 56 //================================================================================================== 57 58 X11Transferable::~X11Transferable() 59 { 60 } 61 62 //================================================================================================== 63 64 Any SAL_CALL X11Transferable::getTransferData( const DataFlavor& rFlavor ) 65 throw(UnsupportedFlavorException, IOException, RuntimeException) 66 { 67 Any aRet; 68 Sequence< sal_Int8 > aData; 69 bool bSuccess = m_rManager.getPasteData( m_aSelection ? m_aSelection : XA_PRIMARY, rFlavor.MimeType, aData ); 70 if( ! bSuccess && m_aSelection == 0 ) 71 bSuccess = m_rManager.getPasteData( m_rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ), rFlavor.MimeType, aData ); 72 73 if( ! bSuccess ) 74 { 75 throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) ); 76 } 77 if( rFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) ) 78 { 79 int nLen = aData.getLength()/2; 80 if( ((sal_Unicode*)aData.getConstArray())[nLen-1] == 0 ) 81 nLen--; 82 OUString aString( (sal_Unicode*)aData.getConstArray(), nLen ); 83 #if OSL_DEBUG_LEVEL > 1 84 fprintf( stderr, "X11Transferable::getTransferData( \"%s\" )\n -> \"%s\"\n", 85 OUStringToOString( rFlavor.MimeType, RTL_TEXTENCODING_ISO_8859_1 ).getStr(), 86 OUStringToOString( aString, RTL_TEXTENCODING_ISO_8859_1 ).getStr() ); 87 #endif 88 aRet <<= aString; 89 } 90 else 91 aRet <<= aData; 92 return aRet; 93 } 94 95 //================================================================================================== 96 97 Sequence< DataFlavor > SAL_CALL X11Transferable::getTransferDataFlavors() 98 throw(RuntimeException) 99 { 100 Sequence< DataFlavor > aFlavorList; 101 bool bSuccess = m_rManager.getPasteDataTypes( m_aSelection ? m_aSelection : XA_PRIMARY, aFlavorList ); 102 if( ! bSuccess && m_aSelection == 0 ) 103 bSuccess = m_rManager.getPasteDataTypes( m_rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ), aFlavorList ); 104 105 return aFlavorList; 106 } 107 108 //================================================================================================== 109 110 sal_Bool SAL_CALL X11Transferable::isDataFlavorSupported( const DataFlavor& aFlavor ) 111 throw(RuntimeException) 112 { 113 if( aFlavor.DataType != getCppuType( (Sequence< sal_Int8 >*)0 ) ) 114 { 115 if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( OUString::createFromAscii( "text/plain;charset=utf-16" ) ) && 116 aFlavor.DataType == getCppuType( (OUString*)0 ) ) 117 return false; 118 } 119 120 Sequence< DataFlavor > aFlavors( getTransferDataFlavors() ); 121 for( int i = 0; i < aFlavors.getLength(); i++ ) 122 if( aFlavor.MimeType.equalsIgnoreAsciiCase( aFlavors.getConstArray()[i].MimeType ) && 123 aFlavor.DataType == aFlavors.getConstArray()[i].DataType ) 124 return sal_True; 125 126 return sal_False; 127 } 128 129 /* vim: set noet sw=4 ts=4: */ 130