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>
24 using namespace com::sun::star::datatransfer
;
25 using namespace com::sun::star::datatransfer::clipboard
;
26 using namespace com::sun::star::lang
;
27 using namespace com::sun::star::uno
;
31 using ::dtrans::GenericClipboard
;
33 GenericClipboard::GenericClipboard() :
34 WeakComponentImplHelper4
< XClipboardEx
, XClipboardNotifier
, XServiceInfo
, XInitialization
> (m_aMutex
),
35 m_bInitialized(sal_False
)
39 // ------------------------------------------------------------------------
41 GenericClipboard::~GenericClipboard()
45 // ------------------------------------------------------------------------
47 void SAL_CALL
GenericClipboard::initialize( const Sequence
< Any
>& aArguments
)
48 throw(Exception
, RuntimeException
)
52 for (sal_Int32 n
= 0, nmax
= aArguments
.getLength(); n
< nmax
; n
++)
53 if (aArguments
[n
].getValueType() == getCppuType((OUString
*) 0))
55 aArguments
[0] >>= m_aName
;
61 // ------------------------------------------------------------------------
63 OUString SAL_CALL
GenericClipboard::getImplementationName( )
64 throw(RuntimeException
)
66 return OUString(GENERIC_CLIPBOARD_IMPLEMENTATION_NAME
);
69 // ------------------------------------------------------------------------
71 sal_Bool SAL_CALL
GenericClipboard::supportsService( const OUString
& ServiceName
)
72 throw(RuntimeException
)
74 Sequence
< OUString
> SupportedServicesNames
= GenericClipboard_getSupportedServiceNames();
76 for ( sal_Int32 n
= SupportedServicesNames
.getLength(); n
--; )
77 if ( SupportedServicesNames
[n
] == ServiceName
)
83 // ------------------------------------------------------------------------
85 Sequence
< OUString
> SAL_CALL
GenericClipboard::getSupportedServiceNames( )
86 throw(RuntimeException
)
88 return GenericClipboard_getSupportedServiceNames();
91 // ------------------------------------------------------------------------
93 Reference
< XTransferable
> SAL_CALL
GenericClipboard::getContents()
94 throw(RuntimeException
)
96 MutexGuard
aGuard(m_aMutex
);
100 // ------------------------------------------------------------------------
102 void SAL_CALL
GenericClipboard::setContents(const Reference
< XTransferable
>& xTrans
,
103 const Reference
< XClipboardOwner
>& xClipboardOwner
)
104 throw(RuntimeException
)
106 // remember old values for callbacks before setting the new ones.
107 ClearableMutexGuard
aGuard(m_aMutex
);
109 Reference
< XClipboardOwner
> oldOwner(m_aOwner
);
110 m_aOwner
= xClipboardOwner
;
112 Reference
< XTransferable
> oldContents(m_aContents
);
113 m_aContents
= xTrans
;
117 // notify old owner on loss of ownership
119 oldOwner
->lostOwnership(static_cast < XClipboard
* > (this), oldContents
);
121 // notify all listeners on content changes
122 OInterfaceContainerHelper
*pContainer
=
123 rBHelper
.aLC
.getContainer(getCppuType( (Reference
< XClipboardListener
> *) 0));
126 ClipboardEvent
aEvent(static_cast < XClipboard
* > (this), m_aContents
);
127 OInterfaceIteratorHelper
aIterator(*pContainer
);
129 while (aIterator
.hasMoreElements())
131 Reference
< XClipboardListener
> xListener(aIterator
.next(), UNO_QUERY
);
133 xListener
->changedContents(aEvent
);
138 // ------------------------------------------------------------------------
140 OUString SAL_CALL
GenericClipboard::getName()
141 throw(RuntimeException
)
146 // ------------------------------------------------------------------------
148 sal_Int8 SAL_CALL
GenericClipboard::getRenderingCapabilities()
149 throw(RuntimeException
)
151 return RenderingCapabilities::Delayed
;
155 // ------------------------------------------------------------------------
157 void SAL_CALL
GenericClipboard::addClipboardListener( const Reference
< XClipboardListener
>& listener
)
158 throw(RuntimeException
)
160 MutexGuard
aGuard( rBHelper
.rMutex
);
161 OSL_ENSURE( !rBHelper
.bInDispose
, "do not add listeners in the dispose call" );
162 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
163 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
164 rBHelper
.aLC
.addInterface( getCppuType( (const ::com::sun::star::uno::Reference
< XClipboardListener
> *) 0), listener
);
167 // ------------------------------------------------------------------------
169 void SAL_CALL
GenericClipboard::removeClipboardListener( const Reference
< XClipboardListener
>& listener
)
170 throw(RuntimeException
)
172 MutexGuard
aGuard( rBHelper
.rMutex
);
173 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
174 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
175 rBHelper
.aLC
.removeInterface( getCppuType( (const Reference
< XClipboardListener
> *) 0 ), listener
); \
178 // ------------------------------------------------------------------------
180 Sequence
< OUString
> SAL_CALL
GenericClipboard_getSupportedServiceNames()
182 Sequence
< OUString
> aRet(1);
183 aRet
[0] = OUString("com.sun.star.datatransfer.clipboard.GenericClipboard");
187 // ------------------------------------------------------------------------
189 Reference
< XInterface
> SAL_CALL
GenericClipboard_createInstance(
190 const Reference
< XMultiServiceFactory
> & /*xMultiServiceFactory*/)
192 return Reference
< XInterface
>( ( OWeakObject
* ) new GenericClipboard());
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */