Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / vcl / unx / generic / dtrans / X11_droptarget.cxx
blobeb726e86fbb1989a9295ee8ad555250cd3180001
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppuhelper/supportsservice.hxx>
21 #include <X11_selection.hxx>
23 using namespace x11;
24 using namespace com::sun::star::uno;
25 using namespace com::sun::star::lang;
26 using namespace com::sun::star::awt;
27 using namespace com::sun::star::datatransfer;
28 using namespace com::sun::star::datatransfer::dnd;
30 DropTarget::DropTarget() :
31 ::cppu::WeakComponentImplHelper3<
32 XDropTarget,
33 XInitialization,
34 XServiceInfo
35 >( m_aMutex ),
36 m_bActive( false ),
37 m_nDefaultActions( 0 ),
38 m_aTargetWindow( None ),
39 m_pSelectionManager( NULL )
43 DropTarget::~DropTarget()
45 if( m_pSelectionManager )
46 m_pSelectionManager->deregisterDropTarget( m_aTargetWindow );
49 void DropTarget::initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception, std::exception )
51 if( arguments.getLength() > 1 )
53 OUString aDisplayName;
54 Reference< XDisplayConnection > xConn;
55 arguments.getConstArray()[0] >>= xConn;
56 if( xConn.is() )
58 Any aIdentifier;
59 aIdentifier >>= aDisplayName;
62 m_pSelectionManager = &SelectionManager::get( aDisplayName );
63 m_xSelectionManager = static_cast< XDragSource* >(m_pSelectionManager);
64 m_pSelectionManager->initialize( arguments );
66 if( m_pSelectionManager->getDisplay() ) // #136582# sanity check
68 sal_Size aWindow = None;
69 arguments.getConstArray()[1] >>= aWindow;
70 m_pSelectionManager->registerDropTarget( aWindow, this );
71 m_aTargetWindow = aWindow;
72 m_bActive = true;
77 void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw(std::exception)
79 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
81 m_aListeners.push_back( xListener );
84 void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw(std::exception)
86 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
88 m_aListeners.remove( xListener );
91 sal_Bool DropTarget::isActive() throw(std::exception)
93 return m_bActive;
96 void DropTarget::setActive( sal_Bool active ) throw(std::exception)
98 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
100 m_bActive = active;
103 sal_Int8 DropTarget::getDefaultActions() throw(std::exception)
105 return m_nDefaultActions;
108 void DropTarget::setDefaultActions( sal_Int8 actions ) throw(std::exception)
110 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
112 m_nDefaultActions = actions;
115 void DropTarget::drop( const DropTargetDropEvent& dtde ) throw()
117 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
118 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
119 aGuard.clear();
121 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
123 (*it)->drop( dtde );
127 void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) throw()
129 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
130 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
131 aGuard.clear();
133 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
135 (*it)->dragEnter( dtde );
139 void DropTarget::dragExit( const DropTargetEvent& dte ) throw()
141 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
142 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
143 aGuard.clear();
145 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
147 (*it)->dragExit( dte );
151 void DropTarget::dragOver( const DropTargetDragEvent& dtde ) throw()
153 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
154 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
155 aGuard.clear();
157 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
159 (*it)->dragOver( dtde );
163 // XServiceInfo
164 OUString DropTarget::getImplementationName() throw(std::exception)
166 return OUString(XDND_DROPTARGET_IMPLEMENTATION_NAME);
169 sal_Bool DropTarget::supportsService( const OUString& ServiceName ) throw(std::exception)
171 return cppu::supportsService(this, ServiceName);
174 Sequence< OUString > DropTarget::getSupportedServiceNames() throw(std::exception)
176 return Xdnd_dropTarget_getSupportedServiceNames();
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */