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>
26 using namespace com::sun::star::datatransfer
;
27 using namespace com::sun::star::datatransfer::clipboard
;
28 using namespace com::sun::star::lang
;
29 using namespace com::sun::star::uno
;
33 using ::dtrans::GenericClipboard
;
35 GenericClipboard::GenericClipboard() :
36 WeakComponentImplHelper
< XClipboardEx
, XClipboardNotifier
, XServiceInfo
, XInitialization
> (m_aMutex
),
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 MutexGuard
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 ClearableMutexGuard
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
98 OInterfaceContainerHelper
*pContainer
=
99 rBHelper
.aLC
.getContainer(cppu::UnoType
<XClipboardListener
>::get());
102 ClipboardEvent
aEvent(static_cast < XClipboard
* > (this), m_aContents
);
103 OInterfaceIteratorHelper
aIterator(*pContainer
);
105 while (aIterator
.hasMoreElements())
107 Reference
< XClipboardListener
> xListener(aIterator
.next(), UNO_QUERY
);
109 xListener
->changedContents(aEvent
);
114 OUString SAL_CALL
GenericClipboard::getName()
119 sal_Int8 SAL_CALL
GenericClipboard::getRenderingCapabilities()
121 return RenderingCapabilities::Delayed
;
124 void SAL_CALL
GenericClipboard::addClipboardListener( const Reference
< XClipboardListener
>& listener
)
126 MutexGuard
aGuard( rBHelper
.rMutex
);
127 OSL_ENSURE( !rBHelper
.bInDispose
, "do not add listeners in the dispose call" );
128 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
129 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
130 rBHelper
.aLC
.addInterface( cppu::UnoType
<XClipboardListener
>::get(), listener
);
133 void SAL_CALL
GenericClipboard::removeClipboardListener( const Reference
< XClipboardListener
>& listener
)
135 MutexGuard
aGuard( rBHelper
.rMutex
);
136 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
137 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
138 rBHelper
.aLC
.removeInterface( cppu::UnoType
<XClipboardListener
>::get(), listener
);
141 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
142 dtrans_GenericClipboard_get_implementation(
143 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
145 return cppu::acquire(static_cast<cppu::OWeakObject
*>(new GenericClipboard()));
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */