1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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 #include <cppuhelper/queryinterface.hxx>
29 using namespace ::com::sun::star
;
31 namespace vcl
{ namespace unohelper
{
33 TextDataObject::TextDataObject( const OUString
& rText
) : maText( rText
)
37 TextDataObject::~TextDataObject()
41 void TextDataObject::CopyStringTo( const OUString
& rContent
,
42 const uno::Reference
< datatransfer::clipboard::XClipboard
>& rxClipboard
)
44 DBG_ASSERT( rxClipboard
.is(), "TextDataObject::CopyStringTo: invalid clipboard!" );
45 if ( !rxClipboard
.is() )
48 TextDataObject
* pDataObj
= new TextDataObject( rContent
);
50 SolarMutexReleaser aReleaser
;
53 rxClipboard
->setContents( pDataObj
, NULL
);
55 uno::Reference
< datatransfer::clipboard::XFlushableClipboard
> xFlushableClipboard( rxClipboard
, uno::UNO_QUERY
);
56 if( xFlushableClipboard
.is() )
57 xFlushableClipboard
->flushClipboard();
59 catch( const uno::Exception
& )
64 // ::com::sun::star::uno::XInterface
65 uno::Any
TextDataObject::queryInterface( const uno::Type
& rType
) throw(uno::RuntimeException
, std::exception
)
67 uno::Any aRet
= ::cppu::queryInterface( rType
, (static_cast< datatransfer::XTransferable
* >(this)) );
68 return (aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
));
71 // ::com::sun::star::datatransfer::XTransferable
72 uno::Any
TextDataObject::getTransferData( const datatransfer::DataFlavor
& rFlavor
) throw(datatransfer::UnsupportedFlavorException
, io::IOException
, uno::RuntimeException
, std::exception
)
76 SotClipboardFormatId nT
= SotExchange::GetFormat( rFlavor
);
77 if ( nT
== SotClipboardFormatId::STRING
)
83 throw datatransfer::UnsupportedFlavorException();
88 uno::Sequence
< datatransfer::DataFlavor
> TextDataObject::getTransferDataFlavors( ) throw(uno::RuntimeException
, std::exception
)
90 uno::Sequence
< datatransfer::DataFlavor
> aDataFlavors(1);
91 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING
, aDataFlavors
.getArray()[0] );
95 sal_Bool
TextDataObject::isDataFlavorSupported( const datatransfer::DataFlavor
& rFlavor
) throw(uno::RuntimeException
, std::exception
)
97 SotClipboardFormatId nT
= SotExchange::GetFormat( rFlavor
);
98 return ( nT
== SotClipboardFormatId::STRING
);
101 }} // namespace vcl::unohelper
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */