1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: intercept.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/embed/EmbedStates.hpp>
34 #include <cppuhelper/weak.hxx>
36 #include "intercept.hxx"
37 #include "docholder.hxx"
38 #include "commonembobj.hxx"
40 using namespace ::com::sun::star
;
46 uno::Sequence
< ::rtl::OUString
> Interceptor::m_aInterceptedURL(IUL
);
51 const rtl::OUString
& rKey1
,
52 const rtl::OUString
& rKey2
) const
54 return !!( rKey1
== rKey2
);
61 size_t operator()( const rtl::OUString
& rName
) const
63 return rName
.hashCode();
69 class StatusChangeListenerContainer
70 : public ::cppu::OMultiTypeInterfaceContainerHelperVar
<
71 rtl::OUString
,hashOUString
,equalOUString
>
74 StatusChangeListenerContainer( ::osl::Mutex
& aMutex
)
75 : cppu::OMultiTypeInterfaceContainerHelperVar
<
76 rtl::OUString
,hashOUString
,equalOUString
>(aMutex
)
82 void Interceptor::DisconnectDocHolder()
84 osl::MutexGuard
aGuard( m_aMutex
);
89 Interceptor::addEventListener(
90 const uno::Reference
<lang::XEventListener
>& Listener
)
91 throw( uno::RuntimeException
)
93 osl::MutexGuard
aGuard( m_aMutex
);
95 if ( ! m_pDisposeEventListeners
)
96 m_pDisposeEventListeners
=
97 new cppu::OInterfaceContainerHelper( m_aMutex
);
99 m_pDisposeEventListeners
->addInterface( Listener
);
104 Interceptor::removeEventListener(
105 const uno::Reference
< lang::XEventListener
>& Listener
)
106 throw( uno::RuntimeException
)
108 osl::MutexGuard
aGuard( m_aMutex
);
110 if ( m_pDisposeEventListeners
)
111 m_pDisposeEventListeners
->removeInterface( Listener
);
115 Interceptor::Interceptor( DocumentHolder
* pDocHolder
)
116 : m_pDocHolder( pDocHolder
),
117 m_pDisposeEventListeners(0),
120 m_aInterceptedURL
[0] = rtl::OUString(
121 RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
122 m_aInterceptedURL
[1] = rtl::OUString(
123 RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAll"));
124 m_aInterceptedURL
[2] = rtl::OUString(
125 RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc"));
126 m_aInterceptedURL
[3] = rtl::OUString(
127 RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin"));
128 m_aInterceptedURL
[4] = rtl::OUString(
129 RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame"));
130 m_aInterceptedURL
[5] = rtl::OUString(
131 RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAs"));
136 Interceptor::~Interceptor()
138 if( m_pDisposeEventListeners
)
139 delete m_pDisposeEventListeners
;
149 Interceptor::dispatch(
150 const util::URL
& URL
,
152 beans::PropertyValue
>& Arguments
)
153 throw (uno::RuntimeException
)
155 osl::MutexGuard
aGuard(m_aMutex
);
158 if(URL
.Complete
== m_aInterceptedURL
[0])
159 m_pDocHolder
->GetEmbedObject()->SaveObject_Impl();
160 else if(URL
.Complete
== m_aInterceptedURL
[2] ||
161 URL
.Complete
== m_aInterceptedURL
[3] ||
162 URL
.Complete
== m_aInterceptedURL
[4])
165 m_pDocHolder
->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING
);
167 catch( uno::Exception
& )
171 else if ( URL
.Complete
== m_aInterceptedURL
[5] )
173 uno::Sequence
< beans::PropertyValue
> aNewArgs
= Arguments
;
176 while( nInd
< aNewArgs
.getLength() )
178 if ( aNewArgs
[nInd
].Name
.equalsAscii( "SaveTo" ) )
180 aNewArgs
[nInd
].Value
<<= sal_True
;
186 if ( nInd
== aNewArgs
.getLength() )
188 aNewArgs
.realloc( nInd
+ 1 );
189 aNewArgs
[nInd
].Name
= ::rtl::OUString::createFromAscii( "SaveTo" );
190 aNewArgs
[nInd
].Value
<<= sal_True
;
193 uno::Reference
< frame::XDispatch
> xDispatch
= m_xSlaveDispatchProvider
->queryDispatch(
194 URL
, ::rtl::OUString::createFromAscii( "_self" ), 0 );
195 if ( xDispatch
.is() )
196 xDispatch
->dispatch( URL
, aNewArgs
);
202 Interceptor::addStatusListener(
203 const uno::Reference
<
204 frame::XStatusListener
>& Control
,
205 const util::URL
& URL
)
207 uno::RuntimeException
213 if(URL
.Complete
== m_aInterceptedURL
[0])
215 frame::FeatureStateEvent aStateEvent
;
216 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[0];
217 aStateEvent
.FeatureDescriptor
= rtl::OUString(
218 RTL_CONSTASCII_USTRINGPARAM("Update"));
219 aStateEvent
.IsEnabled
= sal_True
;
220 aStateEvent
.Requery
= sal_False
;
221 aStateEvent
.State
<<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($1) ")) + m_pDocHolder
->GetTitle() );
222 Control
->statusChanged(aStateEvent
);
225 osl::MutexGuard
aGuard(m_aMutex
);
228 new StatusChangeListenerContainer(m_aMutex
);
231 m_pStatCL
->addInterface(URL
.Complete
,Control
);
236 if(URL
.Complete
== m_aInterceptedURL
[i
] ||
237 URL
.Complete
== m_aInterceptedURL
[++i
] ||
238 URL
.Complete
== m_aInterceptedURL
[++i
] )
239 { // Close and return
240 frame::FeatureStateEvent aStateEvent
;
241 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[i
];
242 aStateEvent
.FeatureDescriptor
= rtl::OUString(
243 RTL_CONSTASCII_USTRINGPARAM("Close and Return"));
244 aStateEvent
.IsEnabled
= sal_True
;
245 aStateEvent
.Requery
= sal_False
;
246 aStateEvent
.State
<<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($2) ")) + m_pDocHolder
->GetTitle() );
247 Control
->statusChanged(aStateEvent
);
251 osl::MutexGuard
aGuard(m_aMutex
);
254 new StatusChangeListenerContainer(m_aMutex
);
257 m_pStatCL
->addInterface(URL
.Complete
,Control
);
261 if(URL
.Complete
== m_aInterceptedURL
[5])
263 frame::FeatureStateEvent aStateEvent
;
264 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[5];
265 aStateEvent
.FeatureDescriptor
= rtl::OUString(
266 RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo"));
267 aStateEvent
.IsEnabled
= sal_True
;
268 aStateEvent
.Requery
= sal_False
;
269 aStateEvent
.State
<<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($3)")));
270 Control
->statusChanged(aStateEvent
);
273 osl::MutexGuard
aGuard(m_aMutex
);
276 new StatusChangeListenerContainer(m_aMutex
);
279 m_pStatCL
->addInterface(URL
.Complete
,Control
);
287 Interceptor::removeStatusListener(
288 const uno::Reference
<
289 frame::XStatusListener
>& Control
,
290 const util::URL
& URL
)
292 uno::RuntimeException
295 if(!(Control
.is() && m_pStatCL
))
298 m_pStatCL
->removeInterface(URL
.Complete
,Control
);
305 uno::Sequence
< ::rtl::OUString
>
307 Interceptor::getInterceptedURLs( )
309 uno::RuntimeException
312 // now implemented as update
314 return m_aInterceptedURL
;
320 uno::Reference
< frame::XDispatch
> SAL_CALL
321 Interceptor::queryDispatch(
322 const util::URL
& URL
,
323 const ::rtl::OUString
& TargetFrameName
,
324 sal_Int32 SearchFlags
)
326 uno::RuntimeException
329 osl::MutexGuard
aGuard(m_aMutex
);
330 if(URL
.Complete
== m_aInterceptedURL
[0])
331 return (frame::XDispatch
*)this;
332 else if(URL
.Complete
== m_aInterceptedURL
[1])
333 return (frame::XDispatch
*)0 ;
334 else if(URL
.Complete
== m_aInterceptedURL
[2])
335 return (frame::XDispatch
*)this;
336 else if(URL
.Complete
== m_aInterceptedURL
[3])
337 return (frame::XDispatch
*)this;
338 else if(URL
.Complete
== m_aInterceptedURL
[4])
339 return (frame::XDispatch
*)this;
340 else if(URL
.Complete
== m_aInterceptedURL
[5])
341 return (frame::XDispatch
*)this;
343 if(m_xSlaveDispatchProvider
.is())
344 return m_xSlaveDispatchProvider
->queryDispatch(
345 URL
,TargetFrameName
,SearchFlags
);
347 return uno::Reference
<frame::XDispatch
>(0);
351 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
352 Interceptor::queryDispatches(
353 const uno::Sequence
<frame::DispatchDescriptor
>& Requests
)
355 uno::RuntimeException
358 uno::Sequence
< uno::Reference
< frame::XDispatch
> > aRet
;
359 osl::MutexGuard
aGuard(m_aMutex
);
360 if(m_xSlaveDispatchProvider
.is())
361 aRet
= m_xSlaveDispatchProvider
->queryDispatches(Requests
);
363 aRet
.realloc(Requests
.getLength());
365 for(sal_Int32 i
= 0; i
< Requests
.getLength(); ++i
)
366 if(m_aInterceptedURL
[0] == Requests
[i
].FeatureURL
.Complete
)
367 aRet
[i
] = (frame::XDispatch
*) this;
368 else if(m_aInterceptedURL
[1] == Requests
[i
].FeatureURL
.Complete
)
369 aRet
[i
] = (frame::XDispatch
*) 0;
370 else if(m_aInterceptedURL
[2] == Requests
[i
].FeatureURL
.Complete
)
371 aRet
[i
] = (frame::XDispatch
*) this;
372 else if(m_aInterceptedURL
[3] == Requests
[i
].FeatureURL
.Complete
)
373 aRet
[i
] = (frame::XDispatch
*) this;
374 else if(m_aInterceptedURL
[4] == Requests
[i
].FeatureURL
.Complete
)
375 aRet
[i
] = (frame::XDispatch
*) this;
376 else if(m_aInterceptedURL
[5] == Requests
[i
].FeatureURL
.Complete
)
377 aRet
[i
] = (frame::XDispatch
*) this;
384 //XDispatchProviderInterceptor
386 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
387 Interceptor::getSlaveDispatchProvider( )
389 uno::RuntimeException
392 osl::MutexGuard
aGuard(m_aMutex
);
393 return m_xSlaveDispatchProvider
;
397 Interceptor::setSlaveDispatchProvider(
398 const uno::Reference
< frame::XDispatchProvider
>& NewDispatchProvider
)
400 uno::RuntimeException
403 osl::MutexGuard
aGuard(m_aMutex
);
404 m_xSlaveDispatchProvider
= NewDispatchProvider
;
408 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
409 Interceptor::getMasterDispatchProvider( )
411 uno::RuntimeException
414 osl::MutexGuard
aGuard(m_aMutex
);
415 return m_xMasterDispatchProvider
;
420 Interceptor::setMasterDispatchProvider(
421 const uno::Reference
< frame::XDispatchProvider
>& NewSupplier
)
423 uno::RuntimeException
426 osl::MutexGuard
aGuard(m_aMutex
);
427 m_xMasterDispatchProvider
= NewSupplier
;