1d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d119d52dSAndrew Rist * distributed with this work for additional information 6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d119d52dSAndrew Rist * software distributed under the License is distributed on an 15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17d119d52dSAndrew Rist * specific language governing permissions and limitations 18d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20d119d52dSAndrew Rist *************************************************************/ 21d119d52dSAndrew Rist 22d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "helpinterceptor.hxx" 28cdf0e10cSrcweir #include "helpdispatch.hxx" 29cdf0e10cSrcweir #include "newhelp.hxx" 30cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 31cdf0e10cSrcweir #include <tools/urlobj.hxx> 32cdf0e10cSrcweir #include <tools/debug.hxx> 33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 34cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp> 35cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 36cdf0e10cSrcweir #include <vcl/window.hxx> 37cdf0e10cSrcweir #include <limits.h> 38cdf0e10cSrcweir 39cdf0e10cSrcweir using namespace ::com::sun::star::beans; 40cdf0e10cSrcweir using namespace ::com::sun::star::frame; 41cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42cdf0e10cSrcweir using namespace ::com::sun::star::util; 43cdf0e10cSrcweir using namespace ::com::sun::star::lang; 44cdf0e10cSrcweir 45cdf0e10cSrcweir extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx 46cdf0e10cSrcweir 47cdf0e10cSrcweir // class HelpInterceptor_Impl -------------------------------------------- 48cdf0e10cSrcweir 49cdf0e10cSrcweir HelpInterceptor_Impl::HelpInterceptor_Impl() : 50cdf0e10cSrcweir 51cdf0e10cSrcweir m_pHistory ( NULL ), 52cdf0e10cSrcweir m_nCurPos ( 0 ) 53cdf0e10cSrcweir 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir // ----------------------------------------------------------------------- 58cdf0e10cSrcweir 59cdf0e10cSrcweir HelpInterceptor_Impl::~HelpInterceptor_Impl() 60cdf0e10cSrcweir { 61cdf0e10cSrcweir for ( sal_uInt16 i = 0; m_pHistory && i < m_pHistory->Count(); ++i ) 62cdf0e10cSrcweir delete m_pHistory->GetObject(i); 63cdf0e10cSrcweir delete m_pHistory; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir // ----------------------------------------------------------------------- 67cdf0e10cSrcweir 68cdf0e10cSrcweir void HelpInterceptor_Impl::addURL( const String& rURL ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir if ( !m_pHistory ) 71cdf0e10cSrcweir m_pHistory = new HelpHistoryList_Impl; 72cdf0e10cSrcweir sal_uIntPtr nCount = m_pHistory->Count(); 73cdf0e10cSrcweir if ( nCount && m_nCurPos < ( nCount - 1 ) ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir for ( sal_uIntPtr i = nCount - 1; i > m_nCurPos; i-- ) 76cdf0e10cSrcweir delete m_pHistory->Remove(i); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY); 79cdf0e10cSrcweir Reference<XController> xController; 80cdf0e10cSrcweir if(xFrame.is()) 81cdf0e10cSrcweir xController = xFrame->getController(); 82cdf0e10cSrcweir Any aViewData; 83cdf0e10cSrcweir if(xController.is() && m_pHistory->Count()) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData(); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir m_aCurrentURL = rURL; 89cdf0e10cSrcweir Any aEmptyViewData; 90cdf0e10cSrcweir m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), LIST_APPEND ); 91cdf0e10cSrcweir m_nCurPos = m_pHistory->Count() - 1; 92cdf0e10cSrcweir // TODO ? 93cdf0e10cSrcweir if ( m_xListener.is() ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir ::com::sun::star::frame::FeatureStateEvent aEvent; 96cdf0e10cSrcweir URL aURL; 97cdf0e10cSrcweir aURL.Complete = rURL; 98cdf0e10cSrcweir aEvent.FeatureURL = aURL; 99cdf0e10cSrcweir aEvent.Source = (::com::sun::star::frame::XDispatch*)this; 100cdf0e10cSrcweir m_xListener->statusChanged( aEvent ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir m_pWindow->UpdateToolbox(); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // ----------------------------------------------------------------------- 107cdf0e10cSrcweir 108cdf0e10cSrcweir void HelpInterceptor_Impl::setInterception( Reference< XFrame > xFrame ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir m_xIntercepted = Reference< XDispatchProviderInterception>( xFrame, UNO_QUERY ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir if ( m_xIntercepted.is() ) 113cdf0e10cSrcweir m_xIntercepted->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor*)this ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir // ----------------------------------------------------------------------- 117cdf0e10cSrcweir 118cdf0e10cSrcweir void HelpInterceptor_Impl::SetStartURL( const String& rURL ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir DBG_ASSERT( !m_pHistory, "invalid history" ); 121cdf0e10cSrcweir if ( !m_pHistory ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir m_pHistory = new HelpHistoryList_Impl; 124cdf0e10cSrcweir Any aEmptyViewData; 125cdf0e10cSrcweir m_pHistory->Insert( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ), ((sal_uIntPtr)0x0) ); 126cdf0e10cSrcweir m_nCurPos = m_pHistory->Count() - 1; 127cdf0e10cSrcweir 128cdf0e10cSrcweir m_pWindow->UpdateToolbox(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir m_aCurrentURL = rURL; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir sal_Bool HelpInterceptor_Impl::HasHistoryPred() const 134cdf0e10cSrcweir { 135cdf0e10cSrcweir return m_pHistory && ( m_nCurPos > 0 ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir sal_Bool HelpInterceptor_Impl::HasHistorySucc() const 139cdf0e10cSrcweir { 140cdf0e10cSrcweir return m_pHistory && ( m_nCurPos < ( m_pHistory->Count() - 1 ) ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir 144cdf0e10cSrcweir // ----------------------------------------------------------------------- 145cdf0e10cSrcweir // XDispatchProvider 146cdf0e10cSrcweir 147cdf0e10cSrcweir Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch( 148cdf0e10cSrcweir 149cdf0e10cSrcweir const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) 150cdf0e10cSrcweir 151cdf0e10cSrcweir throw( RuntimeException ) 152cdf0e10cSrcweir 153cdf0e10cSrcweir { 154cdf0e10cSrcweir Reference< XDispatch > xResult; 155cdf0e10cSrcweir if ( m_xSlaveDispatcher.is() ) 156cdf0e10cSrcweir xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir // INetURLObject aObj( aURL.Complete ); 159cdf0e10cSrcweir // sal_Bool bHelpURL = ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP ); 160cdf0e10cSrcweir sal_Bool bHelpURL = aURL.Complete.toAsciiLowerCase().match(rtl::OUString::createFromAscii("vnd.sun.star.help"),0); 161cdf0e10cSrcweir 162cdf0e10cSrcweir if ( bHelpURL ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir DBG_ASSERT( xResult.is(), "invalid dispatch" ); 165cdf0e10cSrcweir HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult ); 166cdf0e10cSrcweir xResult = Reference< XDispatch >( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir return xResult; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir // ----------------------------------------------------------------------- 173cdf0e10cSrcweir 174cdf0e10cSrcweir Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches( 175cdf0e10cSrcweir 176cdf0e10cSrcweir const Sequence< DispatchDescriptor >& aDescripts ) 177cdf0e10cSrcweir 178cdf0e10cSrcweir throw( RuntimeException ) 179cdf0e10cSrcweir 180cdf0e10cSrcweir { 181cdf0e10cSrcweir Sequence< Reference< XDispatch > > aReturn( aDescripts.getLength() ); 182cdf0e10cSrcweir Reference< XDispatch >* pReturn = aReturn.getArray(); 183cdf0e10cSrcweir const DispatchDescriptor* pDescripts = aDescripts.getConstArray(); 184cdf0e10cSrcweir for ( sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir return aReturn; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir // ----------------------------------------------------------------------- 192cdf0e10cSrcweir // XDispatchProviderInterceptor 193cdf0e10cSrcweir 194cdf0e10cSrcweir Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider() 195cdf0e10cSrcweir 196cdf0e10cSrcweir throw( RuntimeException ) 197cdf0e10cSrcweir 198cdf0e10cSrcweir { 199cdf0e10cSrcweir return m_xSlaveDispatcher; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir // ----------------------------------------------------------------------- 203cdf0e10cSrcweir 204cdf0e10cSrcweir void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave ) 205cdf0e10cSrcweir 206cdf0e10cSrcweir throw( RuntimeException ) 207cdf0e10cSrcweir 208cdf0e10cSrcweir { 209cdf0e10cSrcweir m_xSlaveDispatcher = xNewSlave; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir // ----------------------------------------------------------------------- 213cdf0e10cSrcweir 214cdf0e10cSrcweir Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider() 215cdf0e10cSrcweir 216cdf0e10cSrcweir throw( RuntimeException ) 217cdf0e10cSrcweir 218cdf0e10cSrcweir { 219cdf0e10cSrcweir return m_xMasterDispatcher; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir // ----------------------------------------------------------------------- 223cdf0e10cSrcweir 224cdf0e10cSrcweir void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster ) 225cdf0e10cSrcweir 226cdf0e10cSrcweir throw( RuntimeException ) 227cdf0e10cSrcweir 228cdf0e10cSrcweir { 229cdf0e10cSrcweir m_xMasterDispatcher = xNewMaster; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // ----------------------------------------------------------------------- 233cdf0e10cSrcweir // XInterceptorInfo 234cdf0e10cSrcweir 235cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs() 236cdf0e10cSrcweir 237cdf0e10cSrcweir throw( RuntimeException ) 238cdf0e10cSrcweir 239cdf0e10cSrcweir { 240cdf0e10cSrcweir Sequence< ::rtl::OUString > aURLList( 1 ); 241cdf0e10cSrcweir aURLList[0] = DEFINE_CONST_UNICODE("vnd.sun.star.help://*"); 242*be099857Smseidel return aURLList; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir // ----------------------------------------------------------------------- 246cdf0e10cSrcweir // XDispatch 247cdf0e10cSrcweir 248cdf0e10cSrcweir void SAL_CALL HelpInterceptor_Impl::dispatch( 249cdf0e10cSrcweir const URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue >& ) throw( RuntimeException ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir sal_Bool bBack = ( String( DEFINE_CONST_UNICODE(".uno:Backward") ) == String( aURL.Complete ) ); 252cdf0e10cSrcweir if ( bBack || String( DEFINE_CONST_UNICODE(".uno:Forward") ) == String( aURL.Complete ) ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir if ( m_pHistory ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir if(m_pHistory->Count() > m_nCurPos) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY); 259cdf0e10cSrcweir Reference<XController> xController; 260cdf0e10cSrcweir if(xFrame.is()) 261cdf0e10cSrcweir xController = xFrame->getController(); 262cdf0e10cSrcweir if(xController.is()) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir m_pHistory->GetObject(m_nCurPos)->aViewData = xController->getViewData(); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir sal_uIntPtr nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos 269cdf0e10cSrcweir : ( !bBack && m_nCurPos < m_pHistory->Count() - 1 ) 270cdf0e10cSrcweir ? ++m_nCurPos 271cdf0e10cSrcweir : ULONG_MAX; 272cdf0e10cSrcweir 273cdf0e10cSrcweir if ( nPos < ULONG_MAX ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir HelpHistoryEntry_Impl* pEntry = m_pHistory->GetObject( nPos ); 276cdf0e10cSrcweir if ( pEntry ) 277cdf0e10cSrcweir m_pWindow->loadHelpContent(pEntry->aURL, sal_False); // false => dont add item to history again! 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir m_pWindow->UpdateToolbox(); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // ----------------------------------------------------------------------- 286cdf0e10cSrcweir 287cdf0e10cSrcweir void SAL_CALL HelpInterceptor_Impl::addStatusListener( 288cdf0e10cSrcweir const Reference< XStatusListener >& xControl, const URL& ) throw( RuntimeException ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir DBG_ASSERT( !m_xListener.is(), "listener already exists" ); 291cdf0e10cSrcweir m_xListener = xControl; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir // ----------------------------------------------------------------------- 295cdf0e10cSrcweir 296cdf0e10cSrcweir void SAL_CALL HelpInterceptor_Impl::removeStatusListener( 297cdf0e10cSrcweir const Reference< XStatusListener >&, const URL&) throw( RuntimeException ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir m_xListener = 0; 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir // HelpListener_Impl ----------------------------------------------------- 303cdf0e10cSrcweir 304cdf0e10cSrcweir HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl* pInter ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir pInterceptor = pInter; 307cdf0e10cSrcweir pInterceptor->addStatusListener( this, ::com::sun::star::util::URL() ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir // ----------------------------------------------------------------------- 311cdf0e10cSrcweir 312cdf0e10cSrcweir void SAL_CALL HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) 313cdf0e10cSrcweir 314cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ) 315cdf0e10cSrcweir 316cdf0e10cSrcweir { 317cdf0e10cSrcweir INetURLObject aObj( Event.FeatureURL.Complete ); 318cdf0e10cSrcweir aFactory = aObj.GetHost(); 319cdf0e10cSrcweir aChangeLink.Call( this ); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir // ----------------------------------------------------------------------- 323cdf0e10cSrcweir 324cdf0e10cSrcweir void SAL_CALL HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject& ) 325cdf0e10cSrcweir 326cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException ) 327cdf0e10cSrcweir 328cdf0e10cSrcweir { 329cdf0e10cSrcweir pInterceptor->removeStatusListener( this, ::com::sun::star::util::URL() ); 330cdf0e10cSrcweir pInterceptor = NULL; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir /*-- 05.09.2002 12:17:59--------------------------------------------------- 333cdf0e10cSrcweir 334cdf0e10cSrcweir -----------------------------------------------------------------------*/ 335cdf0e10cSrcweir HelpStatusListener_Impl::HelpStatusListener_Impl( 336cdf0e10cSrcweir Reference < XDispatch > aDispatch, URL& rURL) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir aDispatch->addStatusListener(this, rURL); 339cdf0e10cSrcweir } 340cdf0e10cSrcweir /*-- 05.09.2002 12:17:59--------------------------------------------------- 341cdf0e10cSrcweir 342cdf0e10cSrcweir -----------------------------------------------------------------------*/ 343cdf0e10cSrcweir HelpStatusListener_Impl::~HelpStatusListener_Impl() 344cdf0e10cSrcweir { 345cdf0e10cSrcweir if(xDispatch.is()) 346cdf0e10cSrcweir xDispatch->removeStatusListener(this, com::sun::star::util::URL()); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir /*-- 05.09.2002 12:17:59--------------------------------------------------- 349cdf0e10cSrcweir 350cdf0e10cSrcweir -----------------------------------------------------------------------*/ 351cdf0e10cSrcweir void HelpStatusListener_Impl::statusChanged( 352cdf0e10cSrcweir const FeatureStateEvent& rEvent ) throw( RuntimeException ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir aStateEvent = rEvent; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir /*-- 05.09.2002 12:18:00--------------------------------------------------- 357cdf0e10cSrcweir 358cdf0e10cSrcweir -----------------------------------------------------------------------*/ 359cdf0e10cSrcweir void HelpStatusListener_Impl::disposing( const EventObject& ) throw( RuntimeException ) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir xDispatch->removeStatusListener(this, com::sun::star::util::URL()); 362cdf0e10cSrcweir xDispatch = 0; 363cdf0e10cSrcweir } 364