build fix
[LibreOffice.git] / embeddedobj / source / general / intercept.cxx
blobe40114c178744a9b852ba60f50806d32b5577832
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
30 #define IUL 6
32 uno::Sequence< OUString > Interceptor::m_aInterceptedURL(IUL);
34 class StatusChangeListenerContainer
35 : public cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
37 public:
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 ),
52 m_pStatCL(nullptr)
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()
64 delete m_pStatCL;
67 //XDispatch
68 void SAL_CALL
69 Interceptor::dispatch(
70 const util::URL& URL,
71 const uno::Sequence<
72 beans::PropertyValue >& Arguments )
73 throw (uno::RuntimeException, std::exception)
75 osl::MutexGuard aGuard(m_aMutex);
76 if( m_pDocHolder )
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])
84 try {
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;
94 sal_Int32 nInd = 0;
96 while( nInd < aNewArgs.getLength() )
98 if ( aNewArgs[nInd].Name == "SaveTo" )
100 aNewArgs[nInd].Value <<= true;
101 break;
103 nInd++;
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(
114 URL, "_self", 0 );
115 if ( xDispatch.is() )
116 xDispatch->dispatch( URL, aNewArgs );
121 void SAL_CALL
122 Interceptor::addStatusListener(
123 const uno::Reference<
124 frame::XStatusListener >& Control,
125 const util::URL& URL )
126 throw (
127 uno::RuntimeException, std::exception
130 if(!Control.is())
131 return;
133 if(URL.Complete == m_aInterceptedURL[0])
134 { // Save
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);
145 if(!m_pStatCL)
146 m_pStatCL =
147 new StatusChangeListenerContainer(m_aMutex);
150 m_pStatCL->addInterface(URL.Complete,Control);
151 return;
154 sal_Int32 i = 2;
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);
170 if(!m_pStatCL)
171 m_pStatCL =
172 new StatusChangeListenerContainer(m_aMutex);
175 m_pStatCL->addInterface(URL.Complete,Control);
176 return;
179 if(URL.Complete == m_aInterceptedURL[5])
180 { // SaveAs
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);
191 if(!m_pStatCL)
192 m_pStatCL =
193 new StatusChangeListenerContainer(m_aMutex);
196 m_pStatCL->addInterface(URL.Complete,Control);
197 return;
203 void SAL_CALL
204 Interceptor::removeStatusListener(
205 const uno::Reference<
206 frame::XStatusListener >& Control,
207 const util::URL& URL )
208 throw (
209 uno::RuntimeException, std::exception
212 if(!(Control.is() && m_pStatCL))
213 return;
214 else {
215 m_pStatCL->removeInterface(URL.Complete,Control);
216 return;
221 //XInterceptorInfo
222 uno::Sequence< OUString >
223 SAL_CALL
224 Interceptor::getInterceptedURLs( )
225 throw (
226 uno::RuntimeException, std::exception
229 // now implemented as update
231 return m_aInterceptedURL;
235 // XDispatchProvider
237 uno::Reference< frame::XDispatch > SAL_CALL
238 Interceptor::queryDispatch(
239 const util::URL& URL,
240 const OUString& TargetFrameName,
241 sal_Int32 SearchFlags )
242 throw (
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])
250 return nullptr ;
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);
259 else {
260 if(m_xSlaveDispatchProvider.is())
261 return m_xSlaveDispatchProvider->queryDispatch(
262 URL,TargetFrameName,SearchFlags);
263 else
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 )
271 throw (
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);
279 else
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)
286 aRet[i] = nullptr;
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);
296 return aRet;
300 //XDispatchProviderInterceptor
302 uno::Reference< frame::XDispatchProvider > SAL_CALL
303 Interceptor::getSlaveDispatchProvider( )
304 throw (
305 uno::RuntimeException, std::exception
308 osl::MutexGuard aGuard(m_aMutex);
309 return m_xSlaveDispatchProvider;
312 void SAL_CALL
313 Interceptor::setSlaveDispatchProvider(
314 const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider )
315 throw (
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( )
326 throw (
327 uno::RuntimeException, std::exception
330 osl::MutexGuard aGuard(m_aMutex);
331 return m_xMasterDispatchProvider;
335 void SAL_CALL
336 Interceptor::setMasterDispatchProvider(
337 const uno::Reference< frame::XDispatchProvider >& NewSupplier )
338 throw (
339 uno::RuntimeException, std::exception
342 osl::MutexGuard aGuard(m_aMutex);
343 m_xMasterDispatchProvider = NewSupplier;
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */