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 .
21 #include "helpinterceptor.hxx"
22 #include "helpdispatch.hxx"
23 #include "newhelp.hxx"
24 #include <tools/urlobj.hxx>
25 #include <tools/debug.hxx>
28 using namespace ::com::sun::star::beans
;
29 using namespace ::com::sun::star::frame
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::util
;
32 using namespace ::com::sun::star::lang
;
34 HelpInterceptor_Impl::HelpInterceptor_Impl() :
36 m_pWindow ( nullptr ),
43 HelpInterceptor_Impl::~HelpInterceptor_Impl()
48 void HelpInterceptor_Impl::addURL( const OUString
& rURL
)
50 size_t nCount
= m_vHistoryUrls
.size();
51 if ( nCount
&& m_nCurPos
< ( nCount
- 1 ) )
54 m_vHistoryUrls
.begin() + m_nCurPos
+ 1,
55 m_vHistoryUrls
.end());
57 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
58 Reference
<XController
> xController
;
60 xController
= xFrame
->getController();
63 m_vHistoryUrls
.emplace_back( rURL
);
64 m_nCurPos
= m_vHistoryUrls
.size() - 1;
66 if ( m_xListener
.is() )
68 css::frame::FeatureStateEvent aEvent
;
71 aEvent
.FeatureURL
= aURL
;
72 aEvent
.Source
= static_cast<css::frame::XDispatch
*>(this);
73 m_xListener
->statusChanged( aEvent
);
76 m_pWindow
->UpdateToolbox();
80 void HelpInterceptor_Impl::setInterception( const Reference
< XFrame
>& xFrame
)
82 m_xIntercepted
.set( xFrame
, UNO_QUERY
);
84 if ( m_xIntercepted
.is() )
85 m_xIntercepted
->registerDispatchProviderInterceptor( static_cast<XDispatchProviderInterceptor
*>(this) );
89 bool HelpInterceptor_Impl::HasHistoryPred() const
94 bool HelpInterceptor_Impl::HasHistorySucc() const
96 return m_nCurPos
< ( m_vHistoryUrls
.size() - 1 );
102 Reference
< XDispatch
> SAL_CALL
HelpInterceptor_Impl::queryDispatch(
104 const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
107 Reference
< XDispatch
> xResult
;
108 if ( m_xSlaveDispatcher
.is() )
109 xResult
= m_xSlaveDispatcher
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
111 bool bHelpURL
= aURL
.Complete
.toAsciiLowerCase().match("vnd.sun.star.help",0);
115 DBG_ASSERT( xResult
.is(), "invalid dispatch" );
116 HelpDispatch_Impl
* pHelpDispatch
= new HelpDispatch_Impl( *this, xResult
);
117 xResult
.set( static_cast< ::cppu::OWeakObject
* >(pHelpDispatch
), UNO_QUERY
);
124 Sequence
< Reference
< XDispatch
> > SAL_CALL
HelpInterceptor_Impl::queryDispatches(
126 const Sequence
< DispatchDescriptor
>& aDescripts
)
129 Sequence
< Reference
< XDispatch
> > aReturn( aDescripts
.getLength() );
130 std::transform(aDescripts
.begin(), aDescripts
.end(), aReturn
.begin(),
131 [this](const DispatchDescriptor
& rDescr
) -> Reference
<XDispatch
> {
132 return queryDispatch(rDescr
.FeatureURL
, rDescr
.FrameName
, rDescr
.SearchFlags
); });
137 // XDispatchProviderInterceptor
139 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getSlaveDispatchProvider()
142 return m_xSlaveDispatcher
;
146 void SAL_CALL
HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference
< XDispatchProvider
>& xNewSlave
)
149 m_xSlaveDispatcher
= xNewSlave
;
153 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getMasterDispatchProvider()
156 return m_xMasterDispatcher
;
160 void SAL_CALL
HelpInterceptor_Impl::setMasterDispatchProvider( const Reference
< XDispatchProvider
>& xNewMaster
)
163 m_xMasterDispatcher
= xNewMaster
;
169 Sequence
< OUString
> SAL_CALL
HelpInterceptor_Impl::getInterceptedURLs()
172 Sequence
<OUString
> aURLList
{ "vnd.sun.star.help://*" };
179 void SAL_CALL
HelpInterceptor_Impl::dispatch(
180 const URL
& aURL
, const Sequence
< css::beans::PropertyValue
>& )
182 bool bBack
= aURL
.Complete
== ".uno:Backward";
183 if ( !bBack
&& aURL
.Complete
!= ".uno:Forward" )
186 if ( m_vHistoryUrls
.empty() )
189 size_t nPos
= ( bBack
&& m_nCurPos
> 0 ) ? --m_nCurPos
190 : ( !bBack
&& m_nCurPos
< m_vHistoryUrls
.size() - 1 )
192 : std::numeric_limits
<std::size_t>::max();
194 if ( nPos
< std::numeric_limits
<std::size_t>::max() )
196 m_pWindow
->loadHelpContent(m_vHistoryUrls
[nPos
], false); // false => don't add item to history again!
199 m_pWindow
->UpdateToolbox();
203 void SAL_CALL
HelpInterceptor_Impl::addStatusListener(
204 const Reference
< XStatusListener
>& xControl
, const URL
& )
206 DBG_ASSERT( !m_xListener
.is(), "listener already exists" );
207 m_xListener
= xControl
;
211 void SAL_CALL
HelpInterceptor_Impl::removeStatusListener(
212 const Reference
< XStatusListener
>&, const URL
&)
214 m_xListener
= nullptr;
217 // HelpListener_Impl -----------------------------------------------------
219 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl
* pInter
)
221 pInterceptor
= pInter
;
222 pInterceptor
->addStatusListener( this, css::util::URL() );
226 void SAL_CALL
HelpListener_Impl::statusChanged( const css::frame::FeatureStateEvent
& Event
)
228 INetURLObject
aObj( Event
.FeatureURL
.Complete
);
229 aFactory
= aObj
.GetHost();
230 aChangeLink
.Call( *this );
234 void SAL_CALL
HelpListener_Impl::disposing( const css::lang::EventObject
& )
236 pInterceptor
->removeStatusListener( this, css::util::URL() );
237 pInterceptor
= nullptr;
240 HelpStatusListener_Impl::HelpStatusListener_Impl(
241 Reference
< XDispatch
> const & aDispatch
, URL
const & rURL
)
243 aDispatch
->addStatusListener(this, rURL
);
246 HelpStatusListener_Impl::~HelpStatusListener_Impl()
249 xDispatch
->removeStatusListener(this, css::util::URL());
252 void HelpStatusListener_Impl::statusChanged(
253 const FeatureStateEvent
& rEvent
)
255 aStateEvent
= rEvent
;
258 void HelpStatusListener_Impl::disposing( const EventObject
& )
260 xDispatch
->removeStatusListener(this, css::util::URL());
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */