tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / vcl / unx / generic / dtrans / X11_transferable.cxx
blob80ed9fba8c4c6ed1c16dc5ee083f572b90d57d83
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::uno;
29 using namespace cppu;
31 using namespace x11;
33 X11Transferable::X11Transferable(
34 SelectionManager& rManager,
35 Atom selection
36 ) :
37 m_rManager( rManager ),
38 m_aSelection( selection )
42 X11Transferable::~X11Transferable()
46 Any SAL_CALL X11Transferable::getTransferData( const DataFlavor& rFlavor )
48 Any aRet;
49 Sequence< sal_Int8 > aData;
50 bool bSuccess = m_rManager.getPasteData( m_aSelection ? m_aSelection : XA_PRIMARY, rFlavor.MimeType, aData );
51 if( ! bSuccess && m_aSelection == 0 )
52 bSuccess = m_rManager.getPasteData( m_rManager.getAtom( u"CLIPBOARD"_ustr ), rFlavor.MimeType, aData );
54 if( ! bSuccess )
56 throw UnsupportedFlavorException( rFlavor.MimeType, static_cast < XTransferable * > ( this ) );
58 if( rFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) )
60 int nLen = aData.getLength()/2;
61 if( reinterpret_cast<sal_Unicode const *>(aData.getConstArray())[nLen-1] == 0 )
62 nLen--;
63 OUString aString( reinterpret_cast<sal_Unicode const *>(aData.getConstArray()), nLen );
64 SAL_INFO( "vcl.unx.dtrans", "X11Transferable::getTransferData( \"" << rFlavor.MimeType << "\" )\n -> \"" << aString << "\"");
65 aRet <<= aString.replaceAll("\r\n", "\n");
67 else
68 aRet <<= aData;
69 return aRet;
72 Sequence< DataFlavor > SAL_CALL X11Transferable::getTransferDataFlavors()
74 Sequence< DataFlavor > aFlavorList;
75 bool bSuccess = m_rManager.getPasteDataTypes( m_aSelection ? m_aSelection : XA_PRIMARY, aFlavorList );
76 if( ! bSuccess && m_aSelection == 0 )
77 m_rManager.getPasteDataTypes( m_rManager.getAtom( u"CLIPBOARD"_ustr ), aFlavorList );
79 return aFlavorList;
82 sal_Bool SAL_CALL X11Transferable::isDataFlavorSupported( const DataFlavor& aFlavor )
84 if( aFlavor.DataType != cppu::UnoType<Sequence< sal_Int8 >>::get() )
86 if( ! aFlavor.MimeType.equalsIgnoreAsciiCase( "text/plain;charset=utf-16" ) &&
87 aFlavor.DataType == cppu::UnoType<OUString>::get() )
88 return false;
91 const Sequence< DataFlavor > aFlavors( getTransferDataFlavors() );
92 return std::any_of(aFlavors.begin(), aFlavors.end(),
93 [&aFlavor](const DataFlavor& rFlavor) {
94 return aFlavor.MimeType.equalsIgnoreAsciiCase( rFlavor.MimeType )
95 && aFlavor.DataType == rFlavor.DataType;
96 });
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */