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 <comphelper/multiinterfacecontainer3.hxx>
23 #include <intercept.hxx>
24 #include <docholder.hxx>
25 #include <commonembobj.hxx>
27 using namespace ::com::sun::star
;
29 constexpr OUStringLiteral IU0
= u
".uno:Save";
30 constexpr OUStringLiteral IU1
= u
".uno:SaveAll";
31 constexpr OUStringLiteral IU2
= u
".uno:CloseDoc";
32 constexpr OUStringLiteral IU3
= u
".uno:CloseWin";
33 constexpr OUStringLiteral IU4
= u
".uno:CloseFrame";
34 constexpr OUStringLiteral IU5
= u
".uno:SaveAs";
35 const uno::Sequence
< OUString
> Interceptor::m_aInterceptedURL
{ IU0
, IU1
, IU2
, IU3
, IU4
, IU5
};
37 class StatusChangeListenerContainer
38 : public comphelper::OMultiTypeInterfaceContainerHelperVar3
<frame::XStatusListener
, OUString
>
41 explicit StatusChangeListenerContainer(osl::Mutex
& aMutex
)
42 : comphelper::OMultiTypeInterfaceContainerHelperVar3
<frame::XStatusListener
, OUString
>(aMutex
)
47 void Interceptor::DisconnectDocHolder()
49 osl::MutexGuard
aGuard( m_aMutex
);
50 m_pDocHolder
= nullptr;
53 Interceptor::Interceptor( DocumentHolder
* pDocHolder
)
54 : m_pDocHolder( pDocHolder
)
58 Interceptor::~Interceptor()
64 Interceptor::dispatch(
67 beans::PropertyValue
>& Arguments
)
69 osl::MutexGuard
aGuard(m_aMutex
);
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])
80 m_pDocHolder
->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING
);
82 catch( const uno::Exception
& )
86 else if ( URL
.Complete
== m_aInterceptedURL
[5] )
88 uno::Sequence
< beans::PropertyValue
> aNewArgs
= Arguments
;
91 while( nInd
< aNewArgs
.getLength() )
93 if ( aNewArgs
[nInd
].Name
== "SaveTo" )
95 aNewArgs
.getArray()[nInd
].Value
<<= true;
101 if ( nInd
== aNewArgs
.getLength() )
103 aNewArgs
.realloc( nInd
+ 1 );
104 auto pNewArgs
= aNewArgs
.getArray();
105 pNewArgs
[nInd
].Name
= "SaveTo";
106 pNewArgs
[nInd
].Value
<<= true;
109 uno::Reference
< frame::XDispatch
> xDispatch
= m_xSlaveDispatchProvider
->queryDispatch(
111 if ( xDispatch
.is() )
112 xDispatch
->dispatch( URL
, aNewArgs
);
117 Interceptor::addStatusListener(
118 const uno::Reference
<
119 frame::XStatusListener
>& Control
,
120 const util::URL
& URL
)
125 if(URL
.Complete
== m_aInterceptedURL
[0])
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
);
136 osl::MutexGuard
aGuard(m_aMutex
);
138 m_pStatCL
.reset(new StatusChangeListenerContainer(m_aMutex
));
141 m_pStatCL
->addInterface(URL
.Complete
,Control
);
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
);
160 osl::MutexGuard
aGuard(m_aMutex
);
162 m_pStatCL
.reset(new StatusChangeListenerContainer(m_aMutex
));
165 m_pStatCL
->addInterface(URL
.Complete
,Control
);
169 if(URL
.Complete
!= m_aInterceptedURL
[5])
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
);
182 osl::MutexGuard
aGuard(m_aMutex
);
184 m_pStatCL
.reset(new StatusChangeListenerContainer(m_aMutex
));
187 m_pStatCL
->addInterface(URL
.Complete
,Control
);
194 Interceptor::removeStatusListener(
195 const uno::Reference
<
196 frame::XStatusListener
>& Control
,
197 const util::URL
& URL
)
199 if(!(Control
.is() && m_pStatCL
))
202 m_pStatCL
->removeInterface(URL
.Complete
,Control
);
209 uno::Sequence
< OUString
>
211 Interceptor::getInterceptedURLs( )
213 // now implemented as update
215 return m_aInterceptedURL
;
221 uno::Reference
< frame::XDispatch
> SAL_CALL
222 Interceptor::queryDispatch(
223 const util::URL
& URL
,
224 const OUString
& TargetFrameName
,
225 sal_Int32 SearchFlags
)
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])
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);
241 if(m_xSlaveDispatchProvider
.is())
242 return m_xSlaveDispatchProvider
->queryDispatch(
243 URL
,TargetFrameName
,SearchFlags
);
245 return uno::Reference
<frame::XDispatch
>(nullptr);
249 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
250 Interceptor::queryDispatches(
251 const uno::Sequence
<frame::DispatchDescriptor
>& Requests
)
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());
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);
278 //XDispatchProviderInterceptor
280 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
281 Interceptor::getSlaveDispatchProvider( )
283 osl::MutexGuard
aGuard(m_aMutex
);
284 return m_xSlaveDispatchProvider
;
288 Interceptor::setSlaveDispatchProvider(
289 const uno::Reference
< frame::XDispatchProvider
>& NewDispatchProvider
)
291 osl::MutexGuard
aGuard(m_aMutex
);
292 m_xSlaveDispatchProvider
= NewDispatchProvider
;
296 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
297 Interceptor::getMasterDispatchProvider( )
299 osl::MutexGuard
aGuard(m_aMutex
);
300 return m_xMasterDispatchProvider
;
305 Interceptor::setMasterDispatchProvider(
306 const uno::Reference
< frame::XDispatchProvider
>& NewSupplier
)
308 osl::MutexGuard
aGuard(m_aMutex
);
309 m_xMasterDispatchProvider
= NewSupplier
;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */