sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / source / app / unohelp2.cxx
blob575b9c74417c5f12786f191f147b9da4ee0dba4b
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 <utility>
22 #include <vcl/unohelp2.hxx>
23 #include <sot/exchange.hxx>
24 #include <sot/formats.hxx>
25 #include <vcl/svapp.hxx>
26 #include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
27 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <boost/property_tree/json_parser.hpp>
31 #include <comphelper/lok.hxx>
32 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
34 using namespace ::com::sun::star;
36 namespace vcl::unohelper {
38 TextDataObject::TextDataObject( OUString aText ) : maText(std::move( aText ))
42 TextDataObject::~TextDataObject()
46 void TextDataObject::CopyStringTo( const OUString& rContent,
47 const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard,
48 const vcl::ILibreOfficeKitNotifier* pNotifier)
50 SAL_WARN_IF( !rxClipboard.is(), "vcl", "TextDataObject::CopyStringTo: invalid clipboard!" );
51 if ( !rxClipboard.is() )
52 return;
54 rtl::Reference<TextDataObject> pDataObj = new TextDataObject( rContent );
56 SolarMutexReleaser aReleaser;
57 try
59 rxClipboard->setContents( pDataObj, nullptr );
61 uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
62 if( xFlushableClipboard.is() )
63 xFlushableClipboard->flushClipboard();
65 if (pNotifier != nullptr && comphelper::LibreOfficeKit::isActive())
67 boost::property_tree::ptree aTree;
68 aTree.put("content", rContent);
69 aTree.put("mimeType", "text/plain");
70 std::stringstream aStream;
71 boost::property_tree::write_json(aStream, aTree);
72 pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_CLIPBOARD_CHANGED, OString(aStream.str()));
75 catch( const uno::Exception& )
80 // css::uno::XInterface
81 uno::Any TextDataObject::queryInterface( const uno::Type & rType )
83 uno::Any aRet = ::cppu::queryInterface( rType, static_cast< datatransfer::XTransferable* >(this) );
84 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
87 // css::datatransfer::XTransferable
88 uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor )
90 SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
91 if ( nT != SotClipboardFormatId::STRING )
93 throw datatransfer::UnsupportedFlavorException();
95 return uno::Any(maText);
98 uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( )
100 uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1);
101 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aDataFlavors.getArray()[0] );
102 return aDataFlavors;
105 sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor )
107 SotClipboardFormatId nT = SotExchange::GetFormat( rFlavor );
108 return ( nT == SotClipboardFormatId::STRING );
111 } // namespace vcl::unohelper
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */