Update ooo320-m1
[ooovba.git] / vcl / unx / source / dtrans / X11_droptarget.cxx
blob8523b08d070746fc1b2ed1889cbc2b1bd562dc2b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: X11_droptarget.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include <X11_selection.hxx>
36 using namespace x11;
37 using namespace rtl;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::awt;
40 using namespace com::sun::star::datatransfer;
41 using namespace com::sun::star::datatransfer::dnd;
43 DropTarget::DropTarget() :
44 ::cppu::WeakComponentImplHelper3<
45 XDropTarget,
46 XInitialization,
47 XServiceInfo
48 >( m_aMutex ),
49 m_bActive( false ),
50 m_nDefaultActions( 0 ),
51 m_aTargetWindow( None ),
52 m_pSelectionManager( NULL )
56 DropTarget::~DropTarget()
58 if( m_pSelectionManager )
59 m_pSelectionManager->deregisterDropTarget( m_aTargetWindow );
62 // --------------------------------------------------------------------------
64 void DropTarget::initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception )
66 if( arguments.getLength() > 1 )
68 OUString aDisplayName;
69 Reference< XDisplayConnection > xConn;
70 arguments.getConstArray()[0] >>= xConn;
71 if( xConn.is() )
73 Any aIdentifier;
74 aIdentifier >>= aDisplayName;
77 m_pSelectionManager = &SelectionManager::get( aDisplayName );
78 m_xSelectionManager = static_cast< XDragSource* >(m_pSelectionManager);
79 m_pSelectionManager->initialize( arguments );
81 if( m_pSelectionManager->getDisplay() ) // #136582# sanity check
83 sal_Size aWindow = None;
84 arguments.getConstArray()[1] >>= aWindow;
85 m_pSelectionManager->registerDropTarget( aWindow, this );
86 m_aTargetWindow = aWindow;
87 m_bActive = true;
92 // --------------------------------------------------------------------------
94 void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
96 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
98 m_aListeners.push_back( xListener );
101 // --------------------------------------------------------------------------
103 void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
105 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
107 m_aListeners.remove( xListener );
110 // --------------------------------------------------------------------------
112 sal_Bool DropTarget::isActive() throw()
114 return m_bActive;
117 // --------------------------------------------------------------------------
119 void DropTarget::setActive( sal_Bool active ) throw()
121 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
123 m_bActive = active;
126 // --------------------------------------------------------------------------
128 sal_Int8 DropTarget::getDefaultActions() throw()
130 return m_nDefaultActions;
133 // --------------------------------------------------------------------------
135 void DropTarget::setDefaultActions( sal_Int8 actions ) throw()
137 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
139 m_nDefaultActions = actions;
142 // --------------------------------------------------------------------------
144 void DropTarget::drop( const DropTargetDropEvent& dtde ) throw()
146 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
147 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
148 aGuard.clear();
150 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
152 (*it)->drop( dtde );
156 // --------------------------------------------------------------------------
158 void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) throw()
160 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
161 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
162 aGuard.clear();
164 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
166 (*it)->dragEnter( dtde );
170 // --------------------------------------------------------------------------
172 void DropTarget::dragExit( const DropTargetEvent& dte ) throw()
174 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
175 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
176 aGuard.clear();
178 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
180 (*it)->dragExit( dte );
184 // --------------------------------------------------------------------------
186 void DropTarget::dragOver( const DropTargetDragEvent& dtde ) throw()
188 osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
189 std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
190 aGuard.clear();
192 for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
194 (*it)->dragOver( dtde );
198 // --------------------------------------------------------------------------
201 * XServiceInfo
204 // ------------------------------------------------------------------------
206 OUString DropTarget::getImplementationName() throw()
208 return OUString::createFromAscii(XDND_DROPTARGET_IMPLEMENTATION_NAME);
211 // ------------------------------------------------------------------------
213 sal_Bool DropTarget::supportsService( const OUString& ServiceName ) throw()
215 Sequence < OUString > SupportedServicesNames = Xdnd_dropTarget_getSupportedServiceNames();
217 for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
218 if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
219 return sal_True;
221 return sal_False;
224 // ------------------------------------------------------------------------
226 Sequence< OUString > DropTarget::getSupportedServiceNames() throw()
228 return Xdnd_dropTarget_getSupportedServiceNames();