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: X11_service.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
34 #include <X11_clipboard.hxx>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <com/sun/star/registry/XRegistryKey.hpp>
38 #include <uno/dispatcher.h> // declaration of generic uno interface
39 #include <uno/mapping.hxx> // mapping stuff
40 #include <cppuhelper/factory.hxx>
41 #include <cppuhelper/compbase1.hxx>
45 using namespace com::sun::star::lang
;
46 using namespace com::sun::star::datatransfer::clipboard
;
47 using namespace com::sun::star::awt
;
52 class X11ClipboardFactory
: public ::cppu::WeakComponentImplHelper1
<
53 ::com::sun::star::lang::XSingleServiceFactory
56 ::osl::Mutex m_aMutex
;
57 ::std::hash_map
< OUString
, ::std::hash_map
< Atom
, Reference
< XClipboard
> >, ::rtl::OUStringHash
> m_aInstances
;
59 X11ClipboardFactory();
60 virtual ~X11ClipboardFactory();
63 * XSingleServiceFactory
65 virtual Reference
< XInterface
> createInstance() throw();
66 virtual Reference
< XInterface
> createInstanceWithArguments( const Sequence
< Any
>& rArgs
) throw();
69 // ------------------------------------------------------------------------
71 X11ClipboardFactory::X11ClipboardFactory() :
72 ::cppu::WeakComponentImplHelper1
<
73 ::com::sun::star::lang::XSingleServiceFactory
78 // ------------------------------------------------------------------------
80 X11ClipboardFactory::~X11ClipboardFactory()
84 // ------------------------------------------------------------------------
86 Reference
< XInterface
> X11ClipboardFactory::createInstance() throw()
88 return createInstanceWithArguments( Sequence
< Any
>() );
91 // ------------------------------------------------------------------------
93 Reference
< XInterface
> X11ClipboardFactory::createInstanceWithArguments( const Sequence
< Any
>& arguments
) throw()
95 OUString aDisplayName
;
98 // extract display name from connection argument. An exception is thrown
99 // by SelectionManager.initialize() if no display connection is given.
100 if( arguments
.getLength() > 0 )
102 Reference
< XDisplayConnection
> xConn
;
103 arguments
.getConstArray()[0] >>= xConn
;
107 Any aIdentifier
= xConn
->getIdentifier();
108 aIdentifier
>>= aDisplayName
;
112 SelectionManager
& rManager
= SelectionManager::get( aDisplayName
);
113 rManager
.initialize( arguments
);
115 // check if any other selection than clipboard selection is specified
116 if( arguments
.getLength() > 1 )
118 OUString aSelectionName
;
120 arguments
.getConstArray()[1] >>= aSelectionName
;
121 nSelection
= rManager
.getAtom( aSelectionName
);
125 // default atom is clipboard selection
126 nSelection
= rManager
.getAtom( OUString::createFromAscii( "CLIPBOARD" ) );
129 ::std::hash_map
< Atom
, Reference
< XClipboard
> >& rMap( m_aInstances
[ aDisplayName
] );
130 ::std::hash_map
< Atom
, Reference
< XClipboard
> >::iterator it
= rMap
.find( nSelection
);
131 if( it
!= rMap
.end() )
134 X11Clipboard
* pClipboard
= new X11Clipboard( rManager
, nSelection
);
135 rMap
[ nSelection
] = pClipboard
;
137 return static_cast<OWeakObject
*>(pClipboard
);
140 // ------------------------------------------------------------------------
142 Sequence
< OUString
> SAL_CALL
X11Clipboard_getSupportedServiceNames()
144 Sequence
< OUString
> aRet(1);
145 aRet
[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
149 // ------------------------------------------------------------------------
151 Sequence
< OUString
> SAL_CALL
Xdnd_getSupportedServiceNames()
153 Sequence
< OUString
> aRet(1);
154 aRet
[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DragSource");
158 // ------------------------------------------------------------------------
160 Reference
< XInterface
> SAL_CALL
Xdnd_createInstance(
161 const Reference
< XMultiServiceFactory
> & )
163 return Reference
< XInterface
>( ( OWeakObject
* ) new SelectionManagerHolder() );
166 // ------------------------------------------------------------------------
168 Sequence
< OUString
> SAL_CALL
Xdnd_dropTarget_getSupportedServiceNames()
170 Sequence
< OUString
> aRet(1);
171 aRet
[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DropTarget");
175 // ------------------------------------------------------------------------
177 Reference
< XInterface
> SAL_CALL
Xdnd_dropTarget_createInstance(
178 const Reference
< XMultiServiceFactory
> & )
180 return Reference
< XInterface
>( ( OWeakObject
* ) new DropTarget() );
185 static const OUString
& getClipboardImplementationName()
187 static OUString aImpl
= OUString::createFromAscii(X11_CLIPBOARD_IMPLEMENTATION_NAME
);
191 static const OUString
& getClipboardServiceName()
193 static OUString aImpl
= OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard" );
197 static const OUString
& getXdndImplementationName()
199 static OUString aImpl
= OUString::createFromAscii(XDND_IMPLEMENTATION_NAME
);
203 static const OUString
& getXdndServiceName()
205 static OUString aImpl
= OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DragSource" );
209 static const OUString
& getXdndDropTargetImplementationName()
211 static OUString aImpl
= OUString::createFromAscii(XDND_DROPTARGET_IMPLEMENTATION_NAME
);
215 static const OUString
& getXdndDropTargetServiceName()
217 static OUString aImpl
= OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DropTarget" );
222 void SAL_CALL
component_getImplementationEnvironment(
223 const sal_Char
** ppEnvTypeName
,
226 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
229 sal_Bool SAL_CALL
component_writeInfo( void*, void* pXUnoKey
)
235 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey( reinterpret_cast< ::com::sun::star::registry::XRegistryKey
* >( pXUnoKey
) );
237 OUString aImplName
= OUString::createFromAscii( "/" );
238 aImplName
+= getClipboardImplementationName();
239 aImplName
+= ::rtl::OUString::createFromAscii( "/UNO/SERVICES/" );
240 aImplName
+= getClipboardServiceName();
241 xKey
->createKey( aImplName
);
243 aImplName
= OUString::createFromAscii( "/" );
244 aImplName
+= getXdndImplementationName();
245 aImplName
+= ::rtl::OUString::createFromAscii( "/UNO/SERVICES/" );
246 aImplName
+= getXdndServiceName();
247 xKey
->createKey( aImplName
);
249 aImplName
= OUString::createFromAscii( "/" );
250 aImplName
+= getXdndDropTargetImplementationName();
251 aImplName
+= ::rtl::OUString::createFromAscii( "/UNO/SERVICES/" );
252 aImplName
+= getXdndDropTargetServiceName();
253 xKey
->createKey( aImplName
);
257 catch( ::com::sun::star::registry::InvalidRegistryException
& )
264 void* SAL_CALL
component_getFactory(
265 const sal_Char
* pImplementationName
,
272 ::rtl::OUString
aImplName( ::rtl::OUString::createFromAscii( pImplementationName
) );
276 Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xMgr(
277 reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory
* >( pXUnoSMgr
)
279 Reference
< ::com::sun::star::lang::XSingleServiceFactory
> xFactory
;
280 if( aImplName
.equals( getClipboardImplementationName() ) )
281 xFactory
= new X11ClipboardFactory();
282 else if( aImplName
.equals( getXdndImplementationName() ) )
284 xFactory
= ::cppu::createSingleFactory(
285 xMgr
, aImplName
, Xdnd_createInstance
,
286 Xdnd_getSupportedServiceNames() );
288 else if( aImplName
.equals( getXdndDropTargetImplementationName() ) )
290 xFactory
= ::cppu::createSingleFactory(
291 xMgr
, aImplName
, Xdnd_dropTarget_createInstance
,
292 Xdnd_dropTarget_getSupportedServiceNames() );
297 pRet
= xFactory
.get();