LCOV - code coverage report
Current view: top level - forms/source/helper - formnavigation.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 186 0.0 %
Date: 2014-04-14 Functions: 0 30 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             : #include "formnavigation.hxx"
      21             : #include "urltransformer.hxx"
      22             : #include "controlfeatureinterception.hxx"
      23             : #include "frm_strings.hxx"
      24             : 
      25             : #include <com/sun/star/form/runtime/FormFeature.hpp>
      26             : 
      27             : #include <tools/debug.hxx>
      28             : 
      29             : 
      30             : 
      31             : namespace frm
      32             : {
      33             : 
      34             : 
      35             :     using namespace ::com::sun::star::uno;
      36             :     using namespace ::com::sun::star::beans;
      37             :     using namespace ::com::sun::star::lang;
      38             :     using namespace ::com::sun::star::util;
      39             :     using namespace ::com::sun::star::frame;
      40             :     namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
      41             : 
      42             : 
      43             :     //= OFormNavigationHelper
      44             : 
      45             : 
      46           0 :     OFormNavigationHelper::OFormNavigationHelper( const Reference< XComponentContext >& _rxORB )
      47             :         :m_xORB( _rxORB )
      48           0 :         ,m_nConnectedFeatures( 0 )
      49             :     {
      50           0 :         m_pFeatureInterception.reset( new ControlFeatureInterception( m_xORB ) );
      51           0 :     }
      52             : 
      53             : 
      54           0 :     OFormNavigationHelper::~OFormNavigationHelper()
      55             :     {
      56           0 :     }
      57             : 
      58             : 
      59           0 :     void SAL_CALL OFormNavigationHelper::dispose( ) throw( RuntimeException )
      60             :     {
      61           0 :         m_pFeatureInterception->dispose();
      62           0 :         disconnectDispatchers();
      63           0 :     }
      64             : 
      65             : 
      66           0 :     void OFormNavigationHelper::interceptorsChanged( )
      67             :     {
      68           0 :         updateDispatches();
      69           0 :     }
      70             : 
      71             : 
      72           0 :     void OFormNavigationHelper::featureStateChanged( sal_Int16 /*_nFeatureId*/, sal_Bool /*_bEnabled*/ )
      73             :     {
      74             :         // not interested in
      75           0 :     }
      76             : 
      77             : 
      78           0 :     void OFormNavigationHelper::allFeatureStatesChanged( )
      79             :     {
      80             :         // not interested in
      81           0 :     }
      82             : 
      83             : 
      84           0 :     void SAL_CALL OFormNavigationHelper::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException, std::exception)
      85             :     {
      86           0 :         m_pFeatureInterception->registerDispatchProviderInterceptor( _rxInterceptor );
      87           0 :         interceptorsChanged();
      88           0 :     }
      89             : 
      90             : 
      91           0 :     void SAL_CALL OFormNavigationHelper::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException, std::exception)
      92             :     {
      93           0 :         m_pFeatureInterception->releaseDispatchProviderInterceptor( _rxInterceptor );
      94           0 :         interceptorsChanged();
      95           0 :     }
      96             : 
      97             : 
      98           0 :     void SAL_CALL OFormNavigationHelper::statusChanged( const FeatureStateEvent& _rState ) throw (RuntimeException, std::exception)
      99             :     {
     100           0 :         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
     101           0 :                 aFeature != m_aSupportedFeatures.end();
     102             :                 ++aFeature
     103             :             )
     104             :         {
     105           0 :             if ( aFeature->second.aURL.Main == _rState.FeatureURL.Main )
     106             :             {
     107           0 :                 if  (  ( aFeature->second.bCachedState != _rState.IsEnabled )
     108           0 :                     || ( aFeature->second.aCachedAdditionalState != _rState.State )
     109             :                     )
     110             :                 {
     111             :                     // change the cached state
     112           0 :                     aFeature->second.bCachedState           = _rState.IsEnabled;
     113           0 :                     aFeature->second.aCachedAdditionalState = _rState.State;
     114             :                     // tell derivees what happened
     115           0 :                     featureStateChanged( aFeature->first, _rState.IsEnabled );
     116             :                 }
     117           0 :                 return;
     118             :             }
     119             :         }
     120             : 
     121             :         // unreachable
     122             :         OSL_FAIL( "OFormNavigationHelper::statusChanged: huh? An invalid/unknown URL?" );
     123             :     }
     124             : 
     125             : 
     126           0 :     void SAL_CALL OFormNavigationHelper::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
     127             :     {
     128             :         // was it one of our external dispatchers?
     129           0 :         if ( m_nConnectedFeatures )
     130             :         {
     131           0 :             for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
     132           0 :                     aFeature != m_aSupportedFeatures.end();
     133             :                     ++aFeature
     134             :                 )
     135             :             {
     136           0 :                 if ( aFeature->second.xDispatcher == _rSource.Source )
     137             :                 {
     138           0 :                     aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
     139           0 :                     aFeature->second.xDispatcher = NULL;
     140           0 :                     aFeature->second.bCachedState = sal_False;
     141           0 :                     aFeature->second.aCachedAdditionalState.clear();
     142           0 :                     --m_nConnectedFeatures;
     143             : 
     144           0 :                     featureStateChanged( aFeature->first, sal_False );
     145           0 :                     break;
     146             :                 }
     147             :             }
     148             :         }
     149           0 :     }
     150             : 
     151             : 
     152           0 :     void OFormNavigationHelper::updateDispatches()
     153             :     {
     154           0 :         if ( !m_nConnectedFeatures )
     155             :         {   // we don't have any dispatchers yet -> do the initial connect
     156           0 :             connectDispatchers();
     157           0 :             return;
     158             :         }
     159             : 
     160           0 :         initializeSupportedFeatures();
     161             : 
     162           0 :         m_nConnectedFeatures = 0;
     163             : 
     164           0 :         Reference< XDispatch >  xNewDispatcher;
     165           0 :         Reference< XDispatch >  xCurrentDispatcher;
     166             : 
     167           0 :         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
     168           0 :                 aFeature != m_aSupportedFeatures.end();
     169             :                 ++aFeature
     170             :             )
     171             :         {
     172           0 :             xNewDispatcher = queryDispatch( aFeature->second.aURL );
     173           0 :             xCurrentDispatcher = aFeature->second.xDispatcher;
     174           0 :             if ( xNewDispatcher != xCurrentDispatcher )
     175             :             {
     176             :                 // the dispatcher for this particular URL changed
     177           0 :                 if ( xCurrentDispatcher.is() )
     178           0 :                     xCurrentDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
     179             : 
     180           0 :                 xCurrentDispatcher = aFeature->second.xDispatcher = xNewDispatcher;
     181             : 
     182           0 :                 if ( xCurrentDispatcher.is() )
     183           0 :                     xCurrentDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
     184             :             }
     185             : 
     186           0 :             if ( xCurrentDispatcher.is() )
     187           0 :                 ++m_nConnectedFeatures;
     188             :             else
     189           0 :                 aFeature->second.bCachedState = sal_False;
     190             :         }
     191             : 
     192             :         // notify derivee that (potentially) all features changed their state
     193           0 :         allFeatureStatesChanged( );
     194             :     }
     195             : 
     196             : 
     197           0 :     void OFormNavigationHelper::connectDispatchers()
     198             :     {
     199           0 :         if ( m_nConnectedFeatures )
     200             :         {   // already connected -> just do an update
     201           0 :             updateDispatches();
     202           0 :             return;
     203             :         }
     204             : 
     205           0 :         initializeSupportedFeatures();
     206             : 
     207           0 :         m_nConnectedFeatures = 0;
     208             : 
     209           0 :         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
     210           0 :                 aFeature != m_aSupportedFeatures.end();
     211             :                 ++aFeature
     212             :             )
     213             :         {
     214           0 :             aFeature->second.bCachedState = sal_False;
     215           0 :             aFeature->second.aCachedAdditionalState.clear();
     216           0 :             aFeature->second.xDispatcher = queryDispatch( aFeature->second.aURL );
     217           0 :             if ( aFeature->second.xDispatcher.is() )
     218             :             {
     219           0 :                 ++m_nConnectedFeatures;
     220           0 :                 aFeature->second.xDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
     221             :             }
     222             :         }
     223             : 
     224             :         // notify derivee that (potentially) all features changed their state
     225           0 :         allFeatureStatesChanged( );
     226             :     }
     227             : 
     228             : 
     229           0 :     void OFormNavigationHelper::disconnectDispatchers()
     230             :     {
     231           0 :         if ( m_nConnectedFeatures )
     232             :         {
     233           0 :             for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
     234           0 :                     aFeature != m_aSupportedFeatures.end();
     235             :                     ++aFeature
     236             :                 )
     237             :             {
     238           0 :                 if ( aFeature->second.xDispatcher.is() )
     239           0 :                     aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
     240             : 
     241           0 :                 aFeature->second.xDispatcher = NULL;
     242           0 :                 aFeature->second.bCachedState = sal_False;
     243           0 :                 aFeature->second.aCachedAdditionalState.clear();
     244             :             }
     245             : 
     246           0 :             m_nConnectedFeatures = 0;
     247             :         }
     248             : 
     249             :         // notify derivee that (potentially) all features changed their state
     250           0 :         allFeatureStatesChanged( );
     251           0 :     }
     252             : 
     253             : 
     254           0 :     void OFormNavigationHelper::initializeSupportedFeatures( )
     255             :     {
     256           0 :         if ( m_aSupportedFeatures.empty() )
     257             :         {
     258             :             // ask the derivee which feature ids it wants us to support
     259           0 :             ::std::vector< sal_Int16 > aFeatureIds;
     260           0 :             getSupportedFeatures( aFeatureIds );
     261             : 
     262           0 :             OFormNavigationMapper aUrlMapper( m_xORB );
     263             : 
     264           0 :             for (   ::std::vector< sal_Int16 >::const_iterator aLoop = aFeatureIds.begin();
     265           0 :                     aLoop != aFeatureIds.end();
     266             :                     ++aLoop
     267             :                 )
     268             :             {
     269           0 :                 FeatureInfo aFeatureInfo;
     270             : 
     271             :                 bool bKnownId =
     272           0 :                     aUrlMapper.getFeatureURL( *aLoop, aFeatureInfo.aURL );
     273             :                 DBG_ASSERT( bKnownId, "OFormNavigationHelper::initializeSupportedFeatures: unknown feature id!" );
     274             : 
     275           0 :                 if ( bKnownId )
     276             :                     // add to our map
     277           0 :                     m_aSupportedFeatures.insert( FeatureMap::value_type( *aLoop, aFeatureInfo ) );
     278           0 :             }
     279             :         }
     280           0 :     }
     281             : 
     282             : 
     283           0 :     Reference< XDispatch > OFormNavigationHelper::queryDispatch( const URL& _rURL )
     284             :     {
     285           0 :         return m_pFeatureInterception->queryDispatch( _rURL );
     286             :     }
     287             : 
     288             : 
     289           0 :     void OFormNavigationHelper::dispatchWithArgument( sal_Int16 _nFeatureId, const sal_Char* _pParamAsciiName,
     290             :         const Any& _rParamValue ) const
     291             :     {
     292           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     293           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     294             :         {
     295           0 :             if ( aInfo->second.xDispatcher.is() )
     296             :             {
     297           0 :                 Sequence< PropertyValue > aArgs( 1 );
     298           0 :                 aArgs[0].Name = OUString::createFromAscii( _pParamAsciiName );
     299           0 :                 aArgs[0].Value = _rParamValue;
     300             : 
     301           0 :                 aInfo->second.xDispatcher->dispatch( aInfo->second.aURL, aArgs );
     302             :             }
     303             :         }
     304           0 :     }
     305             : 
     306             : 
     307           0 :     void OFormNavigationHelper::dispatch( sal_Int16 _nFeatureId ) const
     308             :     {
     309           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     310           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     311             :         {
     312           0 :             if ( aInfo->second.xDispatcher.is() )
     313             :             {
     314           0 :                 Sequence< PropertyValue > aEmptyArgs;
     315           0 :                 aInfo->second.xDispatcher->dispatch( aInfo->second.aURL, aEmptyArgs );
     316             :             }
     317             :         }
     318           0 :     }
     319             : 
     320             : 
     321           0 :     bool OFormNavigationHelper::isEnabled( sal_Int16 _nFeatureId ) const
     322             :     {
     323           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     324           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     325           0 :             return aInfo->second.bCachedState;
     326             : 
     327           0 :         return false;
     328             :     }
     329             : 
     330             : 
     331           0 :     bool OFormNavigationHelper::getBooleanState( sal_Int16 _nFeatureId ) const
     332             :     {
     333           0 :         sal_Bool bState = sal_False;
     334             : 
     335           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     336           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     337           0 :             aInfo->second.aCachedAdditionalState >>= bState;
     338             : 
     339           0 :         return (bool)bState;
     340             :     }
     341             : 
     342             : 
     343           0 :     OUString OFormNavigationHelper::getStringState( sal_Int16 _nFeatureId ) const
     344             :     {
     345           0 :         OUString sState;
     346             : 
     347           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     348           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     349           0 :             aInfo->second.aCachedAdditionalState >>= sState;
     350             : 
     351           0 :         return sState;
     352             :     }
     353             : 
     354             : 
     355           0 :     sal_Int32 OFormNavigationHelper::getIntegerState( sal_Int16 _nFeatureId ) const
     356             :     {
     357           0 :         sal_Int32 nState = 0;
     358             : 
     359           0 :         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
     360           0 :         if ( m_aSupportedFeatures.end() != aInfo )
     361           0 :             aInfo->second.aCachedAdditionalState >>= nState;
     362             : 
     363           0 :         return nState;
     364             :     }
     365             : 
     366             : 
     367           0 :     void OFormNavigationHelper::invalidateSupportedFeaturesSet()
     368             :     {
     369           0 :         disconnectDispatchers( );
     370             :         // no supported features anymore:
     371           0 :         FeatureMap aEmpty;
     372           0 :         m_aSupportedFeatures.swap( aEmpty );
     373           0 :     }
     374             : 
     375             : 
     376             :     //= OFormNavigationMapper
     377             : 
     378             : 
     379           0 :     OFormNavigationMapper::OFormNavigationMapper( const Reference< XComponentContext >& _rxORB )
     380             :     {
     381           0 :         m_pUrlTransformer.reset( new UrlTransformer( _rxORB ) );
     382           0 :     }
     383             : 
     384             : 
     385           0 :     OFormNavigationMapper::~OFormNavigationMapper( )
     386             :     {
     387           0 :     }
     388             : 
     389             : 
     390           0 :     bool OFormNavigationMapper::getFeatureURL( sal_Int16 _nFeatureId, URL& /* [out] */ _rURL )
     391             :     {
     392             :         // get the ascii version of the URL
     393           0 :         const char* pAsciiURL = getFeatureURLAscii( _nFeatureId );
     394           0 :         if ( pAsciiURL )
     395           0 :             _rURL = m_pUrlTransformer->getStrictURLFromAscii( pAsciiURL );
     396             : 
     397           0 :         return ( pAsciiURL != NULL );
     398             :     }
     399             : 
     400             : 
     401             :     namespace
     402             :     {
     403             :         struct FeatureURL
     404             :         {
     405             :             const sal_Int16 nFormFeature;
     406             :             const sal_Char* pAsciiURL;
     407             : 
     408           0 :             FeatureURL( const sal_Int16 _nFormFeature, const sal_Char* _pAsciiURL )
     409             :                 :nFormFeature( _nFormFeature )
     410           0 :                 ,pAsciiURL( _pAsciiURL )
     411             :             {
     412           0 :             }
     413             :         };
     414           0 :         const FeatureURL* lcl_getFeatureTable()
     415             :         {
     416             :             static const FeatureURL s_aFeatureURLs[] =
     417             :             {
     418             :                 FeatureURL( FormFeature::MoveAbsolute,            URL_FORM_POSITION ),
     419             :                 FeatureURL( FormFeature::TotalRecords,            URL_FORM_RECORDCOUNT ),
     420             :                 FeatureURL( FormFeature::MoveToFirst,             URL_RECORD_FIRST ),
     421             :                 FeatureURL( FormFeature::MoveToPrevious,          URL_RECORD_PREV ),
     422             :                 FeatureURL( FormFeature::MoveToNext,              URL_RECORD_NEXT ),
     423             :                 FeatureURL( FormFeature::MoveToLast,              URL_RECORD_LAST ),
     424             :                 FeatureURL( FormFeature::SaveRecordChanges,       URL_RECORD_SAVE ),
     425             :                 FeatureURL( FormFeature::UndoRecordChanges,       URL_RECORD_UNDO ),
     426             :                 FeatureURL( FormFeature::MoveToInsertRow,         URL_RECORD_NEW ),
     427             :                 FeatureURL( FormFeature::DeleteRecord,            URL_RECORD_DELETE ),
     428             :                 FeatureURL( FormFeature::ReloadForm,              URL_FORM_REFRESH ),
     429             :                 FeatureURL( FormFeature::RefreshCurrentControl,   URL_FORM_REFRESH_CURRENT_CONTROL ),
     430             :                 FeatureURL( FormFeature::SortAscending,           URL_FORM_SORT_UP ),
     431             :                 FeatureURL( FormFeature::SortDescending,          URL_FORM_SORT_DOWN ),
     432             :                 FeatureURL( FormFeature::InteractiveSort,         URL_FORM_SORT ),
     433             :                 FeatureURL( FormFeature::AutoFilter,              URL_FORM_AUTO_FILTER ),
     434             :                 FeatureURL( FormFeature::InteractiveFilter,       URL_FORM_FILTER ),
     435             :                 FeatureURL( FormFeature::ToggleApplyFilter,       URL_FORM_APPLY_FILTER ),
     436             :                 FeatureURL( FormFeature::RemoveFilterAndSort,     URL_FORM_REMOVE_FILTER ),
     437             :                 FeatureURL( 0, NULL )
     438           0 :             };
     439           0 :             return s_aFeatureURLs;
     440             :         }
     441             :     }
     442             : 
     443             : 
     444           0 :     const char* OFormNavigationMapper::getFeatureURLAscii( sal_Int16 _nFeatureId )
     445             :     {
     446           0 :         const FeatureURL* pFeatures = lcl_getFeatureTable();
     447           0 :         while ( pFeatures->pAsciiURL )
     448             :         {
     449           0 :             if ( pFeatures->nFormFeature == _nFeatureId )
     450           0 :                 return pFeatures->pAsciiURL;
     451           0 :             ++pFeatures;
     452             :         }
     453           0 :         return NULL;
     454             :     }
     455             : 
     456             : 
     457           0 :     sal_Int16 OFormNavigationMapper::getFeatureId( const OUString& _rCompleteURL )
     458             :     {
     459           0 :         const FeatureURL* pFeatures = lcl_getFeatureTable();
     460           0 :         while ( pFeatures->pAsciiURL )
     461             :         {
     462           0 :             if ( _rCompleteURL.equalsAscii( pFeatures->pAsciiURL ) )
     463           0 :                 return pFeatures->nFormFeature;
     464           0 :             ++pFeatures;
     465             :         }
     466           0 :         return -1;
     467             :     }
     468             : 
     469             : 
     470             : }   // namespace frm
     471             : 
     472             : 
     473             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10