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

Generated by: LCOV version 1.10