LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/appl - helpinterceptor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 133 0.8 %
Date: 2013-07-09 Functions: 2 27 7.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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>
      31             : #include <limits.h>
      32             : 
      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;
      38             : 
      39             : extern void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark ); // sfxhelp.cxx
      40             : 
      41             : // class HelpInterceptor_Impl --------------------------------------------
      42             : 
      43           0 : HelpInterceptor_Impl::HelpInterceptor_Impl() :
      44             : 
      45             :     m_pHistory  ( NULL ),
      46             :     m_pWindow  ( NULL ),
      47           0 :     m_nCurPos   ( 0 )
      48             : 
      49             : {
      50           0 : }
      51             : 
      52             : // -----------------------------------------------------------------------
      53             : 
      54           0 : HelpInterceptor_Impl::~HelpInterceptor_Impl()
      55             : {
      56           0 :     if ( m_pHistory )
      57             :     {
      58           0 :         for ( size_t i = 0, n = m_pHistory->size(); i < n; ++i )
      59           0 :             delete m_pHistory->at( i );
      60           0 :         delete m_pHistory;
      61             :     }
      62           0 : }
      63             : 
      64             : // -----------------------------------------------------------------------
      65             : 
      66           0 : void HelpInterceptor_Impl::addURL( const String& rURL )
      67             : {
      68           0 :   if ( !m_pHistory )
      69           0 :         m_pHistory = new HelpHistoryList_Impl;
      70             : 
      71           0 :     size_t nCount = m_pHistory->size();
      72           0 :     if ( nCount && m_nCurPos < ( nCount - 1 ) )
      73             :     {
      74           0 :         for ( size_t i = nCount - 1; i > m_nCurPos; i-- )
      75             :         {
      76           0 :             delete m_pHistory->at( i );
      77           0 :             HelpHistoryList_Impl::iterator it = m_pHistory->begin();
      78           0 :             ::std::advance( it, i );
      79           0 :             m_pHistory->erase( it );
      80             :         }
      81             :     }
      82           0 :     Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
      83           0 :     Reference<XController> xController;
      84           0 :     if(xFrame.is())
      85           0 :         xController = xFrame->getController();
      86           0 :     Any aViewData;
      87           0 :     if(xController.is() && !m_pHistory->empty())
      88             :     {
      89           0 :         m_pHistory->at( m_nCurPos )->aViewData = xController->getViewData();
      90             :     }
      91             : 
      92           0 :     m_aCurrentURL = rURL;
      93           0 :     Any aEmptyViewData;
      94           0 :     m_pHistory->push_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) );
      95           0 :     m_nCurPos = m_pHistory->size() - 1;
      96             : // TODO ?
      97           0 :     if ( m_xListener.is() )
      98             :     {
      99           0 :         ::com::sun::star::frame::FeatureStateEvent aEvent;
     100           0 :         URL aURL;
     101           0 :         aURL.Complete = rURL;
     102           0 :         aEvent.FeatureURL = aURL;
     103           0 :         aEvent.Source = (::com::sun::star::frame::XDispatch*)this;
     104           0 :         m_xListener->statusChanged( aEvent );
     105             :     }
     106             : 
     107           0 :     m_pWindow->UpdateToolbox();
     108           0 : }
     109             : 
     110             : // -----------------------------------------------------------------------
     111             : 
     112           0 : void HelpInterceptor_Impl::setInterception( Reference< XFrame > xFrame )
     113             : {
     114           0 :     m_xIntercepted = Reference< XDispatchProviderInterception>( xFrame, UNO_QUERY );
     115             : 
     116           0 :     if ( m_xIntercepted.is() )
     117           0 :         m_xIntercepted->registerDispatchProviderInterceptor( (XDispatchProviderInterceptor*)this );
     118           0 : }
     119             : 
     120             : // -----------------------------------------------------------------------
     121             : 
     122           0 : sal_Bool HelpInterceptor_Impl::HasHistoryPred() const
     123             : {
     124           0 :     return m_pHistory && ( m_nCurPos > 0 );
     125             : }
     126             : 
     127           0 : sal_Bool HelpInterceptor_Impl::HasHistorySucc() const
     128             : {
     129           0 :     return m_pHistory && ( m_nCurPos < ( m_pHistory->size() - 1 ) );
     130             : }
     131             : 
     132             : 
     133             : // -----------------------------------------------------------------------
     134             : // XDispatchProvider
     135             : 
     136           0 : Reference< XDispatch > SAL_CALL HelpInterceptor_Impl::queryDispatch(
     137             : 
     138             :     const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
     139             : 
     140             :     throw( RuntimeException )
     141             : 
     142             : {
     143           0 :     Reference< XDispatch > xResult;
     144           0 :     if ( m_xSlaveDispatcher.is() )
     145           0 :         xResult = m_xSlaveDispatcher->queryDispatch( aURL, aTargetFrameName, nSearchFlags );
     146             : 
     147           0 :     sal_Bool bHelpURL = aURL.Complete.toAsciiLowerCase().match("vnd.sun.star.help",0);
     148             : 
     149           0 :     if ( bHelpURL )
     150             :     {
     151             :         DBG_ASSERT( xResult.is(), "invalid dispatch" );
     152           0 :         HelpDispatch_Impl* pHelpDispatch = new HelpDispatch_Impl( *this, xResult );
     153           0 :         xResult = Reference< XDispatch >( static_cast< ::cppu::OWeakObject* >(pHelpDispatch), UNO_QUERY );
     154             :     }
     155             : 
     156           0 :     return xResult;
     157             : }
     158             : 
     159             : // -----------------------------------------------------------------------
     160             : 
     161           0 : Sequence < Reference < XDispatch > > SAL_CALL HelpInterceptor_Impl::queryDispatches(
     162             : 
     163             :     const Sequence< DispatchDescriptor >& aDescripts )
     164             : 
     165             :     throw( RuntimeException )
     166             : 
     167             : {
     168           0 :     Sequence< Reference< XDispatch > > aReturn( aDescripts.getLength() );
     169           0 :     Reference< XDispatch >* pReturn = aReturn.getArray();
     170           0 :     const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
     171           0 :     for ( sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
     172             :     {
     173           0 :         *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
     174             :     }
     175           0 :     return aReturn;
     176             : }
     177             : 
     178             : // -----------------------------------------------------------------------
     179             : // XDispatchProviderInterceptor
     180             : 
     181           0 : Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getSlaveDispatchProvider()
     182             : 
     183             :     throw( RuntimeException )
     184             : 
     185             : {
     186           0 :     return m_xSlaveDispatcher;
     187             : }
     188             : 
     189             : // -----------------------------------------------------------------------
     190             : 
     191           0 : void SAL_CALL HelpInterceptor_Impl::setSlaveDispatchProvider( const Reference< XDispatchProvider >& xNewSlave )
     192             : 
     193             :     throw( RuntimeException )
     194             : 
     195             : {
     196           0 :     m_xSlaveDispatcher = xNewSlave;
     197           0 : }
     198             : 
     199             : // -----------------------------------------------------------------------
     200             : 
     201           0 : Reference< XDispatchProvider > SAL_CALL HelpInterceptor_Impl::getMasterDispatchProvider()
     202             : 
     203             :     throw( RuntimeException )
     204             : 
     205             : {
     206           0 :     return m_xMasterDispatcher;
     207             : }
     208             : 
     209             : // -----------------------------------------------------------------------
     210             : 
     211           0 : void SAL_CALL HelpInterceptor_Impl::setMasterDispatchProvider( const Reference< XDispatchProvider >& xNewMaster )
     212             : 
     213             :     throw( RuntimeException )
     214             : 
     215             : {
     216           0 :     m_xMasterDispatcher = xNewMaster;
     217           0 : }
     218             : 
     219             : // -----------------------------------------------------------------------
     220             : // XInterceptorInfo
     221             : 
     222           0 : Sequence< OUString > SAL_CALL HelpInterceptor_Impl::getInterceptedURLs()
     223             : 
     224             :     throw( RuntimeException )
     225             : 
     226             : {
     227           0 :     Sequence< OUString > aURLList( 1 );
     228           0 :     aURLList[0] = "vnd.sun.star.help://*";
     229           0 :     return aURLList;
     230             : }
     231             : 
     232             : // -----------------------------------------------------------------------
     233             : // XDispatch
     234             : 
     235           0 : void SAL_CALL HelpInterceptor_Impl::dispatch(
     236             :     const URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue >& ) throw( RuntimeException )
     237             : {
     238           0 :     sal_Bool bBack = ( String( ".uno:Backward" ) == String( aURL.Complete ) );
     239           0 :     if ( bBack || String( ".uno:Forward" ) == String( aURL.Complete ) )
     240             :     {
     241           0 :         if ( m_pHistory )
     242             :         {
     243           0 :             if(m_pHistory->size() > m_nCurPos)
     244             :             {
     245           0 :                 Reference<XFrame> xFrame(m_xIntercepted, UNO_QUERY);
     246           0 :                 Reference<XController> xController;
     247           0 :                 if(xFrame.is())
     248           0 :                     xController = xFrame->getController();
     249           0 :                 if(xController.is())
     250             :                 {
     251           0 :                     m_pHistory->at( m_nCurPos )->aViewData = xController->getViewData();
     252           0 :                 }
     253             :             }
     254             : 
     255           0 :             sal_uIntPtr nPos = ( bBack && m_nCurPos > 0 ) ? --m_nCurPos
     256           0 :                                                     : ( !bBack && m_nCurPos < m_pHistory->size() - 1 )
     257             :                                                     ? ++m_nCurPos
     258           0 :                                                     : ULONG_MAX;
     259             : 
     260           0 :             if ( nPos < ULONG_MAX )
     261             :             {
     262           0 :                 HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos );
     263           0 :                 if ( pEntry )
     264           0 :                     m_pWindow->loadHelpContent(pEntry->aURL, sal_False); // false => dont add item to history again!
     265             :             }
     266             : 
     267           0 :             m_pWindow->UpdateToolbox();
     268             :         }
     269             :     }
     270           0 : }
     271             : 
     272             : // -----------------------------------------------------------------------
     273             : 
     274           0 : void SAL_CALL HelpInterceptor_Impl::addStatusListener(
     275             :     const Reference< XStatusListener >& xControl, const URL& ) throw( RuntimeException )
     276             : {
     277             :     DBG_ASSERT( !m_xListener.is(), "listener already exists" );
     278           0 :     m_xListener = xControl;
     279           0 : }
     280             : 
     281             : // -----------------------------------------------------------------------
     282             : 
     283           0 : void SAL_CALL HelpInterceptor_Impl::removeStatusListener(
     284             :     const Reference< XStatusListener >&, const URL&) throw( RuntimeException )
     285             : {
     286           0 :     m_xListener = 0;
     287           0 : }
     288             : 
     289             : // HelpListener_Impl -----------------------------------------------------
     290             : 
     291           0 : HelpListener_Impl::HelpListener_Impl( HelpInterceptor_Impl* pInter )
     292             : {
     293           0 :     pInterceptor = pInter;
     294           0 :     pInterceptor->addStatusListener( this, ::com::sun::star::util::URL() );
     295           0 : }
     296             : 
     297             : // -----------------------------------------------------------------------
     298             : 
     299           0 : void SAL_CALL HelpListener_Impl::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
     300             : 
     301             :     throw( ::com::sun::star::uno::RuntimeException )
     302             : 
     303             : {
     304           0 :     INetURLObject aObj( Event.FeatureURL.Complete );
     305           0 :     aFactory = aObj.GetHost();
     306           0 :     aChangeLink.Call( this );
     307           0 : }
     308             : 
     309             : // -----------------------------------------------------------------------
     310             : 
     311           0 : void SAL_CALL HelpListener_Impl::disposing( const ::com::sun::star::lang::EventObject& )
     312             : 
     313             :     throw( ::com::sun::star::uno::RuntimeException )
     314             : 
     315             : {
     316           0 :     pInterceptor->removeStatusListener( this, ::com::sun::star::util::URL() );
     317           0 :     pInterceptor = NULL;
     318           0 : }
     319             : 
     320           0 : HelpStatusListener_Impl::HelpStatusListener_Impl(
     321           0 :         Reference < XDispatch > aDispatch, URL& rURL)
     322             : {
     323           0 :     aDispatch->addStatusListener(this, rURL);
     324           0 : }
     325             : 
     326           0 : HelpStatusListener_Impl::~HelpStatusListener_Impl()
     327             : {
     328           0 :     if(xDispatch.is())
     329           0 :         xDispatch->removeStatusListener(this, com::sun::star::util::URL());
     330           0 : }
     331             : 
     332           0 : void HelpStatusListener_Impl::statusChanged(
     333             :     const FeatureStateEvent& rEvent ) throw( RuntimeException )
     334             : {
     335           0 :     aStateEvent = rEvent;
     336           0 : }
     337             : 
     338           0 : void HelpStatusListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
     339             : {
     340           0 :     xDispatch->removeStatusListener(this, com::sun::star::util::URL());
     341           0 :     xDispatch = 0;
     342         408 : }
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10