merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / source / dtrans / X11_service.cxx
blob88604161d9705c1cf814b35ae046037fbef31472
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: X11_service.cxx,v $
10 * $Revision: 1.11 $
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_vcl.hxx"
34 #include "salinst.h"
36 #include <X11_clipboard.hxx>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <uno/dispatcher.h> // declaration of generic uno interface
41 #include <uno/mapping.hxx> // mapping stuff
42 #include <cppuhelper/factory.hxx>
43 #include <cppuhelper/compbase1.hxx>
45 using namespace rtl;
46 using namespace cppu;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::datatransfer::clipboard;
49 using namespace com::sun::star::awt;
50 using namespace x11;
52 Sequence< OUString > SAL_CALL x11::X11Clipboard_getSupportedServiceNames()
54 Sequence< OUString > aRet(1);
55 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
56 return aRet;
59 Sequence< OUString > SAL_CALL x11::Xdnd_getSupportedServiceNames()
61 Sequence< OUString > aRet(1);
62 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DragSource");
63 return aRet;
66 Sequence< OUString > SAL_CALL x11::Xdnd_dropTarget_getSupportedServiceNames()
68 Sequence< OUString > aRet(1);
69 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DropTarget");
70 return aRet;
73 // ------------------------------------------------------------------------
75 Reference< XInterface > X11SalInstance::CreateClipboard( const Sequence< Any >& arguments )
77 static std::hash_map< OUString, ::std::hash_map< Atom, Reference< XClipboard > >, ::rtl::OUStringHash > m_aInstances;
79 OUString aDisplayName;
80 Atom nSelection;
82 // extract display name from connection argument. An exception is thrown
83 // by SelectionManager.initialize() if no display connection is given.
84 if( arguments.getLength() > 0 )
86 Reference< XDisplayConnection > xConn;
87 arguments.getConstArray()[0] >>= xConn;
89 if( xConn.is() )
91 Any aIdentifier = xConn->getIdentifier();
92 aIdentifier >>= aDisplayName;
96 SelectionManager& rManager = SelectionManager::get( aDisplayName );
97 rManager.initialize( arguments );
99 // check if any other selection than clipboard selection is specified
100 if( arguments.getLength() > 1 )
102 OUString aSelectionName;
104 arguments.getConstArray()[1] >>= aSelectionName;
105 nSelection = rManager.getAtom( aSelectionName );
107 else
109 // default atom is clipboard selection
110 nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) );
113 ::std::hash_map< Atom, Reference< XClipboard > >& rMap( m_aInstances[ aDisplayName ] );
114 ::std::hash_map< Atom, Reference< XClipboard > >::iterator it = rMap.find( nSelection );
115 if( it != rMap.end() )
116 return it->second;
118 X11Clipboard* pClipboard = new X11Clipboard( rManager, nSelection );
119 rMap[ nSelection ] = pClipboard;
121 return static_cast<OWeakObject*>(pClipboard);
124 // ------------------------------------------------------------------------
126 Reference< XInterface > X11SalInstance::CreateDragSource()
128 return Reference < XInterface >( ( OWeakObject * ) new SelectionManagerHolder() );
131 // ------------------------------------------------------------------------
133 Reference< XInterface > X11SalInstance::CreateDropTarget()
135 return Reference < XInterface >( ( OWeakObject * ) new DropTarget() );