xref: /AOO41X/main/vcl/source/window/dndlcon.cxx (revision adad3ae824c589c174fda9eefeacb35ef5ebe483)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <dndlcon.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::cppu;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
36cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //==================================================================================================
39cdf0e10cSrcweir //
40cdf0e10cSrcweir //==================================================================================================
41cdf0e10cSrcweir 
42cdf0e10cSrcweir DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions )
43cdf0e10cSrcweir 	: WeakComponentImplHelper4< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(GetMutex())
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	m_bActive = sal_True;
46cdf0e10cSrcweir 	m_nDefaultActions = nDefaultActions;
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //==================================================================================================
50cdf0e10cSrcweir //
51cdf0e10cSrcweir //==================================================================================================
52cdf0e10cSrcweir 
53cdf0e10cSrcweir DNDListenerContainer::~DNDListenerContainer()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //==================================================================================================
58cdf0e10cSrcweir // DNDListenerContainer::addDragGestureListener
59cdf0e10cSrcweir //==================================================================================================
60cdf0e10cSrcweir 
61cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
62cdf0e10cSrcweir 	throw(RuntimeException)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	rBHelper.addListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //==================================================================================================
68cdf0e10cSrcweir // DNDListenerContainer::removeDragGestureListener
69cdf0e10cSrcweir //==================================================================================================
70cdf0e10cSrcweir 
71cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
72cdf0e10cSrcweir 	throw(RuntimeException)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	rBHelper.removeListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //==================================================================================================
78cdf0e10cSrcweir // DNDListenerContainer::resetRecognizer
79cdf0e10cSrcweir //==================================================================================================
80cdf0e10cSrcweir 
81cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::resetRecognizer(  )
82cdf0e10cSrcweir 	throw(RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //==================================================================================================
87cdf0e10cSrcweir // DNDListenerContainer::addDropTargetListener
88cdf0e10cSrcweir //==================================================================================================
89cdf0e10cSrcweir 
90cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
91cdf0e10cSrcweir 	throw(RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	rBHelper.addListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //==================================================================================================
97cdf0e10cSrcweir // DNDListenerContainer::removeDropTargetListener
98cdf0e10cSrcweir //==================================================================================================
99cdf0e10cSrcweir 
100cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
101cdf0e10cSrcweir 	throw(RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	rBHelper.removeListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //==================================================================================================
107cdf0e10cSrcweir // DNDListenerContainer::isActive
108cdf0e10cSrcweir //==================================================================================================
109cdf0e10cSrcweir 
110cdf0e10cSrcweir sal_Bool SAL_CALL DNDListenerContainer::isActive(  )
111cdf0e10cSrcweir 	throw(RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	return m_bActive;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //==================================================================================================
117cdf0e10cSrcweir // DNDListenerContainer::setActive
118cdf0e10cSrcweir //==================================================================================================
119cdf0e10cSrcweir 
120cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::setActive( sal_Bool active )
121cdf0e10cSrcweir 	throw(RuntimeException)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	m_bActive = active;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //==================================================================================================
127cdf0e10cSrcweir // DNDListenerContainer::getDefaultActions
128cdf0e10cSrcweir //==================================================================================================
129cdf0e10cSrcweir 
130cdf0e10cSrcweir sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions(  )
131cdf0e10cSrcweir 	throw(RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	return m_nDefaultActions;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //==================================================================================================
137cdf0e10cSrcweir // DNDListenerContainer::setDefaultActions
138cdf0e10cSrcweir //==================================================================================================
139cdf0e10cSrcweir 
140cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions )
141cdf0e10cSrcweir 	throw(RuntimeException)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	m_nDefaultActions = actions;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //==================================================================================================
147cdf0e10cSrcweir // DNDListenerContainer::fireDropEvent
148cdf0e10cSrcweir //==================================================================================================
149cdf0e10cSrcweir 
150cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context,
151cdf0e10cSrcweir 	sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
152cdf0e10cSrcweir 	const Reference< XTransferable >& transferable )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
157cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	if( pContainer && m_bActive )
160cdf0e10cSrcweir 	{
161cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         // remember context to use in own context methods
164cdf0e10cSrcweir         m_xDropTargetDropContext = context;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 		// do not construct the event before you are sure at least one listener is registered
167cdf0e10cSrcweir         DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0,
168cdf0e10cSrcweir             static_cast < XDropTargetDropContext * > (this), dropAction,
169cdf0e10cSrcweir             locationX, locationY, sourceActions, transferable );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		while (aIterator.hasMoreElements())
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
174cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 			try
177cdf0e10cSrcweir 			{
178cdf0e10cSrcweir 				// this may result in a runtime exception
179cdf0e10cSrcweir 				Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 				if( xListener.is() )
182cdf0e10cSrcweir 				{
183cdf0e10cSrcweir                     // fire drop until the first one has accepted
184cdf0e10cSrcweir                     if( m_xDropTargetDropContext.is() )
185cdf0e10cSrcweir                         xListener->drop( aEvent );
186cdf0e10cSrcweir                     else
187cdf0e10cSrcweir                     {
188cdf0e10cSrcweir                         DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 );
189cdf0e10cSrcweir                         xListener->dragExit( aDTEvent );
190cdf0e10cSrcweir                     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 					nRet++;
193cdf0e10cSrcweir                 }
194cdf0e10cSrcweir 			}
195cdf0e10cSrcweir 
196*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
197cdf0e10cSrcweir 			{
198cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
199cdf0e10cSrcweir 			}
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         // if context still valid, then reject drop
203cdf0e10cSrcweir         if( m_xDropTargetDropContext.is() )
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             m_xDropTargetDropContext.clear();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir             try
208cdf0e10cSrcweir             {
209cdf0e10cSrcweir                 context->rejectDrop();
210cdf0e10cSrcweir             }
211cdf0e10cSrcweir 
212*adad3ae8SHerbert Dürr             catch( RuntimeException&)
213cdf0e10cSrcweir             {
214cdf0e10cSrcweir             }
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	return nRet;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //==================================================================================================
222cdf0e10cSrcweir // DNDListenerContainer::fireDragExitEvent
223cdf0e10cSrcweir //==================================================================================================
224cdf0e10cSrcweir 
225cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragExitEvent()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
230cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	if( pContainer && m_bActive )
233cdf0e10cSrcweir 	{
234cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		// do not construct the event before you are sure at least one listener is registered
237cdf0e10cSrcweir 		DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 		while (aIterator.hasMoreElements())
240cdf0e10cSrcweir 		{
241cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
242cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 			try
245cdf0e10cSrcweir 			{
246cdf0e10cSrcweir 				// this may result in a runtime exception
247cdf0e10cSrcweir 				Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 				if( xListener.is() )
250cdf0e10cSrcweir 				{
251cdf0e10cSrcweir    					xListener->dragExit( aEvent );
252cdf0e10cSrcweir 					nRet++;
253cdf0e10cSrcweir 				}
254cdf0e10cSrcweir 			}
255cdf0e10cSrcweir 
256*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
257cdf0e10cSrcweir 			{
258cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
259cdf0e10cSrcweir 			}
260cdf0e10cSrcweir 		}
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	return nRet;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //==================================================================================================
267cdf0e10cSrcweir // DNDListenerContainer::fireDragOverEvent
268cdf0e10cSrcweir //==================================================================================================
269cdf0e10cSrcweir 
270cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
271cdf0e10cSrcweir 	sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
276cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	if( pContainer && m_bActive )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         // remember context to use in own context methods
283cdf0e10cSrcweir         m_xDropTargetDragContext = context;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 		// do not construct the event before you are sure at least one listener is registered
286cdf0e10cSrcweir         DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
287cdf0e10cSrcweir             static_cast < XDropTargetDragContext * > (this),
288cdf0e10cSrcweir             dropAction, locationX, locationY, sourceActions );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 		while (aIterator.hasMoreElements())
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
293cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 			try
296cdf0e10cSrcweir 			{
297cdf0e10cSrcweir 				// this may result in a runtime exception
298cdf0e10cSrcweir 				Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 				if( xListener.is() )
301cdf0e10cSrcweir 				{
302cdf0e10cSrcweir                     if( m_xDropTargetDragContext.is() )
303cdf0e10cSrcweir                         xListener->dragOver( aEvent );
304cdf0e10cSrcweir   					nRet++;
305cdf0e10cSrcweir 				}
306cdf0e10cSrcweir 			}
307cdf0e10cSrcweir 
308*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
309cdf0e10cSrcweir 			{
310cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
311cdf0e10cSrcweir 			}
312cdf0e10cSrcweir 		}
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         // if context still valid, then reject drag
315cdf0e10cSrcweir         if( m_xDropTargetDragContext.is() )
316cdf0e10cSrcweir         {
317cdf0e10cSrcweir             m_xDropTargetDragContext.clear();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             try
320cdf0e10cSrcweir             {
321cdf0e10cSrcweir                 context->rejectDrag();
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir 
324*adad3ae8SHerbert Dürr     		catch( RuntimeException&)
325cdf0e10cSrcweir             {
326cdf0e10cSrcweir             }
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	return nRet;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir //==================================================================================================
334cdf0e10cSrcweir // DNDListenerContainer::fireDragEnterEvent
335cdf0e10cSrcweir //==================================================================================================
336cdf0e10cSrcweir 
337cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context,
338cdf0e10cSrcweir 	sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
339cdf0e10cSrcweir 	const Sequence< DataFlavor >& dataFlavors )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
344cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	if( pContainer && m_bActive )
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         // remember context to use in own context methods
351cdf0e10cSrcweir         m_xDropTargetDragContext = context;
352cdf0e10cSrcweir 
353cdf0e10cSrcweir         // do not construct the event before you are sure at least one listener is registered
354cdf0e10cSrcweir         DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0,
355cdf0e10cSrcweir             static_cast < XDropTargetDragContext * > (this),
356cdf0e10cSrcweir             dropAction, locationX, locationY, sourceActions, dataFlavors );
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		while (aIterator.hasMoreElements())
359cdf0e10cSrcweir 		{
360cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
361cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 			try
364cdf0e10cSrcweir 			{
365cdf0e10cSrcweir 				// this may result in a runtime exception
366cdf0e10cSrcweir 				Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 				if( xListener.is() )
369cdf0e10cSrcweir 				{
370cdf0e10cSrcweir                     if( m_xDropTargetDragContext.is() )
371cdf0e10cSrcweir                         xListener->dragEnter( aEvent );
372cdf0e10cSrcweir 					nRet++;
373cdf0e10cSrcweir 				}
374cdf0e10cSrcweir 			}
375cdf0e10cSrcweir 
376*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
377cdf0e10cSrcweir 			{
378cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
379cdf0e10cSrcweir 			}
380cdf0e10cSrcweir 		}
381cdf0e10cSrcweir 
382cdf0e10cSrcweir         // if context still valid, then reject drag
383cdf0e10cSrcweir         if( m_xDropTargetDragContext.is() )
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             m_xDropTargetDragContext.clear();
386cdf0e10cSrcweir 
387cdf0e10cSrcweir             try
388cdf0e10cSrcweir             {
389cdf0e10cSrcweir                 context->rejectDrag();
390cdf0e10cSrcweir             }
391cdf0e10cSrcweir 
392*adad3ae8SHerbert Dürr     		catch( RuntimeException&)
393cdf0e10cSrcweir             {
394cdf0e10cSrcweir             }
395cdf0e10cSrcweir         }
396cdf0e10cSrcweir     }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	return nRet;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir //==================================================================================================
402cdf0e10cSrcweir // DNDListenerContainer::fireDropActionChangedEvent
403cdf0e10cSrcweir //==================================================================================================
404cdf0e10cSrcweir 
405cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
406cdf0e10cSrcweir 	sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
411cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 	if( pContainer && m_bActive )
414cdf0e10cSrcweir 	{
415cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         // remember context to use in own context methods
418cdf0e10cSrcweir         m_xDropTargetDragContext = context;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		// do not construct the event before you are sure at least one listener is registered
421cdf0e10cSrcweir         DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
422cdf0e10cSrcweir             static_cast < XDropTargetDragContext * > (this),
423cdf0e10cSrcweir             dropAction, locationX, locationY, sourceActions );
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 		while (aIterator.hasMoreElements())
426cdf0e10cSrcweir 		{
427cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
428cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 			try
431cdf0e10cSrcweir 			{
432cdf0e10cSrcweir 				// this may result in a runtime exception
433cdf0e10cSrcweir 				Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 				if( xListener.is() )
436cdf0e10cSrcweir 				{
437cdf0e10cSrcweir                     if( m_xDropTargetDragContext.is() )
438cdf0e10cSrcweir                         xListener->dropActionChanged( aEvent );
439cdf0e10cSrcweir    					nRet++;
440cdf0e10cSrcweir 				}
441cdf0e10cSrcweir 			}
442cdf0e10cSrcweir 
443*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
444cdf0e10cSrcweir 			{
445cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
446cdf0e10cSrcweir 			}
447cdf0e10cSrcweir 		}
448cdf0e10cSrcweir 
449cdf0e10cSrcweir         // if context still valid, then reject drag
450cdf0e10cSrcweir         if( m_xDropTargetDragContext.is() )
451cdf0e10cSrcweir         {
452cdf0e10cSrcweir             m_xDropTargetDragContext.clear();
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             try
455cdf0e10cSrcweir             {
456cdf0e10cSrcweir                 context->rejectDrag();
457cdf0e10cSrcweir             }
458cdf0e10cSrcweir 
459*adad3ae8SHerbert Dürr     		catch( RuntimeException&)
460cdf0e10cSrcweir             {
461cdf0e10cSrcweir             }
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	return nRet;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir //==================================================================================================
469cdf0e10cSrcweir // DNDListenerContainer::fireDragGestureEvent
470cdf0e10cSrcweir //==================================================================================================
471cdf0e10cSrcweir 
472cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
473cdf0e10cSrcweir 	sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	sal_uInt32 nRet = 0;
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	// fire DropTargetDropEvent on all XDropTargetListeners
478cdf0e10cSrcweir 	OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDragGestureListener > * ) 0) );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	if( pContainer )
481cdf0e10cSrcweir 	{
482cdf0e10cSrcweir 		OInterfaceIteratorHelper aIterator( *pContainer );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 		// do not construct the event before you are sure at least one listener is registered
485cdf0e10cSrcweir 		DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction,
486cdf0e10cSrcweir 			dragOriginX, dragOriginY, dragSource, triggerEvent );
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 		while( aIterator.hasMoreElements() )
489cdf0e10cSrcweir 		{
490cdf0e10cSrcweir 			// FIXME: this can be simplified as soon as the Iterator has a remove method
491cdf0e10cSrcweir 			Reference< XInterface > xElement( aIterator.next() );
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 			try
494cdf0e10cSrcweir 			{
495cdf0e10cSrcweir 				// this may result in a runtime exception
496cdf0e10cSrcweir 				Reference < XDragGestureListener > xListener( xElement, UNO_QUERY );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir 				if( xListener.is() )
499cdf0e10cSrcweir 				{
500cdf0e10cSrcweir 					xListener->dragGestureRecognized( aEvent );
501cdf0e10cSrcweir 					nRet++;
502cdf0e10cSrcweir 				}
503cdf0e10cSrcweir 			}
504cdf0e10cSrcweir 
505*adad3ae8SHerbert Dürr 			catch( RuntimeException&)
506cdf0e10cSrcweir 			{
507cdf0e10cSrcweir 				pContainer->removeInterface( xElement );
508cdf0e10cSrcweir 			}
509cdf0e10cSrcweir 		}
510cdf0e10cSrcweir 	}
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 	return nRet;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir //==================================================================================================
516cdf0e10cSrcweir // DNDListenerContainer::acceptDrag
517cdf0e10cSrcweir //==================================================================================================
518cdf0e10cSrcweir 
519cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation ) throw (RuntimeException)
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     if( m_xDropTargetDragContext.is() )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         m_xDropTargetDragContext->acceptDrag( dragOperation );
524cdf0e10cSrcweir         m_xDropTargetDragContext.clear();
525cdf0e10cSrcweir     }
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir //==================================================================================================
529cdf0e10cSrcweir // DNDListenerContainer::rejectDrag
530cdf0e10cSrcweir //==================================================================================================
531cdf0e10cSrcweir 
532cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::rejectDrag(  ) throw (RuntimeException)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir     // nothing to do here
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir //==================================================================================================
538cdf0e10cSrcweir // DNDListenerContainer::acceptDrop
539cdf0e10cSrcweir //==================================================================================================
540cdf0e10cSrcweir 
541cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation ) throw (RuntimeException)
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     if( m_xDropTargetDropContext.is() )
544cdf0e10cSrcweir         m_xDropTargetDropContext->acceptDrop( dropOperation );
545cdf0e10cSrcweir }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir //==================================================================================================
548cdf0e10cSrcweir // DNDListenerContainer::rejectDrop
549cdf0e10cSrcweir //==================================================================================================
550cdf0e10cSrcweir 
551cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::rejectDrop(  ) throw (RuntimeException)
552cdf0e10cSrcweir {
553cdf0e10cSrcweir     // nothing to do here
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir //==================================================================================================
557cdf0e10cSrcweir // DNDListenerContainer::dropComplete
558cdf0e10cSrcweir //==================================================================================================
559cdf0e10cSrcweir 
560cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success ) throw (RuntimeException)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     if( m_xDropTargetDropContext.is() )
563cdf0e10cSrcweir     {
564cdf0e10cSrcweir         m_xDropTargetDropContext->dropComplete( success );
565cdf0e10cSrcweir         m_xDropTargetDropContext.clear();
566cdf0e10cSrcweir     }
567cdf0e10cSrcweir }
568