LibreOffice Module embeddedobj (master) 1
intercept.cxx
Go to the documentation of this file.
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#include <com/sun/star/embed/EmbedStates.hpp>
22
23#include <intercept.hxx>
24#include <docholder.hxx>
25#include <commonembobj.hxx>
26
27using namespace ::com::sun::star;
28
29constexpr OUStringLiteral IU0 = u".uno:Save";
30constexpr OUStringLiteral IU1 = u".uno:SaveAll";
31constexpr OUStringLiteral IU2 = u".uno:CloseDoc";
32constexpr OUStringLiteral IU3 = u".uno:CloseWin";
33constexpr OUStringLiteral IU4 = u".uno:CloseFrame";
34constexpr OUStringLiteral IU5 = u".uno:SaveAs";
35const uno::Sequence< OUString > Interceptor::m_aInterceptedURL{ IU0, IU1, IU2, IU3, IU4, IU5 };
36
38 : public comphelper::OMultiTypeInterfaceContainerHelperVar3<frame::XStatusListener, OUString>
39{
40public:
41 explicit StatusChangeListenerContainer(osl::Mutex& aMutex)
42 : comphelper::OMultiTypeInterfaceContainerHelperVar3<frame::XStatusListener, OUString>(aMutex)
43 {
44 }
45};
46
48{
49 osl::MutexGuard aGuard( m_aMutex );
50 m_pDocHolder = nullptr;
51}
52
54 : m_pDocHolder( pDocHolder )
55{
56}
57
59{
60}
61
62//XDispatch
63void SAL_CALL
65 const util::URL& URL,
66 const uno::Sequence<
67 beans::PropertyValue >& Arguments )
68{
69 osl::MutexGuard aGuard(m_aMutex);
70 if( !m_pDocHolder )
71 return;
72
73 if(URL.Complete == m_aInterceptedURL[0])
74 m_pDocHolder->GetEmbedObject()->SaveObject_Impl();
75 else if(URL.Complete == m_aInterceptedURL[2] ||
76 URL.Complete == m_aInterceptedURL[3] ||
77 URL.Complete == m_aInterceptedURL[4])
78 {
79 try {
80 m_pDocHolder->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING );
81 }
82 catch( const uno::Exception& )
83 {
84 }
85 }
86 else if ( URL.Complete == m_aInterceptedURL[5] )
87 {
88 uno::Sequence< beans::PropertyValue > aNewArgs = Arguments;
89 sal_Int32 nInd = 0;
90
91 while( nInd < aNewArgs.getLength() )
92 {
93 if ( aNewArgs[nInd].Name == "SaveTo" )
94 {
95 aNewArgs.getArray()[nInd].Value <<= true;
96 break;
97 }
98 nInd++;
99 }
100
101 if ( nInd == aNewArgs.getLength() )
102 {
103 aNewArgs.realloc( nInd + 1 );
104 auto pNewArgs = aNewArgs.getArray();
105 pNewArgs[nInd].Name = "SaveTo";
106 pNewArgs[nInd].Value <<= true;
107 }
108
109 uno::Reference< frame::XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
110 URL, "_self", 0 );
111 if ( xDispatch.is() )
112 xDispatch->dispatch( URL, aNewArgs );
113 }
114}
115
116void SAL_CALL
118 const uno::Reference<
119 frame::XStatusListener >& Control,
120 const util::URL& URL )
121{
122 if(!Control.is())
123 return;
124
125 if(URL.Complete == m_aInterceptedURL[0])
126 { // Save
127 frame::FeatureStateEvent aStateEvent;
128 aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0];
129 aStateEvent.FeatureDescriptor = "Update";
130 aStateEvent.IsEnabled = true;
131 aStateEvent.Requery = false;
132 aStateEvent.State <<= "($1) " + m_pDocHolder->GetTitle();
133 Control->statusChanged(aStateEvent);
134
135 {
136 osl::MutexGuard aGuard(m_aMutex);
137 if(!m_pStatCL)
139 }
140
142 return;
143 }
144
145 sal_Int32 i = 2;
146 if(URL.Complete == m_aInterceptedURL[i] ||
147 URL.Complete == m_aInterceptedURL[++i] ||
148 URL.Complete == m_aInterceptedURL[++i] )
149 { // Close and return
150 frame::FeatureStateEvent aStateEvent;
151 aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
152 aStateEvent.FeatureDescriptor = "Close and Return";
153 aStateEvent.IsEnabled = true;
154 aStateEvent.Requery = false;
155 aStateEvent.State <<= "($2)" + m_pDocHolder->GetContainerName();
156 Control->statusChanged(aStateEvent);
157
158
159 {
160 osl::MutexGuard aGuard(m_aMutex);
161 if(!m_pStatCL)
163 }
164
166 return;
167 }
168
169 if(URL.Complete != m_aInterceptedURL[5])
170 return;
171
172// SaveAs
173 frame::FeatureStateEvent aStateEvent;
174 aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5];
175 aStateEvent.FeatureDescriptor = "SaveCopyTo";
176 aStateEvent.IsEnabled = true;
177 aStateEvent.Requery = false;
178 aStateEvent.State <<= OUString("($3)");
179 Control->statusChanged(aStateEvent);
180
181 {
182 osl::MutexGuard aGuard(m_aMutex);
183 if(!m_pStatCL)
185 }
186
188 return;
189
190}
191
192
193void SAL_CALL
195 const uno::Reference<
196 frame::XStatusListener >& Control,
197 const util::URL& URL )
198{
199 if(!(Control.is() && m_pStatCL))
200 return;
201 else {
203 return;
204 }
205}
206
207
208//XInterceptorInfo
209uno::Sequence< OUString >
210SAL_CALL
212{
213 // now implemented as update
214
215 return m_aInterceptedURL;
216}
217
218
219// XDispatchProvider
220
221uno::Reference< frame::XDispatch > SAL_CALL
223 const util::URL& URL,
224 const OUString& TargetFrameName,
225 sal_Int32 SearchFlags )
226{
227 osl::MutexGuard aGuard(m_aMutex);
228 if(URL.Complete == m_aInterceptedURL[0])
229 return static_cast<frame::XDispatch*>(this);
230 else if(URL.Complete == m_aInterceptedURL[1])
231 return nullptr ;
232 else if(URL.Complete == m_aInterceptedURL[2])
233 return static_cast<frame::XDispatch*>(this);
234 else if(URL.Complete == m_aInterceptedURL[3])
235 return static_cast<frame::XDispatch*>(this);
236 else if(URL.Complete == m_aInterceptedURL[4])
237 return static_cast<frame::XDispatch*>(this);
238 else if(URL.Complete == m_aInterceptedURL[5])
239 return static_cast<frame::XDispatch*>(this);
240 else {
242 return m_xSlaveDispatchProvider->queryDispatch(
243 URL,TargetFrameName,SearchFlags);
244 else
245 return uno::Reference<frame::XDispatch>(nullptr);
246 }
247}
248
249uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
251 const uno::Sequence<frame::DispatchDescriptor >& Requests )
252{
253 osl::MutexGuard aGuard(m_aMutex);
254 typedef uno::Sequence<uno::Reference<frame::XDispatch>> DispatchSeq;
255 DispatchSeq aRet = m_xSlaveDispatchProvider.is()
256 ? m_xSlaveDispatchProvider->queryDispatches(Requests)
257 : DispatchSeq(Requests.getLength());
258
259 auto aRetRange = asNonConstRange(aRet);
260 for(sal_Int32 i = 0; i < Requests.getLength(); ++i)
261 if(m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete)
262 aRetRange[i] = static_cast<frame::XDispatch*>(this);
263 else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete)
264 aRetRange[i] = nullptr;
265 else if(m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete)
266 aRetRange[i] = static_cast<frame::XDispatch*>(this);
267 else if(m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete)
268 aRetRange[i] = static_cast<frame::XDispatch*>(this);
269 else if(m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete)
270 aRetRange[i] = static_cast<frame::XDispatch*>(this);
271 else if(m_aInterceptedURL[5] == Requests[i].FeatureURL.Complete)
272 aRetRange[i] = static_cast<frame::XDispatch*>(this);
273
274 return aRet;
275}
276
277
278//XDispatchProviderInterceptor
279
280uno::Reference< frame::XDispatchProvider > SAL_CALL
282{
283 osl::MutexGuard aGuard(m_aMutex);
285}
286
287void SAL_CALL
289 const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider )
290{
291 osl::MutexGuard aGuard(m_aMutex);
292 m_xSlaveDispatchProvider = NewDispatchProvider;
293}
294
295
296uno::Reference< frame::XDispatchProvider > SAL_CALL
298{
299 osl::MutexGuard aGuard(m_aMutex);
301}
302
303
304void SAL_CALL
306 const uno::Reference< frame::XDispatchProvider >& NewSupplier )
307{
308 osl::MutexGuard aGuard(m_aMutex);
309 m_xMasterDispatchProvider = NewSupplier;
310}
311
312/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &URL, const OUString &TargetFrameName, sal_Int32 SearchFlags) override
virtual css::uno::Sequence< OUString > SAL_CALL getInterceptedURLs() override
Definition: intercept.cxx:211
void DisconnectDocHolder()
Definition: intercept.cxx:47
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
Definition: intercept.cxx:281
osl::Mutex m_aMutex
Definition: intercept.hxx:105
static const css::uno::Sequence< OUString > m_aInterceptedURL
Definition: intercept.hxx:112
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &Control, const css::util::URL &URL) override
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &NewDispatchProvider) override
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatchProvider
Definition: intercept.hxx:109
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &Requests) override
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &Control, const css::util::URL &URL) override
~Interceptor() override
Definition: intercept.cxx:58
StatusChangeListenerContainer * m_pStatCL
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
Definition: intercept.cxx:297
Interceptor(const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > &xOleAccess, DocumentHolder *pDocH, bool bLink)
virtual void SAL_CALL dispatch(const css::util::URL &URL, const css::uno::Sequence< css::beans::PropertyValue > &Arguments) override
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatchProvider
Definition: intercept.hxx:110
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &NewSupplier) override
virtual void SAL_CALL changeState(sal_Int32 nNewState) override
Definition: embedobj.cxx:476
StatusChangeListenerContainer(osl::Mutex &aMutex)
Definition: intercept.cxx:41
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
Reference< XDispatch > xDispatch
float u
constexpr OUStringLiteral IU0
Definition: intercept.cxx:29
constexpr OUStringLiteral IU1
Definition: intercept.cxx:30
constexpr OUStringLiteral IU2
Definition: intercept.cxx:31
constexpr OUStringLiteral IU4
Definition: intercept.cxx:33
constexpr OUStringLiteral IU5
Definition: intercept.cxx:34
constexpr OUStringLiteral IU3
Definition: intercept.cxx:32
int i
std::mutex aMutex