Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / helpinterceptor.cxx
blob85fd84ca65330730f81d8cc034d50df8ee2f7ae8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "helpinterceptor.hxx"
31 #include "helpdispatch.hxx"
32 #include "newhelp.hxx"
33 #include <sfx2/sfxuno.hxx>
34 #include <tools/urlobj.hxx>
35 #include <tools/debug.hxx>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
38 #include <cppuhelper/interfacecontainer.h>
39 #include <vcl/window.hxx>
40 #include <limits.h>
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::util;
46 using namespace ::com::sun::star::lang;
48 extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
50 // class HelpInterceptor_Impl --------------------------------------------
52 HelpInterceptor_Impl::HelpInterceptor_Impl() :
54 m_pHistory ( NULL ),
55 m_nCurPos ( 0 )
60 // -----------------------------------------------------------------------
62 HelpInterceptor_Impl::~HelpInterceptor_Impl()
64 if ( m_pHistory )
66 for ( size_t i = 0, n = m_pHistory->size(); i < n; ++i )
67 delete m_pHistory->at( i );
68 delete m_pHistory;
72 // -----------------------------------------------------------------------
74 void HelpInterceptor_Impl::addURL( const String& rURL )
76 if ( !m_pHistory )
77 m_pHistory = new HelpHistoryList_Impl;
79 size_t nCount = m_pHistory->size();
80 if ( nCount && m_nCurPos < ( nCount - 1 ) )
82 for ( size_t i = nCount - 1; i > m_nCurPos; i-- )
84 delete m_pHistory->at( i );
85 HelpHistoryList_Impl::iterator it = m_pHistory->begin();
86 ::std::advance( it, i );
87 m_pHistory->erase( it );
90 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
91 Reference<XController> xController;
92 if(xFrame.is())
93 xController = xFrame->getController();
94 Any aViewData;
95 if(xController.is() && !m_pHistory->empty())
97 m_pHistory->at( m_nCurPos )->aViewData = xController->getViewData();
100 m_aCurrentURL = rURL;
101 Any aEmptyViewData;
102 m_pHistory->push_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) );
103 m_nCurPos = m_pHistory->size() - 1;
104 // TODO ?
105 if ( m_xListener.is() )
107 ::com::sun::star::frame::FeatureStateEvent aEvent;
108 URL aURL;
109 aURL.Complete = rURL;
110 aEvent.FeatureURL = aURL;
111 aEvent.Source = (::com::sun::star::frame::XDispatch*)this;
112 m_xListener->statusChanged( aEvent );
115 m_pWindow->UpdateToolbox();
118 // -----------------------------------------------------------------------
120 void HelpInterceptor_Impl::setInterception( Reference< XFrame > xFrame )
122 m_xIntercepted = Reference< XDispatchProviderInterception>( xFrame, UNO_QUERY );
124 if ( m_xIntercepted.is() )
125 m_xIntercepted->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor*)this );
128 // -----------------------------------------------------------------------
130 sal_Bool HelpInterceptor_Impl::HasHistoryPred() const
132 return m_pHistory && ( m_nCurPos > 0 );
135 sal_Bool HelpInterceptor_Impl::HasHistorySucc() const
137 return m_pHistory && ( m_nCurPos < ( m_pHistory->size() - 1 ) );
141 // -----------------------------------------------------------------------
142 // XDispatchProvider
144 Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
146 const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags )
148 throw( RuntimeException )
151 Reference< XDispatch > xResult;
152 if ( m_xSlaveDispatcher.is() )
153 xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags );
155 sal_Bool bHelpURL = aURL.Complete.toAsciiLowerCase().match("vnd.sun.star.help",0);
157 if ( bHelpURL )
159 DBG_ASSERT( xResult.is(), "invalid dispatch" );
160 HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult );
161 xResult = Reference< XDispatch >( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY );
164 return xResult;
167 // -----------------------------------------------------------------------
169 Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches(
171 const Sequence< DispatchDescriptor >& aDescripts )
173 throw( RuntimeException )
176 Sequence< Reference< XDispatch > > aReturn( aDescripts.getLength() );
177 Reference< XDispatch >* pReturn = aReturn.getArray();
178 const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
179 for ( sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
181 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
183 return aReturn;
186 // -----------------------------------------------------------------------
187 // XDispatchProviderInterceptor
189 Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider()
191 throw( RuntimeException )
194 return m_xSlaveDispatcher;
197 // -----------------------------------------------------------------------
199 void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave )
201 throw( RuntimeException )
204 m_xSlaveDispatcher = xNewSlave;
207 // -----------------------------------------------------------------------
209 Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider()
211 throw( RuntimeException )
214 return m_xMasterDispatcher;
217 // -----------------------------------------------------------------------
219 void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster )
221 throw( RuntimeException )
224 m_xMasterDispatcher = xNewMaster;
227 // -----------------------------------------------------------------------
228 // XInterceptorInfo
230 Sequence< ::rtl::OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs()
232 throw( RuntimeException )
235 Sequence< ::rtl::OUString > aURLList( 1 );
236 aURLList[0] = DEFINE_CONST_UNICODE("vnd.sun.star.help://*");
237 return aURLList;
240 // -----------------------------------------------------------------------
241 // XDispatch
243 void SAL_CALL HelpInterceptor_Impl::dispatch(
244 const URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue >& ) throw( RuntimeException )
246 sal_Bool bBack = ( String( DEFINE_CONST_UNICODE(".uno:Backward") ) == String( aURL.Complete ) );
247 if ( bBack || String( DEFINE_CONST_UNICODE(".uno:Forward") ) == String( aURL.Complete ) )
249 if ( m_pHistory )
251 if(m_pHistory->size() > m_nCurPos)
253 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
254 Reference<XController> xController;
255 if(xFrame.is())
256 xController = xFrame->getController();
257 if(xController.is())
259 m_pHistory->at( m_nCurPos )->aViewData = xController->getViewData();
263 sal_uIntPtr nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos
264 : ( !bBack && m_nCurPos < m_pHistory->size() - 1 )
265 ? ++m_nCurPos
266 : ULONG_MAX;
268 if ( nPos < ULONG_MAX )
270 HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos );
271 if ( pEntry )
272 m_pWindow->loadHelpContent(pEntry->aURL, sal_False); // false => dont add item to history again!
275 m_pWindow->UpdateToolbox();
280 // -----------------------------------------------------------------------
282 void SAL_CALL HelpInterceptor_Impl::addStatusListener(
283 const Reference< XStatusListener >& xControl, const URL& ) throw( RuntimeException )
285 DBG_ASSERT( !m_xListener.is(), "listener already exists" );
286 m_xListener = xControl;
289 // -----------------------------------------------------------------------
291 void SAL_CALL HelpInterceptor_Impl::removeStatusListener(
292 const Reference< XStatusListener >&, const URL&) throw( RuntimeException )
294 m_xListener = 0;
297 // HelpListener_Impl -----------------------------------------------------
299 HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl* pInter )
301 pInterceptor = pInter;
302 pInterceptor->addStatusListener( this, ::com::sun::star::util::URL() );
305 // -----------------------------------------------------------------------
307 void SAL_CALL HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
309 throw( ::com::sun::star::uno::RuntimeException )
312 INetURLObject aObj( Event.FeatureURL.Complete );
313 aFactory = aObj.GetHost();
314 aChangeLink.Call( this );
317 // -----------------------------------------------------------------------
319 void SAL_CALL HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject& )
321 throw( ::com::sun::star::uno::RuntimeException )
324 pInterceptor->removeStatusListener( this, ::com::sun::star::util::URL() );
325 pInterceptor = NULL;
328 HelpStatusListener_Impl::HelpStatusListener_Impl(
329 Reference < XDispatch > aDispatch, URL& rURL)
331 aDispatch->addStatusListener(this, rURL);
334 HelpStatusListener_Impl::~HelpStatusListener_Impl()
336 if(xDispatch.is())
337 xDispatch->removeStatusListener(this, com::sun::star::util::URL());
340 void HelpStatusListener_Impl::statusChanged(
341 const FeatureStateEvent& rEvent ) throw( RuntimeException )
343 aStateEvent = rEvent;
346 void HelpStatusListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
348 xDispatch->removeStatusListener(this, com::sun::star::util::URL());
349 xDispatch = 0;
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */