Branch data 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 "intercept.hxx"
22 : : #include "dbastrings.hrc"
23 : :
24 : : #include <com/sun/star/embed/EmbedStates.hpp>
25 : : #include <com/sun/star/document/XEventBroadcaster.hpp>
26 : : #include <com/sun/star/util/XModifiable.hpp>
27 : : #include <cppuhelper/weak.hxx>
28 : :
29 : : #include <comphelper/types.hxx>
30 : : #include <tools/debug.hxx>
31 : : #include <tools/diagnose_ex.h>
32 : :
33 : :
34 : : namespace dbaccess
35 : : {
36 : : using namespace ::com::sun::star::uno;
37 : : using namespace ::com::sun::star::util;
38 : : using namespace ::com::sun::star::ucb;
39 : : using namespace ::com::sun::star::beans;
40 : : using namespace ::com::sun::star::lang;
41 : : using namespace ::com::sun::star::sdbc;
42 : : using namespace ::com::sun::star::frame;
43 : : using namespace ::com::sun::star::io;
44 : : using namespace ::com::sun::star::embed;
45 : : using namespace ::com::sun::star::container;
46 : : using namespace ::comphelper;
47 : : using namespace ::cppu;
48 : :
49 : : #define DISPATCH_SAVEAS 0
50 : : #define DISPATCH_SAVE 1
51 : : #define DISPATCH_CLOSEDOC 2
52 : : #define DISPATCH_CLOSEWIN 3
53 : : #define DISPATCH_CLOSEFRAME 4
54 : : #define DISPATCH_RELOAD 5
55 : : // the OSL_ENSURE in CTOR has to be changed too, when adding new defines
56 : :
57 : 0 : void SAL_CALL OInterceptor::dispose()
58 : : throw( RuntimeException )
59 : : {
60 [ # # ][ # # ]: 0 : EventObject aEvt( *this );
61 : :
62 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
63 : :
64 [ # # ][ # # ]: 0 : if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
[ # # ][ # # ]
65 [ # # ]: 0 : m_pDisposeEventListeners->disposeAndClear( aEvt );
66 : :
67 [ # # ]: 0 : if ( m_pStatCL )
68 [ # # ]: 0 : m_pStatCL->disposeAndClear( aEvt );
69 : :
70 : 0 : m_xSlaveDispatchProvider.clear();
71 : 0 : m_xMasterDispatchProvider.clear();
72 : :
73 [ # # ][ # # ]: 0 : m_pContentHolder = NULL;
74 : 0 : }
75 : :
76 : :
77 : : DBG_NAME(OInterceptor)
78 : :
79 : 0 : OInterceptor::OInterceptor( ODocumentDefinition* _pContentHolder,sal_Bool _bAllowEditDoc )
80 : : :m_pContentHolder( _pContentHolder )
81 : : ,m_aInterceptedURL(7)
82 : : ,m_pDisposeEventListeners(0)
83 : : ,m_pStatCL(0)
84 [ # # ][ # # ]: 0 : ,m_bAllowEditDoc(_bAllowEditDoc)
85 : : {
86 : : DBG_CTOR(OInterceptor,NULL);
87 : :
88 : : OSL_ENSURE(DISPATCH_RELOAD < m_aInterceptedURL.getLength(),"Illegal size.");
89 : :
90 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_SAVEAS] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAs"));
91 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_SAVE] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
92 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_CLOSEDOC] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc"));
93 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_CLOSEWIN] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin"));
94 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_CLOSEFRAME] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame"));
95 [ # # ][ # # ]: 0 : m_aInterceptedURL[DISPATCH_RELOAD] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Reload"));
96 : 0 : }
97 : :
98 : :
99 [ # # ][ # # ]: 0 : OInterceptor::~OInterceptor()
100 : : {
101 [ # # ]: 0 : if( m_pDisposeEventListeners )
102 [ # # ][ # # ]: 0 : delete m_pDisposeEventListeners;
103 : :
104 [ # # ]: 0 : if(m_pStatCL)
105 [ # # ][ # # ]: 0 : delete m_pStatCL;
106 : :
107 : : DBG_DTOR(OInterceptor,NULL);
108 [ # # ]: 0 : }
109 : :
110 [ # # ][ # # ]: 0 : struct DispatchHelper
111 : : {
112 : : URL aURL;
113 : : Sequence<PropertyValue > aArguments;
114 : : };
115 : :
116 : : //XDispatch
117 : 0 : void SAL_CALL OInterceptor::dispatch( const URL& _URL,const Sequence<PropertyValue >& Arguments ) throw (RuntimeException)
118 : : {
119 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
120 [ # # ]: 0 : if ( !m_pContentHolder )
121 : : return;
122 : :
123 [ # # ][ # # ]: 0 : if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_SAVE ] )
124 : : {
125 [ # # ]: 0 : m_pContentHolder->save( sal_False );
126 : : return;
127 : : }
128 : :
129 [ # # ][ # # ]: 0 : if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_RELOAD ] )
130 : : {
131 : : ODocumentDefinition::fillReportData(
132 : 0 : m_pContentHolder->getContext(),
133 : 0 : m_pContentHolder->getComponent(),
134 : 0 : m_pContentHolder->getConnection()
135 [ # # # # ]: 0 : );
136 : : return;
137 : : }
138 : :
139 [ # # ][ # # ]: 0 : if( _URL.Complete == m_aInterceptedURL[ DISPATCH_SAVEAS ] )
140 : : {
141 [ # # ][ # # ]: 0 : if ( m_pContentHolder->isNewReport() )
142 : : {
143 [ # # ]: 0 : m_pContentHolder->saveAs();
144 : : }
145 [ # # ]: 0 : else if ( m_xSlaveDispatchProvider.is() )
146 : : {
147 [ # # ]: 0 : Sequence< PropertyValue > aNewArgs = Arguments;
148 : 0 : sal_Int32 nInd = 0;
149 : :
150 [ # # ]: 0 : while( nInd < aNewArgs.getLength() )
151 : : {
152 [ # # ][ # # ]: 0 : if ( aNewArgs[nInd].Name == "SaveTo" )
153 : : {
154 [ # # ][ # # ]: 0 : aNewArgs[nInd].Value <<= sal_True;
155 : 0 : break;
156 : : }
157 : 0 : nInd++;
158 : : }
159 : :
160 [ # # ]: 0 : if ( nInd == aNewArgs.getLength() )
161 : : {
162 [ # # ]: 0 : aNewArgs.realloc( nInd + 1 );
163 [ # # ][ # # ]: 0 : aNewArgs[nInd].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SaveTo"));
164 [ # # ][ # # ]: 0 : aNewArgs[nInd].Value <<= sal_True;
165 : : }
166 : :
167 [ # # ]: 0 : Reference< XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
168 [ # # ][ # # ]: 0 : _URL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0 );
169 [ # # ]: 0 : if ( xDispatch.is() )
170 [ # # ][ # # ]: 0 : xDispatch->dispatch( _URL, aNewArgs );
[ # # ]
171 : : }
172 : : return;
173 : : }
174 : :
175 [ # # ][ # # : 0 : if ( _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEDOC ]
# # # # ]
[ # # ]
176 [ # # ]: 0 : || _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEWIN ]
177 [ # # ]: 0 : || _URL.Complete == m_aInterceptedURL[ DISPATCH_CLOSEFRAME ]
178 : : )
179 : : {
180 [ # # ][ # # ]: 0 : DispatchHelper* pHelper = new DispatchHelper;
181 [ # # ]: 0 : pHelper->aArguments = Arguments;
182 : 0 : pHelper->aURL = _URL;
183 [ # # ][ # # ]: 0 : Application::PostUserEvent( LINK( this, OInterceptor, OnDispatch ), reinterpret_cast< void* >( pHelper ) );
184 : : return;
185 [ # # ][ # # ]: 0 : }
186 : : }
187 : :
188 : 0 : IMPL_LINK( OInterceptor, OnDispatch, void*, _pDispatcher )
189 : : {
190 : 0 : ::std::auto_ptr<DispatchHelper> pHelper( reinterpret_cast< DispatchHelper* >( _pDispatcher ) );
191 : : try
192 : : {
193 [ # # ][ # # ]: 0 : if ( m_pContentHolder && m_pContentHolder->prepareClose() && m_xSlaveDispatchProvider.is() )
[ # # ][ # # ]
[ # # ]
194 : : {
195 [ # # ]: 0 : Reference< XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
196 [ # # ][ # # ]: 0 : pHelper->aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0 );
197 [ # # ]: 0 : if ( xDispatch.is() )
198 : : {
199 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::document::XEventBroadcaster> xEvtB(m_pContentHolder->getComponent(),UNO_QUERY);
200 [ # # ]: 0 : if ( xEvtB.is() )
201 [ # # ][ # # ]: 0 : xEvtB->removeEventListener(this);
[ # # ]
202 : :
203 [ # # ]: 0 : Reference< XInterface > xKeepContentHolderAlive( *m_pContentHolder );
204 [ # # ][ # # ]: 0 : xDispatch->dispatch( pHelper->aURL,pHelper->aArguments);
205 [ # # ]: 0 : }
206 : : }
207 : : }
208 [ # # ]: 0 : catch ( const Exception& )
209 : : {
210 : : DBG_UNHANDLED_EXCEPTION();
211 : : }
212 : :
213 [ # # ]: 0 : return 0L;
214 : : }
215 : :
216 : 0 : void SAL_CALL OInterceptor::addStatusListener(
217 : : const Reference<
218 : : XStatusListener >& Control,
219 : : const URL& _URL )
220 : : throw (
221 : : RuntimeException
222 : : )
223 : : {
224 [ # # ]: 0 : if(!Control.is())
225 : 0 : return;
226 : :
227 [ # # ][ # # ]: 0 : if ( m_pContentHolder && _URL.Complete == m_aInterceptedURL[DISPATCH_SAVEAS] )
[ # # ]
228 : : { // SaveAs
229 : :
230 [ # # ]: 0 : if ( !m_pContentHolder->isNewReport() )
231 : : {
232 [ # # ]: 0 : FeatureStateEvent aStateEvent;
233 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[DISPATCH_SAVEAS];
234 [ # # ]: 0 : aStateEvent.FeatureDescriptor = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo"));
235 : 0 : aStateEvent.IsEnabled = sal_True;
236 : 0 : aStateEvent.Requery = sal_False;
237 [ # # ][ # # ]: 0 : aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($3)")));
238 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
[ # # ]
239 : : }
240 : :
241 : : {
242 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
243 [ # # ]: 0 : if(!m_pStatCL)
244 [ # # ][ # # ]: 0 : m_pStatCL = new PropertyChangeListenerContainer(m_aMutex);
245 : : }
246 : :
247 : 0 : m_pStatCL->addInterface(_URL.Complete,Control);
248 : : }
249 [ # # ][ # # ]: 0 : else if ( m_pContentHolder && _URL.Complete == m_aInterceptedURL[DISPATCH_SAVE] )
[ # # ]
250 : : { // Save
251 [ # # ]: 0 : FeatureStateEvent aStateEvent;
252 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[DISPATCH_SAVE];
253 [ # # ]: 0 : aStateEvent.FeatureDescriptor = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Update"));
254 [ # # ][ # # ]: 0 : aStateEvent.IsEnabled = m_pContentHolder != NULL && m_pContentHolder->isModified();
[ # # ]
255 : 0 : aStateEvent.Requery = sal_False;
256 : :
257 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
258 : : {
259 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
260 [ # # ]: 0 : if(!m_pStatCL)
261 [ # # ][ # # ]: 0 : m_pStatCL = new PropertyChangeListenerContainer(m_aMutex);
262 : : }
263 : :
264 [ # # ]: 0 : m_pStatCL->addInterface(_URL.Complete,Control);
265 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::document::XEventBroadcaster> xEvtB(m_pContentHolder->getComponent(),UNO_QUERY);
266 [ # # ]: 0 : if ( xEvtB.is() )
267 [ # # ][ # # ]: 0 : xEvtB->addEventListener(this);
[ # # ][ # # ]
268 : : }
269 : : else
270 : : {
271 : 0 : sal_Int32 i = 2;
272 [ # # # # : 0 : if(_URL.Complete == m_aInterceptedURL[i] ||
# # # # ]
[ # # ]
273 : 0 : _URL.Complete == m_aInterceptedURL[++i] ||
274 : 0 : _URL.Complete == m_aInterceptedURL[++i] ||
275 : 0 : _URL.Complete == m_aInterceptedURL[i = DISPATCH_RELOAD] )
276 : : { // Close and return
277 [ # # ]: 0 : FeatureStateEvent aStateEvent;
278 [ # # ]: 0 : aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
279 : : aStateEvent.FeatureDescriptor = rtl::OUString(
280 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("Close and Return"));
281 : 0 : aStateEvent.IsEnabled = sal_True;
282 : 0 : aStateEvent.Requery = sal_False;
283 [ # # ][ # # ]: 0 : Control->statusChanged(aStateEvent);
284 : :
285 : :
286 : : {
287 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
288 [ # # ]: 0 : if(!m_pStatCL)
289 [ # # ][ # # ]: 0 : m_pStatCL = new PropertyChangeListenerContainer(m_aMutex);
290 : : }
291 : :
292 [ # # ]: 0 : m_pStatCL->addInterface(_URL.Complete,Control);
293 [ # # ]: 0 : return;
294 : : }
295 : : }
296 : : }
297 : :
298 : :
299 : 0 : void SAL_CALL OInterceptor::removeStatusListener(
300 : : const Reference<
301 : : XStatusListener >& Control,
302 : : const URL& _URL )
303 : : throw (
304 : : RuntimeException
305 : : )
306 : : {
307 [ # # ][ # # ]: 0 : if(!(Control.is() && m_pStatCL))
[ # # ]
308 : 0 : return;
309 : : else
310 : : {
311 : 0 : m_pStatCL->removeInterface(_URL.Complete,Control);
312 : 0 : return;
313 : : }
314 : : }
315 : :
316 : :
317 : : //XInterceptorInfo
318 : 0 : Sequence< ::rtl::OUString > SAL_CALL OInterceptor::getInterceptedURLs( ) throw ( RuntimeException )
319 : : {
320 : : // now implemented as update
321 : 0 : return m_aInterceptedURL;
322 : : }
323 : :
324 : :
325 : : // XDispatchProvider
326 : :
327 : 0 : Reference< XDispatch > SAL_CALL OInterceptor::queryDispatch( const URL& _URL,const ::rtl::OUString& TargetFrameName,sal_Int32 SearchFlags )
328 : : throw (RuntimeException)
329 : : {
330 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
331 : 0 : const ::rtl::OUString* pIter = m_aInterceptedURL.getConstArray();
332 : 0 : const ::rtl::OUString* pEnd = pIter + m_aInterceptedURL.getLength();
333 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
334 : : {
335 [ # # ]: 0 : if ( _URL.Complete == *pIter )
336 [ # # ]: 0 : return (XDispatch*)this;
337 : : }
338 : :
339 [ # # ]: 0 : if(m_xSlaveDispatchProvider.is())
340 [ # # ][ # # ]: 0 : return m_xSlaveDispatchProvider->queryDispatch(_URL,TargetFrameName,SearchFlags);
341 : : else
342 [ # # ]: 0 : return Reference<XDispatch>();
343 : : }
344 : :
345 : 0 : Sequence< Reference< XDispatch > > SAL_CALL OInterceptor::queryDispatches( const Sequence<DispatchDescriptor >& Requests ) throw ( RuntimeException )
346 : : {
347 [ # # ]: 0 : Sequence< Reference< XDispatch > > aRet;
348 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
349 [ # # ]: 0 : if(m_xSlaveDispatchProvider.is())
350 [ # # ][ # # ]: 0 : aRet = m_xSlaveDispatchProvider->queryDispatches(Requests);
[ # # ][ # # ]
351 : : else
352 [ # # ]: 0 : aRet.realloc(Requests.getLength());
353 : :
354 [ # # ]: 0 : for(sal_Int32 i = 0; i < Requests.getLength(); ++i)
355 : : {
356 : 0 : const ::rtl::OUString* pIter = m_aInterceptedURL.getConstArray();
357 : 0 : const ::rtl::OUString* pEnd = pIter + m_aInterceptedURL.getLength();
358 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
359 : : {
360 [ # # ]: 0 : if ( Requests[i].FeatureURL.Complete == *pIter )
361 : : {
362 [ # # ][ # # ]: 0 : aRet[i] = (XDispatch*) this;
363 : 0 : break;
364 : : }
365 : : }
366 : : }
367 : :
368 [ # # ]: 0 : return aRet;
369 : : }
370 : :
371 : :
372 : :
373 : : //XDispatchProviderInterceptor
374 : :
375 : 0 : Reference< XDispatchProvider > SAL_CALL OInterceptor::getSlaveDispatchProvider( ) throw ( RuntimeException )
376 : : {
377 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
378 [ # # ]: 0 : return m_xSlaveDispatchProvider;
379 : : }
380 : :
381 : : void SAL_CALL
382 : 0 : OInterceptor::setSlaveDispatchProvider( const Reference< XDispatchProvider >& NewDispatchProvider )
383 : : throw ( RuntimeException )
384 : : {
385 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
386 [ # # ][ # # ]: 0 : m_xSlaveDispatchProvider = NewDispatchProvider;
387 : 0 : }
388 : :
389 : :
390 : 0 : Reference< XDispatchProvider > SAL_CALL OInterceptor::getMasterDispatchProvider( )
391 : : throw (
392 : : RuntimeException
393 : : )
394 : : {
395 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
396 [ # # ]: 0 : return m_xMasterDispatchProvider;
397 : : }
398 : :
399 : :
400 : 0 : void SAL_CALL OInterceptor::setMasterDispatchProvider(
401 : : const Reference< XDispatchProvider >& NewSupplier )
402 : : throw (
403 : : RuntimeException
404 : : )
405 : : {
406 [ # # ]: 0 : osl::MutexGuard aGuard(m_aMutex);
407 [ # # ][ # # ]: 0 : m_xMasterDispatchProvider = NewSupplier;
408 : 0 : }
409 : :
410 : 0 : void SAL_CALL OInterceptor::notifyEvent( const ::com::sun::star::document::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException)
411 : : {
412 [ # # ]: 0 : osl::ResettableMutexGuard _rGuard(m_aMutex);
413 [ # # ][ # # ]: 0 : if ( m_pStatCL && Event.EventName == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnModifyChanged")) )
[ # # ][ # # ]
[ # # # #
# # ]
414 : : {
415 [ # # ][ # # ]: 0 : OInterfaceContainerHelper* pListener = m_pStatCL->getContainer(m_aInterceptedURL[DISPATCH_SAVE]);
416 [ # # ]: 0 : if ( pListener )
417 : : {
418 [ # # ]: 0 : FeatureStateEvent aEvt;
419 [ # # ]: 0 : aEvt.FeatureURL.Complete = m_aInterceptedURL[DISPATCH_SAVE];
420 [ # # ]: 0 : aEvt.FeatureDescriptor = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Update"));
421 [ # # ]: 0 : Reference<XModifiable> xModel(Event.Source,UNO_QUERY);
422 [ # # ][ # # ]: 0 : aEvt.IsEnabled = xModel.is() && xModel->isModified();
[ # # ][ # # ]
423 : 0 : aEvt.Requery = sal_False;
424 : :
425 [ # # ][ # # ]: 0 : NOTIFY_LISTERNERS((*pListener),XStatusListener,statusChanged)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
426 : : }
427 [ # # ]: 0 : }
428 : 0 : }
429 : :
430 : 0 : void SAL_CALL OInterceptor::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
431 : : {
432 : 0 : }
433 : :
434 : : } // namespace dbaccess
435 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|