Update ooo320-m1
[ooovba.git] / vcl / source / components / dtranscomp.cxx
blob0568b554993e6974e6cf3db884b5619283b8197f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontident.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_vcl.hxx"
35 #include "com/sun/star/lang/XServiceInfo.hpp"
36 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
37 #include "com/sun/star/lang/XInitialization.hpp"
38 #include "com/sun/star/lang/DisposedException.hpp"
39 #include "com/sun/star/datatransfer/XTransferable.hpp"
40 #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp"
41 #include "com/sun/star/datatransfer/clipboard/XClipboardEx.hpp"
42 #include "com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp"
43 #include "com/sun/star/datatransfer/clipboard/XClipboardListener.hpp"
44 #include "com/sun/star/datatransfer/dnd/XDragSource.hpp"
45 #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp"
46 #include "com/sun/star/datatransfer/dnd/DNDConstants.hpp"
48 #include "vcl/svapp.hxx"
49 #include "vcl/svdata.hxx"
50 #include "vcl/salinst.hxx"
51 #include "vos/mutex.hxx"
52 #include "osl/mutex.hxx"
54 #include "cppuhelper/compbase1.hxx"
55 #include "cppuhelper/compbase2.hxx"
56 #include "cppuhelper/compbase3.hxx"
57 #include "cppuhelper/implbase1.hxx"
59 using rtl::OUString;
60 using namespace com::sun::star;
61 using namespace com::sun::star::uno;
62 using namespace com::sun::star::lang;
64 // -----------------------------------------------------------------------
66 namespace vcl
68 // generic implementation to satisfy SalInstance
69 class GenericClipboard :
70 public cppu::WeakComponentImplHelper3 <
71 datatransfer::clipboard::XClipboardEx,
72 datatransfer::clipboard::XClipboardNotifier,
73 XServiceInfo
76 osl::Mutex m_aMutex;
77 Reference< ::com::sun::star::datatransfer::XTransferable > m_aContents;
78 Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner > m_aOwner;
79 std::list< Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > m_aListeners;
81 void fireChangedContentsEvent();
82 void clearContents();
84 public:
86 GenericClipboard() : cppu::WeakComponentImplHelper3<
87 datatransfer::clipboard::XClipboardEx,
88 datatransfer::clipboard::XClipboardNotifier,
89 XServiceInfo
90 >( m_aMutex )
92 virtual ~GenericClipboard();
95 * XServiceInfo
98 virtual rtl::OUString SAL_CALL getImplementationName() throw( RuntimeException );
99 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException );
100 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( RuntimeException );
102 static rtl::OUString getImplementationName_static();
103 static Sequence< rtl::OUString > getSupportedServiceNames_static();
106 * XClipboard
109 virtual Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents()
110 throw(RuntimeException);
112 virtual void SAL_CALL setContents(
113 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
114 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
115 throw(RuntimeException);
117 virtual ::rtl::OUString SAL_CALL getName()
118 throw(RuntimeException);
121 * XClipboardEx
124 virtual sal_Int8 SAL_CALL getRenderingCapabilities()
125 throw(RuntimeException);
128 * XClipboardNotifier
130 virtual void SAL_CALL addClipboardListener(
131 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
132 throw(RuntimeException);
134 virtual void SAL_CALL removeClipboardListener(
135 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
136 throw(RuntimeException);
139 GenericClipboard::~GenericClipboard()
143 rtl::OUString GenericClipboard::getImplementationName_static()
145 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.VCLGenericClipboard" ) );
148 Sequence< rtl::OUString > GenericClipboard::getSupportedServiceNames_static()
150 Sequence< OUString > aRet(1);
151 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
152 return aRet;
155 rtl::OUString GenericClipboard::getImplementationName() throw( RuntimeException )
157 return getImplementationName_static();
160 Sequence< rtl::OUString > GenericClipboard::getSupportedServiceNames() throw( RuntimeException )
162 return getSupportedServiceNames_static();
165 sal_Bool GenericClipboard::supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException )
167 Sequence< OUString > aServices( getSupportedServiceNames() );
168 sal_Int32 nServices = aServices.getLength();
169 for( sal_Int32 i = 0; i < nServices; i++ )
171 if( aServices[i] == ServiceName )
172 return sal_True;
174 return sal_False;
177 Reference< ::com::sun::star::datatransfer::XTransferable > GenericClipboard::getContents() throw( RuntimeException )
179 return m_aContents;
182 void GenericClipboard::setContents(
183 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans,
184 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner )
185 throw( RuntimeException )
187 osl::ClearableMutexGuard aGuard( m_aMutex );
188 Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner );
189 Reference< datatransfer::XTransferable > xOldContents( m_aContents );
190 m_aContents = xTrans;
191 m_aOwner = xClipboardOwner;
193 std::list< Reference< datatransfer::clipboard::XClipboardListener > > xListeners( m_aListeners );
194 datatransfer::clipboard::ClipboardEvent aEv;
195 aEv.Contents = m_aContents;
197 aGuard.clear();
199 if( xOldOwner.is() && xOldOwner != xClipboardOwner )
200 xOldOwner->lostOwnership( this, xOldContents );
201 for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it =
202 xListeners.begin(); it != xListeners.end() ; ++it )
204 (*it)->changedContents( aEv );
208 rtl::OUString GenericClipboard::getName() throw( RuntimeException )
210 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CLIPBOARD" ) );
213 sal_Int8 GenericClipboard::getRenderingCapabilities() throw( RuntimeException )
215 return 0;
218 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
219 throw( RuntimeException )
221 osl::ClearableMutexGuard aGuard( m_aMutex );
223 m_aListeners.push_back( listener );
226 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
227 throw( RuntimeException )
229 osl::ClearableMutexGuard aGuard( m_aMutex );
231 m_aListeners.remove( listener );
234 // ------------------------------------------------------------------------
236 class ClipboardFactory : public ::cppu::WeakComponentImplHelper1<
237 com::sun::star::lang::XSingleServiceFactory
240 osl::Mutex m_aMutex;
241 public:
242 ClipboardFactory();
243 virtual ~ClipboardFactory();
246 * XSingleServiceFactory
248 virtual Reference< XInterface > SAL_CALL createInstance() throw();
249 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) throw();
252 // ------------------------------------------------------------------------
254 ClipboardFactory::ClipboardFactory() :
255 cppu::WeakComponentImplHelper1<
256 com::sun::star::lang::XSingleServiceFactory
257 >( m_aMutex )
261 // ------------------------------------------------------------------------
263 ClipboardFactory::~ClipboardFactory()
267 // ------------------------------------------------------------------------
269 Reference< XInterface > ClipboardFactory::createInstance() throw()
271 return createInstanceWithArguments( Sequence< Any >() );
274 // ------------------------------------------------------------------------
276 Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) throw()
278 vos::OGuard aGuard( Application::GetSolarMutex() );
279 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments );
280 return xResult;
283 // ------------------------------------------------------------------------
285 Sequence< OUString > SAL_CALL Clipboard_getSupportedServiceNames()
287 Sequence< OUString > aRet(1);
288 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
289 return aRet;
292 OUString SAL_CALL Clipboard_getImplementationName()
294 #if defined UNX
295 return OUString( RTL_CONSTASCII_USTRINGPARAM(
296 #if ! defined QUARTZ
297 "com.sun.star.datatransfer.X11ClipboardSupport"
298 #else
299 "com.sun.star.datatransfer.clipboard.AquaClipboard"
300 #endif
301 ) );
302 #else
303 return GenericClipboard::getImplementationName_static();
304 #endif
307 Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & )
309 return Reference< XSingleServiceFactory >( new ClipboardFactory() );
313 * generic DragSource dummy
315 class GenericDragSource : public cppu::WeakComponentImplHelper2<
316 datatransfer::dnd::XDragSource,
317 XInitialization
320 osl::Mutex m_aMutex;
321 public:
322 GenericDragSource() : cppu::WeakComponentImplHelper2< datatransfer::dnd::XDragSource, XInitialization >( m_aMutex ) {}
323 virtual ~GenericDragSource();
325 // XDragSource
326 virtual sal_Bool SAL_CALL isDragImageSupported() throw();
327 virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw();
328 virtual void SAL_CALL startDrag(
329 const datatransfer::dnd::DragGestureEvent& trigger,
330 sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
331 const Reference< datatransfer::XTransferable >& transferable,
332 const Reference< datatransfer::dnd::XDragSourceListener >& listener
333 ) throw();
335 // XInitialization
336 virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception );
338 static Sequence< OUString > getSupportedServiceNames_static()
340 Sequence< OUString > aRet( 1 );
341 aRet[0] = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.GenericDragSource" );
342 return aRet;
345 static OUString getImplementationName_static()
347 return OUString::createFromAscii( "com.sun.star.datatransfer.dnd.VclGenericDragSource" );
351 GenericDragSource::~GenericDragSource()
355 sal_Bool GenericDragSource::isDragImageSupported() throw()
357 return sal_False;
360 sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 ) throw()
362 return 0;
365 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
366 sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
367 const Reference< datatransfer::XTransferable >&,
368 const Reference< datatransfer::dnd::XDragSourceListener >& listener
369 ) throw()
371 datatransfer::dnd::DragSourceDropEvent aEv;
372 aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
373 aEv.DropSuccess = sal_False;
374 listener->dragDropEnd( aEv );
377 void GenericDragSource::initialize( const Sequence< Any >& ) throw( Exception )
382 Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames()
384 #if defined UNX
385 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM(
386 #if ! defined QUARTZ
387 "com.sun.star.datatransfer.dnd.X11DragSource"
388 #else
389 "com.sun.star.datatransfer.dnd.OleDragSource"
390 #endif
391 ) );
392 static Sequence< OUString > aServiceNames( &aServiceName, 1 );
393 return aServiceNames;
394 #else
395 return GenericDragSource::getSupportedServiceNames_static();
396 #endif
399 OUString SAL_CALL DragSource_getImplementationName()
401 #if defined UNX
402 return OUString( RTL_CONSTASCII_USTRINGPARAM(
403 #if ! defined QUARTZ
404 "com.sun.star.datatransfer.dnd.XdndSupport"
405 #else
406 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
407 #endif
408 ) );
409 #else
410 return GenericDragSource::getImplementationName_static();
411 #endif
414 Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& )
416 vos::OGuard aGuard( Application::GetSolarMutex() );
417 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource();
418 return xResult;
422 * generic DragSource dummy
425 class GenericDropTarget : public cppu::WeakComponentImplHelper2<
426 datatransfer::dnd::XDropTarget,
427 XInitialization
430 osl::Mutex m_aMutex;
431 public:
432 GenericDropTarget() : cppu::WeakComponentImplHelper2<
433 datatransfer::dnd::XDropTarget,
434 XInitialization
435 > ( m_aMutex )
437 virtual ~GenericDropTarget();
439 // XInitialization
440 virtual void SAL_CALL initialize( const Sequence< Any >& args ) throw ( Exception );
442 // XDropTarget
443 virtual void SAL_CALL addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw();
444 virtual void SAL_CALL removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw();
445 virtual sal_Bool SAL_CALL isActive() throw();
446 virtual void SAL_CALL setActive( sal_Bool active ) throw();
447 virtual sal_Int8 SAL_CALL getDefaultActions() throw();
448 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw();
450 static Sequence< OUString > getSupportedServiceNames_static()
452 Sequence< OUString > aRet( 1 );
453 aRet[0] = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.GenericDropTarget" );
454 return aRet;
457 static OUString getImplementationName_static()
459 return OUString::createFromAscii( "com.sun.star.datatransfer.dnd.VclGenericDropTarget" );
463 GenericDropTarget::~GenericDropTarget()
467 void GenericDropTarget::initialize( const Sequence< Any >& ) throw( Exception )
471 void GenericDropTarget::addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw()
475 void GenericDropTarget::removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw()
479 sal_Bool GenericDropTarget::isActive() throw()
481 return sal_False;
484 void GenericDropTarget::setActive( sal_Bool ) throw()
488 sal_Int8 GenericDropTarget::getDefaultActions() throw()
490 return 0;
493 void GenericDropTarget::setDefaultActions( sal_Int8) throw()
497 Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames()
499 #if defined UNX
500 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM(
501 #if ! defined QUARTZ
502 "com.sun.star.datatransfer.dnd.X11DropTarget"
503 #else
504 "com.sun.star.datatransfer.dnd.OleDropTarget"
505 #endif
506 ) );
507 static Sequence< OUString > aServiceNames( &aServiceName, 1 );
508 return aServiceNames;
509 #else
510 return GenericDropTarget::getSupportedServiceNames_static();
511 #endif
514 OUString SAL_CALL DropTarget_getImplementationName()
516 #if defined UNX
517 return OUString( RTL_CONSTASCII_USTRINGPARAM(
518 #if ! defined QUARTZ
519 "com.sun.star.datatransfer.dnd.XdndDropTarget"
520 #else
521 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
522 #endif
523 ) );
524 #else
525 return GenericDropTarget::getImplementationName_static();
526 #endif
529 Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& )
531 vos::OGuard aGuard( Application::GetSolarMutex() );
532 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget();
533 return xResult;
537 } // namespace vcl
540 * SalInstance generic
542 Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& )
544 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericClipboard() );
547 Reference< XInterface > SalInstance::CreateDragSource()
549 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDragSource() );
552 Reference< XInterface > SalInstance::CreateDropTarget()
554 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDropTarget() );