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