LCOV - code coverage report
Current view: top level - sfx2/source/control - msgpool.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 126 50.8 %
Date: 2014-04-11 Functions: 9 13 69.2 %
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         239 : 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         239 :  , _nCurMsg(0)
      44             : {
      45         239 :     if ( !_pResMgr )
      46         143 :         _pResMgr = SfxApplication::GetOrCreate()->GetOffResManager_Impl();
      47         239 : }
      48             : 
      49             : 
      50             : 
      51         123 : SfxSlotPool::~SfxSlotPool()
      52             : {
      53         123 :     _pParentPool = 0;
      54        1499 :     for ( SfxInterface *pIF = FirstInterface(); pIF; pIF = FirstInterface() )
      55        1376 :         delete pIF;
      56         123 :     delete _pInterfaces;
      57         123 :     delete _pGroups;
      58         123 : }
      59             : 
      60             : 
      61             : // registers the availability of the Interface of functions
      62             : 
      63        2913 : void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
      64             : {
      65             :     // add to the list of SfxObjectInterface instances
      66        2913 :     if ( _pInterfaces == NULL )
      67         239 :         _pInterfaces = new SfxInterfaceArr_Impl;
      68        2913 :     _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        2913 :     if ( rInterface.Count() != 0 && !rInterface[0]->nSlotId )
      73        3380 :         return;
      74             : 
      75             :     // possibly add Interface-id and group-ids of funcs to the list of groups
      76        2446 :     if ( !_pGroups )
      77             :     {
      78         239 :         _pGroups = new SfxSlotGroupArr_Impl;
      79             : 
      80         239 :         if ( _pParentPool )
      81             :         {
      82             :             // The Groups in parent Slotpool are also known here
      83          96 :             _pGroups->append( *_pParentPool->_pGroups );
      84             :         }
      85             :     }
      86             : 
      87      163707 :     for ( size_t nFunc = 0; nFunc < rInterface.Count(); ++nFunc )
      88             :     {
      89      161261 :         SfxSlot *pDef = rInterface[nFunc];
      90      318712 :         if ( pDef->GetGroupId() && /* pDef->GetGroupId() != GID_INTERN && */
      91      157451 :              _pGroups->find(pDef->GetGroupId()) == SfxSlotGroupArr_Impl::npos )
      92             :         {
      93        2772 :             if (pDef->GetGroupId() == GID_INTERN)
      94         143 :                 _pGroups->insert(_pGroups->begin(), pDef->GetGroupId());
      95             :             else
      96        2629 :                 _pGroups->push_back(pDef->GetGroupId());
      97             :         }
      98             :     }
      99             : }
     100             : 
     101             : 
     102             : 
     103       46287 : TypeId SfxSlotPool::GetSlotType( sal_uInt16 nId ) const
     104             : {
     105       46287 :     const SfxSlot* pSlot = (const_cast <SfxSlotPool*> (this))->GetSlot( nId );
     106       46287 :     return pSlot ? pSlot->GetType()->Type() : 0;
     107             : }
     108             : 
     109             : 
     110             : // unregisters the availability of the Interface of functions
     111             : 
     112        1376 : void SfxSlotPool::ReleaseInterface( SfxInterface& rInterface )
     113             : {
     114             :     SAL_WARN_IF(!_pInterfaces, "sfx.control", "releasing SfxInterface, but there are none");
     115        1376 :     if (!_pInterfaces)
     116        1376 :         return ;
     117             : 
     118             :     // remove from the list of SfxInterface instances
     119        1376 :     SfxInterfaceArr_Impl::iterator i = std::find(_pInterfaces->begin(), _pInterfaces->end(), &rInterface);
     120        1376 :     if(i != _pInterfaces->end())
     121        1376 :         _pInterfaces->erase(i);
     122             : }
     123             : 
     124             : // get the first SfxMessage for a special Id (e.g. for getting check-mode)
     125             : 
     126      361097 : const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId )
     127             : {
     128             :     SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
     129      361097 :     if (!_pInterfaces)
     130           0 :         return 0;
     131             : 
     132             :     // First, search their own interfaces
     133     4311408 :     for ( sal_uInt16 nInterf = 0; nInterf < _pInterfaces->size(); ++nInterf )
     134             :     {
     135     4208355 :         const SfxSlot *pDef = ((*_pInterfaces)[nInterf])->GetSlot(nId);
     136     4208355 :         if ( pDef )
     137      258044 :             return pDef;
     138             :     }
     139             : 
     140             :     // Then try any of the possible existing parent
     141      103053 :     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 ( !aResId.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        1499 : SfxInterface* SfxSlotPool::FirstInterface()
     293             : {
     294        1499 :     _nCurInterface = 0;
     295        1499 :     if ( !_pInterfaces || !_pInterfaces->size() )
     296         123 :         return 0;
     297        1376 :     return _pParentPool ? _pParentPool->FirstInterface() : (*_pInterfaces)[0];
     298             : }
     299             : 
     300             : 
     301             : 
     302             : 
     303      255670 : const SfxSlot* SfxSlotPool::GetUnoSlot( const OUString& rName )
     304             : {
     305      255670 :     const SfxSlot *pSlot = NULL;
     306     2103111 :     for (sal_uInt16 nInterface = 0; _pInterfaces && nInterface < _pInterfaces->size(); ++nInterface)
     307             :     {
     308     2080517 :         pSlot = (*_pInterfaces)[nInterface]->GetSlot( rName );
     309     2080517 :         if ( pSlot )
     310      233076 :             break;
     311             :     }
     312             : 
     313      255670 :     if ( !pSlot && _pParentPool )
     314       18270 :         pSlot = _pParentPool->GetUnoSlot( rName );
     315             : 
     316      255670 :     return pSlot;
     317             : }
     318             : 
     319      242456 : SfxSlotPool& SfxSlotPool::GetSlotPool( SfxViewFrame *pFrame )
     320             : {
     321      242456 :     SfxModule *pMod = SfxModule::GetActiveModule( pFrame );
     322      242456 :     if ( pMod && pMod->GetSlotPool() )
     323      205360 :         return *pMod->GetSlotPool();
     324             :     else
     325       37096 :         return *SFX_APP()->Get_Impl()->pSlotPool;
     326             : }
     327             : 
     328             : 
     329             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10