build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / window / dndlistenercontainer.cxx
blobb9874fc08086bcbce7ae1a92a373ecc1e136281b
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 "dndlistenercontainer.hxx"
22 using namespace ::cppu;
23 using namespace ::com::sun::star::uno;
24 using namespace ::com::sun::star::datatransfer;
25 using namespace ::com::sun::star::datatransfer::dnd;
27 DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions )
28 : WeakComponentImplHelper< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(GetMutex())
30 m_bActive = true;
31 m_nDefaultActions = nDefaultActions;
34 DNDListenerContainer::~DNDListenerContainer()
38 void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
39 throw(RuntimeException, std::exception)
41 rBHelper.addListener( cppu::UnoType<XDragGestureListener>::get(), dgl );
44 void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
45 throw(RuntimeException, std::exception)
47 rBHelper.removeListener( cppu::UnoType<XDragGestureListener>::get(), dgl );
50 void SAL_CALL DNDListenerContainer::resetRecognizer( )
51 throw(RuntimeException, std::exception)
55 void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
56 throw(RuntimeException, std::exception)
58 rBHelper.addListener( cppu::UnoType<XDropTargetListener>::get(), dtl );
61 void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
62 throw(RuntimeException, std::exception)
64 rBHelper.removeListener( cppu::UnoType<XDropTargetListener>::get(), dtl );
67 sal_Bool SAL_CALL DNDListenerContainer::isActive( )
68 throw(RuntimeException, std::exception)
70 return m_bActive;
73 void SAL_CALL DNDListenerContainer::setActive( sal_Bool active )
74 throw(RuntimeException, std::exception)
76 m_bActive = active;
79 sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions( )
80 throw(RuntimeException, std::exception)
82 return m_nDefaultActions;
85 void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions )
86 throw(RuntimeException, std::exception)
88 m_nDefaultActions = actions;
91 sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context,
92 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
93 const Reference< XTransferable >& transferable )
95 sal_uInt32 nRet = 0;
97 // fire DropTargetDropEvent on all XDropTargetListeners
98 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
100 if( pContainer && m_bActive )
102 OInterfaceIteratorHelper aIterator( *pContainer );
104 // remember context to use in own context methods
105 m_xDropTargetDropContext = context;
107 // do not construct the event before you are sure at least one listener is registered
108 DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0,
109 static_cast < XDropTargetDropContext * > (this), dropAction,
110 locationX, locationY, sourceActions, transferable );
112 while (aIterator.hasMoreElements())
114 // FIXME: this can be simplified as soon as the Iterator has a remove method
115 Reference< XInterface > xElement( aIterator.next() );
119 // this may result in a runtime exception
120 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
122 if( xListener.is() )
124 // fire drop until the first one has accepted
125 if( m_xDropTargetDropContext.is() )
126 xListener->drop( aEvent );
127 else
129 DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 );
130 xListener->dragExit( aDTEvent );
133 nRet++;
136 catch (const RuntimeException&)
138 pContainer->removeInterface( xElement );
142 // if context still valid, then reject drop
143 if( m_xDropTargetDropContext.is() )
145 m_xDropTargetDropContext.clear();
149 context->rejectDrop();
151 catch (const RuntimeException&)
157 return nRet;
160 sal_uInt32 DNDListenerContainer::fireDragExitEvent()
162 sal_uInt32 nRet = 0;
164 // fire DropTargetDropEvent on all XDropTargetListeners
165 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
167 if( pContainer && m_bActive )
169 OInterfaceIteratorHelper aIterator( *pContainer );
171 // do not construct the event before you are sure at least one listener is registered
172 DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
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 );
184 if( xListener.is() )
186 xListener->dragExit( aEvent );
187 nRet++;
190 catch (const RuntimeException&)
192 pContainer->removeInterface( xElement );
197 return nRet;
200 sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
201 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
203 sal_uInt32 nRet = 0;
205 // fire DropTargetDropEvent on all XDropTargetListeners
206 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
208 if( pContainer && m_bActive )
210 OInterfaceIteratorHelper aIterator( *pContainer );
212 // remember context to use in own context methods
213 m_xDropTargetDragContext = context;
215 // do not construct the event before you are sure at least one listener is registered
216 DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
217 static_cast < XDropTargetDragContext * > (this),
218 dropAction, locationX, locationY, sourceActions );
220 while (aIterator.hasMoreElements())
222 // FIXME: this can be simplified as soon as the Iterator has a remove method
223 Reference< XInterface > xElement( aIterator.next() );
227 // this may result in a runtime exception
228 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
230 if( xListener.is() )
232 if( m_xDropTargetDragContext.is() )
233 xListener->dragOver( aEvent );
234 nRet++;
237 catch (const RuntimeException&)
239 pContainer->removeInterface( xElement );
243 // if context still valid, then reject drag
244 if( m_xDropTargetDragContext.is() )
246 m_xDropTargetDragContext.clear();
250 context->rejectDrag();
252 catch (const RuntimeException&)
258 return nRet;
261 sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context,
262 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
263 const Sequence< DataFlavor >& dataFlavors )
265 sal_uInt32 nRet = 0;
267 // fire DropTargetDropEvent on all XDropTargetListeners
268 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
270 if( pContainer && m_bActive )
272 OInterfaceIteratorHelper aIterator( *pContainer );
274 // remember context to use in own context methods
275 m_xDropTargetDragContext = context;
277 // do not construct the event before you are sure at least one listener is registered
278 DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0,
279 static_cast < XDropTargetDragContext * > (this),
280 dropAction, locationX, locationY, sourceActions, dataFlavors );
282 while (aIterator.hasMoreElements())
284 // FIXME: this can be simplified as soon as the Iterator has a remove method
285 Reference< XInterface > xElement( aIterator.next() );
289 // this may result in a runtime exception
290 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
292 if( xListener.is() )
294 if( m_xDropTargetDragContext.is() )
295 xListener->dragEnter( aEvent );
296 nRet++;
299 catch (const RuntimeException&)
301 pContainer->removeInterface( xElement );
305 // if context still valid, then reject drag
306 if( m_xDropTargetDragContext.is() )
308 m_xDropTargetDragContext.clear();
312 context->rejectDrag();
314 catch (const RuntimeException&)
320 return nRet;
323 sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
324 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
326 sal_uInt32 nRet = 0;
328 // fire DropTargetDropEvent on all XDropTargetListeners
329 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
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 DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
340 static_cast < XDropTargetDragContext * > (this),
341 dropAction, locationX, locationY, sourceActions );
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 );
353 if( xListener.is() )
355 if( m_xDropTargetDragContext.is() )
356 xListener->dropActionChanged( aEvent );
357 nRet++;
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&)
381 return nRet;
384 sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
385 sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
387 sal_uInt32 nRet = 0;
389 // fire DropTargetDropEvent on all XDropTargetListeners
390 OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDragGestureListener>::get());
392 if( pContainer )
394 OInterfaceIteratorHelper aIterator( *pContainer );
396 // do not construct the event before you are sure at least one listener is registered
397 DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction,
398 dragOriginX, dragOriginY, dragSource, triggerEvent );
400 while( aIterator.hasMoreElements() )
402 // FIXME: this can be simplified as soon as the Iterator has a remove method
403 Reference< XInterface > xElement( aIterator.next() );
407 // this may result in a runtime exception
408 Reference < XDragGestureListener > xListener( xElement, UNO_QUERY );
410 if( xListener.is() )
412 xListener->dragGestureRecognized( aEvent );
413 nRet++;
416 catch (const RuntimeException&)
418 pContainer->removeInterface( xElement );
423 return nRet;
426 void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation ) throw (RuntimeException, std::exception)
428 if( m_xDropTargetDragContext.is() )
430 m_xDropTargetDragContext->acceptDrag( dragOperation );
431 m_xDropTargetDragContext.clear();
435 void SAL_CALL DNDListenerContainer::rejectDrag( ) throw (RuntimeException, std::exception)
437 // nothing to do here
440 void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation ) throw (RuntimeException, std::exception)
442 if( m_xDropTargetDropContext.is() )
443 m_xDropTargetDropContext->acceptDrop( dropOperation );
446 void SAL_CALL DNDListenerContainer::rejectDrop( ) throw (RuntimeException, std::exception)
448 // nothing to do here
451 void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success ) throw (RuntimeException, std::exception)
453 if( m_xDropTargetDropContext.is() )
455 m_xDropTargetDropContext->dropComplete( success );
456 m_xDropTargetDropContext.clear();
460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */