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

Generated by: LCOV version 1.10