1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/embed/EmbedStates.hpp>
21 #include <cppuhelper/weak.hxx>
23 #include "intercept.hxx"
24 #include "docholder.hxx"
25 #include "commonembobj.hxx"
27 using namespace ::com::sun::star
;
32 uno::Sequence
< OUString
> Interceptor::m_aInterceptedURL(IUL
);
37 const OUString
& rKey1
,
38 const OUString
& rKey2
) const
40 return !!( rKey1
== rKey2
);
47 size_t operator()( const OUString
& rName
) const
49 return rName
.hashCode();
55 class StatusChangeListenerContainer
56 : public ::cppu::OMultiTypeInterfaceContainerHelperVar
<
57 OUString
,hashOUString
,equalOUString
>
60 StatusChangeListenerContainer( ::osl::Mutex
& aMutex
)
61 : cppu::OMultiTypeInterfaceContainerHelperVar
<
62 OUString
,hashOUString
,equalOUString
>(aMutex
)
68 void Interceptor::DisconnectDocHolder()
70 osl::MutexGuard
aGuard( m_aMutex
);
75 Interceptor::addEventListener(
76 const uno::Reference
<lang::XEventListener
>& Listener
)
77 throw( uno::RuntimeException
)
79 osl::MutexGuard
aGuard( m_aMutex
);
81 if ( ! m_pDisposeEventListeners
)
82 m_pDisposeEventListeners
=
83 new cppu::OInterfaceContainerHelper( m_aMutex
);
85 m_pDisposeEventListeners
->addInterface( Listener
);
90 Interceptor::removeEventListener(
91 const uno::Reference
< lang::XEventListener
>& Listener
)
92 throw( uno::RuntimeException
)
94 osl::MutexGuard
aGuard( m_aMutex
);
96 if ( m_pDisposeEventListeners
)
97 m_pDisposeEventListeners
->removeInterface( Listener
);
101 Interceptor::Interceptor( DocumentHolder
* pDocHolder
)
102 : m_pDocHolder( pDocHolder
),
103 m_pDisposeEventListeners(0),
106 m_aInterceptedURL
[0] = ".uno:Save";
107 m_aInterceptedURL
[1] = ".uno:SaveAll";
108 m_aInterceptedURL
[2] = ".uno:CloseDoc";
109 m_aInterceptedURL
[3] = ".uno:CloseWin";
110 m_aInterceptedURL
[4] = ".uno:CloseFrame";
111 m_aInterceptedURL
[5] = ".uno:SaveAs";
116 Interceptor::~Interceptor()
118 if( m_pDisposeEventListeners
)
119 delete m_pDisposeEventListeners
;
129 Interceptor::dispatch(
130 const util::URL
& URL
,
132 beans::PropertyValue
>& Arguments
)
133 throw (uno::RuntimeException
)
135 osl::MutexGuard
aGuard(m_aMutex
);
138 if(URL
.Complete
== m_aInterceptedURL
[0])
139 m_pDocHolder
->GetEmbedObject()->SaveObject_Impl();
140 else if(URL
.Complete
== m_aInterceptedURL
[2] ||
141 URL
.Complete
== m_aInterceptedURL
[3] ||
142 URL
.Complete
== m_aInterceptedURL
[4])
145 m_pDocHolder
->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING
);
147 catch( const uno::Exception
& )
151 else if ( URL
.Complete
== m_aInterceptedURL
[5] )
153 uno::Sequence
< beans::PropertyValue
> aNewArgs
= Arguments
;
156 while( nInd
< aNewArgs
.getLength() )
158 if ( aNewArgs
[nInd
].Name
== "SaveTo" )
160 aNewArgs
[nInd
].Value
<<= sal_True
;
166 if ( nInd
== aNewArgs
.getLength() )
168 aNewArgs
.realloc( nInd
+ 1 );
169 aNewArgs
[nInd
].Name
= "SaveTo";
170 aNewArgs
[nInd
].Value
<<= sal_True
;
173 uno::Reference
< frame::XDispatch
> xDispatch
= m_xSlaveDispatchProvider
->queryDispatch(
174 URL
, OUString( "_self" ), 0 );
175 if ( xDispatch
.is() )
176 xDispatch
->dispatch( URL
, aNewArgs
);
182 Interceptor::addStatusListener(
183 const uno::Reference
<
184 frame::XStatusListener
>& Control
,
185 const util::URL
& URL
)
187 uno::RuntimeException
193 if(URL
.Complete
== m_aInterceptedURL
[0])
195 frame::FeatureStateEvent aStateEvent
;
196 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[0];
197 aStateEvent
.FeatureDescriptor
= "Update";
198 aStateEvent
.IsEnabled
= sal_True
;
199 aStateEvent
.Requery
= sal_False
;
200 aStateEvent
.State
<<= (OUString( "($1) ") + m_pDocHolder
->GetTitle() );
201 Control
->statusChanged(aStateEvent
);
204 osl::MutexGuard
aGuard(m_aMutex
);
207 new StatusChangeListenerContainer(m_aMutex
);
210 m_pStatCL
->addInterface(URL
.Complete
,Control
);
215 if(URL
.Complete
== m_aInterceptedURL
[i
] ||
216 URL
.Complete
== m_aInterceptedURL
[++i
] ||
217 URL
.Complete
== m_aInterceptedURL
[++i
] )
218 { // Close and return
219 frame::FeatureStateEvent aStateEvent
;
220 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[i
];
221 aStateEvent
.FeatureDescriptor
= "Close and Return";
222 aStateEvent
.IsEnabled
= sal_True
;
223 aStateEvent
.Requery
= sal_False
;
224 aStateEvent
.State
<<= (OUString( "($2) ") + m_pDocHolder
->GetTitle() );
225 Control
->statusChanged(aStateEvent
);
229 osl::MutexGuard
aGuard(m_aMutex
);
232 new StatusChangeListenerContainer(m_aMutex
);
235 m_pStatCL
->addInterface(URL
.Complete
,Control
);
239 if(URL
.Complete
== m_aInterceptedURL
[5])
241 frame::FeatureStateEvent aStateEvent
;
242 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[5];
243 aStateEvent
.FeatureDescriptor
= "SaveCopyTo";
244 aStateEvent
.IsEnabled
= sal_True
;
245 aStateEvent
.Requery
= sal_False
;
246 aStateEvent
.State
<<= (OUString( "($3)"));
247 Control
->statusChanged(aStateEvent
);
250 osl::MutexGuard
aGuard(m_aMutex
);
253 new StatusChangeListenerContainer(m_aMutex
);
256 m_pStatCL
->addInterface(URL
.Complete
,Control
);
264 Interceptor::removeStatusListener(
265 const uno::Reference
<
266 frame::XStatusListener
>& Control
,
267 const util::URL
& URL
)
269 uno::RuntimeException
272 if(!(Control
.is() && m_pStatCL
))
275 m_pStatCL
->removeInterface(URL
.Complete
,Control
);
282 uno::Sequence
< OUString
>
284 Interceptor::getInterceptedURLs( )
286 uno::RuntimeException
289 // now implemented as update
291 return m_aInterceptedURL
;
297 uno::Reference
< frame::XDispatch
> SAL_CALL
298 Interceptor::queryDispatch(
299 const util::URL
& URL
,
300 const OUString
& TargetFrameName
,
301 sal_Int32 SearchFlags
)
303 uno::RuntimeException
306 osl::MutexGuard
aGuard(m_aMutex
);
307 if(URL
.Complete
== m_aInterceptedURL
[0])
308 return (frame::XDispatch
*)this;
309 else if(URL
.Complete
== m_aInterceptedURL
[1])
310 return (frame::XDispatch
*)0 ;
311 else if(URL
.Complete
== m_aInterceptedURL
[2])
312 return (frame::XDispatch
*)this;
313 else if(URL
.Complete
== m_aInterceptedURL
[3])
314 return (frame::XDispatch
*)this;
315 else if(URL
.Complete
== m_aInterceptedURL
[4])
316 return (frame::XDispatch
*)this;
317 else if(URL
.Complete
== m_aInterceptedURL
[5])
318 return (frame::XDispatch
*)this;
320 if(m_xSlaveDispatchProvider
.is())
321 return m_xSlaveDispatchProvider
->queryDispatch(
322 URL
,TargetFrameName
,SearchFlags
);
324 return uno::Reference
<frame::XDispatch
>(0);
328 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
329 Interceptor::queryDispatches(
330 const uno::Sequence
<frame::DispatchDescriptor
>& Requests
)
332 uno::RuntimeException
335 uno::Sequence
< uno::Reference
< frame::XDispatch
> > aRet
;
336 osl::MutexGuard
aGuard(m_aMutex
);
337 if(m_xSlaveDispatchProvider
.is())
338 aRet
= m_xSlaveDispatchProvider
->queryDispatches(Requests
);
340 aRet
.realloc(Requests
.getLength());
342 for(sal_Int32 i
= 0; i
< Requests
.getLength(); ++i
)
343 if(m_aInterceptedURL
[0] == Requests
[i
].FeatureURL
.Complete
)
344 aRet
[i
] = (frame::XDispatch
*) this;
345 else if(m_aInterceptedURL
[1] == Requests
[i
].FeatureURL
.Complete
)
346 aRet
[i
] = (frame::XDispatch
*) 0;
347 else if(m_aInterceptedURL
[2] == Requests
[i
].FeatureURL
.Complete
)
348 aRet
[i
] = (frame::XDispatch
*) this;
349 else if(m_aInterceptedURL
[3] == Requests
[i
].FeatureURL
.Complete
)
350 aRet
[i
] = (frame::XDispatch
*) this;
351 else if(m_aInterceptedURL
[4] == Requests
[i
].FeatureURL
.Complete
)
352 aRet
[i
] = (frame::XDispatch
*) this;
353 else if(m_aInterceptedURL
[5] == Requests
[i
].FeatureURL
.Complete
)
354 aRet
[i
] = (frame::XDispatch
*) this;
361 //XDispatchProviderInterceptor
363 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
364 Interceptor::getSlaveDispatchProvider( )
366 uno::RuntimeException
369 osl::MutexGuard
aGuard(m_aMutex
);
370 return m_xSlaveDispatchProvider
;
374 Interceptor::setSlaveDispatchProvider(
375 const uno::Reference
< frame::XDispatchProvider
>& NewDispatchProvider
)
377 uno::RuntimeException
380 osl::MutexGuard
aGuard(m_aMutex
);
381 m_xSlaveDispatchProvider
= NewDispatchProvider
;
385 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
386 Interceptor::getMasterDispatchProvider( )
388 uno::RuntimeException
391 osl::MutexGuard
aGuard(m_aMutex
);
392 return m_xMasterDispatchProvider
;
397 Interceptor::setMasterDispatchProvider(
398 const uno::Reference
< frame::XDispatchProvider
>& NewSupplier
)
400 uno::RuntimeException
403 osl::MutexGuard
aGuard(m_aMutex
);
404 m_xMasterDispatchProvider
= NewSupplier
;
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */