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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_vcl.hxx" 24 25 #include "unx/salinst.h" 26 27 #include <X11_clipboard.hxx> 28 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 30 #include <com/sun/star/registry/XRegistryKey.hpp> 31 #include <uno/dispatcher.h> // declaration of generic uno interface 32 #include <uno/mapping.hxx> // mapping stuff 33 #include <cppuhelper/factory.hxx> 34 #include <cppuhelper/compbase1.hxx> 35 36 namespace { 37 38 namespace css = com::sun::star; 39 40 } 41 42 using namespace rtl; 43 using namespace cppu; 44 using namespace com::sun::star::lang; 45 using namespace com::sun::star::datatransfer::clipboard; 46 using namespace com::sun::star::awt; 47 using namespace x11; 48 49 Sequence< OUString > SAL_CALL x11::X11Clipboard_getSupportedServiceNames() 50 { 51 Sequence< OUString > aRet(1); 52 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard"); 53 return aRet; 54 } 55 56 Sequence< OUString > SAL_CALL x11::Xdnd_getSupportedServiceNames() 57 { 58 Sequence< OUString > aRet(1); 59 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DragSource"); 60 return aRet; 61 } 62 63 Sequence< OUString > SAL_CALL x11::Xdnd_dropTarget_getSupportedServiceNames() 64 { 65 Sequence< OUString > aRet(1); 66 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.dnd.X11DropTarget"); 67 return aRet; 68 } 69 70 // ------------------------------------------------------------------------ 71 72 css::uno::Reference< XInterface > X11SalInstance::CreateClipboard( const Sequence< Any >& arguments ) 73 { 74 static std::hash_map< OUString, ::std::hash_map< Atom, css::uno::Reference< XClipboard > >, ::rtl::OUStringHash > m_aInstances; 75 76 OUString aDisplayName; 77 Atom nSelection; 78 79 // extract display name from connection argument. An exception is thrown 80 // by SelectionManager.initialize() if no display connection is given. 81 if( arguments.getLength() > 0 ) 82 { 83 css::uno::Reference< XDisplayConnection > xConn; 84 arguments.getConstArray()[0] >>= xConn; 85 86 if( xConn.is() ) 87 { 88 Any aIdentifier = xConn->getIdentifier(); 89 aIdentifier >>= aDisplayName; 90 } 91 } 92 93 SelectionManager& rManager = SelectionManager::get( aDisplayName ); 94 rManager.initialize( arguments ); 95 96 // check if any other selection than clipboard selection is specified 97 if( arguments.getLength() > 1 ) 98 { 99 OUString aSelectionName; 100 101 arguments.getConstArray()[1] >>= aSelectionName; 102 nSelection = rManager.getAtom( aSelectionName ); 103 } 104 else 105 { 106 // default atom is clipboard selection 107 nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ); 108 } 109 110 ::std::hash_map< Atom, css::uno::Reference< XClipboard > >& rMap( m_aInstances[ aDisplayName ] ); 111 ::std::hash_map< Atom, css::uno::Reference< XClipboard > >::iterator it = rMap.find( nSelection ); 112 if( it != rMap.end() ) 113 return it->second; 114 115 X11Clipboard* pClipboard = new X11Clipboard( rManager, nSelection ); 116 rMap[ nSelection ] = pClipboard; 117 118 return static_cast<OWeakObject*>(pClipboard); 119 } 120 121 // ------------------------------------------------------------------------ 122 123 css::uno::Reference< XInterface > X11SalInstance::CreateDragSource() 124 { 125 return css::uno::Reference < XInterface >( ( OWeakObject * ) new SelectionManagerHolder() ); 126 } 127 128 // ------------------------------------------------------------------------ 129 130 css::uno::Reference< XInterface > X11SalInstance::CreateDropTarget() 131 { 132 return css::uno::Reference < XInterface >( ( OWeakObject * ) new DropTarget() ); 133 } 134 135 /* vim: set noet sw=4 ts=4: */ 136