bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / app / unohelp2.cxx
blob8321567882159d94a1537c4b474b62258f005618
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 <sal/log.hxx>
21 #include <vcl/unohelp2.hxx>
22 #include <sot/exchange.hxx>
23 #include <sot/formats.hxx>
24 #include <vcl/svapp.hxx>
25 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
26 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
28 #include <cppuhelper/queryinterface.hxx>
30 using namespace ::com::sun::star;
32 namespace vcl { namespace unohelper {
34 TextDataObject::TextDataObject( const OUString& rText ) : maText( rText )
38 TextDataObject::~TextDataObject()
42 void TextDataObject::CopyStringTo( const OUString& rContent,
43 const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
45 SAL_WARN_IF( !rxClipboard.is(), "vcl", "TextDataObject::CopyStringTo: invalid clipboard!" );
46 if ( !rxClipboard.is() )
47 return;
49 TextDataObject* pDataObj = new TextDataObject( rContent );
51 SolarMutexReleaser aReleaser;
52 try
54 rxClipboard->setContents( pDataObj, nullptr );
56 uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
57 if( xFlushableClipboard.is() )
58 xFlushableClipboard->flushClipboard();
60 catch( const uno::Exception& )
65 // css::uno::XInterface
66 uno::Any TextDataObject::queryInterface( const uno::Type & rType )
68 uno::Any aRet = ::cppu::queryInterface( rType, static_cast< datatransfer::XTransferable* >(this) );
69 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
72 // css::datatransfer::XTransferable
73 uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor )
75 SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
76 if ( nT != SotClipboardFormatId::STRING )
78 throw datatransfer::UnsupportedFlavorException();
80 return uno::Any(maText);
83 uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( )
85 uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1);
86 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aDataFlavors.getArray()[0] );
87 return aDataFlavors;
90 sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor )
92 SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
93 return ( nT == SotClipboardFormatId::STRING );
96 }} // namespace vcl::unohelper
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */