2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-22 21:23:29 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-01-31 14:37:29 +00:00
|
|
|
|
|
|
|
#include <generic_clipboard.hxx>
|
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
|
|
|
#include <com/sun/star/datatransfer/clipboard/RenderingCapabilities.hpp>
|
2013-09-25 15:41:29 -03:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2001-01-31 14:37:29 +00:00
|
|
|
|
|
|
|
using namespace com::sun::star::datatransfer;
|
|
|
|
using namespace com::sun::star::datatransfer::clipboard;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace cppu;
|
|
|
|
using namespace osl;
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
using ::dtrans::GenericClipboard;
|
|
|
|
|
|
|
|
GenericClipboard::GenericClipboard() :
|
2015-07-23 16:20:52 +09:00
|
|
|
WeakComponentImplHelper< XClipboardEx, XClipboardNotifier, XServiceInfo, XInitialization > (m_aMutex),
|
2016-10-14 16:57:04 +02:00
|
|
|
m_bInitialized(false)
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
GenericClipboard::~GenericClipboard()
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
void SAL_CALL GenericClipboard::initialize( const Sequence< Any >& aArguments )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
if (!m_bInitialized)
|
|
|
|
{
|
|
|
|
for (sal_Int32 n = 0, nmax = aArguments.getLength(); n < nmax; n++)
|
2014-05-10 00:14:44 +02:00
|
|
|
if (aArguments[n].getValueType() == cppu::UnoType<OUString>::get())
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
aArguments[0] >>= m_aName;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
OUString SAL_CALL GenericClipboard::getImplementationName( )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
2012-06-01 09:39:35 -05:00
|
|
|
return OUString(GENERIC_CLIPBOARD_IMPLEMENTATION_NAME);
|
2001-01-31 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
2013-09-25 15:41:29 -03:00
|
|
|
return cppu::supportsService(this, ServiceName);
|
2001-01-31 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
Sequence< OUString > SAL_CALL GenericClipboard::getSupportedServiceNames( )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
return GenericClipboard_getSupportedServiceNames();
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
Reference< XTransferable > SAL_CALL GenericClipboard::getContents()
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
return m_aContents;
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
void SAL_CALL GenericClipboard::setContents(const Reference< XTransferable >& xTrans,
|
2001-01-31 14:37:29 +00:00
|
|
|
const Reference< XClipboardOwner >& xClipboardOwner )
|
|
|
|
{
|
|
|
|
// remember old values for callbacks before setting the new ones.
|
|
|
|
ClearableMutexGuard aGuard(m_aMutex);
|
|
|
|
|
|
|
|
Reference< XClipboardOwner > oldOwner(m_aOwner);
|
|
|
|
m_aOwner = xClipboardOwner;
|
|
|
|
|
|
|
|
Reference< XTransferable > oldContents(m_aContents);
|
|
|
|
m_aContents = xTrans;
|
|
|
|
|
|
|
|
aGuard.clear();
|
|
|
|
|
|
|
|
// notify old owner on loss of ownership
|
|
|
|
if( oldOwner.is() )
|
|
|
|
oldOwner->lostOwnership(static_cast < XClipboard * > (this), oldContents);
|
|
|
|
|
|
|
|
// notify all listeners on content changes
|
|
|
|
OInterfaceContainerHelper *pContainer =
|
2014-05-22 23:19:05 +02:00
|
|
|
rBHelper.aLC.getContainer(cppu::UnoType<XClipboardListener>::get());
|
2001-01-31 14:37:29 +00:00
|
|
|
if (pContainer)
|
|
|
|
{
|
|
|
|
ClipboardEvent aEvent(static_cast < XClipboard * > (this), m_aContents);
|
|
|
|
OInterfaceIteratorHelper aIterator(*pContainer);
|
|
|
|
|
|
|
|
while (aIterator.hasMoreElements())
|
|
|
|
{
|
|
|
|
Reference < XClipboardListener > xListener(aIterator.next(), UNO_QUERY);
|
|
|
|
if (xListener.is())
|
|
|
|
xListener->changedContents(aEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
OUString SAL_CALL GenericClipboard::getName()
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
return m_aName;
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
sal_Int8 SAL_CALL GenericClipboard::getRenderingCapabilities()
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
return RenderingCapabilities::Delayed;
|
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
void SAL_CALL GenericClipboard::addClipboardListener( const Reference< XClipboardListener >& listener )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( rBHelper.rMutex );
|
2001-03-22 13:28:22 +00:00
|
|
|
OSL_ENSURE( !rBHelper.bInDispose, "do not add listeners in the dispose call" );
|
|
|
|
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
|
2001-01-31 14:37:29 +00:00
|
|
|
if (!rBHelper.bInDispose && !rBHelper.bDisposed)
|
2014-05-17 00:23:39 +02:00
|
|
|
rBHelper.aLC.addInterface( cppu::UnoType<XClipboardListener>::get(), listener );
|
2001-01-31 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
2001-07-27 09:03:36 +00:00
|
|
|
void SAL_CALL GenericClipboard::removeClipboardListener( const Reference< XClipboardListener >& listener )
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard( rBHelper.rMutex );
|
2001-03-22 13:28:22 +00:00
|
|
|
OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
|
2001-01-31 14:37:29 +00:00
|
|
|
if (!rBHelper.bInDispose && !rBHelper.bDisposed)
|
2016-12-28 12:43:31 +01:00
|
|
|
rBHelper.aLC.removeInterface( cppu::UnoType<XClipboardListener>::get(), listener );
|
2001-01-31 14:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sequence< OUString > SAL_CALL GenericClipboard_getSupportedServiceNames()
|
|
|
|
{
|
2015-11-15 08:43:35 +02:00
|
|
|
Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.GenericClipboard" };
|
2001-01-31 14:37:29 +00:00
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInterface > SAL_CALL GenericClipboard_createInstance(
|
2006-06-20 05:00:27 +00:00
|
|
|
const Reference< XMultiServiceFactory > & /*xMultiServiceFactory*/)
|
2001-01-31 14:37:29 +00:00
|
|
|
{
|
2016-10-14 16:57:04 +02:00
|
|
|
return Reference < XInterface >(static_cast<OWeakObject *>(new GenericClipboard()));
|
2001-01-31 14:37:29 +00:00
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|