Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / source / components / dtranscomp.cxx
blobf2d221d743d3225275755010dbb293d8f37a4dae
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/mutex.hxx"
22 #include "vcl/svapp.hxx"
24 #include "factory.hxx"
25 #include "svdata.hxx"
26 #include "salinst.hxx"
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include "com/sun/star/lang/XServiceInfo.hpp"
30 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
31 #include "com/sun/star/lang/XInitialization.hpp"
32 #include "com/sun/star/lang/DisposedException.hpp"
33 #include "com/sun/star/datatransfer/XTransferable.hpp"
34 #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp"
35 #include "com/sun/star/datatransfer/clipboard/XClipboardEx.hpp"
36 #include "com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp"
37 #include "com/sun/star/datatransfer/clipboard/XClipboardListener.hpp"
38 #include "com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp"
39 #include "com/sun/star/datatransfer/dnd/XDragSource.hpp"
40 #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
41 #include "com/sun/star/datatransfer/dnd/DNDConstants.hpp"
43 #include "cppuhelper/compbase.hxx"
44 #include "cppuhelper/implbase1.hxx"
45 #include <cppuhelper/supportsservice.hxx>
47 using namespace com::sun::star;
48 using namespace com::sun::star::uno;
49 using namespace com::sun::star::lang;
51 namespace vcl
53 // generic implementation to satisfy SalInstance
54 class GenericClipboard :
55 public cppu::WeakComponentImplHelper<
56 datatransfer::clipboard::XSystemClipboard,
57 XServiceInfo
60 osl::Mutex m_aMutex;
61 Reference< ::com::sun::star::datatransfer::XTransferable > m_aContents;
62 Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner > m_aOwner;
63 std::list< Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > m_aListeners;
65 public:
67 GenericClipboard() : cppu::WeakComponentImplHelper<
68 datatransfer::clipboard::XSystemClipboard,
69 XServiceInfo
70 >( m_aMutex )
72 virtual ~GenericClipboard();
75 * XServiceInfo
78 virtual OUString SAL_CALL getImplementationName() throw( RuntimeException, std::exception ) SAL_OVERRIDE;
79 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
80 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( RuntimeException, std::exception ) SAL_OVERRIDE;
82 static OUString getImplementationName_static();
83 static Sequence< OUString > getSupportedServiceNames_static();
86 * XClipboard
89 virtual Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents()
90 throw(RuntimeException, std::exception) SAL_OVERRIDE;
92 virtual void SAL_CALL setContents(
93 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
94 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
95 throw(RuntimeException, std::exception) SAL_OVERRIDE;
97 virtual OUString SAL_CALL getName()
98 throw(RuntimeException, std::exception) SAL_OVERRIDE;
101 * XClipboardEx
104 virtual sal_Int8 SAL_CALL getRenderingCapabilities()
105 throw(RuntimeException, std::exception) SAL_OVERRIDE;
108 * XClipboardNotifier
110 virtual void SAL_CALL addClipboardListener(
111 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
112 throw(RuntimeException, std::exception) SAL_OVERRIDE;
114 virtual void SAL_CALL removeClipboardListener(
115 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
116 throw(RuntimeException, std::exception) SAL_OVERRIDE;
119 GenericClipboard::~GenericClipboard()
123 OUString GenericClipboard::getImplementationName_static()
125 return OUString( "com.sun.star.datatransfer.VCLGenericClipboard" );
128 Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
130 Sequence< OUString > aRet(1);
131 aRet[0] = "com.sun.star.datatransfer.clipboard.SystemClipboard";
132 return aRet;
135 OUString GenericClipboard::getImplementationName() throw( RuntimeException, std::exception )
137 return getImplementationName_static();
140 Sequence< OUString > GenericClipboard::getSupportedServiceNames() throw( RuntimeException, std::exception )
142 return getSupportedServiceNames_static();
145 sal_Bool GenericClipboard::supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception )
147 return cppu::supportsService(this, ServiceName);
150 Reference< ::com::sun::star::datatransfer::XTransferable > GenericClipboard::getContents() throw( RuntimeException, std::exception )
152 return m_aContents;
155 void GenericClipboard::setContents(
156 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
157 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
158 throw( RuntimeException, std::exception )
160 osl::ClearableMutexGuard aGuard( m_aMutex );
161 Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
162 Reference< datatransfer::XTransferable > xOldContents( m_aContents );
163 m_aContents = xTrans;
164 m_aOwner = xClipboardOwner;
166 std::list< Reference< datatransfer::clipboard::XClipboardListener > > xListeners( m_aListeners );
167 datatransfer::clipboard::ClipboardEvent aEv;
168 aEv.Contents = m_aContents;
170 aGuard.clear();
172 if( xOldOwner.is() && xOldOwner != xClipboardOwner )
173 xOldOwner->lostOwnership( this, xOldContents );
174 for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it =
175 xListeners.begin(); it != xListeners.end() ; ++it )
177 (*it)->changedContents( aEv );
181 OUString GenericClipboard::getName() throw( RuntimeException, std::exception )
183 return OUString( "CLIPBOARD" );
186 sal_Int8 GenericClipboard::getRenderingCapabilities() throw( RuntimeException, std::exception )
188 return 0;
191 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
192 throw( RuntimeException, std::exception )
194 osl::ClearableMutexGuard aGuard( m_aMutex );
196 m_aListeners.push_back( listener );
199 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
200 throw( RuntimeException, std::exception )
202 osl::ClearableMutexGuard aGuard( m_aMutex );
204 m_aListeners.remove( listener );
207 class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
208 com::sun::star::lang::XSingleServiceFactory
211 osl::Mutex m_aMutex;
212 public:
213 ClipboardFactory();
214 virtual ~ClipboardFactory();
217 * XSingleServiceFactory
219 virtual Reference< XInterface > SAL_CALL createInstance() throw(std::exception) SAL_OVERRIDE;
220 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) throw(std::exception) SAL_OVERRIDE;
223 ClipboardFactory::ClipboardFactory() :
224 cppu::WeakComponentImplHelper<
225 com::sun::star::lang::XSingleServiceFactory
226 >( m_aMutex )
230 ClipboardFactory::~ClipboardFactory()
234 Reference< XInterface > ClipboardFactory::createInstance() throw(std::exception)
236 return createInstanceWithArguments( Sequence< Any >() );
239 Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) throw(std::exception)
241 SolarMutexGuard aGuard;
242 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
243 return xResult;
246 OUString SAL_CALL Clipboard_getImplementationName()
248 #if defined UNX
249 return OUString(
250 #if ! defined MACOSX
251 "com.sun.star.datatransfer.X11ClipboardSupport"
252 #else
253 "com.sun.star.datatransfer.clipboard.AquaClipboard"
254 #endif
256 #else
257 return GenericClipboard::getImplementationName_static();
258 #endif
261 Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & )
263 return Reference< XSingleServiceFactory >( new ClipboardFactory() );
267 * generic DragSource dummy
269 class GenericDragSource : public cppu::WeakComponentImplHelper<
270 datatransfer::dnd::XDragSource,
271 XInitialization,
272 css::lang::XServiceInfo
275 osl::Mutex m_aMutex;
276 public:
277 GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
278 virtual ~GenericDragSource();
280 // XDragSource
281 virtual sal_Bool SAL_CALL isDragImageSupported() throw(std::exception) SAL_OVERRIDE;
282 virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw(std::exception) SAL_OVERRIDE;
283 virtual void SAL_CALL startDrag(
284 const datatransfer::dnd::DragGestureEvent& trigger,
285 sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
286 const Reference< datatransfer::XTransferable >& transferable,
287 const Reference< datatransfer::dnd::XDragSourceListener >& listener
288 ) throw(std::exception) SAL_OVERRIDE;
290 // XInitialization
291 virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception, std::exception ) SAL_OVERRIDE;
293 OUString SAL_CALL getImplementationName()
294 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
295 { return getImplementationName_static(); }
297 sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
298 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
299 { return cppu::supportsService(this, ServiceName); }
301 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
302 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
303 { return getSupportedServiceNames_static(); }
305 static Sequence< OUString > getSupportedServiceNames_static()
307 Sequence< OUString > aRet( 1 );
308 aRet[0] = "com.sun.star.datatransfer.dnd.GenericDragSource";
309 return aRet;
312 static OUString getImplementationName_static()
314 return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource");
318 GenericDragSource::~GenericDragSource()
322 sal_Bool GenericDragSource::isDragImageSupported() throw(std::exception)
324 return false;
327 sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 ) throw(std::exception)
329 return 0;
332 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
333 sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
334 const Reference< datatransfer::XTransferable >&,
335 const Reference< datatransfer::dnd::XDragSourceListener >& listener
336 ) throw(std::exception)
338 datatransfer::dnd::DragSourceDropEvent aEv;
339 aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
340 aEv.DropSuccess = false;
341 listener->dragDropEnd( aEv );
344 void GenericDragSource::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
348 Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames()
350 #if defined UNX
351 OUString aServiceName(
352 #if ! defined MACOSX
353 "com.sun.star.datatransfer.dnd.X11DragSource"
354 #else
355 "com.sun.star.datatransfer.dnd.OleDragSource"
356 #endif
358 return Sequence< OUString >(&aServiceName, 1);
359 #else
360 return GenericDragSource::getSupportedServiceNames_static();
361 #endif
364 OUString SAL_CALL DragSource_getImplementationName()
366 #if defined UNX
367 return OUString(
368 #if ! defined MACOSX
369 "com.sun.star.datatransfer.dnd.XdndSupport"
370 #else
371 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
372 #endif
374 #else
375 return GenericDragSource::getImplementationName_static();
376 #endif
379 Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& )
381 SolarMutexGuard aGuard;
382 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
383 return xResult;
387 * generic DragSource dummy
390 class GenericDropTarget : public cppu::WeakComponentImplHelper<
391 datatransfer::dnd::XDropTarget,
392 XInitialization,
393 css::lang::XServiceInfo
396 osl::Mutex m_aMutex;
397 public:
398 GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
400 virtual ~GenericDropTarget();
402 // XInitialization
403 virtual void SAL_CALL initialize( const Sequence< Any >& args ) throw ( Exception, std::exception ) SAL_OVERRIDE;
405 // XDropTarget
406 virtual void SAL_CALL addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) SAL_OVERRIDE;
407 virtual void SAL_CALL removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) SAL_OVERRIDE;
408 virtual sal_Bool SAL_CALL isActive() throw(std::exception) SAL_OVERRIDE;
409 virtual void SAL_CALL setActive( sal_Bool active ) throw(std::exception) SAL_OVERRIDE;
410 virtual sal_Int8 SAL_CALL getDefaultActions() throw(std::exception) SAL_OVERRIDE;
411 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(std::exception) SAL_OVERRIDE;
413 OUString SAL_CALL getImplementationName()
414 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
415 { return getImplementationName_static(); }
417 sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
418 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
419 { return cppu::supportsService(this, ServiceName); }
421 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
422 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
423 { return getSupportedServiceNames_static(); }
425 static Sequence< OUString > getSupportedServiceNames_static()
427 Sequence< OUString > aRet( 1 );
428 aRet[0] = "com.sun.star.datatransfer.dnd.GenericDropTarget";
429 return aRet;
432 static OUString getImplementationName_static()
434 return OUString("com.sun.star.datatransfer.dnd.VclGenericDropTarget");
438 GenericDropTarget::~GenericDropTarget()
442 void GenericDropTarget::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
446 void GenericDropTarget::addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
450 void GenericDropTarget::removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
454 sal_Bool GenericDropTarget::isActive() throw(std::exception)
456 return false;
459 void GenericDropTarget::setActive( sal_Bool ) throw(std::exception)
463 sal_Int8 GenericDropTarget::getDefaultActions() throw(std::exception)
465 return 0;
468 void GenericDropTarget::setDefaultActions( sal_Int8) throw(std::exception)
472 Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames()
474 #if defined UNX
475 OUString aServiceName(
476 #if ! defined MACOSX
477 "com.sun.star.datatransfer.dnd.X11DropTarget"
478 #else
479 "com.sun.star.datatransfer.dnd.OleDropTarget"
480 #endif
482 return Sequence< OUString >(&aServiceName, 1);
483 #else
484 return GenericDropTarget::getSupportedServiceNames_static();
485 #endif
488 OUString SAL_CALL DropTarget_getImplementationName()
490 #if defined UNX
491 return OUString(
492 #if ! defined MACOSX
493 "com.sun.star.datatransfer.dnd.XdndDropTarget"
494 #else
495 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
496 #endif
498 #else
499 return GenericDropTarget::getImplementationName_static();
500 #endif
503 Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
505 SolarMutexGuard aGuard;
506 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
507 return xResult;
510 } // namespace vcl
513 * SalInstance generic
515 Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
517 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericClipboard() );
520 Reference< XInterface > SalInstance::CreateDragSource()
522 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDragSource() );
525 Reference< XInterface > SalInstance::CreateDropTarget()
527 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDropTarget() );
530 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */