Line data Source code
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 :
20 : #include "osl/mutex.hxx"
21 :
22 : #include "vcl/svapp.hxx"
23 :
24 : #include "factory.hxx"
25 : #include "svdata.hxx"
26 : #include "salinst.hxx"
27 :
28 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 : #include "com/sun/star/lang/XServiceInfo.hpp"
30 : #include "com/sun/star/lang/XSingleServiceFactory.hpp"
31 : #include "com/sun/star/lang/XInitialization.hpp"
32 : #include "com/sun/star/lang/DisposedException.hpp"
33 : #include "com/sun/star/datatransfer/XTransferable.hpp"
34 : #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp"
35 : #include "com/sun/star/datatransfer/clipboard/XClipboardEx.hpp"
36 : #include "com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp"
37 : #include "com/sun/star/datatransfer/clipboard/XClipboardListener.hpp"
38 : #include "com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp"
39 : #include "com/sun/star/datatransfer/dnd/XDragSource.hpp"
40 : #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
41 : #include "com/sun/star/datatransfer/dnd/DNDConstants.hpp"
42 :
43 : #include "cppuhelper/compbase.hxx"
44 : #include "cppuhelper/implbase1.hxx"
45 : #include <cppuhelper/supportsservice.hxx>
46 :
47 : using namespace com::sun::star;
48 : using namespace com::sun::star::uno;
49 : using namespace com::sun::star::lang;
50 :
51 : namespace vcl
52 : {
53 : // generic implementation to satisfy SalInstance
54 : class GenericClipboard :
55 : public cppu::WeakComponentImplHelper<
56 : datatransfer::clipboard::XSystemClipboard,
57 : XServiceInfo
58 : >
59 : {
60 : osl::Mutex m_aMutex;
61 : Reference< ::com::sun::star::datatransfer::XTransferable > m_aContents;
62 : Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner > m_aOwner;
63 : std::list< Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > m_aListeners;
64 :
65 : public:
66 :
67 1165 : GenericClipboard() : cppu::WeakComponentImplHelper<
68 : datatransfer::clipboard::XSystemClipboard,
69 : XServiceInfo
70 1165 : >( m_aMutex )
71 1165 : {}
72 : virtual ~GenericClipboard();
73 :
74 : /*
75 : * XServiceInfo
76 : */
77 :
78 : virtual OUString SAL_CALL getImplementationName() throw( RuntimeException, std::exception ) SAL_OVERRIDE;
79 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception ) SAL_OVERRIDE;
80 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( RuntimeException, std::exception ) SAL_OVERRIDE;
81 :
82 : static OUString getImplementationName_static();
83 : static Sequence< OUString > getSupportedServiceNames_static();
84 :
85 : /*
86 : * XClipboard
87 : */
88 :
89 : virtual Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents()
90 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
91 :
92 : virtual void SAL_CALL setContents(
93 : const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
94 : const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
95 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
96 :
97 : virtual OUString SAL_CALL getName()
98 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
99 :
100 : /*
101 : * XClipboardEx
102 : */
103 :
104 : virtual sal_Int8 SAL_CALL getRenderingCapabilities()
105 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
106 :
107 : /*
108 : * XClipboardNotifier
109 : */
110 : virtual void SAL_CALL addClipboardListener(
111 : const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
112 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
113 :
114 : virtual void SAL_CALL removeClipboardListener(
115 : const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
116 : throw(RuntimeException, std::exception) SAL_OVERRIDE;
117 : };
118 :
119 2034 : GenericClipboard::~GenericClipboard()
120 : {
121 2034 : }
122 :
123 1 : OUString GenericClipboard::getImplementationName_static()
124 : {
125 1 : return OUString( "com.sun.star.datatransfer.VCLGenericClipboard" );
126 : }
127 :
128 1 : Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
129 : {
130 1 : Sequence< OUString > aRet(1);
131 1 : aRet[0] = "com.sun.star.datatransfer.clipboard.SystemClipboard";
132 1 : return aRet;
133 : }
134 :
135 1 : OUString GenericClipboard::getImplementationName() throw( RuntimeException, std::exception )
136 : {
137 1 : return getImplementationName_static();
138 : }
139 :
140 1 : Sequence< OUString > GenericClipboard::getSupportedServiceNames() throw( RuntimeException, std::exception )
141 : {
142 1 : return getSupportedServiceNames_static();
143 : }
144 :
145 0 : sal_Bool GenericClipboard::supportsService( const OUString& ServiceName ) throw( RuntimeException, std::exception )
146 : {
147 0 : return cppu::supportsService(this, ServiceName);
148 : }
149 :
150 1884 : Reference< ::com::sun::star::datatransfer::XTransferable > GenericClipboard::getContents() throw( RuntimeException, std::exception )
151 : {
152 1884 : return m_aContents;
153 : }
154 :
155 146 : void GenericClipboard::setContents(
156 : const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
157 : const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
158 : throw( RuntimeException, std::exception )
159 : {
160 146 : osl::ClearableMutexGuard aGuard( m_aMutex );
161 292 : Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
162 292 : Reference< datatransfer::XTransferable > xOldContents( m_aContents );
163 146 : m_aContents = xTrans;
164 146 : m_aOwner = xClipboardOwner;
165 :
166 292 : std::list< Reference< datatransfer::clipboard::XClipboardListener > > xListeners( m_aListeners );
167 292 : datatransfer::clipboard::ClipboardEvent aEv;
168 146 : aEv.Contents = m_aContents;
169 :
170 146 : aGuard.clear();
171 :
172 146 : if( xOldOwner.is() && xOldOwner != xClipboardOwner )
173 76 : xOldOwner->lostOwnership( this, xOldContents );
174 441 : for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it =
175 440 : xListeners.begin(); it != xListeners.end() ; ++it )
176 : {
177 1 : (*it)->changedContents( aEv );
178 146 : }
179 146 : }
180 :
181 0 : OUString GenericClipboard::getName() throw( RuntimeException, std::exception )
182 : {
183 0 : return OUString( "CLIPBOARD" );
184 : }
185 :
186 0 : sal_Int8 GenericClipboard::getRenderingCapabilities() throw( RuntimeException, std::exception )
187 : {
188 0 : return 0;
189 : }
190 :
191 1723 : void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
192 : throw( RuntimeException, std::exception )
193 : {
194 1723 : osl::ClearableMutexGuard aGuard( m_aMutex );
195 :
196 1723 : m_aListeners.push_back( listener );
197 1723 : }
198 :
199 1720 : void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
200 : throw( RuntimeException, std::exception )
201 : {
202 1720 : osl::ClearableMutexGuard aGuard( m_aMutex );
203 :
204 1720 : m_aListeners.remove( listener );
205 1720 : }
206 :
207 : class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
208 : com::sun::star::lang::XSingleServiceFactory
209 : >
210 : {
211 : osl::Mutex m_aMutex;
212 : public:
213 : ClipboardFactory();
214 : virtual ~ClipboardFactory();
215 :
216 : /*
217 : * XSingleServiceFactory
218 : */
219 : virtual Reference< XInterface > SAL_CALL createInstance() throw(std::exception) SAL_OVERRIDE;
220 : virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) throw(std::exception) SAL_OVERRIDE;
221 : };
222 :
223 59 : ClipboardFactory::ClipboardFactory() :
224 : cppu::WeakComponentImplHelper<
225 : com::sun::star::lang::XSingleServiceFactory
226 59 : >( m_aMutex )
227 : {
228 59 : }
229 :
230 114 : ClipboardFactory::~ClipboardFactory()
231 : {
232 114 : }
233 :
234 1148 : Reference< XInterface > ClipboardFactory::createInstance() throw(std::exception)
235 : {
236 1148 : return createInstanceWithArguments( Sequence< Any >() );
237 : }
238 :
239 1176 : Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) throw(std::exception)
240 : {
241 1176 : SolarMutexGuard aGuard;
242 1176 : Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
243 1176 : return xResult;
244 : }
245 :
246 179 : OUString SAL_CALL Clipboard_getImplementationName()
247 : {
248 : #if defined UNX
249 : return OUString(
250 : #if ! defined MACOSX
251 : "com.sun.star.datatransfer.X11ClipboardSupport"
252 : #else
253 : "com.sun.star.datatransfer.clipboard.AquaClipboard"
254 : #endif
255 179 : );
256 : #else
257 : return GenericClipboard::getImplementationName_static();
258 : #endif
259 : }
260 :
261 59 : Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & )
262 : {
263 59 : return Reference< XSingleServiceFactory >( new ClipboardFactory() );
264 : }
265 :
266 : /*
267 : * generic DragSource dummy
268 : */
269 : class GenericDragSource : public cppu::WeakComponentImplHelper<
270 : datatransfer::dnd::XDragSource,
271 : XInitialization,
272 : css::lang::XServiceInfo
273 : >
274 : {
275 : osl::Mutex m_aMutex;
276 : public:
277 1564 : GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
278 : virtual ~GenericDragSource();
279 :
280 : // XDragSource
281 : virtual sal_Bool SAL_CALL isDragImageSupported() throw(std::exception) SAL_OVERRIDE;
282 : virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw(std::exception) SAL_OVERRIDE;
283 : virtual void SAL_CALL startDrag(
284 : const datatransfer::dnd::DragGestureEvent& trigger,
285 : sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
286 : const Reference< datatransfer::XTransferable >& transferable,
287 : const Reference< datatransfer::dnd::XDragSourceListener >& listener
288 : ) throw(std::exception) SAL_OVERRIDE;
289 :
290 : // XInitialization
291 : virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception, std::exception ) SAL_OVERRIDE;
292 :
293 1 : OUString SAL_CALL getImplementationName()
294 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
295 1 : { return getImplementationName_static(); }
296 :
297 0 : sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
298 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
299 0 : { return cppu::supportsService(this, ServiceName); }
300 :
301 1 : css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
302 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
303 1 : { return getSupportedServiceNames_static(); }
304 :
305 1 : static Sequence< OUString > getSupportedServiceNames_static()
306 : {
307 1 : Sequence< OUString > aRet( 1 );
308 1 : aRet[0] = "com.sun.star.datatransfer.dnd.GenericDragSource";
309 1 : return aRet;
310 : }
311 :
312 1 : static OUString getImplementationName_static()
313 : {
314 1 : return OUString("com.sun.star.datatransfer.dnd.VclGenericDragSource");
315 : }
316 : };
317 :
318 3122 : GenericDragSource::~GenericDragSource()
319 : {
320 3122 : }
321 :
322 0 : sal_Bool GenericDragSource::isDragImageSupported() throw(std::exception)
323 : {
324 0 : return false;
325 : }
326 :
327 0 : sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 ) throw(std::exception)
328 : {
329 0 : return 0;
330 : }
331 :
332 0 : void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
333 : sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
334 : const Reference< datatransfer::XTransferable >&,
335 : const Reference< datatransfer::dnd::XDragSourceListener >& listener
336 : ) throw(std::exception)
337 : {
338 0 : datatransfer::dnd::DragSourceDropEvent aEv;
339 0 : aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
340 0 : aEv.DropSuccess = false;
341 0 : listener->dragDropEnd( aEv );
342 0 : }
343 :
344 1563 : void GenericDragSource::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
345 : {
346 1563 : }
347 :
348 60 : Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames()
349 : {
350 : #if defined UNX
351 : OUString aServiceName(
352 : #if ! defined MACOSX
353 : "com.sun.star.datatransfer.dnd.X11DragSource"
354 : #else
355 : "com.sun.star.datatransfer.dnd.OleDragSource"
356 : #endif
357 60 : );
358 60 : return Sequence< OUString >(&aServiceName, 1);
359 : #else
360 : return GenericDragSource::getSupportedServiceNames_static();
361 : #endif
362 : }
363 :
364 180 : OUString SAL_CALL DragSource_getImplementationName()
365 : {
366 : #if defined UNX
367 : return OUString(
368 : #if ! defined MACOSX
369 : "com.sun.star.datatransfer.dnd.XdndSupport"
370 : #else
371 : "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
372 : #endif
373 180 : );
374 : #else
375 : return GenericDragSource::getImplementationName_static();
376 : #endif
377 : }
378 :
379 1575 : Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& )
380 : {
381 1575 : SolarMutexGuard aGuard;
382 1575 : Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
383 1575 : return xResult;
384 : }
385 :
386 : /*
387 : * generic DragSource dummy
388 : */
389 :
390 : class GenericDropTarget : public cppu::WeakComponentImplHelper<
391 : datatransfer::dnd::XDropTarget,
392 : XInitialization,
393 : css::lang::XServiceInfo
394 : >
395 : {
396 : osl::Mutex m_aMutex;
397 : public:
398 1564 : GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
399 1564 : {}
400 : virtual ~GenericDropTarget();
401 :
402 : // XInitialization
403 : virtual void SAL_CALL initialize( const Sequence< Any >& args ) throw ( Exception, std::exception ) SAL_OVERRIDE;
404 :
405 : // XDropTarget
406 : virtual void SAL_CALL addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) SAL_OVERRIDE;
407 : virtual void SAL_CALL removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception) SAL_OVERRIDE;
408 : virtual sal_Bool SAL_CALL isActive() throw(std::exception) SAL_OVERRIDE;
409 : virtual void SAL_CALL setActive( sal_Bool active ) throw(std::exception) SAL_OVERRIDE;
410 : virtual sal_Int8 SAL_CALL getDefaultActions() throw(std::exception) SAL_OVERRIDE;
411 : virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(std::exception) SAL_OVERRIDE;
412 :
413 1 : OUString SAL_CALL getImplementationName()
414 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
415 1 : { return getImplementationName_static(); }
416 :
417 0 : sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
418 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
419 0 : { return cppu::supportsService(this, ServiceName); }
420 :
421 1 : css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
422 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
423 1 : { return getSupportedServiceNames_static(); }
424 :
425 1 : static Sequence< OUString > getSupportedServiceNames_static()
426 : {
427 1 : Sequence< OUString > aRet( 1 );
428 1 : aRet[0] = "com.sun.star.datatransfer.dnd.GenericDropTarget";
429 1 : return aRet;
430 : }
431 :
432 1 : static OUString getImplementationName_static()
433 : {
434 1 : return OUString("com.sun.star.datatransfer.dnd.VclGenericDropTarget");
435 : }
436 : };
437 :
438 3122 : GenericDropTarget::~GenericDropTarget()
439 : {
440 3122 : }
441 :
442 1563 : void GenericDropTarget::initialize( const Sequence< Any >& ) throw( Exception, std::exception )
443 : {
444 1563 : }
445 :
446 1563 : void GenericDropTarget::addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
447 : {
448 1563 : }
449 :
450 1560 : void GenericDropTarget::removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(std::exception)
451 : {
452 1560 : }
453 :
454 0 : sal_Bool GenericDropTarget::isActive() throw(std::exception)
455 : {
456 0 : return false;
457 : }
458 :
459 0 : void GenericDropTarget::setActive( sal_Bool ) throw(std::exception)
460 : {
461 0 : }
462 :
463 16137 : sal_Int8 GenericDropTarget::getDefaultActions() throw(std::exception)
464 : {
465 16137 : return 0;
466 : }
467 :
468 0 : void GenericDropTarget::setDefaultActions( sal_Int8) throw(std::exception)
469 : {
470 0 : }
471 :
472 60 : Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames()
473 : {
474 : #if defined UNX
475 : OUString aServiceName(
476 : #if ! defined MACOSX
477 : "com.sun.star.datatransfer.dnd.X11DropTarget"
478 : #else
479 : "com.sun.star.datatransfer.dnd.OleDropTarget"
480 : #endif
481 60 : );
482 60 : return Sequence< OUString >(&aServiceName, 1);
483 : #else
484 : return GenericDropTarget::getSupportedServiceNames_static();
485 : #endif
486 : }
487 :
488 120 : OUString SAL_CALL DropTarget_getImplementationName()
489 : {
490 : #if defined UNX
491 : return OUString(
492 : #if ! defined MACOSX
493 : "com.sun.star.datatransfer.dnd.XdndDropTarget"
494 : #else
495 : "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
496 : #endif
497 120 : );
498 : #else
499 : return GenericDropTarget::getImplementationName_static();
500 : #endif
501 : }
502 :
503 1575 : Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
504 : {
505 1575 : SolarMutexGuard aGuard;
506 1575 : Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
507 1575 : return xResult;
508 : }
509 :
510 : } // namespace vcl
511 :
512 : /*
513 : * SalInstance generic
514 : */
515 1165 : Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
516 : {
517 1165 : return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericClipboard()) );
518 : }
519 :
520 1564 : Reference< XInterface > SalInstance::CreateDragSource()
521 : {
522 1564 : return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDragSource()) );
523 : }
524 :
525 1564 : Reference< XInterface > SalInstance::CreateDropTarget()
526 : {
527 1564 : return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDropTarget()) );
528 : }
529 :
530 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|