update dev300-m58
[ooovba.git] / sfx2 / source / appl / helpinterceptor.cxx
blob981752c5d8a030b2900be51d10529b51f8bb1407
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helpinterceptor.cxx,v $
10 * $Revision: 1.28 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "helpinterceptor.hxx"
35 #include "helpdispatch.hxx"
36 #include "newhelp.hxx"
37 #include <sfx2/sfxuno.hxx>
38 #include <tools/urlobj.hxx>
39 #include <tools/debug.hxx>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
42 #include <cppuhelper/interfacecontainer.h>
43 #include <vcl/window.hxx>
44 #include <limits.h>
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::frame;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::lang;
52 extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
54 // class HelpInterceptor_Impl --------------------------------------------
56 HelpInterceptor_Impl::HelpInterceptor_Impl() :
58 m_pHistory ( NULL ),
59 m_nCurPos ( 0 )
64 // -----------------------------------------------------------------------
66 HelpInterceptor_Impl::~HelpInterceptor_Impl()
68 for ( USHORT i = 0; m_pHistory && i < m_pHistory->Count(); ++i )
69 delete m_pHistory->GetObject(i);
70 delete m_pHistory;
73 // -----------------------------------------------------------------------
75 void HelpInterceptor_Impl::addURL( const String& rURL )
77 if ( !m_pHistory )
78 m_pHistory = new HelpHistoryList_Impl;
79 ULONG nCount = m_pHistory->Count();
80 if ( nCount && m_nCurPos < ( nCount - 1 ) )
82 for ( ULONG i = nCount - 1; i > m_nCurPos; i-- )
83 delete m_pHistory->Remove(i);
85 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
86 Reference<XController> xController;
87 if(xFrame.is())
88 xController = xFrame->getController();
89 Any aViewData;
90 if(xController.is() && m_pHistory->Count())
92 m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData();
95 m_aCurrentURL = rURL;
96 Any aEmptyViewData;
97 m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), LIST_APPEND );
98 m_nCurPos = m_pHistory->Count() - 1;
99 // TODO ?
100 if ( m_xListener.is() )
102 ::com::sun::star::frame::FeatureStateEvent aEvent;
103 URL aURL;
104 aURL.Complete = rURL;
105 aEvent.FeatureURL = aURL;
106 aEvent.Source = (::com::sun::star::frame::XDispatch*)this;
107 m_xListener->statusChanged( aEvent );
110 m_pWindow->UpdateToolbox();
113 // -----------------------------------------------------------------------
115 void HelpInterceptor_Impl::setInterception( Reference< XFrame > xFrame )
117 m_xIntercepted = Reference< XDispatchProviderInterception>( xFrame, UNO_QUERY );
119 if ( m_xIntercepted.is() )
120 m_xIntercepted->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor*)this );
123 // -----------------------------------------------------------------------
125 void HelpInterceptor_Impl::SetStartURL( const String& rURL )
127 DBG_ASSERT( !m_pHistory, "invalid history" );
128 if ( !m_pHistory )
130 m_pHistory = new HelpHistoryList_Impl;
131 Any aEmptyViewData;
132 m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), ((ULONG)0x0) );
133 m_nCurPos = m_pHistory->Count() - 1;
135 m_pWindow->UpdateToolbox();
137 m_aCurrentURL = rURL;
140 sal_Bool HelpInterceptor_Impl::HasHistoryPred() const
142 return m_pHistory && ( m_nCurPos > 0 );
145 sal_Bool HelpInterceptor_Impl::HasHistorySucc() const
147 return m_pHistory && ( m_nCurPos < ( m_pHistory->Count() - 1 ) );
151 // -----------------------------------------------------------------------
152 // XDispatchProvider
154 Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
156 const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags )
158 throw( RuntimeException )
161 Reference< XDispatch > xResult;
162 if ( m_xSlaveDispatcher.is() )
163 xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags );
165 // INetURLObject aObj( aURL.Complete );
166 // sal_Bool bHelpURL = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP );
167 BOOL bHelpURL = aURL.Complete.toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0);
169 if ( bHelpURL )
171 DBG_ASSERT( xResult.is(), "invalid dispatch" );
172 HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult );
173 xResult = Reference< XDispatch >( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY );
176 return xResult;
179 // -----------------------------------------------------------------------
181 Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches(
183 const Sequence< DispatchDescriptor >& aDescripts )
185 throw( RuntimeException )
188 Sequence< Reference< XDispatch > > aReturn( aDescripts.getLength() );
189 Reference< XDispatch >* pReturn = aReturn.getArray();
190 const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
191 for ( sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
193 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
195 return aReturn;
198 // -----------------------------------------------------------------------
199 // XDispatchProviderInterceptor
201 Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider()
203 throw( RuntimeException )
206 return m_xSlaveDispatcher;
209 // -----------------------------------------------------------------------
211 void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave )
213 throw( RuntimeException )
216 m_xSlaveDispatcher = xNewSlave;
219 // -----------------------------------------------------------------------
221 Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider()
223 throw( RuntimeException )
226 return m_xMasterDispatcher;
229 // -----------------------------------------------------------------------
231 void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster )
233 throw( RuntimeException )
236 m_xMasterDispatcher = xNewMaster;
239 // -----------------------------------------------------------------------
240 // XInterceptorInfo
242 Sequence< ::rtl::OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs()
244 throw( RuntimeException )
247 Sequence< ::rtl::OUString > aURLList( 1 );
248 aURLList[0] = DEFINE_CONST_UNICODE("vnd.sun.star.help://*");
249 return aURLList;;
252 // -----------------------------------------------------------------------
253 // XDispatch
255 void SAL_CALL HelpInterceptor_Impl::dispatch(
256 const URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue >& ) throw( RuntimeException )
258 sal_Bool bBack = ( String( DEFINE_CONST_UNICODE(".uno:Backward") ) == String( aURL.Complete ) );
259 if ( bBack || String( DEFINE_CONST_UNICODE(".uno:Forward") ) == String( aURL.Complete ) )
261 if ( m_pHistory )
263 if(m_pHistory->Count() > m_nCurPos)
265 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
266 Reference<XController> xController;
267 if(xFrame.is())
268 xController = xFrame->getController();
269 if(xController.is())
271 m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData();
275 ULONG nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos
276 : ( !bBack && m_nCurPos < m_pHistory->Count() - 1 )
277 ? ++m_nCurPos
278 : ULONG_MAX;
280 if ( nPos < ULONG_MAX )
282 HelpHistoryEntry_Impl* pEntry = m_pHistory->GetObject( nPos );
283 if ( pEntry )
284 m_pWindow->loadHelpContent(pEntry->aURL, sal_False); // false => dont add item to history again!
287 m_pWindow->UpdateToolbox();
292 // -----------------------------------------------------------------------
294 void SAL_CALL HelpInterceptor_Impl::addStatusListener(
295 const Reference< XStatusListener >& xControl, const URL& ) throw( RuntimeException )
297 DBG_ASSERT( !m_xListener.is(), "listener already exists" );
298 m_xListener = xControl;
301 // -----------------------------------------------------------------------
303 void SAL_CALL HelpInterceptor_Impl::removeStatusListener(
304 const Reference< XStatusListener >&, const URL&) throw( RuntimeException )
306 m_xListener = 0;
309 // HelpListener_Impl -----------------------------------------------------
311 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl* pInter )
313 pInterceptor = pInter;
314 pInterceptor->addStatusListener( this, ::com::sun::star::util::URL() );
317 // -----------------------------------------------------------------------
319 void SAL_CALL HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
321 throw( ::com::sun::star::uno::RuntimeException )
324 INetURLObject aObj( Event.FeatureURL.Complete );
325 aFactory = aObj.GetHost();
326 aChangeLink.Call( this );
329 // -----------------------------------------------------------------------
331 void SAL_CALL HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject& )
333 throw( ::com::sun::star::uno::RuntimeException )
336 pInterceptor->removeStatusListener( this, ::com::sun::star::util::URL() );
337 pInterceptor = NULL;
339 /*-- 05.09.2002 12:17:59---------------------------------------------------
341 -----------------------------------------------------------------------*/
342 HelpStatusListener_Impl::HelpStatusListener_Impl(
343 Reference < XDispatch > aDispatch, URL& rURL)
345 aDispatch->addStatusListener(this, rURL);
347 /*-- 05.09.2002 12:17:59---------------------------------------------------
349 -----------------------------------------------------------------------*/
350 HelpStatusListener_Impl::~HelpStatusListener_Impl()
352 if(xDispatch.is())
353 xDispatch->removeStatusListener(this, com::sun::star::util::URL());
355 /*-- 05.09.2002 12:17:59---------------------------------------------------
357 -----------------------------------------------------------------------*/
358 void HelpStatusListener_Impl::statusChanged(
359 const FeatureStateEvent& rEvent ) throw( RuntimeException )
361 aStateEvent = rEvent;
363 /*-- 05.09.2002 12:18:00---------------------------------------------------
365 -----------------------------------------------------------------------*/
366 void HelpStatusListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
368 xDispatch->removeStatusListener(this, com::sun::star::util::URL());
369 xDispatch = 0;