build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / components / dtranscomp.cxx
blobfcdf217c25d3523179c5be7eb162ae67629cfc6c
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() throw( RuntimeException, std::exception ) override;
77 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) override;
78 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( RuntimeException, std::exception ) override;
80 static Sequence< OUString > getSupportedServiceNames_static();
83 * XClipboard
86 virtual Reference< css::datatransfer::XTransferable > SAL_CALL getContents()
87 throw(RuntimeException, std::exception) override;
89 virtual void SAL_CALL setContents(
90 const Reference< css::datatransfer::XTransferable >& xTrans,
91 const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
92 throw(RuntimeException, std::exception) override;
94 virtual OUString SAL_CALL getName()
95 throw(RuntimeException, std::exception) override;
98 * XClipboardEx
101 virtual sal_Int8 SAL_CALL getRenderingCapabilities()
102 throw(RuntimeException, std::exception) override;
105 * XClipboardNotifier
107 virtual void SAL_CALL addClipboardListener(
108 const Reference< css::datatransfer::clipboard::XClipboardListener >& listener )
109 throw(RuntimeException, std::exception) override;
111 virtual void SAL_CALL removeClipboardListener(
112 const Reference< css::datatransfer::clipboard::XClipboardListener >& listener )
113 throw(RuntimeException, std::exception) override;
116 Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
118 Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.SystemClipboard" };
119 return aRet;
122 OUString GenericClipboard::getImplementationName() throw( RuntimeException, std::exception )
124 return OUString("com.sun.star.datatransfer.VCLGenericClipboard");
127 Sequence< OUString > GenericClipboard::getSupportedServiceNames() throw( RuntimeException, std::exception )
129 return getSupportedServiceNames_static();
132 sal_Bool GenericClipboard::supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception )
134 return cppu::supportsService(this, ServiceName);
137 Reference< css::datatransfer::XTransferable > GenericClipboard::getContents() throw( RuntimeException, std::exception )
139 return m_aContents;
142 void GenericClipboard::setContents(
143 const Reference< css::datatransfer::XTransferable >& xTrans,
144 const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
145 throw( RuntimeException, std::exception )
147 osl::ClearableMutexGuard aGuard( m_aMutex );
148 Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
149 Reference< datatransfer::XTransferable > xOldContents( m_aContents );
150 m_aContents = xTrans;
151 m_aOwner = xClipboardOwner;
153 std::list< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
154 datatransfer::clipboard::ClipboardEvent aEv;
155 aEv.Contents = m_aContents;
157 aGuard.clear();
159 if( xOldOwner.is() && xOldOwner != xClipboardOwner )
160 xOldOwner->lostOwnership( this, xOldContents );
161 for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it =
162 aListeners.begin(); it != aListeners.end() ; ++it )
164 (*it)->changedContents( aEv );
168 OUString GenericClipboard::getName() throw( RuntimeException, std::exception )
170 return OUString( "CLIPBOARD" );
173 sal_Int8 GenericClipboard::getRenderingCapabilities() throw( RuntimeException, std::exception )
175 return 0;
178 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
179 throw( RuntimeException, std::exception )
181 osl::ClearableMutexGuard aGuard( m_aMutex );
183 m_aListeners.push_back( listener );
186 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
187 throw( RuntimeException, std::exception )
189 osl::ClearableMutexGuard aGuard( m_aMutex );
191 m_aListeners.remove( listener );
194 class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
195 css::lang::XSingleServiceFactory
198 osl::Mutex m_aMutex;
199 public:
200 ClipboardFactory();
203 * XSingleServiceFactory
205 virtual Reference< XInterface > SAL_CALL createInstance() throw(std::exception) override;
206 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) throw(std::exception) override;
209 ClipboardFactory::ClipboardFactory() :
210 cppu::WeakComponentImplHelper<
211 css::lang::XSingleServiceFactory
212 >( m_aMutex )
216 Reference< XInterface > ClipboardFactory::createInstance() throw(std::exception)
218 return createInstanceWithArguments( Sequence< Any >() );
221 Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) throw(std::exception)
223 SolarMutexGuard aGuard;
224 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
225 return xResult;
228 OUString SAL_CALL Clipboard_getImplementationName()
230 return OUString(
231 #if defined MACOSX
232 "com.sun.star.datatransfer.clipboard.AquaClipboard"
233 #elif defined UNX
234 "com.sun.star.datatransfer.X11ClipboardSupport"
235 #else
236 "com.sun.star.datatransfer.VCLGenericClipboard"
237 #endif
241 Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & )
243 return Reference< XSingleServiceFactory >( new ClipboardFactory() );
247 * generic DragSource dummy
249 class GenericDragSource : public cppu::WeakComponentImplHelper<
250 datatransfer::dnd::XDragSource,
251 XInitialization,
252 css::lang::XServiceInfo
255 osl::Mutex m_aMutex;
256 public:
257 GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
259 // XDragSource
260 virtual sal_Bool SAL_CALL isDragImageSupported() throw(std::exception) override;
261 virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw(std::exception) override;
262 virtual void SAL_CALL startDrag(
263 const datatransfer::dnd::DragGestureEvent& trigger,
264 sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
265 const Reference< datatransfer::XTransferable >& transferable,
266 const Reference< datatransfer::dnd::XDragSourceListener >& listener
267 ) throw(std::exception) override;
269 // XInitialization
270 virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) throw( css::uno::Exception, std::exception ) override;
272 OUString SAL_CALL getImplementationName()
273 throw (css::uno::RuntimeException, std::exception) override
274 { return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource"); }
276 sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
277 throw (css::uno::RuntimeException, std::exception) override
278 { return cppu::supportsService(this, ServiceName); }
280 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
281 throw (css::uno::RuntimeException, std::exception) override
282 { return getSupportedServiceNames_static(); }
284 static Sequence< OUString > getSupportedServiceNames_static()
286 Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDragSource" };
287 return aRet;
291 sal_Bool GenericDragSource::isDragImageSupported() throw(std::exception)
293 return false;
296 sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 ) throw(std::exception)
298 return 0;
301 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
302 sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
303 const Reference< datatransfer::XTransferable >&,
304 const Reference< datatransfer::dnd::XDragSourceListener >& listener
305 ) throw(std::exception)
307 datatransfer::dnd::DragSourceDropEvent aEv;
308 aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
309 aEv.DropSuccess = false;
310 listener->dragDropEnd( aEv );
313 void GenericDragSource::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
317 Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames()
319 #if defined MACOSX
320 return { "com.sun.star.datatransfer.dnd.OleDragSource" };
321 #elif defined UNX
322 return { "com.sun.star.datatransfer.dnd.X11DragSource" };
323 #else
324 return { "com.sun.star.datatransfer.dnd.VclGenericDragSource" };
325 #endif
328 OUString SAL_CALL DragSource_getImplementationName()
330 #if defined MACOSX
331 return OUString("com.sun.star.comp.datatransfer.dnd.OleDragSource_V1");
332 #elif defined UNX
333 return OUString("com.sun.star.datatransfer.dnd.XdndSupport");
334 #else
335 return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource");
336 #endif
339 Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& )
341 SolarMutexGuard aGuard;
342 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
343 return xResult;
347 * generic DragSource dummy
350 class GenericDropTarget : public cppu::WeakComponentImplHelper<
351 datatransfer::dnd::XDropTarget,
352 XInitialization,
353 css::lang::XServiceInfo
356 osl::Mutex m_aMutex;
357 public:
358 GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
361 // XInitialization
362 virtual void SAL_CALL initialize( const Sequence< Any >& args ) throw ( Exception, std::exception ) override;
364 // XDropTarget
365 virtual void SAL_CALL addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) override;
366 virtual void SAL_CALL removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) override;
367 virtual sal_Bool SAL_CALL isActive() throw(std::exception) override;
368 virtual void SAL_CALL setActive( sal_Bool active ) throw(std::exception) override;
369 virtual sal_Int8 SAL_CALL getDefaultActions() throw(std::exception) override;
370 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(std::exception) override;
372 OUString SAL_CALL getImplementationName()
373 throw (css::uno::RuntimeException, std::exception) override
374 { return OUString("com.sun.star.datatransfer.dnd.VclGenericDropTarget"); }
376 sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
377 throw (css::uno::RuntimeException, std::exception) override
378 { return cppu::supportsService(this, ServiceName); }
380 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
381 throw (css::uno::RuntimeException, std::exception) override
382 { return getSupportedServiceNames_static(); }
384 static Sequence< OUString > getSupportedServiceNames_static()
386 Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDropTarget" };
387 return aRet;
391 void GenericDropTarget::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
395 void GenericDropTarget::addDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
399 void GenericDropTarget::removeDropTargetListener( const Reference< css::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
403 sal_Bool GenericDropTarget::isActive() throw(std::exception)
405 return false;
408 void GenericDropTarget::setActive( sal_Bool ) throw(std::exception)
412 sal_Int8 GenericDropTarget::getDefaultActions() throw(std::exception)
414 return 0;
417 void GenericDropTarget::setDefaultActions( sal_Int8) throw(std::exception)
421 Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames()
423 #if defined MACOSX
424 return Sequence< OUString > { "com.sun.star.datatransfer.dnd.OleDropTarget" };
425 #elif defined UNX
426 return Sequence< OUString > { "com.sun.star.datatransfer.dnd.X11DropTarget" };
427 #else
428 return GenericDropTarget::getSupportedServiceNames_static();
429 #endif
432 OUString SAL_CALL DropTarget_getImplementationName()
434 return OUString(
435 #if defined MACOSX
436 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
437 #elif defined UNX
438 "com.sun.star.datatransfer.dnd.XdndDropTarget"
439 #else
440 "com.sun.star.datatransfer.dnd.VclGenericDropTarget"
441 #endif
445 Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
447 SolarMutexGuard aGuard;
448 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
449 return xResult;
452 } // namespace vcl
455 * SalInstance generic
457 Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
459 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericClipboard()) );
462 Reference< XInterface > SalInstance::CreateDragSource()
464 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDragSource()) );
467 Reference< XInterface > SalInstance::CreateDropTarget()
469 return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDropTarget()) );
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */