fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / win32 / clipb / WinClipboard.cxx
blob9c053155926593b5965aa1234376537d8f5bf0a7
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 <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
30 using namespace osl;
31 using namespace std;
32 using namespace cppu;
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"
41 // helper functions
43 namespace
45 Sequence< OUString > SAL_CALL WinClipboard_getSupportedServiceNames()
47 Sequence< OUString > aRet(1);
48 aRet[0] = "com.sun.star.datatransfer.clipboard.SystemClipboard";
49 return aRet;
53 // ctor
55 /*XEventListener,*/
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 ) );
63 // XClipboard
65 // getContent
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
70 // DOTransferable
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 >( );
86 // setContent
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 );
102 // getName
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( );
113 return OUString("");
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( );
130 // XClipboardEx
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( );
141 return 0;
144 // XClipboardNotifier
146 // getName
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 ),
159 1 );
161 rBHelper.aLC.addInterface( cppu::UnoType<decltype(listener)>::get(), listener );
164 // getName
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 ),
177 1 );
179 rBHelper.aLC.removeInterface( cppu::UnoType<decltype(listener)>::get(), listener );
182 // getName
184 void SAL_CALL CWinClipboard::notifyAllClipboardListener( )
186 if ( !rBHelper.bDisposed )
188 ClearableMutexGuard aGuard( rBHelper.rMutex );
189 if ( !rBHelper.bDisposed )
191 aGuard.clear( );
193 OInterfaceContainerHelper* pICHelper = rBHelper.aLC.getContainer(
194 cppu::UnoType<XClipboardListener>::get());
196 if ( pICHelper )
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();
226 } // end if
227 } // end if
228 } // end if
231 // overwritten base class method which will be
232 // called by the base class dispose method
234 void SAL_CALL CWinClipboard::disposing()
236 // do my own stuff
237 m_pImpl->dispose( );
239 // force destruction of the impl class
240 m_pImpl.reset();
243 // XServiceInfo
245 OUString SAL_CALL CWinClipboard::getImplementationName( )
246 throw(RuntimeException)
248 return OUString( WINCLIPBOARD_IMPL_NAME );
251 // XServiceInfo
252 sal_Bool SAL_CALL CWinClipboard::supportsService( const OUString& ServiceName )
253 throw(RuntimeException)
255 return cppu::supportsService(this, ServiceName);
258 // XServiceInfo
260 Sequence< OUString > SAL_CALL CWinClipboard::getSupportedServiceNames( )
261 throw(RuntimeException)
263 return WinClipboard_getSupportedServiceNames();
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */