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 .
21 #include "osl/mutex.hxx"
23 #include "vcl/svapp.hxx"
26 #include "salinst.hxx"
28 #include "com/sun/star/lang/XServiceInfo.hpp"
29 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
30 #include "com/sun/star/lang/XInitialization.hpp"
31 #include "com/sun/star/lang/DisposedException.hpp"
32 #include "com/sun/star/datatransfer/XTransferable.hpp"
33 #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp"
34 #include "com/sun/star/datatransfer/clipboard/XClipboardEx.hpp"
35 #include "com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp"
36 #include "com/sun/star/datatransfer/clipboard/XClipboardListener.hpp"
37 #include "com/sun/star/datatransfer/dnd/XDragSource.hpp"
38 #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
39 #include "com/sun/star/datatransfer/dnd/DNDConstants.hpp"
41 #include "cppuhelper/compbase1.hxx"
42 #include "cppuhelper/compbase2.hxx"
43 #include "cppuhelper/compbase3.hxx"
44 #include "cppuhelper/implbase1.hxx"
46 using namespace com::sun::star
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::lang
;
50 // -----------------------------------------------------------------------
54 // generic implementation to satisfy SalInstance
55 class GenericClipboard
:
56 public cppu::WeakComponentImplHelper3
<
57 datatransfer::clipboard::XClipboardEx
,
58 datatransfer::clipboard::XClipboardNotifier
,
63 Reference
< ::com::sun::star::datatransfer::XTransferable
> m_aContents
;
64 Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardOwner
> m_aOwner
;
65 std::list
< Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
> > m_aListeners
;
67 void fireChangedContentsEvent();
72 GenericClipboard() : cppu::WeakComponentImplHelper3
<
73 datatransfer::clipboard::XClipboardEx
,
74 datatransfer::clipboard::XClipboardNotifier
,
78 virtual ~GenericClipboard();
84 virtual OUString SAL_CALL
getImplementationName() throw( RuntimeException
);
85 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw( RuntimeException
);
86 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw( RuntimeException
);
88 static OUString
getImplementationName_static();
89 static Sequence
< OUString
> getSupportedServiceNames_static();
95 virtual Reference
< ::com::sun::star::datatransfer::XTransferable
> SAL_CALL
getContents()
96 throw(RuntimeException
);
98 virtual void SAL_CALL
setContents(
99 const Reference
< ::com::sun::star::datatransfer::XTransferable
>& xTrans
,
100 const Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
101 throw(RuntimeException
);
103 virtual OUString SAL_CALL
getName()
104 throw(RuntimeException
);
110 virtual sal_Int8 SAL_CALL
getRenderingCapabilities()
111 throw(RuntimeException
);
116 virtual void SAL_CALL
addClipboardListener(
117 const Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
>& listener
)
118 throw(RuntimeException
);
120 virtual void SAL_CALL
removeClipboardListener(
121 const Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardListener
>& listener
)
122 throw(RuntimeException
);
125 GenericClipboard::~GenericClipboard()
129 OUString
GenericClipboard::getImplementationName_static()
131 return OUString( "com.sun.star.datatransfer.VCLGenericClipboard" );
134 Sequence
< OUString
> GenericClipboard::getSupportedServiceNames_static()
136 Sequence
< OUString
> aRet(1);
137 aRet
[0] = OUString("com.sun.star.datatransfer.clipboard.SystemClipboard");
141 OUString
GenericClipboard::getImplementationName() throw( RuntimeException
)
143 return getImplementationName_static();
146 Sequence
< OUString
> GenericClipboard::getSupportedServiceNames() throw( RuntimeException
)
148 return getSupportedServiceNames_static();
151 sal_Bool
GenericClipboard::supportsService( const OUString
& ServiceName
) throw( RuntimeException
)
153 Sequence
< OUString
> aServices( getSupportedServiceNames() );
154 sal_Int32 nServices
= aServices
.getLength();
155 for( sal_Int32 i
= 0; i
< nServices
; i
++ )
157 if( aServices
[i
] == ServiceName
)
163 Reference
< ::com::sun::star::datatransfer::XTransferable
> GenericClipboard::getContents() throw( RuntimeException
)
168 void GenericClipboard::setContents(
169 const Reference
< ::com::sun::star::datatransfer::XTransferable
>& xTrans
,
170 const Reference
< ::com::sun::star::datatransfer::clipboard::XClipboardOwner
>& xClipboardOwner
)
171 throw( RuntimeException
)
173 osl::ClearableMutexGuard
aGuard( m_aMutex
);
174 Reference
< datatransfer::clipboard::XClipboardOwner
> xOldOwner( m_aOwner
);
175 Reference
< datatransfer::XTransferable
> xOldContents( m_aContents
);
176 m_aContents
= xTrans
;
177 m_aOwner
= xClipboardOwner
;
179 std::list
< Reference
< datatransfer::clipboard::XClipboardListener
> > xListeners( m_aListeners
);
180 datatransfer::clipboard::ClipboardEvent aEv
;
181 aEv
.Contents
= m_aContents
;
185 if( xOldOwner
.is() && xOldOwner
!= xClipboardOwner
)
186 xOldOwner
->lostOwnership( this, xOldContents
);
187 for( std::list
< Reference
< datatransfer::clipboard::XClipboardListener
> >::iterator it
=
188 xListeners
.begin(); it
!= xListeners
.end() ; ++it
)
190 (*it
)->changedContents( aEv
);
194 OUString
GenericClipboard::getName() throw( RuntimeException
)
196 return OUString( "CLIPBOARD" );
199 sal_Int8
GenericClipboard::getRenderingCapabilities() throw( RuntimeException
)
204 void GenericClipboard::addClipboardListener( const Reference
< datatransfer::clipboard::XClipboardListener
>& listener
)
205 throw( RuntimeException
)
207 osl::ClearableMutexGuard
aGuard( m_aMutex
);
209 m_aListeners
.push_back( listener
);
212 void GenericClipboard::removeClipboardListener( const Reference
< datatransfer::clipboard::XClipboardListener
>& listener
)
213 throw( RuntimeException
)
215 osl::ClearableMutexGuard
aGuard( m_aMutex
);
217 m_aListeners
.remove( listener
);
220 // ------------------------------------------------------------------------
222 class ClipboardFactory
: public ::cppu::WeakComponentImplHelper1
<
223 com::sun::star::lang::XSingleServiceFactory
229 virtual ~ClipboardFactory();
232 * XSingleServiceFactory
234 virtual Reference
< XInterface
> SAL_CALL
createInstance() throw();
235 virtual Reference
< XInterface
> SAL_CALL
createInstanceWithArguments( const Sequence
< Any
>& rArgs
) throw();
238 // ------------------------------------------------------------------------
240 ClipboardFactory::ClipboardFactory() :
241 cppu::WeakComponentImplHelper1
<
242 com::sun::star::lang::XSingleServiceFactory
247 // ------------------------------------------------------------------------
249 ClipboardFactory::~ClipboardFactory()
253 // ------------------------------------------------------------------------
255 Reference
< XInterface
> ClipboardFactory::createInstance() throw()
257 return createInstanceWithArguments( Sequence
< Any
>() );
260 // ------------------------------------------------------------------------
262 Reference
< XInterface
> ClipboardFactory::createInstanceWithArguments( const Sequence
< Any
>& arguments
) throw()
264 SolarMutexGuard aGuard
;
265 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateClipboard( arguments
);
269 OUString SAL_CALL
Clipboard_getImplementationName()
274 "com.sun.star.datatransfer.X11ClipboardSupport"
276 "com.sun.star.datatransfer.clipboard.AquaClipboard"
280 return GenericClipboard::getImplementationName_static();
284 Reference
< XSingleServiceFactory
> SAL_CALL
Clipboard_createFactory( const Reference
< XMultiServiceFactory
> & )
286 return Reference
< XSingleServiceFactory
>( new ClipboardFactory() );
290 * generic DragSource dummy
292 class GenericDragSource
: public cppu::WeakComponentImplHelper2
<
293 datatransfer::dnd::XDragSource
,
299 GenericDragSource() : cppu::WeakComponentImplHelper2
< datatransfer::dnd::XDragSource
, XInitialization
>( m_aMutex
) {}
300 virtual ~GenericDragSource();
303 virtual sal_Bool SAL_CALL
isDragImageSupported() throw();
304 virtual sal_Int32 SAL_CALL
getDefaultCursor( sal_Int8 dragAction
) throw();
305 virtual void SAL_CALL
startDrag(
306 const datatransfer::dnd::DragGestureEvent
& trigger
,
307 sal_Int8 sourceActions
, sal_Int32 cursor
, sal_Int32 image
,
308 const Reference
< datatransfer::XTransferable
>& transferable
,
309 const Reference
< datatransfer::dnd::XDragSourceListener
>& listener
313 virtual void SAL_CALL
initialize( const Sequence
< Any
>& arguments
) throw( ::com::sun::star::uno::Exception
);
315 static Sequence
< OUString
> getSupportedServiceNames_static()
317 Sequence
< OUString
> aRet( 1 );
318 aRet
[0] = OUString("com.sun.star.datatransfer.dnd.GenericDragSource");
322 static OUString
getImplementationName_static()
324 return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource");
328 GenericDragSource::~GenericDragSource()
332 sal_Bool
GenericDragSource::isDragImageSupported() throw()
337 sal_Int32
GenericDragSource::getDefaultCursor( sal_Int8
) throw()
342 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent
&,
343 sal_Int8
/*sourceActions*/, sal_Int32
/*cursor*/, sal_Int32
/*image*/,
344 const Reference
< datatransfer::XTransferable
>&,
345 const Reference
< datatransfer::dnd::XDragSourceListener
>& listener
348 datatransfer::dnd::DragSourceDropEvent aEv
;
349 aEv
.DropAction
= datatransfer::dnd::DNDConstants::ACTION_COPY
;
350 aEv
.DropSuccess
= sal_False
;
351 listener
->dragDropEnd( aEv
);
354 void GenericDragSource::initialize( const Sequence
< Any
>& ) throw( Exception
)
359 Sequence
< OUString
> SAL_CALL
DragSource_getSupportedServiceNames()
362 OUString
aServiceName(
364 "com.sun.star.datatransfer.dnd.X11DragSource"
366 "com.sun.star.datatransfer.dnd.OleDragSource"
369 return Sequence
< OUString
>(&aServiceName
, 1);
371 return GenericDragSource::getSupportedServiceNames_static();
375 OUString SAL_CALL
DragSource_getImplementationName()
380 "com.sun.star.datatransfer.dnd.XdndSupport"
382 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
386 return GenericDragSource::getImplementationName_static();
390 Reference
< XInterface
> SAL_CALL
DragSource_createInstance( const Reference
< XMultiServiceFactory
>& )
392 SolarMutexGuard aGuard
;
393 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDragSource();
398 * generic DragSource dummy
401 class GenericDropTarget
: public cppu::WeakComponentImplHelper2
<
402 datatransfer::dnd::XDropTarget
,
408 GenericDropTarget() : cppu::WeakComponentImplHelper2
<
409 datatransfer::dnd::XDropTarget
,
413 virtual ~GenericDropTarget();
416 virtual void SAL_CALL
initialize( const Sequence
< Any
>& args
) throw ( Exception
);
419 virtual void SAL_CALL
addDropTargetListener( const Reference
< ::com::sun::star::datatransfer::dnd::XDropTargetListener
>& ) throw();
420 virtual void SAL_CALL
removeDropTargetListener( const Reference
< ::com::sun::star::datatransfer::dnd::XDropTargetListener
>& ) throw();
421 virtual sal_Bool SAL_CALL
isActive() throw();
422 virtual void SAL_CALL
setActive( sal_Bool active
) throw();
423 virtual sal_Int8 SAL_CALL
getDefaultActions() throw();
424 virtual void SAL_CALL
setDefaultActions( sal_Int8 actions
) throw();
426 static Sequence
< OUString
> getSupportedServiceNames_static()
428 Sequence
< OUString
> aRet( 1 );
429 aRet
[0] = OUString("com.sun.star.datatransfer.dnd.GenericDropTarget");
433 static OUString
getImplementationName_static()
435 return OUString("com.sun.star.datatransfer.dnd.VclGenericDropTarget");
439 GenericDropTarget::~GenericDropTarget()
443 void GenericDropTarget::initialize( const Sequence
< Any
>& ) throw( Exception
)
447 void GenericDropTarget::addDropTargetListener( const Reference
< ::com::sun::star::datatransfer::dnd::XDropTargetListener
>& ) throw()
451 void GenericDropTarget::removeDropTargetListener( const Reference
< ::com::sun::star::datatransfer::dnd::XDropTargetListener
>& ) throw()
455 sal_Bool
GenericDropTarget::isActive() throw()
460 void GenericDropTarget::setActive( sal_Bool
) throw()
464 sal_Int8
GenericDropTarget::getDefaultActions() throw()
469 void GenericDropTarget::setDefaultActions( sal_Int8
) throw()
473 Sequence
< OUString
> SAL_CALL
DropTarget_getSupportedServiceNames()
476 OUString
aServiceName(
478 "com.sun.star.datatransfer.dnd.X11DropTarget"
480 "com.sun.star.datatransfer.dnd.OleDropTarget"
483 return Sequence
< OUString
>(&aServiceName
, 1);
485 return GenericDropTarget::getSupportedServiceNames_static();
489 OUString SAL_CALL
DropTarget_getImplementationName()
494 "com.sun.star.datatransfer.dnd.XdndDropTarget"
496 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
500 return GenericDropTarget::getImplementationName_static();
504 Reference
< XInterface
> SAL_CALL
DropTarget_createInstance( const Reference
< XMultiServiceFactory
>& )
506 SolarMutexGuard aGuard
;
507 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDropTarget();
515 * SalInstance generic
517 Reference
< XInterface
> SalInstance::CreateClipboard( const Sequence
< Any
>& )
519 return Reference
< XInterface
>( ( cppu::OWeakObject
* )new vcl::GenericClipboard() );
522 Reference
< XInterface
> SalInstance::CreateDragSource()
524 return Reference
< XInterface
>( ( cppu::OWeakObject
* )new vcl::GenericDragSource() );
527 Reference
< XInterface
> SalInstance::CreateDropTarget()
529 return Reference
< XInterface
>( ( cppu::OWeakObject
* )new vcl::GenericDropTarget() );
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */