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