Update ooo320-m1
[ooovba.git] / dtrans / source / win32 / clipb / WinClipboard.cxx
blob748cfe0cbf6d9897693e2d0d922b68c13a519c13
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WinClipboard.cxx,v $
10 * $Revision: 1.15 $
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 //------------------------------------------------------------------------
35 // includes
36 //------------------------------------------------------------------------
37 #include <osl/diagnose.h>
38 #include "WinClipboard.hxx"
39 #include <com/sun/star/datatransfer/clipboard/ClipboardEvent.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/lang/IllegalArgumentException.hpp>
42 #include "WinClipbImpl.hxx"
44 //------------------------------------------------------------------------
45 // namespace directives
46 //------------------------------------------------------------------------
48 using namespace rtl;
49 using namespace osl;
50 using namespace std;
51 using namespace cppu;
53 using namespace com::sun::star::uno;
54 using namespace com::sun::star::datatransfer;
55 using namespace com::sun::star::datatransfer::clipboard;
56 using namespace com::sun::star::lang;
58 //------------------------------------------------------------------------
59 // defines
60 //------------------------------------------------------------------------
62 #define WINCLIPBOARD_IMPL_NAME "com.sun.star.datatransfer.clipboard.ClipboardW32"
64 //------------------------------------------------------------------------
65 // helper functions
66 //------------------------------------------------------------------------
68 namespace
70 Sequence< OUString > SAL_CALL WinClipboard_getSupportedServiceNames()
72 Sequence< OUString > aRet(1);
73 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
74 return aRet;
78 //------------------------------------------------------------------------
79 // ctor
80 //------------------------------------------------------------------------
81 /*XEventListener,*/
82 CWinClipboard::CWinClipboard( const Reference< XMultiServiceFactory >& rServiceManager, const OUString& aClipboardName ) :
83 WeakComponentImplHelper4< XClipboardEx, XFlushableClipboard, XClipboardNotifier, XServiceInfo >( m_aCbListenerMutex ),
84 m_SrvMgr( rServiceManager )
86 m_pImpl.reset( new CWinClipbImpl( aClipboardName, this ) );
89 //========================================================================
90 // XClipboard
91 //========================================================================
93 //------------------------------------------------------------------------
94 // getContent
95 // to avoid unecessary traffic we check first if there is a clipboard
96 // content which was set via setContent, in this case we don't need
97 // to query the content from the clipboard, create a new wrapper object
98 // and so on, we simply return the orignial XTransferable instead of our
99 // DOTransferable
100 //------------------------------------------------------------------------
102 Reference< XTransferable > SAL_CALL CWinClipboard::getContents( ) throw( RuntimeException )
104 MutexGuard aGuard( m_aMutex );
106 if ( rBHelper.bDisposed )
107 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
108 static_cast< XClipboardEx* >( this ) );
110 if ( NULL != m_pImpl.get( ) )
111 return m_pImpl->getContents( );
113 return Reference< XTransferable >( );
116 //------------------------------------------------------------------------
117 // setContent
118 //------------------------------------------------------------------------
120 void SAL_CALL CWinClipboard::setContents( const Reference< XTransferable >& xTransferable,
121 const Reference< XClipboardOwner >& xClipboardOwner )
122 throw( RuntimeException )
124 MutexGuard aGuard( m_aMutex );
126 if ( rBHelper.bDisposed )
127 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
128 static_cast< XClipboardEx* >( this ) );
130 if ( NULL != m_pImpl.get( ) )
131 m_pImpl->setContents( xTransferable, xClipboardOwner );
134 //------------------------------------------------------------------------
135 // getName
136 //------------------------------------------------------------------------
138 OUString SAL_CALL CWinClipboard::getName( ) throw( RuntimeException )
140 if ( rBHelper.bDisposed )
141 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
142 static_cast< XClipboardEx* >( this ) );
144 if ( NULL != m_pImpl.get( ) )
145 return m_pImpl->getName( );
147 return OUString::createFromAscii( "" );
150 //========================================================================
151 // XFlushableClipboard
152 //========================================================================
154 void SAL_CALL CWinClipboard::flushClipboard( ) throw( RuntimeException )
156 MutexGuard aGuard( m_aMutex );
158 if ( rBHelper.bDisposed )
159 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
160 static_cast< XClipboardEx* >( this ) );
162 if ( NULL != m_pImpl.get( ) )
163 m_pImpl->flushClipboard( );
166 //========================================================================
167 // XClipboardEx
168 //========================================================================
170 sal_Int8 SAL_CALL CWinClipboard::getRenderingCapabilities( ) throw( RuntimeException )
172 if ( rBHelper.bDisposed )
173 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
174 static_cast< XClipboardEx* >( this ) );
176 if ( NULL != m_pImpl.get( ) )
177 return m_pImpl->getRenderingCapabilities( );
179 return 0;
182 //========================================================================
183 // XClipboardNotifier
184 //========================================================================
186 //------------------------------------------------------------------------
187 // getName
188 //------------------------------------------------------------------------
190 void SAL_CALL CWinClipboard::addClipboardListener( const Reference< XClipboardListener >& listener )
191 throw( RuntimeException )
193 if ( rBHelper.bDisposed )
194 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
195 static_cast< XClipboardEx* >( this ) );
197 // check input parameter
198 if ( !listener.is( ) )
199 throw IllegalArgumentException( OUString::createFromAscii( "empty reference" ),
200 static_cast< XClipboardEx* >( this ),
201 1 );
203 rBHelper.aLC.addInterface( getCppuType( &listener ), listener );
206 //------------------------------------------------------------------------
207 // getName
208 //------------------------------------------------------------------------
210 void SAL_CALL CWinClipboard::removeClipboardListener( const Reference< XClipboardListener >& listener )
211 throw( RuntimeException )
213 if ( rBHelper.bDisposed )
214 throw DisposedException( OUString::createFromAscii( "object is already disposed" ),
215 static_cast< XClipboardEx* >( this ) );
217 // check input parameter
218 if ( !listener.is( ) )
219 throw IllegalArgumentException( OUString::createFromAscii( "empty reference" ),
220 static_cast< XClipboardEx* >( this ),
221 1 );
223 rBHelper.aLC.removeInterface( getCppuType( &listener ), listener );
226 //------------------------------------------------------------------------
227 // getName
228 //------------------------------------------------------------------------
230 void SAL_CALL CWinClipboard::notifyAllClipboardListener( )
232 if ( !rBHelper.bDisposed )
234 ClearableMutexGuard aGuard( rBHelper.rMutex );
235 if ( !rBHelper.bDisposed )
237 aGuard.clear( );
239 OInterfaceContainerHelper* pICHelper = rBHelper.aLC.getContainer(
240 getCppuType( ( Reference< XClipboardListener > * ) 0 ) );
242 if ( pICHelper )
246 OInterfaceIteratorHelper iter(*pICHelper);
247 Reference<XTransferable> rXTransf(m_pImpl->getContents());
248 ClipboardEvent aClipbEvent(static_cast<XClipboard*>(this), rXTransf);
250 while(iter.hasMoreElements())
254 Reference<XClipboardListener> xCBListener(iter.next(), UNO_QUERY);
255 if (xCBListener.is())
256 xCBListener->changedContents(aClipbEvent);
258 catch(RuntimeException&)
260 OSL_ENSURE( false, "RuntimeException caught" );
264 catch(const ::com::sun::star::lang::DisposedException&)
266 OSL_ENSURE(false, "Service Manager disposed");
268 // no further clipboard changed notifications
269 m_pImpl->unregisterClipboardViewer();
272 } // end if
273 } // end if
274 } // end if
277 //------------------------------------------------
278 // overwritten base class method which will be
279 // called by the base class dispose method
280 //------------------------------------------------
282 void SAL_CALL CWinClipboard::disposing()
284 // do my own stuff
285 m_pImpl->dispose( );
287 // force destruction of the impl class
288 m_pImpl.reset( NULL );
291 // -------------------------------------------------
292 // XServiceInfo
293 // -------------------------------------------------
295 OUString SAL_CALL CWinClipboard::getImplementationName( )
296 throw(RuntimeException)
298 return OUString::createFromAscii( WINCLIPBOARD_IMPL_NAME );
301 // -------------------------------------------------
302 // XServiceInfo
303 // -------------------------------------------------
305 sal_Bool SAL_CALL CWinClipboard::supportsService( const OUString& ServiceName )
306 throw(RuntimeException)
308 Sequence < OUString > SupportedServicesNames = WinClipboard_getSupportedServiceNames();
310 for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
311 if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
312 return sal_True;
314 return sal_False;
317 // -------------------------------------------------
318 // XServiceInfo
319 // -------------------------------------------------
321 Sequence< OUString > SAL_CALL CWinClipboard::getSupportedServiceNames( )
322 throw(RuntimeException)
324 return WinClipboard_getSupportedServiceNames();