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 "generic_clipboard.hxx"
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <com/sun/star/datatransfer/clipboard/RenderingCapabilities.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <osl/diagnose.h>
27 using namespace com::sun::star::datatransfer
;
28 using namespace com::sun::star::datatransfer::clipboard
;
29 using namespace com::sun::star::lang
;
30 using namespace com::sun::star::uno
;
34 using ::dtrans::GenericClipboard
;
36 GenericClipboard::GenericClipboard() :
41 GenericClipboard::~GenericClipboard()
45 void SAL_CALL
GenericClipboard::initialize( const Sequence
< Any
>& aArguments
)
49 for (Any
const & arg
: aArguments
)
50 if (arg
.getValueType() == cppu::UnoType
<OUString
>::get())
58 OUString SAL_CALL
GenericClipboard::getImplementationName( )
60 return "com.sun.star.comp.datatransfer.clipboard.GenericClipboard";
63 sal_Bool SAL_CALL
GenericClipboard::supportsService( const OUString
& ServiceName
)
65 return cppu::supportsService(this, ServiceName
);
68 Sequence
< OUString
> SAL_CALL
GenericClipboard::getSupportedServiceNames( )
70 return { "com.sun.star.datatransfer.clipboard.GenericClipboard" };
73 Reference
< XTransferable
> SAL_CALL
GenericClipboard::getContents()
75 std::unique_lock
aGuard(m_aMutex
);
79 void SAL_CALL
GenericClipboard::setContents(const Reference
< XTransferable
>& xTrans
,
80 const Reference
< XClipboardOwner
>& xClipboardOwner
)
82 // remember old values for callbacks before setting the new ones.
83 std::unique_lock
aGuard(m_aMutex
);
85 Reference
< XClipboardOwner
> oldOwner(m_aOwner
);
86 m_aOwner
= xClipboardOwner
;
88 Reference
< XTransferable
> oldContents(m_aContents
);
93 // notify old owner on loss of ownership
95 oldOwner
->lostOwnership(static_cast < XClipboard
* > (this), oldContents
);
97 // notify all listeners on content changes
99 ClipboardEvent
aEvent(static_cast < XClipboard
* > (this), m_aContents
);
100 maClipboardListeners
.notifyEach(aGuard
, &XClipboardListener::changedContents
, aEvent
);
103 OUString SAL_CALL
GenericClipboard::getName()
108 sal_Int8 SAL_CALL
GenericClipboard::getRenderingCapabilities()
110 return RenderingCapabilities::Delayed
;
113 void SAL_CALL
GenericClipboard::addClipboardListener( const Reference
< XClipboardListener
>& listener
)
115 std::unique_lock
aGuard( m_aMutex
);
116 OSL_ENSURE( !m_bDisposed
, "object is disposed" );
118 maClipboardListeners
.addInterface( aGuard
, listener
);
121 void SAL_CALL
GenericClipboard::removeClipboardListener( const Reference
< XClipboardListener
>& listener
)
123 std::unique_lock
aGuard( m_aMutex
);
124 OSL_ENSURE( !m_bDisposed
, "object is disposed" );
126 maClipboardListeners
.removeInterface( aGuard
, listener
);
129 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
130 dtrans_GenericClipboard_get_implementation(
131 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
133 return cppu::acquire(new GenericClipboard());
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */