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