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