1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dndlcon.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
36 using namespace ::cppu
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::datatransfer
;
39 using namespace ::com::sun::star::datatransfer::dnd
;
41 //==================================================================================================
43 //==================================================================================================
45 DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions
)
46 : WeakComponentImplHelper4
< XDragGestureRecognizer
, XDropTargetDragContext
, XDropTargetDropContext
, XDropTarget
>(GetMutex())
49 m_nDefaultActions
= nDefaultActions
;
52 //==================================================================================================
54 //==================================================================================================
56 DNDListenerContainer::~DNDListenerContainer()
60 //==================================================================================================
61 // DNDListenerContainer::addDragGestureListener
62 //==================================================================================================
64 void SAL_CALL
DNDListenerContainer::addDragGestureListener( const Reference
< XDragGestureListener
>& dgl
)
65 throw(RuntimeException
)
67 rBHelper
.addListener( getCppuType( ( const Reference
< XDragGestureListener
> * ) 0 ), dgl
);
70 //==================================================================================================
71 // DNDListenerContainer::removeDragGestureListener
72 //==================================================================================================
74 void SAL_CALL
DNDListenerContainer::removeDragGestureListener( const Reference
< XDragGestureListener
>& dgl
)
75 throw(RuntimeException
)
77 rBHelper
.removeListener( getCppuType( ( const Reference
< XDragGestureListener
> * ) 0 ), dgl
);
80 //==================================================================================================
81 // DNDListenerContainer::resetRecognizer
82 //==================================================================================================
84 void SAL_CALL
DNDListenerContainer::resetRecognizer( )
85 throw(RuntimeException
)
89 //==================================================================================================
90 // DNDListenerContainer::addDropTargetListener
91 //==================================================================================================
93 void SAL_CALL
DNDListenerContainer::addDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
94 throw(RuntimeException
)
96 rBHelper
.addListener( getCppuType( ( const Reference
< XDropTargetListener
> * ) 0 ), dtl
);
99 //==================================================================================================
100 // DNDListenerContainer::removeDropTargetListener
101 //==================================================================================================
103 void SAL_CALL
DNDListenerContainer::removeDropTargetListener( const Reference
< XDropTargetListener
>& dtl
)
104 throw(RuntimeException
)
106 rBHelper
.removeListener( getCppuType( ( const Reference
< XDropTargetListener
> * ) 0 ), dtl
);
109 //==================================================================================================
110 // DNDListenerContainer::isActive
111 //==================================================================================================
113 sal_Bool SAL_CALL
DNDListenerContainer::isActive( )
114 throw(RuntimeException
)
119 //==================================================================================================
120 // DNDListenerContainer::setActive
121 //==================================================================================================
123 void SAL_CALL
DNDListenerContainer::setActive( sal_Bool active
)
124 throw(RuntimeException
)
129 //==================================================================================================
130 // DNDListenerContainer::getDefaultActions
131 //==================================================================================================
133 sal_Int8 SAL_CALL
DNDListenerContainer::getDefaultActions( )
134 throw(RuntimeException
)
136 return m_nDefaultActions
;
139 //==================================================================================================
140 // DNDListenerContainer::setDefaultActions
141 //==================================================================================================
143 void SAL_CALL
DNDListenerContainer::setDefaultActions( sal_Int8 actions
)
144 throw(RuntimeException
)
146 m_nDefaultActions
= actions
;
149 //==================================================================================================
150 // DNDListenerContainer::fireDropEvent
151 //==================================================================================================
153 sal_uInt32
DNDListenerContainer::fireDropEvent( const Reference
< XDropTargetDropContext
>& context
,
154 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
,
155 const Reference
< XTransferable
>& transferable
)
159 // fire DropTargetDropEvent on all XDropTargetListeners
160 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
162 if( pContainer
&& m_bActive
)
164 OInterfaceIteratorHelper
aIterator( *pContainer
);
166 // remember context to use in own context methods
167 m_xDropTargetDropContext
= context
;
169 // do not construct the event before you are sure at least one listener is registered
170 DropTargetDropEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
171 static_cast < XDropTargetDropContext
* > (this), dropAction
,
172 locationX
, locationY
, sourceActions
, transferable
);
174 while (aIterator
.hasMoreElements())
176 // FIXME: this can be simplified as soon as the Iterator has a remove method
177 Reference
< XInterface
> xElement( aIterator
.next() );
181 // this may result in a runtime exception
182 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
186 // fire drop until the first one has accepted
187 if( m_xDropTargetDropContext
.is() )
188 xListener
->drop( aEvent
);
191 DropTargetEvent
aDTEvent( static_cast < XDropTarget
* > (this), 0 );
192 xListener
->dragExit( aDTEvent
);
199 catch( RuntimeException exc
)
201 pContainer
->removeInterface( xElement
);
205 // if context still valid, then reject drop
206 if( m_xDropTargetDropContext
.is() )
208 m_xDropTargetDropContext
.clear();
212 context
->rejectDrop();
215 catch( RuntimeException exc
)
224 //==================================================================================================
225 // DNDListenerContainer::fireDragExitEvent
226 //==================================================================================================
228 sal_uInt32
DNDListenerContainer::fireDragExitEvent()
232 // fire DropTargetDropEvent on all XDropTargetListeners
233 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
235 if( pContainer
&& m_bActive
)
237 OInterfaceIteratorHelper
aIterator( *pContainer
);
239 // do not construct the event before you are sure at least one listener is registered
240 DropTargetEvent
aEvent( static_cast < XDropTarget
* > (this), 0 );
242 while (aIterator
.hasMoreElements())
244 // FIXME: this can be simplified as soon as the Iterator has a remove method
245 Reference
< XInterface
> xElement( aIterator
.next() );
249 // this may result in a runtime exception
250 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
254 xListener
->dragExit( aEvent
);
259 catch( RuntimeException exc
)
261 pContainer
->removeInterface( xElement
);
269 //==================================================================================================
270 // DNDListenerContainer::fireDragOverEvent
271 //==================================================================================================
273 sal_uInt32
DNDListenerContainer::fireDragOverEvent( const Reference
< XDropTargetDragContext
>& context
,
274 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
)
278 // fire DropTargetDropEvent on all XDropTargetListeners
279 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
281 if( pContainer
&& m_bActive
)
283 OInterfaceIteratorHelper
aIterator( *pContainer
);
285 // remember context to use in own context methods
286 m_xDropTargetDragContext
= context
;
288 // do not construct the event before you are sure at least one listener is registered
289 DropTargetDragEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
290 static_cast < XDropTargetDragContext
* > (this),
291 dropAction
, locationX
, locationY
, sourceActions
);
293 while (aIterator
.hasMoreElements())
295 // FIXME: this can be simplified as soon as the Iterator has a remove method
296 Reference
< XInterface
> xElement( aIterator
.next() );
300 // this may result in a runtime exception
301 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
305 if( m_xDropTargetDragContext
.is() )
306 xListener
->dragOver( aEvent
);
311 catch( RuntimeException exc
)
313 pContainer
->removeInterface( xElement
);
317 // if context still valid, then reject drag
318 if( m_xDropTargetDragContext
.is() )
320 m_xDropTargetDragContext
.clear();
324 context
->rejectDrag();
327 catch( RuntimeException exc
)
336 //==================================================================================================
337 // DNDListenerContainer::fireDragEnterEvent
338 //==================================================================================================
340 sal_uInt32
DNDListenerContainer::fireDragEnterEvent( const Reference
< XDropTargetDragContext
>& context
,
341 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
,
342 const Sequence
< DataFlavor
>& dataFlavors
)
346 // fire DropTargetDropEvent on all XDropTargetListeners
347 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
349 if( pContainer
&& m_bActive
)
351 OInterfaceIteratorHelper
aIterator( *pContainer
);
353 // remember context to use in own context methods
354 m_xDropTargetDragContext
= context
;
356 // do not construct the event before you are sure at least one listener is registered
357 DropTargetDragEnterEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
358 static_cast < XDropTargetDragContext
* > (this),
359 dropAction
, locationX
, locationY
, sourceActions
, dataFlavors
);
361 while (aIterator
.hasMoreElements())
363 // FIXME: this can be simplified as soon as the Iterator has a remove method
364 Reference
< XInterface
> xElement( aIterator
.next() );
368 // this may result in a runtime exception
369 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
373 if( m_xDropTargetDragContext
.is() )
374 xListener
->dragEnter( aEvent
);
379 catch( RuntimeException exc
)
381 pContainer
->removeInterface( xElement
);
385 // if context still valid, then reject drag
386 if( m_xDropTargetDragContext
.is() )
388 m_xDropTargetDragContext
.clear();
392 context
->rejectDrag();
395 catch( RuntimeException exc
)
404 //==================================================================================================
405 // DNDListenerContainer::fireDropActionChangedEvent
406 //==================================================================================================
408 sal_uInt32
DNDListenerContainer::fireDropActionChangedEvent( const Reference
< XDropTargetDragContext
>& context
,
409 sal_Int8 dropAction
, sal_Int32 locationX
, sal_Int32 locationY
, sal_Int8 sourceActions
)
413 // fire DropTargetDropEvent on all XDropTargetListeners
414 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDropTargetListener
> * ) 0) );
416 if( pContainer
&& m_bActive
)
418 OInterfaceIteratorHelper
aIterator( *pContainer
);
420 // remember context to use in own context methods
421 m_xDropTargetDragContext
= context
;
423 // do not construct the event before you are sure at least one listener is registered
424 DropTargetDragEvent
aEvent( static_cast < XDropTarget
* > (this), 0,
425 static_cast < XDropTargetDragContext
* > (this),
426 dropAction
, locationX
, locationY
, sourceActions
);
428 while (aIterator
.hasMoreElements())
430 // FIXME: this can be simplified as soon as the Iterator has a remove method
431 Reference
< XInterface
> xElement( aIterator
.next() );
435 // this may result in a runtime exception
436 Reference
< XDropTargetListener
> xListener( xElement
, UNO_QUERY
);
440 if( m_xDropTargetDragContext
.is() )
441 xListener
->dropActionChanged( aEvent
);
446 catch( RuntimeException exc
)
448 pContainer
->removeInterface( xElement
);
452 // if context still valid, then reject drag
453 if( m_xDropTargetDragContext
.is() )
455 m_xDropTargetDragContext
.clear();
459 context
->rejectDrag();
462 catch( RuntimeException exc
)
471 //==================================================================================================
472 // DNDListenerContainer::fireDragGestureEvent
473 //==================================================================================================
475 sal_uInt32
DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction
, sal_Int32 dragOriginX
,
476 sal_Int32 dragOriginY
, const Reference
< XDragSource
>& dragSource
, const Any
& triggerEvent
)
480 // fire DropTargetDropEvent on all XDropTargetListeners
481 OInterfaceContainerHelper
*pContainer
= rBHelper
.getContainer( getCppuType( ( Reference
< XDragGestureListener
> * ) 0) );
485 OInterfaceIteratorHelper
aIterator( *pContainer
);
487 // do not construct the event before you are sure at least one listener is registered
488 DragGestureEvent
aEvent( static_cast < XDragGestureRecognizer
* > (this), dragAction
,
489 dragOriginX
, dragOriginY
, dragSource
, triggerEvent
);
491 while( aIterator
.hasMoreElements() )
493 // FIXME: this can be simplified as soon as the Iterator has a remove method
494 Reference
< XInterface
> xElement( aIterator
.next() );
498 // this may result in a runtime exception
499 Reference
< XDragGestureListener
> xListener( xElement
, UNO_QUERY
);
503 xListener
->dragGestureRecognized( aEvent
);
508 catch( RuntimeException exc
)
510 pContainer
->removeInterface( xElement
);
518 //==================================================================================================
519 // DNDListenerContainer::acceptDrag
520 //==================================================================================================
522 void SAL_CALL
DNDListenerContainer::acceptDrag( sal_Int8 dragOperation
) throw (RuntimeException
)
524 if( m_xDropTargetDragContext
.is() )
526 m_xDropTargetDragContext
->acceptDrag( dragOperation
);
527 m_xDropTargetDragContext
.clear();
531 //==================================================================================================
532 // DNDListenerContainer::rejectDrag
533 //==================================================================================================
535 void SAL_CALL
DNDListenerContainer::rejectDrag( ) throw (RuntimeException
)
537 // nothing to do here
540 //==================================================================================================
541 // DNDListenerContainer::acceptDrop
542 //==================================================================================================
544 void SAL_CALL
DNDListenerContainer::acceptDrop( sal_Int8 dropOperation
) throw (RuntimeException
)
546 if( m_xDropTargetDropContext
.is() )
547 m_xDropTargetDropContext
->acceptDrop( dropOperation
);
550 //==================================================================================================
551 // DNDListenerContainer::rejectDrop
552 //==================================================================================================
554 void SAL_CALL
DNDListenerContainer::rejectDrop( ) throw (RuntimeException
)
556 // nothing to do here
559 //==================================================================================================
560 // DNDListenerContainer::dropComplete
561 //==================================================================================================
563 void SAL_CALL
DNDListenerContainer::dropComplete( sal_Bool success
) throw (RuntimeException
)
565 if( m_xDropTargetDropContext
.is() )
567 m_xDropTargetDropContext
->dropComplete( success
);
568 m_xDropTargetDropContext
.clear();