LibreOffice Module sfx2 (master) 1
helpinterceptor.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
21#include "helpinterceptor.hxx"
22#include "helpdispatch.hxx"
23#include "newhelp.hxx"
24#include <tools/urlobj.hxx>
25#include <tools/debug.hxx>
26
27using namespace ::com::sun::star::beans;
28using namespace ::com::sun::star::frame;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::util;
31using namespace ::com::sun::star::lang;
32
34
35 m_pWindow ( nullptr ),
36 m_nCurPos ( 0 )
37
38{
39}
40
41
43{
44}
45
46
47void HelpInterceptor_Impl::addURL( const OUString& rURL )
48{
49 size_t nCount = m_vHistoryUrls.size();
50 if ( nCount && m_nCurPos < ( nCount - 1 ) )
51 {
52 m_vHistoryUrls.erase(
53 m_vHistoryUrls.begin() + m_nCurPos + 1,
54 m_vHistoryUrls.end());
55 }
56 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
57 Reference<XController> xController;
58 if(xFrame.is())
59 xController = xFrame->getController();
60
61 m_aCurrentURL = rURL;
62 m_vHistoryUrls.emplace_back( rURL );
63 m_nCurPos = m_vHistoryUrls.size() - 1;
64// TODO ?
65 if ( m_xListener.is() )
66 {
67 css::frame::FeatureStateEvent aEvent;
68 URL aURL;
69 aURL.Complete = rURL;
70 aEvent.FeatureURL = aURL;
71 aEvent.Source = static_cast<css::frame::XDispatch*>(this);
72 m_xListener->statusChanged( aEvent );
73 }
74
75 m_pWindow->UpdateToolbox();
76}
77
78
79void HelpInterceptor_Impl::setInterception( const Reference< XFrame >& xFrame )
80{
81 m_xIntercepted.set( xFrame, UNO_QUERY );
82
83 if ( m_xIntercepted.is() )
84 m_xIntercepted->registerDispatchProviderInterceptor( static_cast<XDispatchProviderInterceptor*>(this) );
85}
86
87
89{
90 return m_nCurPos > 0;
91}
92
94{
95 return m_nCurPos < ( m_vHistoryUrls.size() - 1 );
96}
97
98
99// XDispatchProvider
100
101Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
102
103 const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
104
105{
106 Reference< XDispatch > xResult;
107 if ( m_xSlaveDispatcher.is() )
108 xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags );
109
110 bool bHelpURL = aURL.Complete.toAsciiLowerCase().match("vnd.sun.star.help",0);
111
112 if ( bHelpURL )
113 {
114 DBG_ASSERT( xResult.is(), "invalid dispatch" );
115 xResult = new HelpDispatch_Impl( *this, xResult );
116 }
117
118 return xResult;
119}
120
121
122Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches(
123
124 const Sequence< DispatchDescriptor >& aDescripts )
125
126{
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); });
131 return aReturn;
132}
133
134
135// XDispatchProviderInterceptor
136
137Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider()
138
139{
140 return m_xSlaveDispatcher;
141}
142
143
144void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave )
145
146{
147 m_xSlaveDispatcher = xNewSlave;
148}
149
150
151Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider()
152
153{
154 return m_xMasterDispatcher;
155}
156
157
158void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster )
159
160{
161 m_xMasterDispatcher = xNewMaster;
162}
163
164
165// XInterceptorInfo
166
167Sequence< OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs()
168
169{
170 Sequence<OUString> aURLList { "vnd.sun.star.help://*" };
171 return aURLList;
172}
173
174
175// XDispatch
176
178 const URL& aURL, const Sequence< css::beans::PropertyValue >& )
179{
180 bool bBack = aURL.Complete == ".uno:Backward";
181 if ( !bBack && aURL.Complete != ".uno:Forward" )
182 return;
183
184 if ( m_vHistoryUrls.empty() )
185 return;
186
187 size_t nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos
188 : ( !bBack && m_nCurPos < m_vHistoryUrls.size() - 1 )
189 ? ++m_nCurPos
190 : std::numeric_limits<std::size_t>::max();
191
192 if ( nPos < std::numeric_limits<std::size_t>::max() )
193 {
194 m_pWindow->loadHelpContent(m_vHistoryUrls[nPos], false); // false => don't add item to history again!
195 }
196
197 m_pWindow->UpdateToolbox();
198}
199
200
202 const Reference< XStatusListener >& xControl, const URL& )
203{
204 DBG_ASSERT( !m_xListener.is(), "listener already exists" );
205 m_xListener = xControl;
206}
207
208
210 const Reference< XStatusListener >&, const URL&)
211{
212 m_xListener = nullptr;
213}
214
215// HelpListener_Impl -----------------------------------------------------
216
218{
219 pInterceptor = pInter;
220 pInterceptor->addStatusListener( this, css::util::URL() );
221}
222
223
224void SAL_CALL HelpListener_Impl::statusChanged( const css::frame::FeatureStateEvent& Event )
225{
226 INetURLObject aObj( Event.FeatureURL.Complete );
227 aFactory = aObj.GetHost();
228 aChangeLink.Call( *this );
229}
230
231
232void SAL_CALL HelpListener_Impl::disposing( const css::lang::EventObject& )
233{
234 pInterceptor->removeStatusListener( this, css::util::URL() );
235 pInterceptor = nullptr;
236}
237
239 Reference < XDispatch > const & aDispatch, URL const & rURL)
240{
241 aDispatch->addStatusListener(this, rURL);
242}
243
245{
246 if(xDispatch.is())
247 xDispatch->removeStatusListener(this, css::util::URL());
248}
249
251 const FeatureStateEvent& rEvent )
252{
253 aStateEvent = rEvent;
254}
255
256void HelpStatusListener_Impl::disposing( const EventObject& )
257{
258 xDispatch->removeStatusListener(this, css::util::URL());
259 xDispatch = nullptr;
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher
void setInterception(const css::uno::Reference< css::frame::XFrame > &xFrame)
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
css::uno::Reference< css::frame::XStatusListener > m_xListener
virtual css::uno::Sequence< OUString > SAL_CALL getInterceptedURLs() override
css::uno::Reference< css::frame::XDispatchProviderInterception > m_xIntercepted
VclPtr< SfxHelpWindow_Impl > m_pWindow
std::vector< OUString > m_vHistoryUrls
void addURL(const OUString &rURL)
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewMaster) override
bool HasHistorySucc() const
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewSlave) override
virtual ~HelpInterceptor_Impl() override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
bool HasHistoryPred() const
friend class HelpDispatch_Impl
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
HelpInterceptor_Impl * pInterceptor
virtual void SAL_CALL disposing(const css::lang::EventObject &obj) override
Link< HelpListener_Impl &, void > aChangeLink
HelpListener_Impl(HelpInterceptor_Impl *pInter)
css::uno::Reference< css::frame::XDispatch > xDispatch
virtual void SAL_CALL disposing(const css::lang::EventObject &obj) override
css::frame::FeatureStateEvent aStateEvent
virtual ~HelpStatusListener_Impl() override
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
HelpStatusListener_Impl(css::uno::Reference< css::frame::XDispatch > const &xDispatch, css::util::URL const &rURL)
OUString GetHost(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
int nCount
#define DBG_ASSERT(sCon, aError)
URL aURL
sal_uInt16 nPos
Definition: linksrc.cxx:118
sal_Int32 m_nCurPos
Reference< XController > xController
Reference< XFrame > xFrame