1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "unx/salinst.h"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <X11_clipboard.hxx>
30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
33cdf0e10cSrcweir #include <uno/dispatcher.h> // declaration of generic uno interface
34cdf0e10cSrcweir #include <uno/mapping.hxx> // mapping stuff
35cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
36cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace css = com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace rtl;
45cdf0e10cSrcweir using namespace cppu;
46cdf0e10cSrcweir using namespace com::sun::star::lang;
47cdf0e10cSrcweir using namespace com::sun::star::datatransfer::clipboard;
48cdf0e10cSrcweir using namespace com::sun::star::awt;
49cdf0e10cSrcweir using namespace x11;
50cdf0e10cSrcweir 
X11Clipboard_getSupportedServiceNames()51cdf0e10cSrcweir Sequence< OUString > SAL_CALL x11::X11Clipboard_getSupportedServiceNames()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	Sequence< OUString > aRet(1);
54cdf0e10cSrcweir 	aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard");
55cdf0e10cSrcweir 	return aRet;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
Xdnd_getSupportedServiceNames()58cdf0e10cSrcweir Sequence< OUString > SAL_CALL x11::Xdnd_getSupportedServiceNames()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	Sequence< OUString > aRet(1);
61cdf0e10cSrcweir 	aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DragSource");
62cdf0e10cSrcweir 	return aRet;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
Xdnd_dropTarget_getSupportedServiceNames()65cdf0e10cSrcweir Sequence< OUString > SAL_CALL x11::Xdnd_dropTarget_getSupportedServiceNames()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	Sequence< OUString > aRet(1);
68cdf0e10cSrcweir 	aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DropTarget");
69cdf0e10cSrcweir 	return aRet;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ------------------------------------------------------------------------
73cdf0e10cSrcweir 
CreateClipboard(const Sequence<Any> & arguments)74cdf0e10cSrcweir css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const Sequence< Any >& arguments )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     static std::hash_map< OUString, ::std::hash_map< Atom, css::uno::Reference< XClipboard > >, ::rtl::OUStringHash > m_aInstances;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	OUString aDisplayName;
79cdf0e10cSrcweir     Atom nSelection;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     // extract display name from connection argument. An exception is thrown
82cdf0e10cSrcweir     // by SelectionManager.initialize() if no display connection is given.
83cdf0e10cSrcweir     if( arguments.getLength() > 0 )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		css::uno::Reference< XDisplayConnection > xConn;
86cdf0e10cSrcweir 		arguments.getConstArray()[0] >>= xConn;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		if( xConn.is() )
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			Any aIdentifier = xConn->getIdentifier();
91cdf0e10cSrcweir 			aIdentifier >>= aDisplayName;
92cdf0e10cSrcweir 		}
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	SelectionManager& rManager = SelectionManager::get( aDisplayName );
96cdf0e10cSrcweir 	rManager.initialize( arguments );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     // check if any other selection than clipboard selection is specified
99cdf0e10cSrcweir     if( arguments.getLength() > 1 )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         OUString aSelectionName;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         arguments.getConstArray()[1] >>= aSelectionName;
104cdf0e10cSrcweir         nSelection = rManager.getAtom( aSelectionName );
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir     else
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         // default atom is clipboard selection
109cdf0e10cSrcweir         nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) );
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	::std::hash_map< Atom, css::uno::Reference< XClipboard > >& rMap( m_aInstances[ aDisplayName ] );
113cdf0e10cSrcweir 	::std::hash_map< Atom, css::uno::Reference< XClipboard > >::iterator it = rMap.find( nSelection );
114cdf0e10cSrcweir 	if( it != rMap.end() )
115cdf0e10cSrcweir 		return it->second;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	X11Clipboard* pClipboard = new X11Clipboard( rManager, nSelection );
118cdf0e10cSrcweir 	rMap[ nSelection ] = pClipboard;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	return static_cast<OWeakObject*>(pClipboard);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // ------------------------------------------------------------------------
124cdf0e10cSrcweir 
CreateDragSource()125cdf0e10cSrcweir css::uno::Reference< XInterface > X11SalInstance::CreateDragSource()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	return css::uno::Reference < XInterface >( ( OWeakObject * ) new SelectionManagerHolder() );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // ------------------------------------------------------------------------
131cdf0e10cSrcweir 
CreateDropTarget()132cdf0e10cSrcweir css::uno::Reference< XInterface > X11SalInstance::CreateDropTarget()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	return css::uno::Reference < XInterface >( ( OWeakObject * ) new DropTarget() );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138