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