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
;
70 aEvent
.FeatureURL
= aURL
;
71 aEvent
.Source
= static_cast<css::frame::XDispatch
*>(this);
72 m_xListener
->statusChanged( aEvent
);
75 m_pWindow
->UpdateToolbox();
79 void HelpInterceptor_Impl::setInterception( const Reference
< XFrame
>& xFrame
)
81 m_xIntercepted
.set( xFrame
, UNO_QUERY
);
83 if ( m_xIntercepted
.is() )
84 m_xIntercepted
->registerDispatchProviderInterceptor( static_cast<XDispatchProviderInterceptor
*>(this) );
88 bool HelpInterceptor_Impl::HasHistoryPred() const
93 bool HelpInterceptor_Impl::HasHistorySucc() const
95 return m_nCurPos
< ( m_vHistoryUrls
.size() - 1 );
101 Reference
< XDispatch
> SAL_CALL
HelpInterceptor_Impl::queryDispatch(
103 const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
106 Reference
< XDispatch
> xResult
;
107 if ( m_xSlaveDispatcher
.is() )
108 xResult
= m_xSlaveDispatcher
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
110 bool bHelpURL
= aURL
.Complete
.toAsciiLowerCase().match("vnd.sun.star.help",0);
114 DBG_ASSERT( xResult
.is(), "invalid dispatch" );
115 xResult
= new HelpDispatch_Impl( *this, xResult
);
122 Sequence
< Reference
< XDispatch
> > SAL_CALL
HelpInterceptor_Impl::queryDispatches(
124 const Sequence
< DispatchDescriptor
>& aDescripts
)
127 Sequence
< Reference
< XDispatch
> > aReturn( aDescripts
.getLength() );
128 std::transform(aDescripts
.begin(), aDescripts
.end(), aReturn
.getArray(),
129 [this](const DispatchDescriptor
& rDescr
) -> Reference
<XDispatch
> {
130 return queryDispatch(rDescr
.FeatureURL
, rDescr
.FrameName
, rDescr
.SearchFlags
); });
135 // XDispatchProviderInterceptor
137 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getSlaveDispatchProvider()
140 return m_xSlaveDispatcher
;
144 void SAL_CALL
HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference
< XDispatchProvider
>& xNewSlave
)
147 m_xSlaveDispatcher
= xNewSlave
;
151 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getMasterDispatchProvider()
154 return m_xMasterDispatcher
;
158 void SAL_CALL
HelpInterceptor_Impl::setMasterDispatchProvider( const Reference
< XDispatchProvider
>& xNewMaster
)
161 m_xMasterDispatcher
= xNewMaster
;
167 Sequence
< OUString
> SAL_CALL
HelpInterceptor_Impl::getInterceptedURLs()
170 Sequence
<OUString
> aURLList
{ "vnd.sun.star.help://*" };
177 void SAL_CALL
HelpInterceptor_Impl::dispatch(
178 const URL
& aURL
, const Sequence
< css::beans::PropertyValue
>& )
180 bool bBack
= aURL
.Complete
== ".uno:Backward";
181 if ( !bBack
&& aURL
.Complete
!= ".uno:Forward" )
184 if ( m_vHistoryUrls
.empty() )
187 size_t nPos
= ( bBack
&& m_nCurPos
> 0 ) ? --m_nCurPos
188 : ( !bBack
&& m_nCurPos
< m_vHistoryUrls
.size() - 1 )
190 : std::numeric_limits
<std::size_t>::max();
192 if ( nPos
< std::numeric_limits
<std::size_t>::max() )
194 m_pWindow
->loadHelpContent(m_vHistoryUrls
[nPos
], false); // false => don't add item to history again!
197 m_pWindow
->UpdateToolbox();
201 void SAL_CALL
HelpInterceptor_Impl::addStatusListener(
202 const Reference
< XStatusListener
>& xControl
, const URL
& )
204 DBG_ASSERT( !m_xListener
.is(), "listener already exists" );
205 m_xListener
= xControl
;
209 void SAL_CALL
HelpInterceptor_Impl::removeStatusListener(
210 const Reference
< XStatusListener
>&, const URL
&)
212 m_xListener
= nullptr;
215 // HelpListener_Impl -----------------------------------------------------
217 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl
* pInter
)
219 pInterceptor
= pInter
;
220 pInterceptor
->addStatusListener( this, css::util::URL() );
224 void SAL_CALL
HelpListener_Impl::statusChanged( const css::frame::FeatureStateEvent
& Event
)
226 INetURLObject
aObj( Event
.FeatureURL
.Complete
);
227 aFactory
= aObj
.GetHost();
228 aChangeLink
.Call( *this );
232 void SAL_CALL
HelpListener_Impl::disposing( const css::lang::EventObject
& )
234 pInterceptor
->removeStatusListener( this, css::util::URL() );
235 pInterceptor
= nullptr;
238 HelpStatusListener_Impl::HelpStatusListener_Impl(
239 Reference
< XDispatch
> const & aDispatch
, URL
const & rURL
)
241 aDispatch
->addStatusListener(this, rURL
);
244 HelpStatusListener_Impl::~HelpStatusListener_Impl()
247 xDispatch
->removeStatusListener(this, css::util::URL());
250 void HelpStatusListener_Impl::statusChanged(
251 const FeatureStateEvent
& rEvent
)
253 aStateEvent
= rEvent
;
256 void HelpStatusListener_Impl::disposing( const EventObject
& )
258 xDispatch
->removeStatusListener(this, css::util::URL());
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */