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