tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / vcl / unx / generic / dtrans / X11_droptarget.cxx
blob9933d490a886bf2bc4fe785485f011abd1199a6e
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::WeakComponentImplHelper<
32 XDropTarget,
33 XInitialization,
34 XServiceInfo
35 >( m_aMutex ),
36 m_bActive( false ),
37 m_nDefaultActions( 0 ),
38 m_aTargetWindow( None )
42 DropTarget::~DropTarget()
44 if( m_xSelectionManager.is() )
45 m_xSelectionManager->deregisterDropTarget( m_aTargetWindow );
48 void DropTarget::initialize( const Sequence< Any >& arguments )
50 if( arguments.getLength() <= 1 )
51 return;
53 OUString aDisplayName;
54 Reference< XDisplayConnection > xConn;
55 arguments.getConstArray()[0] >>= xConn;
56 if( xConn.is() )
58 Any aIdentifier;
59 aIdentifier >>= aDisplayName;
62 m_xSelectionManager = &SelectionManager::get( aDisplayName );
63 m_xSelectionManager->initialize( arguments );
65 if( m_xSelectionManager->getDisplay() ) // #136582# sanity check
67 sal_IntPtr aWindow = None;
68 arguments.getConstArray()[1] >>= aWindow;
69 m_xSelectionManager->registerDropTarget( aWindow, this );
70 m_aTargetWindow = aWindow;
71 m_bActive = true;
75 void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener )
77 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
79 m_aListeners.push_back( xListener );
82 void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener )
84 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
86 std::erase(m_aListeners, xListener);
89 sal_Bool DropTarget::isActive()
91 return m_bActive;
94 void DropTarget::setActive( sal_Bool active )
96 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
98 m_bActive = active;
101 sal_Int8 DropTarget::getDefaultActions()
103 return m_nDefaultActions;
106 void DropTarget::setDefaultActions( sal_Int8 actions )
108 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
110 m_nDefaultActions = actions;
113 void DropTarget::drop( const DropTargetDropEvent& dtde ) noexcept
115 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
116 std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners );
117 aGuard.clear();
119 for (auto const& listener : aListeners)
121 listener->drop(dtde);
125 void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) noexcept
127 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
128 std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners );
129 aGuard.clear();
131 for (auto const& listener : aListeners)
133 listener->dragEnter(dtde);
137 void DropTarget::dragExit( const DropTargetEvent& dte ) noexcept
139 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
140 std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners );
141 aGuard.clear();
143 for (auto const& listener : aListeners)
145 listener->dragExit(dte);
149 void DropTarget::dragOver( const DropTargetDragEvent& dtde ) noexcept
151 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
152 std::vector< Reference< XDropTargetListener > > aListeners( m_aListeners );
153 aGuard.clear();
155 for (auto const& listener : aListeners)
157 listener->dragOver(dtde);
161 // XServiceInfo
162 OUString DropTarget::getImplementationName()
164 return u"com.sun.star.datatransfer.dnd.XdndDropTarget"_ustr;
167 sal_Bool DropTarget::supportsService( const OUString& ServiceName )
169 return cppu::supportsService(this, ServiceName);
172 Sequence< OUString > DropTarget::getSupportedServiceNames()
174 return Xdnd_dropTarget_getSupportedServiceNames();
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */