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

Generated by: LCOV version 1.10