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

Generated by: LCOV version 1.10