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