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 <dndlcon.hxx>
23 using namespace ::cppu
;
24 using namespace ::com::sun::star::uno
;
25 using namespace ::com::sun::star::datatransfer
;
26 using namespace ::com::sun::star::datatransfer::dnd
;
28 //==================================================================================================
30 //==================================================================================================
32 DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions
)
33 : WeakComponentImplHelper4
< XDragGestureRecognizer
, XDropTargetDragContext
, XDropTargetDropContext
, XDropTarget
>(GetMutex())
36 m_nDefaultActions
= nDefaultActions
;
39 //==================================================================================================
41 //==================================================================================================
43 DNDListenerContainer::~DNDListenerContainer()
47 //==================================================================================================
48 // DNDListenerContainer::addDragGestureListener
49 //==================================================================================================
51 void SAL_CALL
DNDListenerContainer::addDragGestureListener( const Reference
< XDragGestureListener
>& dgl
)
52 throw(RuntimeException
)
54 rBHelper
.addListener( getCppuType( ( const Reference
< XDragGestureListener
> * ) 0 ), dgl
);
57 //==================================================================================================
58 // DNDListenerContainer::removeDragGestureListener
59 //==================================================================================================
61 void SAL_CALL
DNDListenerContainer::removeDragGestureListener( const Reference
< XDragGestureListener
>& dgl
)
62 throw(RuntimeException
)
64 rBHelper
.removeListener( getCppuType( ( const Reference
< XDragGestureListener
> * ) 0 ), dgl
);
67 //==================================================================================================
68 // DNDListenerContainer::resetRecognizer
69 //==================================================================================================
71 void SAL_CALL
DNDListenerContainer::resetRecognizer( )
72 throw(RuntimeException
)
76 //==================================================================================================
77 // DNDListenerContainer::addDropTargetListener
78 //==================================================================================================
80 void SAL_CALL
DNDListenerContainer::addDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
81 throw(RuntimeException
)
83 rBHelper
.addListener( getCppuType( ( const Reference
< XDropTargetListener
> * ) 0 ), dtl
);
86 //==================================================================================================
87 // DNDListenerContainer::removeDropTargetListener
88 //==================================================================================================
90 void SAL_CALL
DNDListenerContainer::removeDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
91 throw(RuntimeException
)
93 rBHelper
.removeListener( getCppuType( ( const Reference
< XDropTargetListener
> * ) 0 ), dtl
);
96 //==================================================================================================
97 // DNDListenerContainer::isActive
98 //==================================================================================================
100 sal_Bool SAL_CALL
DNDListenerContainer::isActive( )
101 throw(RuntimeException
)
106 //==================================================================================================
107 // DNDListenerContainer::setActive
108 //==================================================================================================
110 void SAL_CALL
DNDListenerContainer::setActive( sal_Bool active
)
111 throw(RuntimeException
)
116 //==================================================================================================
117 // DNDListenerContainer::getDefaultActions
118 //==================================================================================================
120 sal_Int8 SAL_CALL
DNDListenerContainer::getDefaultActions( )
121 throw(RuntimeException
)
123 return m_nDefaultActions
;
126 //==================================================================================================
127 // DNDListenerContainer::setDefaultActions
128 //==================================================================================================
130 void SAL_CALL
DNDListenerContainer::setDefaultActions( sal_Int8 actions
)
131 throw(RuntimeException
)
133 m_nDefaultActions
= actions
;
136 //==================================================================================================
137 // DNDListenerContainer::fireDropEvent
138 //==================================================================================================
140 sal_uInt32
DNDListenerContainer::fireDropEvent( const Reference
< XDropTargetDropContext
>& context
,
141 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
,
142 const Reference
< XTransferable
>& transferable
)
146 // fire DropTargetDropEvent on all XDropTargetListeners
147 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
149 if( pContainer
&& m_bActive
)
151 OInterfaceIteratorHelper
aIterator( *pContainer
);
153 // remember context to use in own context methods
154 m_xDropTargetDropContext
= context
;
156 // do not construct the event before you are sure at least one listener is registered
157 DropTargetDropEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
158 static_cast < XDropTargetDropContext
* > (this), dropAction
,
159 locationX
, locationY
, sourceActions
, transferable
);
161 while (aIterator
.hasMoreElements())
163 // FIXME: this can be simplified as soon as the Iterator has a remove method
164 Reference
< XInterface
> xElement( aIterator
.next() );
168 // this may result in a runtime exception
169 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
173 // fire drop until the first one has accepted
174 if( m_xDropTargetDropContext
.is() )
175 xListener
->drop( aEvent
);
178 DropTargetEvent
aDTEvent( static_cast < XDropTarget
* > (this), 0 );
179 xListener
->dragExit( aDTEvent
);
185 catch (const RuntimeException
&)
187 pContainer
->removeInterface( xElement
);
191 // if context still valid, then reject drop
192 if( m_xDropTargetDropContext
.is() )
194 m_xDropTargetDropContext
.clear();
198 context
->rejectDrop();
200 catch (const RuntimeException
&)
209 //==================================================================================================
210 // DNDListenerContainer::fireDragExitEvent
211 //==================================================================================================
213 sal_uInt32
DNDListenerContainer::fireDragExitEvent()
217 // fire DropTargetDropEvent on all XDropTargetListeners
218 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
220 if( pContainer
&& m_bActive
)
222 OInterfaceIteratorHelper
aIterator( *pContainer
);
224 // do not construct the event before you are sure at least one listener is registered
225 DropTargetEvent
aEvent( static_cast < XDropTarget
* > (this), 0 );
227 while (aIterator
.hasMoreElements())
229 // FIXME: this can be simplified as soon as the Iterator has a remove method
230 Reference
< XInterface
> xElement( aIterator
.next() );
234 // this may result in a runtime exception
235 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
239 xListener
->dragExit( aEvent
);
243 catch (const RuntimeException
&)
245 pContainer
->removeInterface( xElement
);
253 //==================================================================================================
254 // DNDListenerContainer::fireDragOverEvent
255 //==================================================================================================
257 sal_uInt32
DNDListenerContainer::fireDragOverEvent( const Reference
< XDropTargetDragContext
>& context
,
258 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
)
262 // fire DropTargetDropEvent on all XDropTargetListeners
263 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
265 if( pContainer
&& m_bActive
)
267 OInterfaceIteratorHelper
aIterator( *pContainer
);
269 // remember context to use in own context methods
270 m_xDropTargetDragContext
= context
;
272 // do not construct the event before you are sure at least one listener is registered
273 DropTargetDragEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
274 static_cast < XDropTargetDragContext
* > (this),
275 dropAction
, locationX
, locationY
, sourceActions
);
277 while (aIterator
.hasMoreElements())
279 // FIXME: this can be simplified as soon as the Iterator has a remove method
280 Reference
< XInterface
> xElement( aIterator
.next() );
284 // this may result in a runtime exception
285 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
289 if( m_xDropTargetDragContext
.is() )
290 xListener
->dragOver( aEvent
);
294 catch (const RuntimeException
&)
296 pContainer
->removeInterface( xElement
);
300 // if context still valid, then reject drag
301 if( m_xDropTargetDragContext
.is() )
303 m_xDropTargetDragContext
.clear();
307 context
->rejectDrag();
309 catch (const RuntimeException
&)
318 //==================================================================================================
319 // DNDListenerContainer::fireDragEnterEvent
320 //==================================================================================================
322 sal_uInt32
DNDListenerContainer::fireDragEnterEvent( const Reference
< XDropTargetDragContext
>& context
,
323 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
,
324 const Sequence
< DataFlavor
>& dataFlavors
)
328 // fire DropTargetDropEvent on all XDropTargetListeners
329 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
331 if( pContainer
&& m_bActive
)
333 OInterfaceIteratorHelper
aIterator( *pContainer
);
335 // remember context to use in own context methods
336 m_xDropTargetDragContext
= context
;
338 // do not construct the event before you are sure at least one listener is registered
339 DropTargetDragEnterEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
340 static_cast < XDropTargetDragContext
* > (this),
341 dropAction
, locationX
, locationY
, sourceActions
, dataFlavors
);
343 while (aIterator
.hasMoreElements())
345 // FIXME: this can be simplified as soon as the Iterator has a remove method
346 Reference
< XInterface
> xElement( aIterator
.next() );
350 // this may result in a runtime exception
351 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
355 if( m_xDropTargetDragContext
.is() )
356 xListener
->dragEnter( aEvent
);
360 catch (const RuntimeException
&)
362 pContainer
->removeInterface( xElement
);
366 // if context still valid, then reject drag
367 if( m_xDropTargetDragContext
.is() )
369 m_xDropTargetDragContext
.clear();
373 context
->rejectDrag();
375 catch (const RuntimeException
&)
384 //==================================================================================================
385 // DNDListenerContainer::fireDropActionChangedEvent
386 //==================================================================================================
388 sal_uInt32
DNDListenerContainer::fireDropActionChangedEvent( const Reference
< XDropTargetDragContext
>& context
,
389 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
)
393 // fire DropTargetDropEvent on all XDropTargetListeners
394 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
396 if( pContainer
&& m_bActive
)
398 OInterfaceIteratorHelper
aIterator( *pContainer
);
400 // remember context to use in own context methods
401 m_xDropTargetDragContext
= context
;
403 // do not construct the event before you are sure at least one listener is registered
404 DropTargetDragEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
405 static_cast < XDropTargetDragContext
* > (this),
406 dropAction
, locationX
, locationY
, sourceActions
);
408 while (aIterator
.hasMoreElements())
410 // FIXME: this can be simplified as soon as the Iterator has a remove method
411 Reference
< XInterface
> xElement( aIterator
.next() );
415 // this may result in a runtime exception
416 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
420 if( m_xDropTargetDragContext
.is() )
421 xListener
->dropActionChanged( aEvent
);
425 catch (const RuntimeException
&)
427 pContainer
->removeInterface( xElement
);
431 // if context still valid, then reject drag
432 if( m_xDropTargetDragContext
.is() )
434 m_xDropTargetDragContext
.clear();
438 context
->rejectDrag();
440 catch (const RuntimeException
&)
449 //==================================================================================================
450 // DNDListenerContainer::fireDragGestureEvent
451 //==================================================================================================
453 sal_uInt32
DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction
, sal_Int32 dragOriginX
,
454 sal_Int32 dragOriginY
, const Reference
< XDragSource
>& dragSource
, const Any
& triggerEvent
)
458 // fire DropTargetDropEvent on all XDropTargetListeners
459 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDragGestureListener
> * ) 0) );
463 OInterfaceIteratorHelper
aIterator( *pContainer
);
465 // do not construct the event before you are sure at least one listener is registered
466 DragGestureEvent
aEvent( static_cast < XDragGestureRecognizer
* > (this), dragAction
,
467 dragOriginX
, dragOriginY
, dragSource
, triggerEvent
);
469 while( aIterator
.hasMoreElements() )
471 // FIXME: this can be simplified as soon as the Iterator has a remove method
472 Reference
< XInterface
> xElement( aIterator
.next() );
476 // this may result in a runtime exception
477 Reference
< XDragGestureListener
> xListener( xElement
, UNO_QUERY
);
481 xListener
->dragGestureRecognized( aEvent
);
485 catch (const RuntimeException
&)
487 pContainer
->removeInterface( xElement
);
495 //==================================================================================================
496 // DNDListenerContainer::acceptDrag
497 //==================================================================================================
499 void SAL_CALL
DNDListenerContainer::acceptDrag( sal_Int8 dragOperation
) throw (RuntimeException
)
501 if( m_xDropTargetDragContext
.is() )
503 m_xDropTargetDragContext
->acceptDrag( dragOperation
);
504 m_xDropTargetDragContext
.clear();
508 //==================================================================================================
509 // DNDListenerContainer::rejectDrag
510 //==================================================================================================
512 void SAL_CALL
DNDListenerContainer::rejectDrag( ) throw (RuntimeException
)
514 // nothing to do here
517 //==================================================================================================
518 // DNDListenerContainer::acceptDrop
519 //==================================================================================================
521 void SAL_CALL
DNDListenerContainer::acceptDrop( sal_Int8 dropOperation
) throw (RuntimeException
)
523 if( m_xDropTargetDropContext
.is() )
524 m_xDropTargetDropContext
->acceptDrop( dropOperation
);
527 //==================================================================================================
528 // DNDListenerContainer::rejectDrop
529 //==================================================================================================
531 void SAL_CALL
DNDListenerContainer::rejectDrop( ) throw (RuntimeException
)
533 // nothing to do here
536 //==================================================================================================
537 // DNDListenerContainer::dropComplete
538 //==================================================================================================
540 void SAL_CALL
DNDListenerContainer::dropComplete( sal_Bool success
) throw (RuntimeException
)
542 if( m_xDropTargetDropContext
.is() )
544 m_xDropTargetDropContext
->dropComplete( success
);
545 m_xDropTargetDropContext
.clear();
549 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */