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 <osl/diagnose.h>
21 #include "WinClipboard.hxx"
22 #include <com/sun/star/datatransfer/clipboard/ClipboardEvent.hpp>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include "WinClipbImpl.hxx"
28 // namespace directives
34 using namespace com::sun::star::uno
;
35 using namespace com::sun::star::datatransfer
;
36 using namespace com::sun::star::datatransfer::clipboard
;
37 using namespace com::sun::star::lang
;
39 #define WINCLIPBOARD_IMPL_NAME "com.sun.star.datatransfer.clipboard.ClipboardW32"
45 Sequence
< OUString
> SAL_CALL
WinClipboard_getSupportedServiceNames()
47 Sequence
< OUString
> aRet(1);
48 aRet
[0] = "com.sun.star.datatransfer.clipboard.SystemClipboard";
56 CWinClipboard::CWinClipboard( const Reference
< XComponentContext
>& rxContext
, const OUString
& aClipboardName
) :
57 WeakComponentImplHelper3
< XSystemClipboard
, XFlushableClipboard
, XServiceInfo
>( m_aCbListenerMutex
),
58 m_xContext( rxContext
)
60 m_pImpl
.reset( new CWinClipbImpl( aClipboardName
, this ) );
66 // to avoid unnecessary traffic we check first if there is a clipboard
67 // content which was set via setContent, in this case we don't need
68 // to query the content from the clipboard, create a new wrapper object
69 // and so on, we simply return the orignial XTransferable instead of our
72 Reference
< XTransferable
> SAL_CALL
CWinClipboard::getContents( ) throw( RuntimeException
)
74 MutexGuard
aGuard( m_aMutex
);
76 if ( rBHelper
.bDisposed
)
77 throw DisposedException("object is already disposed",
78 static_cast< XClipboardEx
* >( this ) );
80 if ( NULL
!= m_pImpl
.get( ) )
81 return m_pImpl
->getContents( );
83 return Reference
< XTransferable
>( );
88 void SAL_CALL
CWinClipboard::setContents( const Reference
< XTransferable
>& xTransferable
,
89 const Reference
< XClipboardOwner
>& xClipboardOwner
)
90 throw( RuntimeException
)
92 MutexGuard
aGuard( m_aMutex
);
94 if ( rBHelper
.bDisposed
)
95 throw DisposedException("object is already disposed",
96 static_cast< XClipboardEx
* >( this ) );
98 if ( NULL
!= m_pImpl
.get( ) )
99 m_pImpl
->setContents( xTransferable
, xClipboardOwner
);
104 OUString SAL_CALL
CWinClipboard::getName( ) throw( RuntimeException
)
106 if ( rBHelper
.bDisposed
)
107 throw DisposedException("object is already disposed",
108 static_cast< XClipboardEx
* >( this ) );
110 if ( NULL
!= m_pImpl
.get( ) )
111 return m_pImpl
->getName( );
116 // XFlushableClipboard
118 void SAL_CALL
CWinClipboard::flushClipboard( ) throw( RuntimeException
)
120 MutexGuard
aGuard( m_aMutex
);
122 if ( rBHelper
.bDisposed
)
123 throw DisposedException("object is already disposed",
124 static_cast< XClipboardEx
* >( this ) );
126 if ( NULL
!= m_pImpl
.get( ) )
127 m_pImpl
->flushClipboard( );
132 sal_Int8 SAL_CALL
CWinClipboard::getRenderingCapabilities( ) throw( RuntimeException
)
134 if ( rBHelper
.bDisposed
)
135 throw DisposedException("object is already disposed",
136 static_cast< XClipboardEx
* >( this ) );
138 if ( NULL
!= m_pImpl
.get( ) )
139 return m_pImpl
->getRenderingCapabilities( );
144 // XClipboardNotifier
148 void SAL_CALL
CWinClipboard::addClipboardListener( const Reference
< XClipboardListener
>& listener
)
149 throw( RuntimeException
)
151 if ( rBHelper
.bDisposed
)
152 throw DisposedException("object is already disposed",
153 static_cast< XClipboardEx
* >( this ) );
155 // check input parameter
156 if ( !listener
.is( ) )
157 throw IllegalArgumentException("empty reference",
158 static_cast< XClipboardEx
* >( this ),
161 rBHelper
.aLC
.addInterface( cppu::UnoType
<decltype(listener
)>::get(), listener
);
166 void SAL_CALL
CWinClipboard::removeClipboardListener( const Reference
< XClipboardListener
>& listener
)
167 throw( RuntimeException
)
169 if ( rBHelper
.bDisposed
)
170 throw DisposedException("object is already disposed",
171 static_cast< XClipboardEx
* >( this ) );
173 // check input parameter
174 if ( !listener
.is( ) )
175 throw IllegalArgumentException("empty reference",
176 static_cast< XClipboardEx
* >( this ),
179 rBHelper
.aLC
.removeInterface( cppu::UnoType
<decltype(listener
)>::get(), listener
);
184 void SAL_CALL
CWinClipboard::notifyAllClipboardListener( )
186 if ( !rBHelper
.bDisposed
)
188 ClearableMutexGuard
aGuard( rBHelper
.rMutex
);
189 if ( !rBHelper
.bDisposed
)
193 OInterfaceContainerHelper
* pICHelper
= rBHelper
.aLC
.getContainer(
194 cppu::UnoType
<XClipboardListener
>::get());
200 OInterfaceIteratorHelper
iter(*pICHelper
);
201 Reference
<XTransferable
> rXTransf(m_pImpl
->getContents());
202 ClipboardEvent
aClipbEvent(static_cast<XClipboard
*>(this), rXTransf
);
204 while(iter
.hasMoreElements())
208 Reference
<XClipboardListener
> xCBListener(iter
.next(), UNO_QUERY
);
209 if (xCBListener
.is())
210 xCBListener
->changedContents(aClipbEvent
);
212 catch(RuntimeException
&)
214 OSL_FAIL( "RuntimeException caught" );
218 catch(const ::com::sun::star::lang::DisposedException
&)
220 OSL_FAIL("Service Manager disposed");
222 // no further clipboard changed notifications
223 m_pImpl
->unregisterClipboardViewer();
231 // overwritten base class method which will be
232 // called by the base class dispose method
234 void SAL_CALL
CWinClipboard::disposing()
239 // force destruction of the impl class
245 OUString SAL_CALL
CWinClipboard::getImplementationName( )
246 throw(RuntimeException
)
248 return OUString( WINCLIPBOARD_IMPL_NAME
);
252 sal_Bool SAL_CALL
CWinClipboard::supportsService( const OUString
& ServiceName
)
253 throw(RuntimeException
)
255 return cppu::supportsService(this, ServiceName
);
260 Sequence
< OUString
> SAL_CALL
CWinClipboard::getSupportedServiceNames( )
261 throw(RuntimeException
)
263 return WinClipboard_getSupportedServiceNames();
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */