LibreOffice Module vcl (master) 1
dndlistenercontainer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22using namespace ::cppu;
23using namespace ::com::sun::star::uno;
24using namespace ::com::sun::star::datatransfer;
25using namespace ::com::sun::star::datatransfer::dnd;
26
28{
29 m_bActive = true;
30 m_nDefaultActions = nDefaultActions;
31}
32
34{
35}
36
37void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
38{
39 std::unique_lock g(m_aMutex);
41}
42
43void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
44{
45 std::unique_lock g(m_aMutex);
47}
48
50{
51}
52
53void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
54{
55 std::unique_lock g(m_aMutex);
57}
58
59void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
60{
61 std::unique_lock g(m_aMutex);
63}
64
66{
67 return m_bActive;
68}
69
71{
72 m_bActive = active;
73}
74
76{
77 return m_nDefaultActions;
78}
79
81{
82 m_nDefaultActions = actions;
83}
84
85sal_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 )
88{
89 std::unique_lock g(m_aMutex);
91 return 0;
92
93 sal_uInt32 nRet = 0;
94
96
97 // remember context to use in own context methods
99
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 );
104
105 while (aIterator.hasMoreElements())
106 {
107 Reference< XDropTargetListener > xListener( aIterator.next() );
108 try
109 {
110 // fire drop until the first one has accepted
111 if( m_xDropTargetDropContext.is() )
112 {
113 g.unlock();
114 xListener->drop( aEvent );
115 }
116 else
117 {
118 g.unlock();
119 DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 );
120 xListener->dragExit( aDTEvent );
121 }
122
123 g.lock();
124 nRet++;
125 }
126 catch (const RuntimeException&)
127 {
128 aIterator.remove( g );
129 }
130 }
131
132 // if context still valid, then reject drop
133 if( m_xDropTargetDropContext.is() )
134 {
136
137 try
138 {
139 context->rejectDrop();
140 }
141 catch (const RuntimeException&)
142 {
143 }
144 }
145
146 return nRet;
147}
148
150{
151 std::unique_lock g(m_aMutex);
153 return 0;
154
155 sal_uInt32 nRet = 0;
156
157 // do not construct the event before you are sure at least one listener is registered
158 DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
159
161 g.unlock();
162 while (aIterator.hasMoreElements())
163 {
164 Reference< XDropTargetListener > xListener( aIterator.next() );
165 try
166 {
167 xListener->dragExit( aEvent );
168 nRet++;
169 }
170 catch (const RuntimeException&)
171 {
172 g.lock();
173 aIterator.remove( g );
174 g.unlock();
175 }
176 }
177
178 return nRet;
179}
180
181sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
182 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
183{
184 std::unique_lock g(m_aMutex);
186 return 0;
187
188 sal_uInt32 nRet = 0;
189
190 // fire DropTargetDropEvent on all XDropTargetListeners
191
193
194 // remember context to use in own context methods
195 m_xDropTargetDragContext = context;
196
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 );
201
202 while (aIterator.hasMoreElements())
203 {
204 Reference< XDropTargetListener > xListener( aIterator.next() );
205 try
206 {
207 if( m_xDropTargetDragContext.is() )
208 {
209 g.unlock();
210 xListener->dragOver( aEvent );
211 g.lock();
212 }
213 nRet++;
214 }
215 catch (const RuntimeException&)
216 {
217 aIterator.remove(g);
218 }
219 }
220
221 // if context still valid, then reject drag
222 if( m_xDropTargetDragContext.is() )
223 {
225
226 try
227 {
228 context->rejectDrag();
229 }
230 catch (const RuntimeException&)
231 {
232 }
233 }
234
235 return nRet;
236}
237
238sal_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 )
241{
242 std::unique_lock g(m_aMutex);
244 return 0;
245
246 sal_uInt32 nRet = 0;
247
249
250 // remember context to use in own context methods
251 m_xDropTargetDragContext = context;
252
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 );
257
258 while (aIterator.hasMoreElements())
259 {
260 Reference< XDropTargetListener > xListener( aIterator.next() );
261 try
262 {
263 if( m_xDropTargetDragContext.is() )
264 {
265 g.unlock();
266 xListener->dragEnter( aEvent );
267 g.lock();
268 }
269 nRet++;
270 }
271 catch (const RuntimeException&)
272 {
273 aIterator.remove( g );
274 }
275 }
276
277 // if context still valid, then reject drag
278 if( m_xDropTargetDragContext.is() )
279 {
281
282 try
283 {
284 context->rejectDrag();
285 }
286 catch (const RuntimeException&)
287 {
288 }
289 }
290
291 return nRet;
292}
293
294sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
295 sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
296{
297 std::unique_lock g(m_aMutex);
299 return 0;
300
301 sal_uInt32 nRet = 0;
302
303 // fire DropTargetDropEvent on all XDropTargetListeners
304
306
307 // remember context to use in own context methods
308 m_xDropTargetDragContext = context;
309
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 );
314
315 while (aIterator.hasMoreElements())
316 {
317 Reference< XDropTargetListener > xListener( aIterator.next() );
318 try
319 {
320 if( m_xDropTargetDragContext.is() )
321 {
322 g.unlock();
323 xListener->dropActionChanged( aEvent );
324 g.lock();
325 }
326 nRet++;
327 }
328 catch (const RuntimeException&)
329 {
330 aIterator.remove( g );
331 }
332 }
333
334 // if context still valid, then reject drag
335 if( m_xDropTargetDragContext.is() )
336 {
338
339 try
340 {
341 context->rejectDrag();
342 }
343 catch (const RuntimeException&)
344 {
345 }
346 }
347
348 return nRet;
349}
350
351sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
352 sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
353{
354 std::unique_lock g(m_aMutex);
356 return 0;
357
358 sal_uInt32 nRet = 0;
359
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 );
363
365 g.unlock();
366 while( aIterator.hasMoreElements() )
367 {
368 Reference< XDragGestureListener > xListener( aIterator.next() );
369 try
370 {
371 xListener->dragGestureRecognized( aEvent );
372 nRet++;
373 }
374 catch (const RuntimeException&)
375 {
376 g.lock();
377 aIterator.remove( g );
378 g.unlock();
379 }
380 }
381
382 return nRet;
383}
384
385void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation )
386{
387 if( m_xDropTargetDragContext.is() )
388 {
389 m_xDropTargetDragContext->acceptDrag( dragOperation );
391 }
392}
393
395{
396 // nothing to do here
397}
398
399void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation )
400{
401 if( m_xDropTargetDropContext.is() )
402 m_xDropTargetDropContext->acceptDrop( dropOperation );
403}
404
406{
407 // nothing to do here
408}
409
411{
412 if( m_xDropTargetDropContext.is() )
413 {
414 m_xDropTargetDropContext->dropComplete( success );
416 }
417}
418
419/*
420 * GenericDropTargetDropContext
421 */
422
424{
425}
426
428{
429}
430
432{
433}
434
436{
437}
438
439/*
440 * GenericDropTargetDragContext
441 */
442
444{
445}
446
448{
449}
450
452{
453}
454
455/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
sal_uInt32 fireDragOverEvent(const css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > &context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions)
css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > m_xDropTargetDragContext
virtual void SAL_CALL removeDragGestureListener(const css::uno::Reference< css::datatransfer::dnd::XDragGestureListener > &dgl) override
virtual sal_Bool SAL_CALL isActive() override
virtual void SAL_CALL addDragGestureListener(const css::uno::Reference< css::datatransfer::dnd::XDragGestureListener > &dgl) override
virtual void SAL_CALL resetRecognizer() override
virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) override
comphelper::OInterfaceContainerHelper4< css::datatransfer::dnd::XDropTargetListener > maDropTargetListeners
virtual void SAL_CALL rejectDrag() override
sal_uInt32 fireDragEnterEvent(const css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > &context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, const css::uno::Sequence< css::datatransfer::DataFlavor > &dataFlavor)
virtual void SAL_CALL addDropTargetListener(const css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > &dtl) override
sal_uInt32 fireDragGestureEvent(sal_Int8 dragAction, sal_Int32 dragOriginX, sal_Int32 dragOriginY, const css::uno::Reference< css::datatransfer::dnd::XDragSource > &dragSource, const css::uno::Any &triggerEvent)
virtual void SAL_CALL dropComplete(sal_Bool success) override
virtual void SAL_CALL setActive(sal_Bool active) override
virtual ~DNDListenerContainer() override
DNDListenerContainer(sal_Int8 nDefaultActions)
comphelper::OInterfaceContainerHelper4< css::datatransfer::dnd::XDragGestureListener > maDragGestureListeners
sal_uInt32 fireDropActionChangedEvent(const css::uno::Reference< css::datatransfer::dnd::XDropTargetDragContext > &context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions)
virtual void SAL_CALL removeDropTargetListener(const css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > &dtl) override
sal_uInt32 fireDropEvent(const css::uno::Reference< css::datatransfer::dnd::XDropTargetDropContext > &context, sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, const css::uno::Reference< css::datatransfer::XTransferable > &transferable)
virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override
virtual void SAL_CALL rejectDrop() override
virtual sal_Int8 SAL_CALL getDefaultActions() override
virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override
css::uno::Reference< css::datatransfer::dnd::XDropTargetDropContext > m_xDropTargetDropContext
virtual void SAL_CALL rejectDrag() override
virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override
virtual void SAL_CALL rejectDrop() override
virtual void SAL_CALL acceptDrop(sal_Int8 dragOperation) override
virtual void SAL_CALL dropComplete(sal_Bool success) override
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
css::uno::Reference< ListenerT > const & next()
void remove(::std::unique_lock<::std::mutex > &rGuard)
unsigned char sal_Bool
signed char sal_Int8