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 <vcl/unohelp2.hxx>
21 : #include <sot/exchange.hxx>
22 : #include <sot/formats.hxx>
23 : #include <tools/debug.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26 : #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27 :
28 : using namespace ::com::sun::star;
29 :
30 : namespace vcl { namespace unohelper {
31 :
32 0 : TextDataObject::TextDataObject( const OUString& rText ) : maText( rText )
33 : {
34 0 : }
35 :
36 0 : TextDataObject::~TextDataObject()
37 : {
38 0 : }
39 :
40 0 : void TextDataObject::CopyStringTo( const OUString& rContent,
41 : const uno::Reference< datatransfer::clipboard::XClipboard >& rxClipboard )
42 : {
43 : DBG_ASSERT( rxClipboard.is(), "TextDataObject::CopyStringTo: invalid clipboard!" );
44 0 : if ( !rxClipboard.is() )
45 0 : return;
46 :
47 0 : TextDataObject* pDataObj = new TextDataObject( rContent );
48 :
49 0 : const sal_uInt32 nRef = Application::ReleaseSolarMutex();
50 : try
51 : {
52 0 : rxClipboard->setContents( pDataObj, NULL );
53 :
54 0 : uno::Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, uno::UNO_QUERY );
55 0 : if( xFlushableClipboard.is() )
56 0 : xFlushableClipboard->flushClipboard();
57 : }
58 0 : catch( const uno::Exception& )
59 : {
60 : }
61 0 : Application::AcquireSolarMutex( nRef );
62 : }
63 :
64 : // ::com::sun::star::uno::XInterface
65 0 : uno::Any TextDataObject::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
66 : {
67 0 : uno::Any aRet = ::cppu::queryInterface( rType, (static_cast< datatransfer::XTransferable* >(this)) );
68 0 : return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
69 : }
70 :
71 : // ::com::sun::star::datatransfer::XTransferable
72 0 : uno::Any TextDataObject::getTransferData( const datatransfer::DataFlavor& rFlavor ) throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException, std::exception)
73 : {
74 0 : uno::Any aAny;
75 :
76 0 : sal_uLong nT = SotExchange::GetFormat( rFlavor );
77 0 : if ( nT == SOT_FORMAT_STRING )
78 : {
79 0 : aAny <<= GetString();
80 : }
81 : else
82 : {
83 0 : throw datatransfer::UnsupportedFlavorException();
84 : }
85 0 : return aAny;
86 : }
87 :
88 0 : uno::Sequence< datatransfer::DataFlavor > TextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException, std::exception)
89 : {
90 0 : uno::Sequence< datatransfer::DataFlavor > aDataFlavors(1);
91 0 : SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aDataFlavors.getArray()[0] );
92 0 : return aDataFlavors;
93 : }
94 :
95 0 : sal_Bool TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor& rFlavor ) throw(uno::RuntimeException, std::exception)
96 : {
97 0 : sal_uLong nT = SotExchange::GetFormat( rFlavor );
98 0 : return ( nT == SOT_FORMAT_STRING );
99 : }
100 :
101 1233 : }} // namespace vcl::unohelper
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|