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 HelpInterceptor_Impl::HelpInterceptor_Impl() :
50 HelpInterceptor_Impl::~HelpInterceptor_Impl()
54 for ( size_t i
= 0, n
= m_pHistory
->size(); i
< n
; ++i
)
55 delete m_pHistory
->at( i
);
62 void HelpInterceptor_Impl::addURL( const OUString
& rURL
)
65 m_pHistory
= new HelpHistoryList_Impl
;
67 size_t nCount
= m_pHistory
->size();
68 if ( nCount
&& m_nCurPos
< ( nCount
- 1 ) )
70 for ( size_t i
= nCount
- 1; i
> m_nCurPos
; i
-- )
72 delete m_pHistory
->at( i
);
73 HelpHistoryList_Impl::iterator it
= m_pHistory
->begin();
74 ::std::advance( it
, i
);
75 m_pHistory
->erase( it
);
78 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
79 Reference
<XController
> xController
;
81 xController
= xFrame
->getController();
82 if(xController
.is() && !m_pHistory
->empty())
84 m_pHistory
->at( m_nCurPos
)->aViewData
= xController
->getViewData();
89 m_pHistory
->push_back( new HelpHistoryEntry_Impl( rURL
, aEmptyViewData
) );
90 m_nCurPos
= m_pHistory
->size() - 1;
92 if ( m_xListener
.is() )
94 ::com::sun::star::frame::FeatureStateEvent aEvent
;
97 aEvent
.FeatureURL
= aURL
;
98 aEvent
.Source
= (::com::sun::star::frame::XDispatch
*)this;
99 m_xListener
->statusChanged( aEvent
);
102 m_pWindow
->UpdateToolbox();
107 void HelpInterceptor_Impl::setInterception( Reference
< XFrame
> xFrame
)
109 m_xIntercepted
= Reference
< XDispatchProviderInterception
>( xFrame
, UNO_QUERY
);
111 if ( m_xIntercepted
.is() )
112 m_xIntercepted
->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor
*)this );
117 bool HelpInterceptor_Impl::HasHistoryPred() const
119 return m_pHistory
&& ( m_nCurPos
> 0 );
122 bool HelpInterceptor_Impl::HasHistorySucc() const
124 return m_pHistory
&& ( m_nCurPos
< ( m_pHistory
->size() - 1 ) );
131 Reference
< XDispatch
> SAL_CALL
HelpInterceptor_Impl::queryDispatch(
133 const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
135 throw( RuntimeException
, std::exception
)
138 Reference
< XDispatch
> xResult
;
139 if ( m_xSlaveDispatcher
.is() )
140 xResult
= m_xSlaveDispatcher
->queryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
142 bool bHelpURL
= aURL
.Complete
.toAsciiLowerCase().match("vnd.sun.star.help",0);
146 DBG_ASSERT( xResult
.is(), "invalid dispatch" );
147 HelpDispatch_Impl
* pHelpDispatch
= new HelpDispatch_Impl( *this, xResult
);
148 xResult
= Reference
< XDispatch
>( static_cast< ::cppu::OWeakObject
* >(pHelpDispatch
), UNO_QUERY
);
156 Sequence
< Reference
< XDispatch
> > SAL_CALL
HelpInterceptor_Impl::queryDispatches(
158 const Sequence
< DispatchDescriptor
>& aDescripts
)
160 throw( RuntimeException
, std::exception
)
163 Sequence
< Reference
< XDispatch
> > aReturn( aDescripts
.getLength() );
164 Reference
< XDispatch
>* pReturn
= aReturn
.getArray();
165 const DispatchDescriptor
* pDescripts
= aDescripts
.getConstArray();
166 for ( sal_Int16 i
= 0; i
< aDescripts
.getLength(); ++i
, ++pReturn
, ++pDescripts
)
168 *pReturn
= queryDispatch( pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
174 // XDispatchProviderInterceptor
176 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getSlaveDispatchProvider()
178 throw( RuntimeException
, std::exception
)
181 return m_xSlaveDispatcher
;
186 void SAL_CALL
HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference
< XDispatchProvider
>& xNewSlave
)
188 throw( RuntimeException
, std::exception
)
191 m_xSlaveDispatcher
= xNewSlave
;
196 Reference
< XDispatchProvider
> SAL_CALL
HelpInterceptor_Impl::getMasterDispatchProvider()
198 throw( RuntimeException
, std::exception
)
201 return m_xMasterDispatcher
;
206 void SAL_CALL
HelpInterceptor_Impl::setMasterDispatchProvider( const Reference
< XDispatchProvider
>& xNewMaster
)
208 throw( RuntimeException
, std::exception
)
211 m_xMasterDispatcher
= xNewMaster
;
217 Sequence
< OUString
> SAL_CALL
HelpInterceptor_Impl::getInterceptedURLs()
219 throw( RuntimeException
, std::exception
)
222 Sequence
< OUString
> aURLList( 1 );
223 aURLList
[0] = "vnd.sun.star.help://*";
230 void SAL_CALL
HelpInterceptor_Impl::dispatch(
231 const URL
& aURL
, const Sequence
< ::com::sun::star::beans::PropertyValue
>& ) throw( RuntimeException
, std::exception
)
233 bool bBack
= aURL
.Complete
== ".uno:Backward";
234 if ( bBack
|| aURL
.Complete
== ".uno:Forward" )
238 if(m_pHistory
->size() > m_nCurPos
)
240 Reference
<XFrame
> xFrame(m_xIntercepted
, UNO_QUERY
);
241 Reference
<XController
> xController
;
243 xController
= xFrame
->getController();
246 m_pHistory
->at( m_nCurPos
)->aViewData
= xController
->getViewData();
250 sal_uIntPtr nPos
= ( bBack
&& m_nCurPos
> 0 ) ? --m_nCurPos
251 : ( !bBack
&& m_nCurPos
< m_pHistory
->size() - 1 )
255 if ( nPos
< ULONG_MAX
)
257 HelpHistoryEntry_Impl
* pEntry
= m_pHistory
->at( nPos
);
259 m_pWindow
->loadHelpContent(pEntry
->aURL
, false); // false => dont add item to history again!
262 m_pWindow
->UpdateToolbox();
269 void SAL_CALL
HelpInterceptor_Impl::addStatusListener(
270 const Reference
< XStatusListener
>& xControl
, const URL
& ) throw( RuntimeException
, std::exception
)
272 DBG_ASSERT( !m_xListener
.is(), "listener already exists" );
273 m_xListener
= xControl
;
278 void SAL_CALL
HelpInterceptor_Impl::removeStatusListener(
279 const Reference
< XStatusListener
>&, const URL
&) throw( RuntimeException
, std::exception
)
284 // HelpListener_Impl -----------------------------------------------------
286 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl
* pInter
)
288 pInterceptor
= pInter
;
289 pInterceptor
->addStatusListener( this, ::com::sun::star::util::URL() );
294 void SAL_CALL
HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
)
296 throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
299 INetURLObject
aObj( Event
.FeatureURL
.Complete
);
300 aFactory
= aObj
.GetHost();
301 aChangeLink
.Call( this );
306 void SAL_CALL
HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject
& )
308 throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
311 pInterceptor
->removeStatusListener( this, ::com::sun::star::util::URL() );
315 HelpStatusListener_Impl::HelpStatusListener_Impl(
316 Reference
< XDispatch
> aDispatch
, URL
& rURL
)
318 aDispatch
->addStatusListener(this, rURL
);
321 HelpStatusListener_Impl::~HelpStatusListener_Impl()
324 xDispatch
->removeStatusListener(this, com::sun::star::util::URL());
327 void HelpStatusListener_Impl::statusChanged(
328 const FeatureStateEvent
& rEvent
) throw( RuntimeException
, std::exception
)
330 aStateEvent
= rEvent
;
333 void HelpStatusListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
, std::exception
)
335 xDispatch
->removeStatusListener(this, com::sun::star::util::URL());
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */