LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/control - msgpool.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 120 52.5 %
Date: 2013-07-09 Functions: 11 15 73.3 %
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 <tools/stream.hxx>
      21             : #include <rsc/rscsfx.hxx>
      22             : 
      23             : // due to pSlotPool
      24             : #include "appdata.hxx"
      25             : #include <sfx2/msgpool.hxx>
      26             : #include <sfx2/msg.hxx>
      27             : #include <sfx2/app.hxx>
      28             : #include <sfx2/objface.hxx>
      29             : #include "sfxtypes.hxx"
      30             : #include "sfx2/sfxresid.hxx"
      31             : #include "arrdecl.hxx"
      32             : #include <sfx2/module.hxx>
      33             : 
      34             : #include <sfx2/sfx.hrc>
      35             : 
      36         215 : SfxSlotPool::SfxSlotPool( SfxSlotPool *pParent, ResMgr* pResManager )
      37             :  : _pGroups(0)
      38             :  , _pParentPool( pParent )
      39             :  , _pResMgr( pResManager )
      40             :  , _pInterfaces(0)
      41             :  , _nCurGroup(0)
      42             :  , _nCurInterface(0)
      43         215 :  , _nCurMsg(0)
      44             : {
      45         215 :     if ( !_pResMgr )
      46         133 :         _pResMgr = SfxApplication::GetOrCreate()->GetOffResManager_Impl();
      47         215 : }
      48             : 
      49             : //====================================================================
      50             : 
      51         122 : SfxSlotPool::~SfxSlotPool()
      52             : {
      53         122 :     _pParentPool = 0;
      54        1542 :     for ( SfxInterface *pIF = FirstInterface(); pIF; pIF = FirstInterface() )
      55        1420 :         delete pIF;
      56         122 :     delete _pInterfaces;
      57         122 :     delete _pGroups;
      58         122 : }
      59             : 
      60             : //====================================================================
      61             : // registers the availability of the Interface of functions
      62             : 
      63        2627 : void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
      64             : {
      65             :     // add to the list of SfxObjectInterface instances
      66        2627 :     if ( _pInterfaces == NULL )
      67         215 :         _pInterfaces = new SfxInterfaceArr_Impl;
      68        2627 :     _pInterfaces->push_back(&rInterface);
      69             : 
      70             :     // Stop at a (single) Null-slot (for syntactic reasons the interfaces
      71             :     // always contain at least one slot)
      72        2627 :     if ( rInterface.Count() != 0 && !rInterface[0]->nSlotId )
      73        3066 :         return;
      74             : 
      75             :     // possibly add Interface-id and group-ids of funcs to the list of groups
      76        2188 :     if ( !_pGroups )
      77             :     {
      78         215 :         _pGroups = new SfxSlotGroupArr_Impl;
      79             : 
      80         215 :         if ( _pParentPool )
      81             :         {
      82             :             // The Groups in parent Slotpool are also known here
      83          82 :             _pGroups->append( *_pParentPool->_pGroups );
      84             :         }
      85             :     }
      86             : 
      87      140242 :     for ( size_t nFunc = 0; nFunc < rInterface.Count(); ++nFunc )
      88             :     {
      89      138054 :         SfxSlot *pDef = rInterface[nFunc];
      90      272569 :         if ( pDef->GetGroupId() && /* pDef->GetGroupId() != GID_INTERN && */
      91      134515 :              _pGroups->find(pDef->GetGroupId()) == SfxSlotGroupArr_Impl::npos )
      92             :         {
      93        2531 :             if (pDef->GetGroupId() == GID_INTERN)
      94         133 :                 _pGroups->insert(_pGroups->begin(), pDef->GetGroupId());
      95             :             else
      96        2398 :                 _pGroups->push_back(pDef->GetGroupId());
      97             :         }
      98             :     }
      99             : }
     100             : 
     101             : //====================================================================
     102             : 
     103       43288 : TypeId SfxSlotPool::GetSlotType( sal_uInt16 nId ) const
     104             : {
     105       43288 :     const SfxSlot* pSlot = (const_cast <SfxSlotPool*> (this))->GetSlot( nId );
     106       43288 :     return pSlot ? pSlot->GetType()->Type() : 0;
     107             : }
     108             : 
     109             : //====================================================================
     110             : // unregisters the availability of the Interface of functions
     111             : 
     112        1420 : void SfxSlotPool::ReleaseInterface( SfxInterface& rInterface )
     113             : {
     114             :     DBG_ASSERT( _pInterfaces, "releasing SfxInterface, but there are none" );
     115             :     // remove from the list of SfxInterface instances
     116        1420 :     SfxInterfaceArr_Impl::iterator i = std::find(_pInterfaces->begin(), _pInterfaces->end(), &rInterface);
     117        1420 :     if(i != _pInterfaces->end())
     118        1420 :         _pInterfaces->erase(i);
     119        1420 : }
     120             : 
     121             : // get the first SfxMessage for a special Id (e.g. for getting check-mode)
     122             : 
     123      234275 : const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId )
     124             : {
     125             :     DBG_ASSERT( _pInterfaces != NULL, "no Interfaces registered" );
     126             : 
     127             :     // First, search their own interfaces
     128     2682312 :     for ( sal_uInt16 nInterf = 0; nInterf < _pInterfaces->size(); ++nInterf )
     129             :     {
     130     2617685 :         const SfxSlot *pDef = ((*_pInterfaces)[nInterf])->GetSlot(nId);
     131     2617685 :         if ( pDef )
     132      169648 :             return pDef;
     133             :     }
     134             : 
     135             :     // Then try any of the possible existing parent
     136       64627 :     return _pParentPool ? _pParentPool->GetSlot( nId ) : 0;
     137             : }
     138             : 
     139             : //--------------------------------------------------------------------
     140             : 
     141             : // skips to the next group
     142             : 
     143           0 : String SfxSlotPool::SeekGroup( sal_uInt16 nNo )
     144             : {
     145             :     DBG_ASSERT( _pInterfaces != NULL, "no Interfaces registered" );
     146             : 
     147             :     // if the group exists, use it
     148           0 :     if ( _pGroups && nNo < _pGroups->size() )
     149             :     {
     150           0 :         _nCurGroup = nNo;
     151           0 :         if ( _pParentPool )
     152             :         {
     153             :             // In most cases, the order of the IDs agree
     154           0 :             sal_uInt16 nParentCount = _pParentPool->_pGroups->size();
     155           0 :             if ( nNo < nParentCount && (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[nNo] )
     156           0 :                 _pParentPool->_nCurGroup = nNo;
     157             :             else
     158             :             {
     159             :                 // Otherwise search. If the group is not found in the parent
     160             :                 // pool, _nCurGroup is set outside the valid range
     161             :                 sal_uInt16 i;
     162           0 :                 for ( i=1; i<nParentCount; i++ )
     163           0 :                     if ( (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[i] )
     164           0 :                         break;
     165           0 :                 _pParentPool->_nCurGroup = i;
     166             :             }
     167             :         }
     168             : 
     169           0 :         SfxResId aResId( (*_pGroups)[_nCurGroup] );
     170           0 :         aResId.SetRT(RSC_STRING);
     171           0 :         if ( !aResId.GetResMgr()->IsAvailable(aResId) )
     172             :         {
     173             :             OSL_FAIL( "GroupId-Name not defined in SFX!" );
     174           0 :             return OUString();
     175             :         }
     176             : 
     177           0 :         return aResId.toString();
     178             :     }
     179             : 
     180           0 :     return OUString();
     181             : }
     182             : 
     183             : 
     184             : //--------------------------------------------------------------------
     185             : 
     186           0 : sal_uInt16 SfxSlotPool::GetGroupCount()
     187             : {
     188           0 :     return _pGroups->size();
     189             : }
     190             : 
     191             : 
     192             : //--------------------------------------------------------------------
     193             : 
     194             : // internal search loop
     195             : 
     196           0 : const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface )
     197             : {
     198             :     DBG_ASSERT( _pInterfaces != NULL, "no Interfaces registered" );
     199             : 
     200             :     // The numbering starts at the interfaces of the parent pool
     201           0 :     sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
     202             : 
     203             :     // have reached the end of the Parent-Pools?
     204           0 :     if ( nStartInterface < nFirstInterface &&
     205           0 :          _pParentPool->_nCurGroup >= _pParentPool->_pGroups->size() )
     206           0 :         nStartInterface = nFirstInterface;
     207             : 
     208             :     // Is the Interface still in the Parent-Pool?
     209           0 :     if ( nStartInterface < nFirstInterface )
     210             :     {
     211             :         DBG_ASSERT( _pParentPool, "No parent pool!" );
     212           0 :         _nCurInterface = nStartInterface;
     213           0 :         return _pParentPool->SeekSlot( nStartInterface );
     214             :     }
     215             : 
     216             :     // find the first func-def with the current group id
     217           0 :     sal_uInt16 nCount = _pInterfaces->size() + nFirstInterface;
     218           0 :     for ( _nCurInterface = nStartInterface;
     219           0 :             _nCurInterface < nCount;
     220             :           ++_nCurInterface )
     221             :     {
     222           0 :         SfxInterface* pInterface = (*_pInterfaces)[_nCurInterface-nFirstInterface];
     223           0 :         for ( _nCurMsg = 0;
     224           0 :               _nCurMsg < pInterface->Count();
     225             :               ++_nCurMsg )
     226             :         {
     227           0 :             const SfxSlot* pMsg = (*pInterface)[_nCurMsg];
     228           0 :             if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) )
     229           0 :                 return pMsg;
     230             :         }
     231             :     }
     232             : 
     233           0 :     return 0;
     234             : }
     235             : 
     236             : //--------------------------------------------------------------------
     237             : // skips to the next func in the current group
     238             : 
     239           0 : const SfxSlot* SfxSlotPool::NextSlot()
     240             : {
     241             :     DBG_ASSERT( _pInterfaces != NULL, "no Interfaces registered" );
     242             : 
     243             :     // The numbering starts at the interfaces of the parent pool
     244           0 :     sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
     245             : 
     246           0 :     if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->size() )
     247           0 :         _nCurInterface = nFirstInterface;
     248             : 
     249           0 :     if ( _nCurInterface < nFirstInterface )
     250             :     {
     251             :         DBG_ASSERT( _pParentPool, "No parent pool!" );
     252           0 :         const SfxSlot *pSlot = _pParentPool->NextSlot();
     253           0 :         _nCurInterface = _pParentPool->_nCurInterface;
     254           0 :         if ( pSlot )
     255           0 :             return pSlot;
     256           0 :         if ( _nCurInterface == nFirstInterface )
     257             :             // parent pool is ready
     258           0 :             return SeekSlot( nFirstInterface );
     259             :     }
     260             : 
     261           0 :     sal_uInt16 nInterface = _nCurInterface - nFirstInterface;
     262             :     // possibly we are already at the end
     263           0 :     if ( nInterface >= _pInterfaces->size() )
     264           0 :         return 0;
     265             : 
     266             :     // look for further matching func-defs within the same Interface
     267           0 :     SfxInterface* pInterface = (*_pInterfaces)[nInterface];
     268           0 :     while ( ++_nCurMsg < pInterface->Count() )
     269             :     {
     270           0 :         SfxSlot* pMsg = (*pInterface)[_nCurMsg];
     271           0 :         if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) )
     272           0 :             return pMsg;
     273             :     }
     274             : 
     275           0 :     return SeekSlot(++_nCurInterface );
     276             : }
     277             : 
     278             : 
     279             : //--------------------------------------------------------------------
     280             : // Query SlotName with help text
     281             : //--------------------------------------------------------------------
     282             : 
     283        1542 : SfxInterface* SfxSlotPool::FirstInterface()
     284             : {
     285        1542 :     _nCurInterface = 0;
     286        1542 :     if ( !_pInterfaces || !_pInterfaces->size() )
     287         122 :         return 0;
     288        1420 :     return _pParentPool ? _pParentPool->FirstInterface() : (*_pInterfaces)[0];
     289             : }
     290             : 
     291             : 
     292             : //--------------------------------------------------------------------
     293             : 
     294      245349 : const SfxSlot* SfxSlotPool::GetUnoSlot( const String& rName )
     295             : {
     296      245349 :     const SfxSlot *pSlot = NULL;
     297     2034502 :     for ( sal_uInt16 nInterface=0; nInterface<_pInterfaces->size(); ++nInterface )
     298             :     {
     299     2012405 :         pSlot = (*_pInterfaces)[nInterface]->GetSlot( rName );
     300     2012405 :         if ( pSlot )
     301      223252 :             break;
     302             :     }
     303             : 
     304      245349 :     if ( !pSlot && _pParentPool )
     305       17881 :         pSlot = _pParentPool->GetUnoSlot( rName );
     306             : 
     307      245349 :     return pSlot;
     308             : }
     309             : 
     310      215286 : SfxSlotPool& SfxSlotPool::GetSlotPool( SfxViewFrame *pFrame )
     311             : {
     312      215286 :     SfxModule *pMod = SfxModule::GetActiveModule( pFrame );
     313      215286 :     if ( pMod && pMod->GetSlotPool() )
     314      195245 :         return *pMod->GetSlotPool();
     315             :     else
     316       20041 :         return *SFX_APP()->Get_Impl()->pSlotPool;
     317         408 : }
     318             : 
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10