bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / window / dndlistenercontainer.cxx
blob9ff128c808bbc594cc99e7809a51ea6f71cc594b
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 )
29 m_bActive = true;
30 m_nDefaultActions = nDefaultActions;
33 DNDListenerContainer::~DNDListenerContainer()
37 void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
39 std::unique_lock g(m_aMutex);
40 maDragGestureListeners.addInterface( g, dgl );
43 void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
45 std::unique_lock g(m_aMutex);
46 maDragGestureListeners.removeInterface( g, dgl );
49 void SAL_CALL DNDListenerContainer::resetRecognizer( )
53 void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
55 std::unique_lock g(m_aMutex);
56 maDropTargetListeners.addInterface( g, dtl );
59 void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
61 std::unique_lock g(m_aMutex);
62 maDropTargetListeners.removeInterface( g, dtl );
65 sal_Bool SAL_CALL DNDListenerContainer::isActive( )
67 return m_bActive;
70 void SAL_CALL DNDListenerContainer::setActive( sal_Bool active )
72 m_bActive = active;
75 sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions( )
77 return m_nDefaultActions;
80 void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions )
82 m_nDefaultActions = actions;
85 sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context,
86 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
87 const Reference< XTransferable >& transferable )
89 std::unique_lock g(m_aMutex);
90 if (!m_bActive || maDropTargetListeners.getLength(g) == 0)
91 return 0;
93 sal_uInt32 nRet = 0;
95 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners );
97 // remember context to use in own context methods
98 m_xDropTargetDropContext = context;
100 // do not construct the event before you are sure at least one listener is registered
101 DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0,
102 static_cast < XDropTargetDropContext * > (this), dropAction,
103 locationX, locationY, sourceActions, transferable );
105 while (aIterator.hasMoreElements())
107 Reference< XDropTargetListener > xListener( aIterator.next() );
110 // fire drop until the first one has accepted
111 if( m_xDropTargetDropContext.is() )
113 g.unlock();
114 xListener->drop( aEvent );
116 else
118 g.unlock();
119 DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 );
120 xListener->dragExit( aDTEvent );
123 g.lock();
124 nRet++;
126 catch (const RuntimeException&)
128 aIterator.remove( g );
132 // if context still valid, then reject drop
133 if( m_xDropTargetDropContext.is() )
135 m_xDropTargetDropContext.clear();
139 context->rejectDrop();
141 catch (const RuntimeException&)
146 return nRet;
149 sal_uInt32 DNDListenerContainer::fireDragExitEvent()
151 std::unique_lock g(m_aMutex);
152 if (!m_bActive || maDropTargetListeners.getLength(g) == 0)
153 return 0;
155 sal_uInt32 nRet = 0;
157 // do not construct the event before you are sure at least one listener is registered
158 DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
160 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners );
161 g.unlock();
162 while (aIterator.hasMoreElements())
164 Reference< XDropTargetListener > xListener( aIterator.next() );
167 xListener->dragExit( aEvent );
168 nRet++;
170 catch (const RuntimeException&)
172 g.lock();
173 aIterator.remove( g );
174 g.unlock();
178 return nRet;
181 sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
182 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
184 std::unique_lock g(m_aMutex);
185 if (!m_bActive || maDropTargetListeners.getLength(g) == 0)
186 return 0;
188 sal_uInt32 nRet = 0;
190 // fire DropTargetDropEvent on all XDropTargetListeners
192 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners );
194 // remember context to use in own context methods
195 m_xDropTargetDragContext = context;
197 // do not construct the event before you are sure at least one listener is registered
198 DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
199 static_cast < XDropTargetDragContext * > (this),
200 dropAction, locationX, locationY, sourceActions );
202 while (aIterator.hasMoreElements())
204 Reference< XDropTargetListener > xListener( aIterator.next() );
207 if( m_xDropTargetDragContext.is() )
209 g.unlock();
210 xListener->dragOver( aEvent );
211 g.lock();
213 nRet++;
215 catch (const RuntimeException&)
217 aIterator.remove(g);
221 // if context still valid, then reject drag
222 if( m_xDropTargetDragContext.is() )
224 m_xDropTargetDragContext.clear();
228 context->rejectDrag();
230 catch (const RuntimeException&)
235 return nRet;
238 sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context,
239 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
240 const Sequence< DataFlavor >& dataFlavors )
242 std::unique_lock g(m_aMutex);
243 if (!m_bActive || maDropTargetListeners.getLength(g) == 0)
244 return 0;
246 sal_uInt32 nRet = 0;
248 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners );
250 // remember context to use in own context methods
251 m_xDropTargetDragContext = context;
253 // do not construct the event before you are sure at least one listener is registered
254 DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0,
255 static_cast < XDropTargetDragContext * > (this),
256 dropAction, locationX, locationY, sourceActions, dataFlavors );
258 while (aIterator.hasMoreElements())
260 Reference< XDropTargetListener > xListener( aIterator.next() );
263 if( m_xDropTargetDragContext.is() )
265 g.unlock();
266 xListener->dragEnter( aEvent );
267 g.lock();
269 nRet++;
271 catch (const RuntimeException&)
273 aIterator.remove( g );
277 // if context still valid, then reject drag
278 if( m_xDropTargetDragContext.is() )
280 m_xDropTargetDragContext.clear();
284 context->rejectDrag();
286 catch (const RuntimeException&)
291 return nRet;
294 sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
295 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
297 std::unique_lock g(m_aMutex);
298 if (!m_bActive || maDropTargetListeners.getLength(g) == 0)
299 return 0;
301 sal_uInt32 nRet = 0;
303 // fire DropTargetDropEvent on all XDropTargetListeners
305 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDropTargetListeners );
307 // remember context to use in own context methods
308 m_xDropTargetDragContext = context;
310 // do not construct the event before you are sure at least one listener is registered
311 DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
312 static_cast < XDropTargetDragContext * > (this),
313 dropAction, locationX, locationY, sourceActions );
315 while (aIterator.hasMoreElements())
317 Reference< XDropTargetListener > xListener( aIterator.next() );
320 if( m_xDropTargetDragContext.is() )
322 g.unlock();
323 xListener->dropActionChanged( aEvent );
324 g.lock();
326 nRet++;
328 catch (const RuntimeException&)
330 aIterator.remove( g );
334 // if context still valid, then reject drag
335 if( m_xDropTargetDragContext.is() )
337 m_xDropTargetDragContext.clear();
341 context->rejectDrag();
343 catch (const RuntimeException&)
348 return nRet;
351 sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
352 sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
354 std::unique_lock g(m_aMutex);
355 if (maDragGestureListeners.getLength(g) == 0)
356 return 0;
358 sal_uInt32 nRet = 0;
360 // do not construct the event before you are sure at least one listener is registered
361 DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction,
362 dragOriginX, dragOriginY, dragSource, triggerEvent );
364 comphelper::OInterfaceIteratorHelper4 aIterator( g, maDragGestureListeners );
365 g.unlock();
366 while( aIterator.hasMoreElements() )
368 Reference< XDragGestureListener > xListener( aIterator.next() );
371 xListener->dragGestureRecognized( aEvent );
372 nRet++;
374 catch (const RuntimeException&)
376 g.lock();
377 aIterator.remove( g );
378 g.unlock();
382 return nRet;
385 void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation )
387 if( m_xDropTargetDragContext.is() )
389 m_xDropTargetDragContext->acceptDrag( dragOperation );
390 m_xDropTargetDragContext.clear();
394 void SAL_CALL DNDListenerContainer::rejectDrag( )
396 // nothing to do here
399 void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation )
401 if( m_xDropTargetDropContext.is() )
402 m_xDropTargetDropContext->acceptDrop( dropOperation );
405 void SAL_CALL DNDListenerContainer::rejectDrop( )
407 // nothing to do here
410 void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success )
412 if( m_xDropTargetDropContext.is() )
414 m_xDropTargetDropContext->dropComplete( success );
415 m_xDropTargetDropContext.clear();
420 * GenericDropTargetDropContext
423 GenericDropTargetDropContext::GenericDropTargetDropContext()
427 void GenericDropTargetDropContext::acceptDrop( sal_Int8 /*dragOperation*/ )
431 void GenericDropTargetDropContext::rejectDrop()
435 void GenericDropTargetDropContext::dropComplete( sal_Bool /*success*/ )
440 * GenericDropTargetDragContext
443 GenericDropTargetDragContext::GenericDropTargetDragContext()
447 void GenericDropTargetDragContext::acceptDrag( sal_Int8 /*dragOperation*/ )
451 void GenericDropTargetDragContext::rejectDrag()
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */