1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontident.cxx,v $
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"
60 using namespace com::sun::star
;
61 using namespace com::sun::star::uno
;
62 using namespace com::sun::star::lang
;
64 // -----------------------------------------------------------------------
68 // generic implementation to satisfy SalInstance
69 class GenericClipboard
:
70 public cppu::WeakComponentImplHelper3
<
71 datatransfer::clipboard::XClipboardEx
,
72 datatransfer::clipboard::XClipboardNotifier
,
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();
86 GenericClipboard() : cppu::WeakComponentImplHelper3
<
87 datatransfer::clipboard::XClipboardEx
,
88 datatransfer::clipboard::XClipboardNotifier
,
92 virtual ~GenericClipboard();
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();
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
);
124 virtual sal_Int8 SAL_CALL
getRenderingCapabilities()
125 throw(RuntimeException
);
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");
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
)
177 Reference
< ::com::sun::star::datatransfer::XTransferable
> GenericClipboard::getContents() throw( RuntimeException
)
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
;
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
)
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
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
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
);
283 // ------------------------------------------------------------------------
285 Sequence
< OUString
> SAL_CALL
Clipboard_getSupportedServiceNames()
287 Sequence
< OUString
> aRet(1);
288 aRet
[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
292 OUString SAL_CALL
Clipboard_getImplementationName()
295 return OUString( RTL_CONSTASCII_USTRINGPARAM(
297 "com.sun.star.datatransfer.X11ClipboardSupport"
299 "com.sun.star.datatransfer.clipboard.AquaClipboard"
303 return GenericClipboard::getImplementationName_static();
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
,
322 GenericDragSource() : cppu::WeakComponentImplHelper2
< datatransfer::dnd::XDragSource
, XInitialization
>( m_aMutex
) {}
323 virtual ~GenericDragSource();
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
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" );
345 static OUString
getImplementationName_static()
347 return OUString::createFromAscii( "com.sun.star.datatransfer.dnd.VclGenericDragSource" );
351 GenericDragSource::~GenericDragSource()
355 sal_Bool
GenericDragSource::isDragImageSupported() throw()
360 sal_Int32
GenericDragSource::getDefaultCursor( sal_Int8
) throw()
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
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()
385 static OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM(
387 "com.sun.star.datatransfer.dnd.X11DragSource"
389 "com.sun.star.datatransfer.dnd.OleDragSource"
392 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
393 return aServiceNames
;
395 return GenericDragSource::getSupportedServiceNames_static();
399 OUString SAL_CALL
DragSource_getImplementationName()
402 return OUString( RTL_CONSTASCII_USTRINGPARAM(
404 "com.sun.star.datatransfer.dnd.XdndSupport"
406 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1"
410 return GenericDragSource::getImplementationName_static();
414 Reference
< XInterface
> SAL_CALL
DragSource_createInstance( const Reference
< XMultiServiceFactory
>& )
416 vos::OGuard
aGuard( Application::GetSolarMutex() );
417 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDragSource();
422 * generic DragSource dummy
425 class GenericDropTarget
: public cppu::WeakComponentImplHelper2
<
426 datatransfer::dnd::XDropTarget
,
432 GenericDropTarget() : cppu::WeakComponentImplHelper2
<
433 datatransfer::dnd::XDropTarget
,
437 virtual ~GenericDropTarget();
440 virtual void SAL_CALL
initialize( const Sequence
< Any
>& args
) throw ( Exception
);
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" );
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()
484 void GenericDropTarget::setActive( sal_Bool
) throw()
488 sal_Int8
GenericDropTarget::getDefaultActions() throw()
493 void GenericDropTarget::setDefaultActions( sal_Int8
) throw()
497 Sequence
< OUString
> SAL_CALL
DropTarget_getSupportedServiceNames()
500 static OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM(
502 "com.sun.star.datatransfer.dnd.X11DropTarget"
504 "com.sun.star.datatransfer.dnd.OleDropTarget"
507 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
508 return aServiceNames
;
510 return GenericDropTarget::getSupportedServiceNames_static();
514 OUString SAL_CALL
DropTarget_getImplementationName()
517 return OUString( RTL_CONSTASCII_USTRINGPARAM(
519 "com.sun.star.datatransfer.dnd.XdndDropTarget"
521 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
525 return GenericDropTarget::getImplementationName_static();
529 Reference
< XInterface
> SAL_CALL
DropTarget_createInstance( const Reference
< XMultiServiceFactory
>& )
531 vos::OGuard
aGuard( Application::GetSolarMutex() );
532 Reference
< XInterface
> xResult
= ImplGetSVData()->mpDefInst
->CreateDropTarget();
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() );