1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
;
53 // generic implementation to satisfy SalInstance
54 class GenericClipboard
:
55 public cppu::WeakComponentImplHelper
<
56 datatransfer::clipboard::XSystemClipboard
,
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
;
67 GenericClipboard() : cppu::WeakComponentImplHelper
<
68 datatransfer::clipboard::XSystemClipboard
,
72 virtual ~GenericClipboard();
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();
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
;
104 virtual sal_Int8 SAL_CALL
getRenderingCapabilities()
105 throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
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";
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
)
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
;
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
)
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
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
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
);
246 OUString SAL_CALL
Clipboard_getImplementationName()
251 "com.sun.star.datatransfer.X11ClipboardSupport"
253 "com.sun.star.datatransfer.clipboard.AquaClipboard"
257 return GenericClipboard::getImplementationName_static();
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
,
272 css::lang::XServiceInfo
277 GenericDragSource() : WeakComponentImplHelper( m_aMutex
) {}
278 virtual ~GenericDragSource();
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
;
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";
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
)
327 sal_Int32
GenericDragSource::getDefaultCursor( sal_Int8
) throw(std::exception
)
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()
351 OUString
aServiceName(
353 "com.sun.star.datatransfer.dnd.X11DragSource"
355 "com.sun.star.datatransfer.dnd.OleDragSource"
358 return Sequence
< OUString
>(&aServiceName
, 1);
360 return GenericDragSource::getSupportedServiceNames_static();
364 OUString SAL_CALL
DragSource_getImplementationName()
369 "com.sun.star.datatransfer.dnd.XdndSupport"
371 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
375 return GenericDragSource::getImplementationName_static();
379 Reference
< XInterface
> SAL_CALL
DragSource_createInstance( const Reference
< XMultiServiceFactory
>& )
381 SolarMutexGuard aGuard
;
382 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDragSource();
387 * generic DragSource dummy
390 class GenericDropTarget
: public cppu::WeakComponentImplHelper
<
391 datatransfer::dnd::XDropTarget
,
393 css::lang::XServiceInfo
398 GenericDropTarget() : WeakComponentImplHelper( m_aMutex
)
400 virtual ~GenericDropTarget();
403 virtual void SAL_CALL
initialize( const Sequence
< Any
>& args
) throw ( Exception
, std::exception
) SAL_OVERRIDE
;
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";
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
)
459 void GenericDropTarget::setActive( sal_Bool
) throw(std::exception
)
463 sal_Int8
GenericDropTarget::getDefaultActions() throw(std::exception
)
468 void GenericDropTarget::setDefaultActions( sal_Int8
) throw(std::exception
)
472 Sequence
< OUString
> SAL_CALL
DropTarget_getSupportedServiceNames()
475 OUString
aServiceName(
477 "com.sun.star.datatransfer.dnd.X11DropTarget"
479 "com.sun.star.datatransfer.dnd.OleDropTarget"
482 return Sequence
< OUString
>(&aServiceName
, 1);
484 return GenericDropTarget::getSupportedServiceNames_static();
488 OUString SAL_CALL
DropTarget_getImplementationName()
493 "com.sun.star.datatransfer.dnd.XdndDropTarget"
495 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
499 return GenericDropTarget::getImplementationName_static();
503 Reference
< XInterface
> SAL_CALL
DropTarget_createInstance( const Reference
< XMultiServiceFactory
>& )
505 SolarMutexGuard aGuard
;
506 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDropTarget();
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: */