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 <sfx2/sfxuno.hxx>
25 #include <tools/urlobj.hxx>
26 #include <tools/debug.hxx>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
29 #include <cppuhelper/interfacecontainer.h>
30 #include <vcl/window.hxx>
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::frame
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::util
;
37 using namespace ::com::sun::star::lang
;
39 extern void AppendConfigToken_Impl( OUString
& rURL
, sal_Bool bQuestionMark
); // sfxhelp.cxx
41 // class HelpInterceptor_Impl --------------------------------------------
43 HelpInterceptor_Impl::HelpInterceptor_Impl() :
52 // -----------------------------------------------------------------------
54 HelpInterceptor_Impl::~HelpInterceptor_Impl()
58 for ( size_t i
= 0, n
= m_pHistory
->size(); i
< n
; ++i
)
59 delete m_pHistory
->at( i
);
64 // -----------------------------------------------------------------------
66 void HelpInterceptor_Impl::addURL( const OUString
& rURL
)
69 m_pHistory
= new HelpHistoryList_Impl
;
71 size_t nCount
= m_pHistory
->size();
72 if ( nCount
&& m_nCurPos
< ( nCount
- 1 ) )
74 for ( size_t i
= nCount
- 1; i
> m_nCurPos
; i
-- )
76 delete m_pHistory
->at( i
);
77 HelpHistoryList_Impl::iterator it
= m_pHistory
->begin();
78 ::std::advance( it
, i
);
79 m_pHistory
->erase( it
);
82 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
83 Reference
<XController
> xController
;
85 xController
= xFrame
->getController();
86 if(xController
.is() && !m_pHistory
->empty())
88 m_pHistory
->at( m_nCurPos
)->aViewData
= xController
->getViewData();
93 m_pHistory
->push_back( new HelpHistoryEntry_Impl( rURL
, aEmptyViewData
) );
94 m_nCurPos
= m_pHistory
->size() - 1;
96 if ( m_xListener
.is() )
98 ::com::sun::star::frame::FeatureStateEvent aEvent
;
100 aURL
.Complete
= rURL
;
101 aEvent
.FeatureURL
= aURL
;
102 aEvent
.Source
= (::com::sun::star::frame::XDispatch
*)this;
103 m_xListener
->statusChanged( aEvent
);
106 m_pWindow
->UpdateToolbox();
109 // -----------------------------------------------------------------------
111 void HelpInterceptor_Impl::setInterception( Reference
< XFrame
> xFrame
)
113 m_xIntercepted
= Reference
< XDispatchProviderInterception
>( xFrame
, UNO_QUERY
);
115 if ( m_xIntercepted
.is() )
116 m_xIntercepted
->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor
*)this );
119 // -----------------------------------------------------------------------
121 sal_Bool
HelpInterceptor_Impl::HasHistoryPred() const
123 return m_pHistory
&& ( m_nCurPos
> 0 );
126 sal_Bool
HelpInterceptor_Impl::HasHistorySucc() const
128 return m_pHistory
&& ( m_nCurPos
< ( m_pHistory
->size() - 1 ) );
132 // -----------------------------------------------------------------------
135 Reference
< XDispatch
> SAL_CALL
HelpInterceptor_Impl::queryDispatch(
137 const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
139 throw( RuntimeException
)
142 Reference
< XDispatch
> xResult
;
143 if ( m_xSlaveDispatcher
.is() )
144 xResult
= m_xSlaveDispatcher
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
146 sal_Bool bHelpURL
= aURL
.Complete
.toAsciiLowerCase().match("vnd.sun.star.help",0);
150 DBG_ASSERT( xResult
.is(), "invalid dispatch" );
151 HelpDispatch_Impl
* pHelpDispatch
= new HelpDispatch_Impl( *this, xResult
);
152 xResult
= Reference
< XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pHelpDispatch
), UNO_QUERY
);
158 // -----------------------------------------------------------------------
160 Sequence
< Reference
< XDispatch
> > SAL_CALL
HelpInterceptor_Impl::queryDispatches(
162 const Sequence
< DispatchDescriptor
>& aDescripts
)
164 throw( RuntimeException
)
167 Sequence
< Reference
< XDispatch
> > aReturn( aDescripts
.getLength() );
168 Reference
< XDispatch
>* pReturn
= aReturn
.getArray();
169 const DispatchDescriptor
* pDescripts
= aDescripts
.getConstArray();
170 for ( sal_Int16 i
= 0; i
< aDescripts
.getLength(); ++i
, ++pReturn
, ++pDescripts
)
172 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
177 // -----------------------------------------------------------------------
178 // XDispatchProviderInterceptor
180 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getSlaveDispatchProvider()
182 throw( RuntimeException
)
185 return m_xSlaveDispatcher
;
188 // -----------------------------------------------------------------------
190 void SAL_CALL
HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference
< XDispatchProvider
>& xNewSlave
)
192 throw( RuntimeException
)
195 m_xSlaveDispatcher
= xNewSlave
;
198 // -----------------------------------------------------------------------
200 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getMasterDispatchProvider()
202 throw( RuntimeException
)
205 return m_xMasterDispatcher
;
208 // -----------------------------------------------------------------------
210 void SAL_CALL
HelpInterceptor_Impl::setMasterDispatchProvider( const Reference
< XDispatchProvider
>& xNewMaster
)
212 throw( RuntimeException
)
215 m_xMasterDispatcher
= xNewMaster
;
218 // -----------------------------------------------------------------------
221 Sequence
< OUString
> SAL_CALL
HelpInterceptor_Impl::getInterceptedURLs()
223 throw( RuntimeException
)
226 Sequence
< OUString
> aURLList( 1 );
227 aURLList
[0] = "vnd.sun.star.help://*";
231 // -----------------------------------------------------------------------
234 void SAL_CALL
HelpInterceptor_Impl::dispatch(
235 const URL
& aURL
, const Sequence
< ::com::sun::star::beans::PropertyValue
>& ) throw( RuntimeException
)
237 sal_Bool bBack
= ( OUString( ".uno:Backward" ) == aURL
.Complete
);
238 if ( bBack
|| OUString( ".uno:Forward" ) == aURL
.Complete
)
242 if(m_pHistory
->size() > m_nCurPos
)
244 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
245 Reference
<XController
> xController
;
247 xController
= xFrame
->getController();
250 m_pHistory
->at( m_nCurPos
)->aViewData
= xController
->getViewData();
254 sal_uIntPtr nPos
= ( bBack
&& m_nCurPos
> 0 ) ? --m_nCurPos
255 : ( !bBack
&& m_nCurPos
< m_pHistory
->size() - 1 )
259 if ( nPos
< ULONG_MAX
)
261 HelpHistoryEntry_Impl
* pEntry
= m_pHistory
->at( nPos
);
263 m_pWindow
->loadHelpContent(pEntry
->aURL
, sal_False
); // false => dont add item to history again!
266 m_pWindow
->UpdateToolbox();
271 // -----------------------------------------------------------------------
273 void SAL_CALL
HelpInterceptor_Impl::addStatusListener(
274 const Reference
< XStatusListener
>& xControl
, const URL
& ) throw( RuntimeException
)
276 DBG_ASSERT( !m_xListener
.is(), "listener already exists" );
277 m_xListener
= xControl
;
280 // -----------------------------------------------------------------------
282 void SAL_CALL
HelpInterceptor_Impl::removeStatusListener(
283 const Reference
< XStatusListener
>&, const URL
&) throw( RuntimeException
)
288 // HelpListener_Impl -----------------------------------------------------
290 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl
* pInter
)
292 pInterceptor
= pInter
;
293 pInterceptor
->addStatusListener( this, ::com::sun::star::util::URL() );
296 // -----------------------------------------------------------------------
298 void SAL_CALL
HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
300 throw( ::com::sun::star::uno::RuntimeException
)
303 INetURLObject
aObj( Event
.FeatureURL
.Complete
);
304 aFactory
= aObj
.GetHost();
305 aChangeLink
.Call( this );
308 // -----------------------------------------------------------------------
310 void SAL_CALL
HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject
& )
312 throw( ::com::sun::star::uno::RuntimeException
)
315 pInterceptor
->removeStatusListener( this, ::com::sun::star::util::URL() );
319 HelpStatusListener_Impl::HelpStatusListener_Impl(
320 Reference
< XDispatch
> aDispatch
, URL
& rURL
)
322 aDispatch
->addStatusListener(this, rURL
);
325 HelpStatusListener_Impl::~HelpStatusListener_Impl()
328 xDispatch
->removeStatusListener(this, com::sun::star::util::URL());
331 void HelpStatusListener_Impl::statusChanged(
332 const FeatureStateEvent
& rEvent
) throw( RuntimeException
)
334 aStateEvent
= rEvent
;
337 void HelpStatusListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
)
339 xDispatch
->removeStatusListener(this, com::sun::star::util::URL());
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */