Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <X11_selection.hxx>
31 : :
32 : : using namespace x11;
33 : : using namespace com::sun::star::lang;
34 : : using namespace com::sun::star::awt;
35 : : using namespace com::sun::star::datatransfer;
36 : : using namespace com::sun::star::datatransfer::dnd;
37 : :
38 : : using ::rtl::OUString;
39 : :
40 : 0 : DropTarget::DropTarget() :
41 : : ::cppu::WeakComponentImplHelper3<
42 : : XDropTarget,
43 : : XInitialization,
44 : : XServiceInfo
45 : : >( m_aMutex ),
46 : : m_bActive( false ),
47 : : m_nDefaultActions( 0 ),
48 : : m_aTargetWindow( None ),
49 : 0 : m_pSelectionManager( NULL )
50 : : {
51 : 0 : }
52 : :
53 : 0 : DropTarget::~DropTarget()
54 : : {
55 : 0 : if( m_pSelectionManager )
56 : 0 : m_pSelectionManager->deregisterDropTarget( m_aTargetWindow );
57 : 0 : }
58 : :
59 : : // --------------------------------------------------------------------------
60 : :
61 : 0 : void DropTarget::initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception )
62 : : {
63 : 0 : if( arguments.getLength() > 1 )
64 : : {
65 : 0 : OUString aDisplayName;
66 : 0 : Reference< XDisplayConnection > xConn;
67 : 0 : arguments.getConstArray()[0] >>= xConn;
68 : 0 : if( xConn.is() )
69 : : {
70 : 0 : Any aIdentifier;
71 : 0 : aIdentifier >>= aDisplayName;
72 : : }
73 : :
74 : 0 : m_pSelectionManager = &SelectionManager::get( aDisplayName );
75 : 0 : m_xSelectionManager = static_cast< XDragSource* >(m_pSelectionManager);
76 : 0 : m_pSelectionManager->initialize( arguments );
77 : :
78 : 0 : if( m_pSelectionManager->getDisplay() ) // #136582# sanity check
79 : : {
80 : 0 : sal_Size aWindow = None;
81 : 0 : arguments.getConstArray()[1] >>= aWindow;
82 : 0 : m_pSelectionManager->registerDropTarget( aWindow, this );
83 : 0 : m_aTargetWindow = aWindow;
84 : 0 : m_bActive = true;
85 : 0 : }
86 : : }
87 : 0 : }
88 : :
89 : : // --------------------------------------------------------------------------
90 : :
91 : 0 : void DropTarget::addDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
92 : : {
93 : 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
94 : :
95 : 0 : m_aListeners.push_back( xListener );
96 : 0 : }
97 : :
98 : : // --------------------------------------------------------------------------
99 : :
100 : 0 : void DropTarget::removeDropTargetListener( const Reference< XDropTargetListener >& xListener ) throw()
101 : : {
102 : 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
103 : :
104 : 0 : m_aListeners.remove( xListener );
105 : 0 : }
106 : :
107 : : // --------------------------------------------------------------------------
108 : :
109 : 0 : sal_Bool DropTarget::isActive() throw()
110 : : {
111 : 0 : return m_bActive;
112 : : }
113 : :
114 : : // --------------------------------------------------------------------------
115 : :
116 : 0 : void DropTarget::setActive( sal_Bool active ) throw()
117 : : {
118 : 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
119 : :
120 : 0 : m_bActive = active;
121 : 0 : }
122 : :
123 : : // --------------------------------------------------------------------------
124 : :
125 : 0 : sal_Int8 DropTarget::getDefaultActions() throw()
126 : : {
127 : 0 : return m_nDefaultActions;
128 : : }
129 : :
130 : : // --------------------------------------------------------------------------
131 : :
132 : 0 : void DropTarget::setDefaultActions( sal_Int8 actions ) throw()
133 : : {
134 : 0 : ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
135 : :
136 : 0 : m_nDefaultActions = actions;
137 : 0 : }
138 : :
139 : : // --------------------------------------------------------------------------
140 : :
141 : 0 : void DropTarget::drop( const DropTargetDropEvent& dtde ) throw()
142 : : {
143 : 0 : osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
144 : 0 : std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
145 : 0 : aGuard.clear();
146 : :
147 : 0 : for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
148 : : {
149 : 0 : (*it)->drop( dtde );
150 : 0 : }
151 : 0 : }
152 : :
153 : : // --------------------------------------------------------------------------
154 : :
155 : 0 : void DropTarget::dragEnter( const DropTargetDragEnterEvent& dtde ) throw()
156 : : {
157 : 0 : osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
158 : 0 : std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
159 : 0 : aGuard.clear();
160 : :
161 : 0 : for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
162 : : {
163 : 0 : (*it)->dragEnter( dtde );
164 : 0 : }
165 : 0 : }
166 : :
167 : : // --------------------------------------------------------------------------
168 : :
169 : 0 : void DropTarget::dragExit( const DropTargetEvent& dte ) throw()
170 : : {
171 : 0 : osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
172 : 0 : std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
173 : 0 : aGuard.clear();
174 : :
175 : 0 : for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
176 : : {
177 : 0 : (*it)->dragExit( dte );
178 : 0 : }
179 : 0 : }
180 : :
181 : : // --------------------------------------------------------------------------
182 : :
183 : 0 : void DropTarget::dragOver( const DropTargetDragEvent& dtde ) throw()
184 : : {
185 : 0 : osl::ClearableGuard< ::osl::Mutex > aGuard( m_aMutex );
186 : 0 : std::list< Reference< XDropTargetListener > > aListeners( m_aListeners );
187 : 0 : aGuard.clear();
188 : :
189 : 0 : for( std::list< Reference< XDropTargetListener > >::iterator it = aListeners.begin(); it!= aListeners.end(); ++it )
190 : : {
191 : 0 : (*it)->dragOver( dtde );
192 : 0 : }
193 : 0 : }
194 : :
195 : : // --------------------------------------------------------------------------
196 : :
197 : : /*
198 : : * XServiceInfo
199 : : */
200 : :
201 : : // ------------------------------------------------------------------------
202 : :
203 : 0 : OUString DropTarget::getImplementationName() throw()
204 : : {
205 : 0 : return OUString(XDND_DROPTARGET_IMPLEMENTATION_NAME);
206 : : }
207 : :
208 : : // ------------------------------------------------------------------------
209 : :
210 : 0 : sal_Bool DropTarget::supportsService( const OUString& ServiceName ) throw()
211 : : {
212 : 0 : Sequence < OUString > SupportedServicesNames = Xdnd_dropTarget_getSupportedServiceNames();
213 : :
214 : 0 : for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
215 : 0 : if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
216 : 0 : return sal_True;
217 : :
218 : 0 : return sal_False;
219 : : }
220 : :
221 : : // ------------------------------------------------------------------------
222 : :
223 : 0 : Sequence< OUString > DropTarget::getSupportedServiceNames() throw()
224 : : {
225 : 0 : return Xdnd_dropTarget_getSupportedServiceNames();
226 : : }
227 : :
228 : :
229 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|