1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: generic_clipboard.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
34 #include <generic_clipboard.hxx>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/datatransfer/clipboard/RenderingCapabilities.hpp>
38 using namespace com::sun::star::datatransfer
;
39 using namespace com::sun::star::datatransfer::clipboard
;
40 using namespace com::sun::star::lang
;
41 using namespace com::sun::star::uno
;
45 using ::dtrans::GenericClipboard
;
46 using ::rtl::OUString
;
48 GenericClipboard::GenericClipboard() :
49 WeakComponentImplHelper4
< XClipboardEx
, XClipboardNotifier
, XServiceInfo
, XInitialization
> (m_aMutex
),
50 m_bInitialized(sal_False
)
54 // ------------------------------------------------------------------------
56 GenericClipboard::~GenericClipboard()
60 // ------------------------------------------------------------------------
62 void SAL_CALL
GenericClipboard::initialize( const Sequence
< Any
>& aArguments
)
63 throw(Exception
, RuntimeException
)
67 for (sal_Int32 n
= 0, nmax
= aArguments
.getLength(); n
< nmax
; n
++)
68 if (aArguments
[n
].getValueType() == getCppuType((OUString
*) 0))
70 aArguments
[0] >>= m_aName
;
76 // ------------------------------------------------------------------------
78 OUString SAL_CALL
GenericClipboard::getImplementationName( )
79 throw(RuntimeException
)
81 return OUString::createFromAscii(GENERIC_CLIPBOARD_IMPLEMENTATION_NAME
);
84 // ------------------------------------------------------------------------
86 sal_Bool SAL_CALL
GenericClipboard::supportsService( const OUString
& ServiceName
)
87 throw(RuntimeException
)
89 Sequence
< OUString
> SupportedServicesNames
= GenericClipboard_getSupportedServiceNames();
91 for ( sal_Int32 n
= SupportedServicesNames
.getLength(); n
--; )
92 if (SupportedServicesNames
[n
].compareTo(ServiceName
) == 0)
98 // ------------------------------------------------------------------------
100 Sequence
< OUString
> SAL_CALL
GenericClipboard::getSupportedServiceNames( )
101 throw(RuntimeException
)
103 return GenericClipboard_getSupportedServiceNames();
106 // ------------------------------------------------------------------------
108 Reference
< XTransferable
> SAL_CALL
GenericClipboard::getContents()
109 throw(RuntimeException
)
111 MutexGuard
aGuard(m_aMutex
);
115 // ------------------------------------------------------------------------
117 void SAL_CALL
GenericClipboard::setContents(const Reference
< XTransferable
>& xTrans
,
118 const Reference
< XClipboardOwner
>& xClipboardOwner
)
119 throw(RuntimeException
)
121 // remember old values for callbacks before setting the new ones.
122 ClearableMutexGuard
aGuard(m_aMutex
);
124 Reference
< XClipboardOwner
> oldOwner(m_aOwner
);
125 m_aOwner
= xClipboardOwner
;
127 Reference
< XTransferable
> oldContents(m_aContents
);
128 m_aContents
= xTrans
;
132 // notify old owner on loss of ownership
134 oldOwner
->lostOwnership(static_cast < XClipboard
* > (this), oldContents
);
136 // notify all listeners on content changes
137 OInterfaceContainerHelper
*pContainer
=
138 rBHelper
.aLC
.getContainer(getCppuType( (Reference
< XClipboardListener
> *) 0));
141 ClipboardEvent
aEvent(static_cast < XClipboard
* > (this), m_aContents
);
142 OInterfaceIteratorHelper
aIterator(*pContainer
);
144 while (aIterator
.hasMoreElements())
146 Reference
< XClipboardListener
> xListener(aIterator
.next(), UNO_QUERY
);
148 xListener
->changedContents(aEvent
);
153 // ------------------------------------------------------------------------
155 OUString SAL_CALL
GenericClipboard::getName()
156 throw(RuntimeException
)
161 // ------------------------------------------------------------------------
163 sal_Int8 SAL_CALL
GenericClipboard::getRenderingCapabilities()
164 throw(RuntimeException
)
166 return RenderingCapabilities::Delayed
;
170 // ------------------------------------------------------------------------
172 void SAL_CALL
GenericClipboard::addClipboardListener( const Reference
< XClipboardListener
>& listener
)
173 throw(RuntimeException
)
175 MutexGuard
aGuard( rBHelper
.rMutex
);
176 OSL_ENSURE( !rBHelper
.bInDispose
, "do not add listeners in the dispose call" );
177 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
178 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
179 rBHelper
.aLC
.addInterface( getCppuType( (const ::com::sun::star::uno::Reference
< XClipboardListener
> *) 0), listener
);
182 // ------------------------------------------------------------------------
184 void SAL_CALL
GenericClipboard::removeClipboardListener( const Reference
< XClipboardListener
>& listener
)
185 throw(RuntimeException
)
187 MutexGuard
aGuard( rBHelper
.rMutex
);
188 OSL_ENSURE( !rBHelper
.bDisposed
, "object is disposed" );
189 if (!rBHelper
.bInDispose
&& !rBHelper
.bDisposed
)
190 rBHelper
.aLC
.removeInterface( getCppuType( (const Reference
< XClipboardListener
> *) 0 ), listener
); \
193 // ------------------------------------------------------------------------
195 Sequence
< OUString
> SAL_CALL
GenericClipboard_getSupportedServiceNames()
197 Sequence
< OUString
> aRet(1);
198 aRet
[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.GenericClipboard");
202 // ------------------------------------------------------------------------
204 Reference
< XInterface
> SAL_CALL
GenericClipboard_createInstance(
205 const Reference
< XMultiServiceFactory
> & /*xMultiServiceFactory*/)
207 return Reference
< XInterface
>( ( OWeakObject
* ) new GenericClipboard());