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