nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / generic / dtrans / X11_transferable.cxx
blob1310f70bc234e71e8f527b6860f2808f7a5f8119
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "X11_transferable.hxx"
21 #include <X11/Xatom.h>
22 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
23 #include <com/sun/star/io/IOException.hpp>
24 #include <sal/log.hxx>
26 using namespace com::sun::star::datatransfer;
27 using namespace com::sun::star::lang;
28 using namespace com::sun::star::io;
29 using namespace com::sun::star::uno;
30 using namespace cppu;
31 using namespace osl;
33 using namespace x11;
35 X11Transferable::X11Transferable(
36 SelectionManager& rManager,
37 Atom selection
38 ) :
39 m_rManager( rManager ),
40 m_aSelection( selection )
44 X11Transferable::~X11Transferable()
48 Any SAL_CALL X11Transferable::getTransferData( const DataFlavor& rFlavor )
50 Any aRet;
51 Sequence< sal_Int8 > aData;
52 bool bSuccess = m_rManager.getPasteData( m_aSelection ? m_aSelection : XA_PRIMARY, rFlavor.MimeType, aData );
53 if( ! bSuccess && m_aSelection == 0 )
54 bSuccess = m_rManager.getPasteData( m_rManager.getAtom( "CLIPBOARD" ), rFlavor.MimeType, aData );
56 if( ! bSuccess )
58 throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) );
60 if( rFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) )
62 int nLen = aData.getLength()/2;
63 if( reinterpret_cast<sal_Unicode const *>(aData.getConstArray())[nLen-1] == 0 )
64 nLen--;
65 OUString aString( reinterpret_cast<sal_Unicode const *>(aData.getConstArray()), nLen );
66 SAL_INFO( "vcl.unx.dtrans", "X11Transferable::getTransferData( \"" << rFlavor.MimeType << "\" )\n -> \"" << aString << "\"");
67 aRet <<= aString.replaceAll("\r\n", "\n");
69 else
70 aRet <<= aData;
71 return aRet;
74 Sequence< DataFlavor > SAL_CALL X11Transferable::getTransferDataFlavors()
76 Sequence< DataFlavor > aFlavorList;
77 bool bSuccess = m_rManager.getPasteDataTypes( m_aSelection ? m_aSelection : XA_PRIMARY, aFlavorList );
78 if( ! bSuccess && m_aSelection == 0 )
79 m_rManager.getPasteDataTypes( m_rManager.getAtom( "CLIPBOARD" ), aFlavorList );
81 return aFlavorList;
84 sal_Bool SAL_CALL X11Transferable::isDataFlavorSupported( const DataFlavor& aFlavor )
86 if( aFlavor.DataType != cppu::UnoType<Sequence< sal_Int8 >>::get() )
88 if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) &&
89 aFlavor.DataType == cppu::UnoType<OUString>::get() )
90 return false;
93 Sequence< DataFlavor > aFlavors( getTransferDataFlavors() );
94 return std::any_of(aFlavors.begin(), aFlavors.end(),
95 [&aFlavor](const DataFlavor& rFlavor) {
96 return aFlavor.MimeType.equalsIgnoreAsciiCase( rFlavor.MimeType )
97 && aFlavor.DataType == rFlavor.DataType;
98 });
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */