Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <X11_transferable.hxx>
21 : #include <X11/Xatom.h>
22 : #include <com/sun/star/io/IOException.hpp>
23 :
24 : using namespace com::sun::star::datatransfer;
25 : using namespace com::sun::star::lang;
26 : using namespace com::sun::star::io;
27 : using namespace com::sun::star::uno;
28 : using namespace cppu;
29 : using namespace osl;
30 :
31 : using namespace x11;
32 :
33 3 : X11Transferable::X11Transferable(
34 : SelectionManager& rManager,
35 : Atom selection
36 : ) :
37 : m_rManager( rManager ),
38 3 : m_aSelection( selection )
39 : {
40 3 : }
41 :
42 0 : X11Transferable::~X11Transferable()
43 : {
44 0 : }
45 :
46 0 : Any SAL_CALL X11Transferable::getTransferData( const DataFlavor& rFlavor )
47 : throw(UnsupportedFlavorException, IOException, RuntimeException, std::exception)
48 : {
49 0 : Any aRet;
50 0 : Sequence< sal_Int8 > aData;
51 0 : bool bSuccess = m_rManager.getPasteData( m_aSelection ? m_aSelection : XA_PRIMARY, rFlavor.MimeType, aData );
52 0 : if( ! bSuccess && m_aSelection == 0 )
53 0 : bSuccess = m_rManager.getPasteData( m_rManager.getAtom( OUString("CLIPBOARD") ), rFlavor.MimeType, aData );
54 :
55 0 : if( ! bSuccess )
56 : {
57 0 : throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) );
58 : }
59 0 : if( rFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) )
60 : {
61 0 : int nLen = aData.getLength()/2;
62 0 : if( reinterpret_cast<sal_Unicode const *>(aData.getConstArray())[nLen-1] == 0 )
63 0 : nLen--;
64 0 : OUString aString( reinterpret_cast<sal_Unicode const *>(aData.getConstArray()), nLen );
65 : SAL_INFO( "vcl", "X11Transferable::getTransferData( \"" << rFlavor.MimeType << "\" )\n -> \"" << aString << "\"\n");
66 0 : aRet <<= aString.replaceAll("\r\n", "\n");
67 : }
68 : else
69 0 : aRet <<= aData;
70 0 : return aRet;
71 : }
72 :
73 1 : Sequence< DataFlavor > SAL_CALL X11Transferable::getTransferDataFlavors()
74 : throw(RuntimeException, std::exception)
75 : {
76 1 : Sequence< DataFlavor > aFlavorList;
77 1 : bool bSuccess = m_rManager.getPasteDataTypes( m_aSelection ? m_aSelection : XA_PRIMARY, aFlavorList );
78 1 : if( ! bSuccess && m_aSelection == 0 )
79 0 : bSuccess = m_rManager.getPasteDataTypes( m_rManager.getAtom( OUString("CLIPBOARD") ), aFlavorList );
80 :
81 1 : return aFlavorList;
82 : }
83 :
84 0 : sal_Bool SAL_CALL X11Transferable::isDataFlavorSupported( const DataFlavor& aFlavor )
85 : throw(RuntimeException, std::exception)
86 : {
87 0 : if( aFlavor.DataType != cppu::UnoType<Sequence< sal_Int8 >>::get() )
88 : {
89 0 : if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) &&
90 0 : aFlavor.DataType == cppu::UnoType<OUString>::get() )
91 0 : return false;
92 : }
93 :
94 0 : Sequence< DataFlavor > aFlavors( getTransferDataFlavors() );
95 0 : for( int i = 0; i < aFlavors.getLength(); i++ )
96 0 : if( aFlavor.MimeType.equalsIgnoreAsciiCase( aFlavors.getConstArray()[i].MimeType ) &&
97 0 : aFlavor.DataType == aFlavors.getConstArray()[i].DataType )
98 0 : return true;
99 :
100 0 : return false;
101 : }
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|