Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dtrans / source / generic / generic_clipboard.cxx
blob4fa49b3d5ebe1fcfa9856f907c585cf9a7011c25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cppuhelper/supportsservice.hxx>
25 using namespace com::sun::star::datatransfer;
26 using namespace com::sun::star::datatransfer::clipboard;
27 using namespace com::sun::star::lang;
28 using namespace com::sun::star::uno;
29 using namespace cppu;
30 using namespace osl;
32 using ::dtrans::GenericClipboard;
34 GenericClipboard::GenericClipboard() :
35 WeakComponentImplHelper< XClipboardEx, XClipboardNotifier, XServiceInfo, XInitialization > (m_aMutex),
36 m_bInitialized(false)
40 GenericClipboard::~GenericClipboard()
44 void SAL_CALL GenericClipboard::initialize( const Sequence< Any >& aArguments )
46 if (!m_bInitialized)
48 for (sal_Int32 n = 0, nmax = aArguments.getLength(); n < nmax; n++)
49 if (aArguments[n].getValueType() == cppu::UnoType<OUString>::get())
51 aArguments[0] >>= m_aName;
52 break;
57 OUString SAL_CALL GenericClipboard::getImplementationName( )
59 return GENERIC_CLIPBOARD_IMPLEMENTATION_NAME;
62 sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName )
64 return cppu::supportsService(this, ServiceName);
67 Sequence< OUString > SAL_CALL GenericClipboard::getSupportedServiceNames( )
69 return GenericClipboard_getSupportedServiceNames();
72 Reference< XTransferable > SAL_CALL GenericClipboard::getContents()
74 MutexGuard aGuard(m_aMutex);
75 return m_aContents;
78 void SAL_CALL GenericClipboard::setContents(const Reference< XTransferable >& xTrans,
79 const Reference< XClipboardOwner >& xClipboardOwner )
81 // remember old values for callbacks before setting the new ones.
82 ClearableMutexGuard aGuard(m_aMutex);
84 Reference< XClipboardOwner > oldOwner(m_aOwner);
85 m_aOwner = xClipboardOwner;
87 Reference< XTransferable > oldContents(m_aContents);
88 m_aContents = xTrans;
90 aGuard.clear();
92 // notify old owner on loss of ownership
93 if( oldOwner.is() )
94 oldOwner->lostOwnership(static_cast < XClipboard * > (this), oldContents);
96 // notify all listeners on content changes
97 OInterfaceContainerHelper *pContainer =
98 rBHelper.aLC.getContainer(cppu::UnoType<XClipboardListener>::get());
99 if (pContainer)
101 ClipboardEvent aEvent(static_cast < XClipboard * > (this), m_aContents);
102 OInterfaceIteratorHelper aIterator(*pContainer);
104 while (aIterator.hasMoreElements())
106 Reference < XClipboardListener > xListener(aIterator.next(), UNO_QUERY);
107 if (xListener.is())
108 xListener->changedContents(aEvent);
113 OUString SAL_CALL GenericClipboard::getName()
115 return m_aName;
118 sal_Int8 SAL_CALL GenericClipboard::getRenderingCapabilities()
120 return RenderingCapabilities::Delayed;
123 void SAL_CALL GenericClipboard::addClipboardListener( const Reference< XClipboardListener >& listener )
125 MutexGuard aGuard( rBHelper.rMutex );
126 OSL_ENSURE( !rBHelper.bInDispose, "do not add listeners in the dispose call" );
127 OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
128 if (!rBHelper.bInDispose && !rBHelper.bDisposed)
129 rBHelper.aLC.addInterface( cppu::UnoType<XClipboardListener>::get(), listener );
132 void SAL_CALL GenericClipboard::removeClipboardListener( const Reference< XClipboardListener >& listener )
134 MutexGuard aGuard( rBHelper.rMutex );
135 OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
136 if (!rBHelper.bInDispose && !rBHelper.bDisposed)
137 rBHelper.aLC.removeInterface( cppu::UnoType<XClipboardListener>::get(), listener );
140 Sequence< OUString > GenericClipboard_getSupportedServiceNames()
142 Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.GenericClipboard" };
143 return aRet;
146 Reference< XInterface > GenericClipboard_createInstance(
147 const Reference< XMultiServiceFactory > & /*xMultiServiceFactory*/)
149 return Reference < XInterface >(static_cast<OWeakObject *>(new GenericClipboard()));
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */