fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / generic / generic_clipboard.cxx
blob42d8fc947ec039a8d05cf91934143c2148c830ab
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 WeakComponentImplHelper4< XClipboardEx, XClipboardNotifier, XServiceInfo, XInitialization > (m_aMutex),
36 m_bInitialized(sal_False)
40 GenericClipboard::~GenericClipboard()
44 void SAL_CALL GenericClipboard::initialize( const Sequence< Any >& aArguments )
45 throw(Exception, RuntimeException)
47 if (!m_bInitialized)
49 for (sal_Int32 n = 0, nmax = aArguments.getLength(); n < nmax; n++)
50 if (aArguments[n].getValueType() == cppu::UnoType<OUString>::get())
52 aArguments[0] >>= m_aName;
53 break;
58 OUString SAL_CALL GenericClipboard::getImplementationName( )
59 throw(RuntimeException)
61 return OUString(GENERIC_CLIPBOARD_IMPLEMENTATION_NAME);
64 sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName )
65 throw(RuntimeException)
67 return cppu::supportsService(this, ServiceName);
70 Sequence< OUString > SAL_CALL GenericClipboard::getSupportedServiceNames( )
71 throw(RuntimeException)
73 return GenericClipboard_getSupportedServiceNames();
76 Reference< XTransferable > SAL_CALL GenericClipboard::getContents()
77 throw(RuntimeException)
79 MutexGuard aGuard(m_aMutex);
80 return m_aContents;
83 void SAL_CALL GenericClipboard::setContents(const Reference< XTransferable >& xTrans,
84 const Reference< XClipboardOwner >& xClipboardOwner )
85 throw(RuntimeException)
87 // remember old values for callbacks before setting the new ones.
88 ClearableMutexGuard aGuard(m_aMutex);
90 Reference< XClipboardOwner > oldOwner(m_aOwner);
91 m_aOwner = xClipboardOwner;
93 Reference< XTransferable > oldContents(m_aContents);
94 m_aContents = xTrans;
96 aGuard.clear();
98 // notify old owner on loss of ownership
99 if( oldOwner.is() )
100 oldOwner->lostOwnership(static_cast < XClipboard * > (this), oldContents);
102 // notify all listeners on content changes
103 OInterfaceContainerHelper *pContainer =
104 rBHelper.aLC.getContainer(cppu::UnoType<XClipboardListener>::get());
105 if (pContainer)
107 ClipboardEvent aEvent(static_cast < XClipboard * > (this), m_aContents);
108 OInterfaceIteratorHelper aIterator(*pContainer);
110 while (aIterator.hasMoreElements())
112 Reference < XClipboardListener > xListener(aIterator.next(), UNO_QUERY);
113 if (xListener.is())
114 xListener->changedContents(aEvent);
119 OUString SAL_CALL GenericClipboard::getName()
120 throw(RuntimeException)
122 return m_aName;
125 sal_Int8 SAL_CALL GenericClipboard::getRenderingCapabilities()
126 throw(RuntimeException)
128 return RenderingCapabilities::Delayed;
131 void SAL_CALL GenericClipboard::addClipboardListener( const Reference< XClipboardListener >& listener )
132 throw(RuntimeException)
134 MutexGuard aGuard( rBHelper.rMutex );
135 OSL_ENSURE( !rBHelper.bInDispose, "do not add listeners in the dispose call" );
136 OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
137 if (!rBHelper.bInDispose && !rBHelper.bDisposed)
138 rBHelper.aLC.addInterface( cppu::UnoType<XClipboardListener>::get(), listener );
141 void SAL_CALL GenericClipboard::removeClipboardListener( const Reference< XClipboardListener >& listener )
142 throw(RuntimeException)
144 MutexGuard aGuard( rBHelper.rMutex );
145 OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
146 if (!rBHelper.bInDispose && !rBHelper.bDisposed)
147 rBHelper.aLC.removeInterface( cppu::UnoType<XClipboardListener>::get(), listener ); \
150 Sequence< OUString > SAL_CALL GenericClipboard_getSupportedServiceNames()
152 Sequence< OUString > aRet(1);
153 aRet[0] = "com.sun.star.datatransfer.clipboard.GenericClipboard";
154 return aRet;
157 Reference< XInterface > SAL_CALL GenericClipboard_createInstance(
158 const Reference< XMultiServiceFactory > & /*xMultiServiceFactory*/)
160 return Reference < XInterface >( ( OWeakObject * ) new GenericClipboard());
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */