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>
27 using namespace ::com::sun::star::beans
;
28 using namespace ::com::sun::star::frame
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::util
;
31 using namespace ::com::sun::star::lang
;
33 HelpInterceptor_Impl::HelpInterceptor_Impl() :
35 m_pWindow ( nullptr ),
42 HelpInterceptor_Impl::~HelpInterceptor_Impl()
47 void HelpInterceptor_Impl::addURL( const OUString
& rURL
)
49 size_t nCount
= m_vHistoryUrls
.size();
50 if ( nCount
&& m_nCurPos
< ( nCount
- 1 ) )
53 m_vHistoryUrls
.begin() + m_nCurPos
+ 1,
54 m_vHistoryUrls
.end());
56 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
57 Reference
<XController
> xController
;
59 xController
= xFrame
->getController();
62 m_vHistoryUrls
.emplace_back( rURL
);
63 m_nCurPos
= m_vHistoryUrls
.size() - 1;
65 if ( m_xListener
.is() )
67 css::frame::FeatureStateEvent aEvent
;
68 aEvent
.FeatureURL
.Complete
= rURL
;
69 aEvent
.Source
= static_cast<css::frame::XDispatch
*>(this);
70 m_xListener
->statusChanged( aEvent
);
73 m_pWindow
->UpdateToolbox();
77 void HelpInterceptor_Impl::setInterception( const Reference
< XFrame
>& xFrame
)
79 m_xIntercepted
.set( xFrame
, UNO_QUERY
);
81 if ( m_xIntercepted
.is() )
82 m_xIntercepted
->registerDispatchProviderInterceptor( static_cast<XDispatchProviderInterceptor
*>(this) );
86 bool HelpInterceptor_Impl::HasHistoryPred() const
91 bool HelpInterceptor_Impl::HasHistorySucc() const
93 return m_nCurPos
< ( m_vHistoryUrls
.size() - 1 );
99 Reference
< XDispatch
> SAL_CALL
HelpInterceptor_Impl::queryDispatch(
101 const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
104 Reference
< XDispatch
> xResult
;
105 if ( m_xSlaveDispatcher
.is() )
106 xResult
= m_xSlaveDispatcher
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
108 bool bHelpURL
= aURL
.Complete
.toAsciiLowerCase().match("vnd.sun.star.help",0);
112 DBG_ASSERT( xResult
.is(), "invalid dispatch" );
113 xResult
= new HelpDispatch_Impl( *this, xResult
);
120 Sequence
< Reference
< XDispatch
> > SAL_CALL
HelpInterceptor_Impl::queryDispatches(
122 const Sequence
< DispatchDescriptor
>& aDescripts
)
125 Sequence
< Reference
< XDispatch
> > aReturn( aDescripts
.getLength() );
126 std::transform(aDescripts
.begin(), aDescripts
.end(), aReturn
.getArray(),
127 [this](const DispatchDescriptor
& rDescr
) -> Reference
<XDispatch
> {
128 return queryDispatch(rDescr
.FeatureURL
, rDescr
.FrameName
, rDescr
.SearchFlags
); });
133 // XDispatchProviderInterceptor
135 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getSlaveDispatchProvider()
138 return m_xSlaveDispatcher
;
142 void SAL_CALL
HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference
< XDispatchProvider
>& xNewSlave
)
145 m_xSlaveDispatcher
= xNewSlave
;
149 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getMasterDispatchProvider()
152 return m_xMasterDispatcher
;
156 void SAL_CALL
HelpInterceptor_Impl::setMasterDispatchProvider( const Reference
< XDispatchProvider
>& xNewMaster
)
159 m_xMasterDispatcher
= xNewMaster
;
165 Sequence
< OUString
> SAL_CALL
HelpInterceptor_Impl::getInterceptedURLs()
168 Sequence
<OUString
> aURLList
{ u
"vnd.sun.star.help://*"_ustr
};
175 void SAL_CALL
HelpInterceptor_Impl::dispatch(
176 const URL
& aURL
, const Sequence
< css::beans::PropertyValue
>& )
178 bool bBack
= aURL
.Complete
== ".uno:Backward";
179 if ( !bBack
&& aURL
.Complete
!= ".uno:Forward" )
182 if ( m_vHistoryUrls
.empty() )
185 size_t nPos
= ( bBack
&& m_nCurPos
> 0 ) ? --m_nCurPos
186 : ( !bBack
&& m_nCurPos
< m_vHistoryUrls
.size() - 1 )
188 : std::numeric_limits
<std::size_t>::max();
190 if ( nPos
< std::numeric_limits
<std::size_t>::max() )
192 m_pWindow
->loadHelpContent(m_vHistoryUrls
[nPos
], false); // false => don't add item to history again!
195 m_pWindow
->UpdateToolbox();
199 void SAL_CALL
HelpInterceptor_Impl::addStatusListener(
200 const Reference
< XStatusListener
>& xControl
, const URL
& )
202 DBG_ASSERT( !m_xListener
.is(), "listener already exists" );
203 m_xListener
= xControl
;
207 void SAL_CALL
HelpInterceptor_Impl::removeStatusListener(
208 const Reference
< XStatusListener
>&, const URL
&)
210 m_xListener
= nullptr;
213 // HelpListener_Impl -----------------------------------------------------
215 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl
* pInter
)
217 pInterceptor
= pInter
;
218 pInterceptor
->addStatusListener( this, css::util::URL() );
222 void SAL_CALL
HelpListener_Impl::statusChanged( const css::frame::FeatureStateEvent
& Event
)
224 INetURLObject
aObj( Event
.FeatureURL
.Complete
);
225 aFactory
= aObj
.GetHost();
226 aChangeLink
.Call( *this );
230 void SAL_CALL
HelpListener_Impl::disposing( const css::lang::EventObject
& )
232 pInterceptor
->removeStatusListener( this, css::util::URL() );
233 pInterceptor
= nullptr;
236 HelpStatusListener_Impl::HelpStatusListener_Impl(
237 Reference
< XDispatch
> const & aDispatch
, URL
const & rURL
)
239 aDispatch
->addStatusListener(this, rURL
);
242 HelpStatusListener_Impl::~HelpStatusListener_Impl()
245 xDispatch
->removeStatusListener(this, css::util::URL());
248 void HelpStatusListener_Impl::statusChanged(
249 const FeatureStateEvent
& rEvent
)
251 aStateEvent
= rEvent
;
254 void HelpStatusListener_Impl::disposing( const EventObject
& )
256 xDispatch
->removeStatusListener(this, css::util::URL());
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */