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 <X11_selection.hxx>
28 
29 using namespace x11;
30 using namespace rtl;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::awt;
33 using namespace com::sun::star::datatransfer;
34 using namespace com::sun::star::datatransfer::dnd;
35 
DropTarget()36 DropTarget::DropTarget() :
37 		::cppu::WeakComponentImplHelper3<
38 			XDropTarget,
39 			XInitialization,
40 			XServiceInfo
41 		>( m_aMutex ),
42 	m_bActive( false ),
43 	m_nDefaultActions( 0 ),
44 	m_aTargetWindow( None ),
45 	m_pSelectionManager( NULL )
46 {
47 }
48 
~DropTarget()49 DropTarget::~DropTarget()
50 {
51 	if( m_pSelectionManager )
52 		m_pSelectionManager->deregisterDropTarget( m_aTargetWindow );
53 }
54 
55 // --------------------------------------------------------------------------
56 
initialize(const Sequence<Any> & arguments)57 void DropTarget::initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception )
58 {
59 	if( arguments.getLength() > 1 )
60 	{
61 		OUString aDisplayName;
62 		Reference< XDisplayConnection > xConn;
63 		arguments.getConstArray()[0] >>= xConn;
64 		if( xConn.is() )
65 		{
66 			Any aIdentifier;
67 			aIdentifier >>= aDisplayName;
68 		}
69 
70 		m_pSelectionManager = &SelectionManager::get( aDisplayName );
71 		m_xSelectionManager = static_cast< XDragSource* >(m_pSelectionManager);
72 		m_pSelectionManager->initialize( arguments );
73 
74         if( m_pSelectionManager->getDisplay() ) // #136582# sanity check
75         {
76             sal_Size aWindow = None;
77             arguments.getConstArray()[1] >>= aWindow;
78             m_pSelectionManager->registerDropTarget( aWindow, this );
79             m_aTargetWindow = aWindow;
80             m_bActive = true;
81         }
82 	}
83 }
84 
85 // --------------------------------------------------------------------------
86 
addDropTargetListener(const Reference<XDropTargetListener> & xListener)87 void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
88 {
89 	::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
90 
91 	m_aListeners.push_back( xListener );
92 }
93 
94 // --------------------------------------------------------------------------
95 
removeDropTargetListener(const Reference<XDropTargetListener> & xListener)96 void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
97 {
98 	::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
99 
100 	m_aListeners.remove( xListener );
101 }
102 
103 // --------------------------------------------------------------------------
104 
isActive()105 sal_Bool DropTarget::isActive() throw()
106 {
107 	return m_bActive;
108 }
109 
110 // --------------------------------------------------------------------------
111 
setActive(sal_Bool active)112 void DropTarget::setActive( sal_Bool active ) throw()
113 {
114 	::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
115 
116 	m_bActive = active;
117 }
118 
119 // --------------------------------------------------------------------------
120 
getDefaultActions()121 sal_Int8 DropTarget::getDefaultActions() throw()
122 {
123 	return m_nDefaultActions;
124 }
125 
126 // --------------------------------------------------------------------------
127 
setDefaultActions(sal_Int8 actions)128 void DropTarget::setDefaultActions( sal_Int8 actions ) throw()
129 {
130 	::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
131 
132 	m_nDefaultActions = actions;
133 }
134 
135 // --------------------------------------------------------------------------
136 
drop(const DropTargetDropEvent & dtde)137 void DropTarget::drop( const DropTargetDropEvent& dtde ) throw()
138 {
139 	osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
140 	std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
141 	aGuard.clear();
142 
143 	for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
144 	{
145 		(*it)->drop( dtde );
146 	}
147 }
148 
149 // --------------------------------------------------------------------------
150 
dragEnter(const DropTargetDragEnterEvent & dtde)151 void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) throw()
152 {
153 	osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
154 	std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
155 	aGuard.clear();
156 
157 	for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
158 	{
159 		(*it)->dragEnter( dtde );
160 	}
161 }
162 
163 // --------------------------------------------------------------------------
164 
dragExit(const DropTargetEvent & dte)165 void DropTarget::dragExit( const DropTargetEvent& dte ) throw()
166 {
167 	osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
168 	std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
169 	aGuard.clear();
170 
171 	for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
172 	{
173 		(*it)->dragExit( dte );
174 	}
175 }
176 
177 // --------------------------------------------------------------------------
178 
dragOver(const DropTargetDragEvent & dtde)179 void DropTarget::dragOver( const DropTargetDragEvent& dtde ) throw()
180 {
181 	osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
182 	std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
183 	aGuard.clear();
184 
185 	for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
186 	{
187 		(*it)->dragOver( dtde );
188 	}
189 }
190 
191 // --------------------------------------------------------------------------
192 
193 /*
194  *	XServiceInfo
195  */
196 
197 // ------------------------------------------------------------------------
198 
getImplementationName()199 OUString DropTarget::getImplementationName() throw()
200 {
201 	return OUString::createFromAscii(XDND_DROPTARGET_IMPLEMENTATION_NAME);
202 }
203 
204 // ------------------------------------------------------------------------
205 
supportsService(const OUString & ServiceName)206 sal_Bool DropTarget::supportsService( const OUString& ServiceName ) throw()
207 {
208 	Sequence < OUString > SupportedServicesNames = Xdnd_dropTarget_getSupportedServiceNames();
209 
210 	for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
211 		if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
212 			return sal_True;
213 
214 	return sal_False;
215 }
216 
217 // ------------------------------------------------------------------------
218 
getSupportedServiceNames()219 Sequence< OUString > DropTarget::getSupportedServiceNames() throw()
220 {
221 	return Xdnd_dropTarget_getSupportedServiceNames();
222 }
223 
224 
225