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