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>
22 #include <cppuhelper/interfacecontainer.hxx>
24 #include "intercept.hxx"
25 #include "docholder.hxx"
26 #include "commonembobj.hxx"
28 using namespace ::com::sun::star
;
32 uno::Sequence
< OUString
> Interceptor::m_aInterceptedURL(IUL
);
34 class StatusChangeListenerContainer
35 : public cppu::OMultiTypeInterfaceContainerHelperVar
<OUString
>
38 explicit StatusChangeListenerContainer(osl::Mutex
& aMutex
)
39 : cppu::OMultiTypeInterfaceContainerHelperVar
<OUString
>(aMutex
)
44 void Interceptor::DisconnectDocHolder()
46 osl::MutexGuard
aGuard( m_aMutex
);
47 m_pDocHolder
= nullptr;
50 Interceptor::Interceptor( DocumentHolder
* pDocHolder
)
51 : m_pDocHolder( pDocHolder
),
54 m_aInterceptedURL
[0] = ".uno:Save";
55 m_aInterceptedURL
[1] = ".uno:SaveAll";
56 m_aInterceptedURL
[2] = ".uno:CloseDoc";
57 m_aInterceptedURL
[3] = ".uno:CloseWin";
58 m_aInterceptedURL
[4] = ".uno:CloseFrame";
59 m_aInterceptedURL
[5] = ".uno:SaveAs";
62 Interceptor::~Interceptor()
69 Interceptor::dispatch(
72 beans::PropertyValue
>& Arguments
)
73 throw (uno::RuntimeException
, std::exception
)
75 osl::MutexGuard
aGuard(m_aMutex
);
78 if(URL
.Complete
== m_aInterceptedURL
[0])
79 m_pDocHolder
->GetEmbedObject()->SaveObject_Impl();
80 else if(URL
.Complete
== m_aInterceptedURL
[2] ||
81 URL
.Complete
== m_aInterceptedURL
[3] ||
82 URL
.Complete
== m_aInterceptedURL
[4])
85 m_pDocHolder
->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING
);
87 catch( const uno::Exception
& )
91 else if ( URL
.Complete
== m_aInterceptedURL
[5] )
93 uno::Sequence
< beans::PropertyValue
> aNewArgs
= Arguments
;
96 while( nInd
< aNewArgs
.getLength() )
98 if ( aNewArgs
[nInd
].Name
== "SaveTo" )
100 aNewArgs
[nInd
].Value
<<= true;
106 if ( nInd
== aNewArgs
.getLength() )
108 aNewArgs
.realloc( nInd
+ 1 );
109 aNewArgs
[nInd
].Name
= "SaveTo";
110 aNewArgs
[nInd
].Value
<<= true;
113 uno::Reference
< frame::XDispatch
> xDispatch
= m_xSlaveDispatchProvider
->queryDispatch(
115 if ( xDispatch
.is() )
116 xDispatch
->dispatch( URL
, aNewArgs
);
122 Interceptor::addStatusListener(
123 const uno::Reference
<
124 frame::XStatusListener
>& Control
,
125 const util::URL
& URL
)
127 uno::RuntimeException
, std::exception
133 if(URL
.Complete
== m_aInterceptedURL
[0])
135 frame::FeatureStateEvent aStateEvent
;
136 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[0];
137 aStateEvent
.FeatureDescriptor
= "Update";
138 aStateEvent
.IsEnabled
= true;
139 aStateEvent
.Requery
= false;
140 aStateEvent
.State
<<= ( "($1) " + m_pDocHolder
->GetTitle() );
141 Control
->statusChanged(aStateEvent
);
144 osl::MutexGuard
aGuard(m_aMutex
);
147 new StatusChangeListenerContainer(m_aMutex
);
150 m_pStatCL
->addInterface(URL
.Complete
,Control
);
155 if(URL
.Complete
== m_aInterceptedURL
[i
] ||
156 URL
.Complete
== m_aInterceptedURL
[++i
] ||
157 URL
.Complete
== m_aInterceptedURL
[++i
] )
158 { // Close and return
159 frame::FeatureStateEvent aStateEvent
;
160 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[i
];
161 aStateEvent
.FeatureDescriptor
= "Close and Return";
162 aStateEvent
.IsEnabled
= true;
163 aStateEvent
.Requery
= false;
164 aStateEvent
.State
<<= ( "($2)" + m_pDocHolder
->GetContainerName() );
165 Control
->statusChanged(aStateEvent
);
169 osl::MutexGuard
aGuard(m_aMutex
);
172 new StatusChangeListenerContainer(m_aMutex
);
175 m_pStatCL
->addInterface(URL
.Complete
,Control
);
179 if(URL
.Complete
== m_aInterceptedURL
[5])
181 frame::FeatureStateEvent aStateEvent
;
182 aStateEvent
.FeatureURL
.Complete
= m_aInterceptedURL
[5];
183 aStateEvent
.FeatureDescriptor
= "SaveCopyTo";
184 aStateEvent
.IsEnabled
= true;
185 aStateEvent
.Requery
= false;
186 aStateEvent
.State
<<= (OUString( "($3)"));
187 Control
->statusChanged(aStateEvent
);
190 osl::MutexGuard
aGuard(m_aMutex
);
193 new StatusChangeListenerContainer(m_aMutex
);
196 m_pStatCL
->addInterface(URL
.Complete
,Control
);
204 Interceptor::removeStatusListener(
205 const uno::Reference
<
206 frame::XStatusListener
>& Control
,
207 const util::URL
& URL
)
209 uno::RuntimeException
, std::exception
212 if(!(Control
.is() && m_pStatCL
))
215 m_pStatCL
->removeInterface(URL
.Complete
,Control
);
222 uno::Sequence
< OUString
>
224 Interceptor::getInterceptedURLs( )
226 uno::RuntimeException
, std::exception
229 // now implemented as update
231 return m_aInterceptedURL
;
237 uno::Reference
< frame::XDispatch
> SAL_CALL
238 Interceptor::queryDispatch(
239 const util::URL
& URL
,
240 const OUString
& TargetFrameName
,
241 sal_Int32 SearchFlags
)
243 uno::RuntimeException
, std::exception
246 osl::MutexGuard
aGuard(m_aMutex
);
247 if(URL
.Complete
== m_aInterceptedURL
[0])
248 return static_cast<frame::XDispatch
*>(this);
249 else if(URL
.Complete
== m_aInterceptedURL
[1])
251 else if(URL
.Complete
== m_aInterceptedURL
[2])
252 return static_cast<frame::XDispatch
*>(this);
253 else if(URL
.Complete
== m_aInterceptedURL
[3])
254 return static_cast<frame::XDispatch
*>(this);
255 else if(URL
.Complete
== m_aInterceptedURL
[4])
256 return static_cast<frame::XDispatch
*>(this);
257 else if(URL
.Complete
== m_aInterceptedURL
[5])
258 return static_cast<frame::XDispatch
*>(this);
260 if(m_xSlaveDispatchProvider
.is())
261 return m_xSlaveDispatchProvider
->queryDispatch(
262 URL
,TargetFrameName
,SearchFlags
);
264 return uno::Reference
<frame::XDispatch
>(nullptr);
268 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
269 Interceptor::queryDispatches(
270 const uno::Sequence
<frame::DispatchDescriptor
>& Requests
)
272 uno::RuntimeException
, std::exception
275 uno::Sequence
< uno::Reference
< frame::XDispatch
> > aRet
;
276 osl::MutexGuard
aGuard(m_aMutex
);
277 if(m_xSlaveDispatchProvider
.is())
278 aRet
= m_xSlaveDispatchProvider
->queryDispatches(Requests
);
280 aRet
.realloc(Requests
.getLength());
282 for(sal_Int32 i
= 0; i
< Requests
.getLength(); ++i
)
283 if(m_aInterceptedURL
[0] == Requests
[i
].FeatureURL
.Complete
)
284 aRet
[i
] = static_cast<frame::XDispatch
*>(this);
285 else if(m_aInterceptedURL
[1] == Requests
[i
].FeatureURL
.Complete
)
287 else if(m_aInterceptedURL
[2] == Requests
[i
].FeatureURL
.Complete
)
288 aRet
[i
] = static_cast<frame::XDispatch
*>(this);
289 else if(m_aInterceptedURL
[3] == Requests
[i
].FeatureURL
.Complete
)
290 aRet
[i
] = static_cast<frame::XDispatch
*>(this);
291 else if(m_aInterceptedURL
[4] == Requests
[i
].FeatureURL
.Complete
)
292 aRet
[i
] = static_cast<frame::XDispatch
*>(this);
293 else if(m_aInterceptedURL
[5] == Requests
[i
].FeatureURL
.Complete
)
294 aRet
[i
] = static_cast<frame::XDispatch
*>(this);
300 //XDispatchProviderInterceptor
302 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
303 Interceptor::getSlaveDispatchProvider( )
305 uno::RuntimeException
, std::exception
308 osl::MutexGuard
aGuard(m_aMutex
);
309 return m_xSlaveDispatchProvider
;
313 Interceptor::setSlaveDispatchProvider(
314 const uno::Reference
< frame::XDispatchProvider
>& NewDispatchProvider
)
316 uno::RuntimeException
, std::exception
319 osl::MutexGuard
aGuard(m_aMutex
);
320 m_xSlaveDispatchProvider
= NewDispatchProvider
;
324 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
325 Interceptor::getMasterDispatchProvider( )
327 uno::RuntimeException
, std::exception
330 osl::MutexGuard
aGuard(m_aMutex
);
331 return m_xMasterDispatchProvider
;
336 Interceptor::setMasterDispatchProvider(
337 const uno::Reference
< frame::XDispatchProvider
>& NewSupplier
)
339 uno::RuntimeException
, std::exception
342 osl::MutexGuard
aGuard(m_aMutex
);
343 m_xMasterDispatchProvider
= NewSupplier
;
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */