Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / components / dtranscomp.cxx
blob0946b0e34fa57ae5fb8d39a07dfbe0eacdcb916f
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/supportsservice.hxx>
46 using namespace com::sun::star;
47 using namespace com::sun::star::uno;
48 using namespace com::sun::star::lang;
50 namespace vcl
52 // generic implementation to satisfy SalInstance
53 class GenericClipboard :
54 public cppu::WeakComponentImplHelper<
55 datatransfer::clipboard::XSystemClipboard,
56 XServiceInfo
59 osl::Mutex m_aMutex;
60 Reference< css::datatransfer::XTransferable > m_aContents;
61 Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner;
62 std::list< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners;
64 public:
66 GenericClipboard() : cppu::WeakComponentImplHelper<
67 datatransfer::clipboard::XSystemClipboard,
68 XServiceInfo
69 >( m_aMutex )
73 * XServiceInfo
76 virtual OUString SAL_CALL getImplementationName() override;
77 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
78 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
80 static Sequence< OUString > getSupportedServiceNames_static();
83 * XClipboard
86 virtual Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override;
88 virtual void SAL_CALL setContents(
89 const Reference< css::datatransfer::XTransferable >& xTrans,
90 const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) override;
92 virtual OUString SAL_CALL getName() override;
95 * XClipboardEx
98 virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
101 * XClipboardNotifier
103 virtual void SAL_CALL addClipboardListener(
104 const Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
106 virtual void SAL_CALL removeClipboardListener(
107 const Reference< css::datatransfer::clipboard::XClipboardListener >& listener ) override;
110 Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
112 Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.SystemClipboard" };
113 return aRet;
116 OUString GenericClipboard::getImplementationName()
118 return OUString("com.sun.star.datatransfer.VCLGenericClipboard");
121 Sequence< OUString > GenericClipboard::getSupportedServiceNames()
123 return getSupportedServiceNames_static();
126 sal_Bool GenericClipboard::supportsService( const OUString& ServiceName )
128 return cppu::supportsService(this, ServiceName);
131 Reference< css::datatransfer::XTransferable > GenericClipboard::getContents()
133 return m_aContents;
136 void GenericClipboard::setContents(
137 const Reference< css::datatransfer::XTransferable >& xTrans,
138 const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
140 osl::ClearableMutexGuard aGuard( m_aMutex );
141 Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
142 Reference< datatransfer::XTransferable > xOldContents( m_aContents );
143 m_aContents = xTrans;
144 m_aOwner = xClipboardOwner;
146 std::list< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
147 datatransfer::clipboard::ClipboardEvent aEv;
148 aEv.Contents = m_aContents;
150 aGuard.clear();
152 if( xOldOwner.is() && xOldOwner != xClipboardOwner )
153 xOldOwner->lostOwnership( this, xOldContents );
154 for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it =
155 aListeners.begin(); it != aListeners.end() ; ++it )
157 (*it)->changedContents( aEv );
161 OUString GenericClipboard::getName()
163 return OUString( "CLIPBOARD" );
166 sal_Int8 GenericClipboard::getRenderingCapabilities()
168 return 0;
171 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
173 osl::ClearableMutexGuard aGuard( m_aMutex );
175 m_aListeners.push_back( listener );
178 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
180 osl::ClearableMutexGuard aGuard( m_aMutex );
182 m_aListeners.remove( listener );
185 class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
186 css::lang::XSingleServiceFactory
189 osl::Mutex m_aMutex;
190 public:
191 ClipboardFactory();
194 * XSingleServiceFactory
196 virtual Reference< XInterface > SAL_CALL createInstance() override;
197 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) override;
200 ClipboardFactory::ClipboardFactory() :
201 cppu::WeakComponentImplHelper<
202 css::lang::XSingleServiceFactory
203 >( m_aMutex )
207 Reference< XInterface > ClipboardFactory::createInstance()
209 return createInstanceWithArguments( Sequence< Any >() );
212 Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments )
214 SolarMutexGuard aGuard;
215 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
216 return xResult;
219 OUString SAL_CALL Clipboard_getImplementationName()
221 return OUString(
222 #if defined MACOSX
223 "com.sun.star.datatransfer.clipboard.AquaClipboard"
224 #elif defined ANDROID
225 "com.sun.star.datatransfer.VCLGenericClipboard"
226 #elif defined UNX
227 "com.sun.star.datatransfer.X11ClipboardSupport"
228 #else
229 "com.sun.star.datatransfer.VCLGenericClipboard"
230 #endif
234 Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & )
236 return Reference< XSingleServiceFactory >( new ClipboardFactory() );
240 * generic DragSource dummy
242 class GenericDragSource : public cppu::WeakComponentImplHelper<
243 datatransfer::dnd::XDragSource,
244 XInitialization,
245 css::lang::XServiceInfo
248 osl::Mutex m_aMutex;
249 public:
250 GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
252 // XDragSource
253 virtual sal_Bool SAL_CALL isDragImageSupported() override;
254 virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) override;
255 virtual void SAL_CALL startDrag(
256 const datatransfer::dnd::DragGestureEvent& trigger,
257 sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
258 const Reference< datatransfer::XTransferable >& transferable,
259 const Reference< datatransfer::dnd::XDragSourceListener >& listener
260 ) override;
262 // XInitialization
263 virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) override;
265 OUString SAL_CALL getImplementationName() override
266 { return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource"); }
268 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
269 { return cppu::supportsService(this, ServiceName); }
271 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
272 { return getSupportedServiceNames_static(); }
274 static Sequence< OUString > getSupportedServiceNames_static()
276 Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDragSource" };
277 return aRet;
281 sal_Bool GenericDragSource::isDragImageSupported()
283 return false;
286 sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 )
288 return 0;
291 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
292 sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
293 const Reference< datatransfer::XTransferable >&,
294 const Reference< datatransfer::dnd::XDragSourceListener >& listener
297 datatransfer::dnd::DragSourceDropEvent aEv;
298 aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
299 aEv.DropSuccess = false;
300 listener->dragDropEnd( aEv );
303 void GenericDragSource::initialize( const Sequence< Any >& )
307 Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames()
309 #if defined MACOSX
310 return { "com.sun.star.datatransfer.dnd.OleDragSource" };
311 #elif defined UNX
312 return { "com.sun.star.datatransfer.dnd.X11DragSource" };
313 #else
314 return { "com.sun.star.datatransfer.dnd.VclGenericDragSource" };
315 #endif
318 OUString SAL_CALL DragSource_getImplementationName()
320 #if defined MACOSX
321 return OUString("com.sun.star.comp.datatransfer.dnd.OleDragSource_V1");
322 #elif defined UNX
323 return OUString("com.sun.star.datatransfer.dnd.XdndSupport");
324 #else
325 return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource");
326 #endif
329 Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& )
331 SolarMutexGuard aGuard;
332 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
333 return xResult;
337 * generic DragSource dummy
340 class GenericDropTarget : public cppu::WeakComponentImplHelper<
341 datatransfer::dnd::XDropTarget,
342 XInitialization,
343 css::lang::XServiceInfo
346 osl::Mutex m_aMutex;
347 public:
348 GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
351 // XInitialization
352 virtual void SAL_CALL initialize( const Sequence< Any >& args ) override;
354 // XDropTarget
355 virtual void SAL_CALL addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) override;
356 virtual void SAL_CALL removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) override;
357 virtual sal_Bool SAL_CALL isActive() override;
358 virtual void SAL_CALL setActive( sal_Bool active ) override;
359 virtual sal_Int8 SAL_CALL getDefaultActions() override;
360 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) override;
362 OUString SAL_CALL getImplementationName() override
363 { return OUString("com.sun.star.datatransfer.dnd.VclGenericDropTarget"); }
365 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
366 { return cppu::supportsService(this, ServiceName); }
368 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
369 { return getSupportedServiceNames_static(); }
371 static Sequence< OUString > getSupportedServiceNames_static()
373 Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDropTarget" };
374 return aRet;
378 void GenericDropTarget::initialize( const Sequence< Any >& )
382 void GenericDropTarget::addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& )
386 void GenericDropTarget::removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& )
390 sal_Bool GenericDropTarget::isActive()
392 return false;
395 void GenericDropTarget::setActive( sal_Bool )
399 sal_Int8 GenericDropTarget::getDefaultActions()
401 return 0;
404 void GenericDropTarget::setDefaultActions( sal_Int8)
408 Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames()
410 #if defined MACOSX
411 return Sequence< OUString > { "com.sun.star.datatransfer.dnd.OleDropTarget" };
412 #elif defined UNX
413 return Sequence< OUString > { "com.sun.star.datatransfer.dnd.X11DropTarget" };
414 #else
415 return GenericDropTarget::getSupportedServiceNames_static();
416 #endif
419 OUString SAL_CALL DropTarget_getImplementationName()
421 return OUString(
422 #if defined MACOSX
423 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
424 #elif defined UNX
425 "com.sun.star.datatransfer.dnd.XdndDropTarget"
426 #else
427 "com.sun.star.datatransfer.dnd.VclGenericDropTarget"
428 #endif
432 Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
434 SolarMutexGuard aGuard;
435 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
436 return xResult;
439 } // namespace vcl
442 * SalInstance generic
444 Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
446 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericClipboard()) );
449 Reference< XInterface > SalInstance::CreateDragSource()
451 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDragSource()) );
454 Reference< XInterface > SalInstance::CreateDropTarget()
456 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDropTarget()) );
459 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */