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 : : #include <com/sun/star/embed/EmbedStates.hpp>
30 : : #include <cppuhelper/weak.hxx>
31 : :
32 : : #include "intercept.hxx"
33 : : #include "docholder.hxx"
34 : : #include "commonembobj.hxx"
35 : :
36 : : using namespace ::com::sun::star;
37 : :
38 : : #define IUL 6
39 : :
40 : :
41 : 25 : uno::Sequence< ::rtl::OUString > Interceptor::m_aInterceptedURL(IUL);
42 : :
43 : : struct equalOUString
44 : : {
45 : 0 : bool operator()(
46 : : const rtl::OUString& rKey1,
47 : : const rtl::OUString& rKey2 ) const
48 : : {
49 : 0 : return !!( rKey1 == rKey2 );
50 : : }
51 : : };
52 : :
53 : :
54 : : struct hashOUString
55 : : {
56 : : size_t operator()( const rtl::OUString& rName ) const
57 : : {
58 : : return rName.hashCode();
59 : : }
60 : : };
61 : :
62 : :
63 : :
64 : 0 : class StatusChangeListenerContainer
65 : : : public ::cppu::OMultiTypeInterfaceContainerHelperVar<
66 : : rtl::OUString,hashOUString,equalOUString>
67 : : {
68 : : public:
69 : 0 : StatusChangeListenerContainer( ::osl::Mutex& aMutex )
70 : : : cppu::OMultiTypeInterfaceContainerHelperVar<
71 : 0 : rtl::OUString,hashOUString,equalOUString>(aMutex)
72 : : {
73 : 0 : }
74 : : };
75 : :
76 : :
77 : 0 : void Interceptor::DisconnectDocHolder()
78 : : {
79 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
80 [ # # ]: 0 : m_pDocHolder = NULL;
81 : 0 : }
82 : :
83 : : void SAL_CALL
84 : 0 : Interceptor::addEventListener(
85 : : const uno::Reference<lang::XEventListener >& Listener )
86 : : throw( uno::RuntimeException )
87 : : {
88 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
89 : :
90 [ # # ]: 0 : if ( ! m_pDisposeEventListeners )
91 : : m_pDisposeEventListeners =
92 [ # # ]: 0 : new cppu::OInterfaceContainerHelper( m_aMutex );
93 : :
94 [ # # ][ # # ]: 0 : m_pDisposeEventListeners->addInterface( Listener );
95 : 0 : }
96 : :
97 : :
98 : : void SAL_CALL
99 : 0 : Interceptor::removeEventListener(
100 : : const uno::Reference< lang::XEventListener >& Listener )
101 : : throw( uno::RuntimeException )
102 : : {
103 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
104 : :
105 [ # # ]: 0 : if ( m_pDisposeEventListeners )
106 [ # # ][ # # ]: 0 : m_pDisposeEventListeners->removeInterface( Listener );
107 : 0 : }
108 : :
109 : :
110 : 0 : Interceptor::Interceptor( DocumentHolder* pDocHolder )
111 : : : m_pDocHolder( pDocHolder ),
112 : : m_pDisposeEventListeners(0),
113 [ # # ]: 0 : m_pStatCL(0)
114 : : {
115 [ # # ]: 0 : m_aInterceptedURL[0] = rtl::OUString(
116 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
117 [ # # ]: 0 : m_aInterceptedURL[1] = rtl::OUString(
118 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAll"));
119 [ # # ]: 0 : m_aInterceptedURL[2] = rtl::OUString(
120 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc"));
121 [ # # ]: 0 : m_aInterceptedURL[3] = rtl::OUString(
122 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin"));
123 [ # # ]: 0 : m_aInterceptedURL[4] = rtl::OUString(
124 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame"));
125 [ # # ]: 0 : m_aInterceptedURL[5] = rtl::OUString(
126 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAs"));
127 : :
128 : 0 : }
129 : :
130 : :
131 [ # # ]: 0 : Interceptor::~Interceptor()
132 : : {
133 [ # # ]: 0 : if( m_pDisposeEventListeners )
134 [ # # ][ # # ]: 0 : delete m_pDisposeEventListeners;
135 : :
136 [ # # ]: 0 : if(m_pStatCL)
137 [ # # ][ # # ]: 0 : delete m_pStatCL;
138 [ # # ]: 0 : }
139 : :
140 : :
141 : :
142 : : //XDispatch
143 : : void SAL_CALL
144 : 0 : Interceptor::dispatch(
145 : : const util::URL& URL,
146 : : const uno::Sequence<
147 : : beans::PropertyValue >& Arguments )
148 : : throw (uno::RuntimeException)
149 : : {
150 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
151 [ # # ]: 0 : if( m_pDocHolder )
152 : : {
153 [ # # ][ # # ]: 0 : if(URL.Complete == m_aInterceptedURL[0])
154 [ # # ]: 0 : m_pDocHolder->GetEmbedObject()->SaveObject_Impl();
155 [ # # ][ # # : 0 : else if(URL.Complete == m_aInterceptedURL[2] ||
# # # # ]
[ # # ]
156 [ # # ]: 0 : URL.Complete == m_aInterceptedURL[3] ||
157 [ # # ]: 0 : URL.Complete == m_aInterceptedURL[4])
158 : : {
159 : : try {
160 [ # # ]: 0 : m_pDocHolder->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING );
161 : : }
162 [ # # ]: 0 : catch( const uno::Exception& )
163 : : {
164 : : }
165 : : }
166 [ # # ][ # # ]: 0 : else if ( URL.Complete == m_aInterceptedURL[5] )
167 : : {
168 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aNewArgs = Arguments;
169 : 0 : sal_Int32 nInd = 0;
170 : :
171 [ # # ]: 0 : while( nInd < aNewArgs.getLength() )
172 : : {
173 [ # # ][ # # ]: 0 : if ( aNewArgs[nInd].Name == "SaveTo" )
174 : : {
175 [ # # ][ # # ]: 0 : aNewArgs[nInd].Value <<= sal_True;
176 : 0 : break;
177 : : }
178 : 0 : nInd++;
179 : : }
180 : :
181 [ # # ]: 0 : if ( nInd == aNewArgs.getLength() )
182 : : {
183 [ # # ]: 0 : aNewArgs.realloc( nInd + 1 );
184 [ # # ][ # # ]: 0 : aNewArgs[nInd].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "SaveTo" ));
185 [ # # ][ # # ]: 0 : aNewArgs[nInd].Value <<= sal_True;
186 : : }
187 : :
188 [ # # ]: 0 : uno::Reference< frame::XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
189 [ # # ][ # # ]: 0 : URL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "_self" )), 0 );
190 [ # # ]: 0 : if ( xDispatch.is() )
191 [ # # ][ # # ]: 0 : xDispatch->dispatch( URL, aNewArgs );
[ # # ]
192 : : }
193 [ # # ]: 0 : }
194 [ # # ]: 0 : }
195 : :
196 : : void SAL_CALL
197 : 0 : Interceptor::addStatusListener(
198 : : const uno::Reference<
199 : : frame::XStatusListener >& Control,
200 : : const util::URL& URL )
201 : : throw (
202 : : uno::RuntimeException
203 : : )
204 : : {
205 [ # # ]: 0 : if(!Control.is())
206 : 0 : return;
207 : :
208 [ # # ]: 0 : if(URL.Complete == m_aInterceptedURL[0])
209 : : { // Save
210 [ # # ]: 0 : frame::FeatureStateEvent aStateEvent;
211 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0];
212 : : aStateEvent.FeatureDescriptor = rtl::OUString(
213 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("Update"));
214 : 0 : aStateEvent.IsEnabled = sal_True;
215 : 0 : aStateEvent.Requery = sal_False;
216 [ # # ][ # # ]: 0 : aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($1) ")) + m_pDocHolder->GetTitle() );
[ # # ]
217 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
218 : :
219 : : {
220 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
221 [ # # ]: 0 : if(!m_pStatCL)
222 : : m_pStatCL =
223 [ # # ][ # # ]: 0 : new StatusChangeListenerContainer(m_aMutex);
224 : : }
225 : :
226 [ # # ]: 0 : m_pStatCL->addInterface(URL.Complete,Control);
227 [ # # ]: 0 : return;
228 : : }
229 : :
230 : 0 : sal_Int32 i = 2;
231 [ # # # # : 0 : if(URL.Complete == m_aInterceptedURL[i] ||
# # ][ # # ]
232 : 0 : URL.Complete == m_aInterceptedURL[++i] ||
233 : 0 : URL.Complete == m_aInterceptedURL[++i] )
234 : : { // Close and return
235 [ # # ]: 0 : frame::FeatureStateEvent aStateEvent;
236 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
237 : : aStateEvent.FeatureDescriptor = rtl::OUString(
238 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("Close and Return"));
239 : 0 : aStateEvent.IsEnabled = sal_True;
240 : 0 : aStateEvent.Requery = sal_False;
241 [ # # ][ # # ]: 0 : aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($2) ")) + m_pDocHolder->GetTitle() );
[ # # ]
242 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
243 : :
244 : :
245 : : {
246 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
247 [ # # ]: 0 : if(!m_pStatCL)
248 : : m_pStatCL =
249 [ # # ][ # # ]: 0 : new StatusChangeListenerContainer(m_aMutex);
250 : : }
251 : :
252 [ # # ]: 0 : m_pStatCL->addInterface(URL.Complete,Control);
253 [ # # ]: 0 : return;
254 : : }
255 : :
256 [ # # ]: 0 : if(URL.Complete == m_aInterceptedURL[5])
257 : : { // SaveAs
258 [ # # ]: 0 : frame::FeatureStateEvent aStateEvent;
259 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5];
260 : : aStateEvent.FeatureDescriptor = rtl::OUString(
261 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo"));
262 : 0 : aStateEvent.IsEnabled = sal_True;
263 : 0 : aStateEvent.Requery = sal_False;
264 [ # # ][ # # ]: 0 : aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($3)")));
265 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
266 : :
267 : : {
268 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
269 [ # # ]: 0 : if(!m_pStatCL)
270 : : m_pStatCL =
271 [ # # ][ # # ]: 0 : new StatusChangeListenerContainer(m_aMutex);
272 : : }
273 : :
274 [ # # ]: 0 : m_pStatCL->addInterface(URL.Complete,Control);
275 [ # # ]: 0 : return;
276 : : }
277 : :
278 : : }
279 : :
280 : :
281 : : void SAL_CALL
282 : 0 : Interceptor::removeStatusListener(
283 : : const uno::Reference<
284 : : frame::XStatusListener >& Control,
285 : : const util::URL& URL )
286 : : throw (
287 : : uno::RuntimeException
288 : : )
289 : : {
290 [ # # ][ # # ]: 0 : if(!(Control.is() && m_pStatCL))
[ # # ]
291 : 0 : return;
292 : : else {
293 : 0 : m_pStatCL->removeInterface(URL.Complete,Control);
294 : 0 : return;
295 : : }
296 : : }
297 : :
298 : :
299 : : //XInterceptorInfo
300 : : uno::Sequence< ::rtl::OUString >
301 : : SAL_CALL
302 : 0 : Interceptor::getInterceptedURLs( )
303 : : throw (
304 : : uno::RuntimeException
305 : : )
306 : : {
307 : : // now implemented as update
308 : :
309 : 0 : return m_aInterceptedURL;
310 : : }
311 : :
312 : :
313 : : // XDispatchProvider
314 : :
315 : : uno::Reference< frame::XDispatch > SAL_CALL
316 : 0 : Interceptor::queryDispatch(
317 : : const util::URL& URL,
318 : : const ::rtl::OUString& TargetFrameName,
319 : : sal_Int32 SearchFlags )
320 : : throw (
321 : : uno::RuntimeException
322 : : )
323 : : {
324 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
325 [ # # ][ # # ]: 0 : if(URL.Complete == m_aInterceptedURL[0])
326 [ # # ]: 0 : return (frame::XDispatch*)this;
327 [ # # ][ # # ]: 0 : else if(URL.Complete == m_aInterceptedURL[1])
328 [ # # ]: 0 : return (frame::XDispatch*)0 ;
329 [ # # ][ # # ]: 0 : else if(URL.Complete == m_aInterceptedURL[2])
330 [ # # ]: 0 : return (frame::XDispatch*)this;
331 [ # # ][ # # ]: 0 : else if(URL.Complete == m_aInterceptedURL[3])
332 [ # # ]: 0 : return (frame::XDispatch*)this;
333 [ # # ][ # # ]: 0 : else if(URL.Complete == m_aInterceptedURL[4])
334 [ # # ]: 0 : return (frame::XDispatch*)this;
335 [ # # ][ # # ]: 0 : else if(URL.Complete == m_aInterceptedURL[5])
336 [ # # ]: 0 : return (frame::XDispatch*)this;
337 : : else {
338 [ # # ]: 0 : if(m_xSlaveDispatchProvider.is())
339 [ # # ]: 0 : return m_xSlaveDispatchProvider->queryDispatch(
340 [ # # ]: 0 : URL,TargetFrameName,SearchFlags);
341 : : else
342 [ # # ]: 0 : return uno::Reference<frame::XDispatch>(0);
343 [ # # ]: 0 : }
344 : : }
345 : :
346 : : uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
347 : 0 : Interceptor::queryDispatches(
348 : : const uno::Sequence<frame::DispatchDescriptor >& Requests )
349 : : throw (
350 : : uno::RuntimeException
351 : : )
352 : : {
353 [ # # ]: 0 : uno::Sequence< uno::Reference< frame::XDispatch > > aRet;
354 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
355 [ # # ]: 0 : if(m_xSlaveDispatchProvider.is())
356 [ # # ][ # # ]: 0 : aRet = m_xSlaveDispatchProvider->queryDispatches(Requests);
[ # # ][ # # ]
357 : : else
358 [ # # ]: 0 : aRet.realloc(Requests.getLength());
359 : :
360 [ # # ]: 0 : for(sal_Int32 i = 0; i < Requests.getLength(); ++i)
361 [ # # ][ # # ]: 0 : if(m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete)
362 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) this;
363 [ # # ][ # # ]: 0 : else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete)
364 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) 0;
365 [ # # ][ # # ]: 0 : else if(m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete)
366 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) this;
367 [ # # ][ # # ]: 0 : else if(m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete)
368 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) this;
369 [ # # ][ # # ]: 0 : else if(m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete)
370 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) this;
371 [ # # ][ # # ]: 0 : else if(m_aInterceptedURL[5] == Requests[i].FeatureURL.Complete)
372 [ # # ][ # # ]: 0 : aRet[i] = (frame::XDispatch*) this;
373 : :
374 [ # # ]: 0 : return aRet;
375 : : }
376 : :
377 : :
378 : :
379 : : //XDispatchProviderInterceptor
380 : :
381 : : uno::Reference< frame::XDispatchProvider > SAL_CALL
382 : 0 : Interceptor::getSlaveDispatchProvider( )
383 : : throw (
384 : : uno::RuntimeException
385 : : )
386 : : {
387 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
388 [ # # ]: 0 : return m_xSlaveDispatchProvider;
389 : : }
390 : :
391 : : void SAL_CALL
392 : 0 : Interceptor::setSlaveDispatchProvider(
393 : : const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider )
394 : : throw (
395 : : uno::RuntimeException
396 : : )
397 : : {
398 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
399 [ # # ][ # # ]: 0 : m_xSlaveDispatchProvider = NewDispatchProvider;
400 : 0 : }
401 : :
402 : :
403 : : uno::Reference< frame::XDispatchProvider > SAL_CALL
404 : 0 : Interceptor::getMasterDispatchProvider( )
405 : : throw (
406 : : uno::RuntimeException
407 : : )
408 : : {
409 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
410 [ # # ]: 0 : return m_xMasterDispatchProvider;
411 : : }
412 : :
413 : :
414 : : void SAL_CALL
415 : 0 : Interceptor::setMasterDispatchProvider(
416 : : const uno::Reference< frame::XDispatchProvider >& NewSupplier )
417 : : throw (
418 : : uno::RuntimeException
419 : : )
420 : : {
421 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
422 [ # # ][ # # ]: 0 : m_xMasterDispatchProvider = NewSupplier;
423 [ + - ][ + - ]: 75 : }
424 : :
425 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|