1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/stream.hxx>
#include <rsc/rscsfx.hxx>
// due to pSlotPool
#include "appdata.hxx"
#include <sfx2/msgpool.hxx>
#include <sfx2/msg.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objface.hxx>
#include "sfxtypes.hxx"
#include <sfx2/sfxresid.hxx>
#include "arrdecl.hxx"
#include <sfx2/module.hxx>
#include <sfx2/sfx.hrc>
SfxSlotPool::SfxSlotPool(SfxSlotPool *pParent)
: _pGroups(nullptr)
, _pParentPool( pParent )
, _pInterfaces(nullptr)
, _nCurGroup(0)
, _nCurInterface(0)
, _nCurMsg(0)
{
}
SfxSlotPool::~SfxSlotPool()
{
_pParentPool = nullptr;
for ( SfxInterface *pIF = FirstInterface(); pIF; pIF = FirstInterface() )
delete pIF;
delete _pInterfaces;
delete _pGroups;
}
// registers the availability of the Interface of functions
void SfxSlotPool::RegisterInterface( SfxInterface& rInterface )
{
// add to the list of SfxObjectInterface instances
if ( _pInterfaces == nullptr )
_pInterfaces = new SfxInterfaceArr_Impl;
_pInterfaces->push_back(&rInterface);
// Stop at a (single) Null-slot (for syntactic reasons the interfaces
// always contain at least one slot)
if ( rInterface.Count() != 0 && !rInterface[0]->nSlotId )
return;
// possibly add Interface-id and group-ids of funcs to the list of groups
if ( !_pGroups )
{
_pGroups = new SfxSlotGroupArr_Impl;
if ( _pParentPool )
{
// The Groups in parent Slotpool are also known here
_pGroups->append( *_pParentPool->_pGroups );
}
}
for ( size_t nFunc = 0; nFunc < rInterface.Count(); ++nFunc )
{
SfxSlot *pDef = rInterface[nFunc];
if ( pDef->GetGroupId() && /* pDef->GetGroupId() != GID_INTERN && */
_pGroups->find(pDef->GetGroupId()) == SfxSlotGroupArr_Impl::npos )
{
if (pDef->GetGroupId() == GID_INTERN)
_pGroups->insert(_pGroups->begin(), pDef->GetGroupId());
else
_pGroups->push_back(pDef->GetGroupId());
}
}
}
const std::type_info* SfxSlotPool::GetSlotType( sal_uInt16 nId ) const
{
const SfxSlot* pSlot = (const_cast <SfxSlotPool*> (this))->GetSlot( nId );
return pSlot ? pSlot->GetType()->Type() : nullptr;
}
// unregisters the availability of the Interface of functions
void SfxSlotPool::ReleaseInterface( SfxInterface& rInterface )
{
SAL_WARN_IF(!_pInterfaces, "sfx.control", "releasing SfxInterface, but there are none");
if (!_pInterfaces)
return ;
// remove from the list of SfxInterface instances
SfxInterfaceArr_Impl::iterator i = std::find(_pInterfaces->begin(), _pInterfaces->end(), &rInterface);
if(i != _pInterfaces->end())
_pInterfaces->erase(i);
}
// get the first SfxMessage for a special Id (e.g. for getting check-mode)
const SfxSlot* SfxSlotPool::GetSlot( sal_uInt16 nId )
{
SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
if (!_pInterfaces)
return nullptr;
// First, search their own interfaces
for (SfxInterface* _pInterface : *_pInterfaces)
{
const SfxSlot *pDef = _pInterface->GetSlot(nId);
if ( pDef )
return pDef;
}
// Then try any of the possible existing parent
return _pParentPool ? _pParentPool->GetSlot( nId ) : nullptr;
}
// skips to the next group
OUString SfxSlotPool::SeekGroup( sal_uInt16 nNo )
{
SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
// if the group exists, use it
if ( _pGroups && nNo < _pGroups->size() )
{
_nCurGroup = nNo;
if ( _pParentPool )
{
// In most cases, the order of the IDs agree
sal_uInt16 nParentCount = _pParentPool->_pGroups->size();
if ( nNo < nParentCount && (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[nNo] )
_pParentPool->_nCurGroup = nNo;
else
{
// Otherwise search. If the group is not found in the parent
// pool, _nCurGroup is set outside the valid range
sal_uInt16 i;
for ( i=1; i<nParentCount; i++ )
if ( (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[i] )
break;
_pParentPool->_nCurGroup = i;
}
}
SfxResId aResId( (*_pGroups)[_nCurGroup] );
aResId.SetRT(RSC_STRING);
if ( !SfxResId::GetResMgr()->IsAvailable(aResId) )
{
OSL_FAIL( "GroupId-Name not defined in SFX!" );
return OUString();
}
return aResId.toString();
}
return OUString();
}
sal_uInt16 SfxSlotPool::GetGroupCount()
{
return _pGroups->size();
}
// internal search loop
const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface )
{
SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
if (!_pInterfaces)
return nullptr;
// The numbering starts at the interfaces of the parent pool
sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
// have reached the end of the Parent-Pools?
if ( nStartInterface < nFirstInterface &&
_pParentPool->_nCurGroup >= _pParentPool->_pGroups->size() )
nStartInterface = nFirstInterface;
// Is the Interface still in the Parent-Pool?
if ( nStartInterface < nFirstInterface )
{
SAL_WARN_IF(!_pParentPool, "sfx.control", "No parent pool!");
_nCurInterface = nStartInterface;
return _pParentPool->SeekSlot( nStartInterface );
}
// find the first func-def with the current group id
sal_uInt16 nCount = _pInterfaces->size() + nFirstInterface;
for ( _nCurInterface = nStartInterface;
_nCurInterface < nCount;
++_nCurInterface )
{
SfxInterface* pInterface = (*_pInterfaces)[_nCurInterface-nFirstInterface];
for ( _nCurMsg = 0;
_nCurMsg < pInterface->Count();
++_nCurMsg )
{
const SfxSlot* pMsg = (*pInterface)[_nCurMsg];
if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) )
return pMsg;
}
}
return nullptr;
}
// skips to the next func in the current group
const SfxSlot* SfxSlotPool::NextSlot()
{
SAL_WARN_IF(!_pInterfaces, "sfx.control", "no Interfaces registered");
if (!_pInterfaces)
return nullptr;
// The numbering starts at the interfaces of the parent pool
sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->size() : 0;
if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->size() )
_nCurInterface = nFirstInterface;
if ( _nCurInterface < nFirstInterface )
{
SAL_WARN_IF(!_pParentPool, "sfx.control", "No parent pool!");
const SfxSlot *pSlot = _pParentPool->NextSlot();
_nCurInterface = _pParentPool->_nCurInterface;
if ( pSlot )
return pSlot;
if ( _nCurInterface == nFirstInterface )
// parent pool is ready
return SeekSlot( nFirstInterface );
}
sal_uInt16 nInterface = _nCurInterface - nFirstInterface;
// possibly we are already at the end
if ( nInterface >= _pInterfaces->size() )
return nullptr;
// look for further matching func-defs within the same Interface
SfxInterface* pInterface = (*_pInterfaces)[nInterface];
while ( ++_nCurMsg < pInterface->Count() )
{
SfxSlot* pMsg = (*pInterface)[_nCurMsg];
if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) )
return pMsg;
}
return SeekSlot(++_nCurInterface );
}
// Query SlotName with help text
SfxInterface* SfxSlotPool::FirstInterface()
{
_nCurInterface = 0;
if ( !_pInterfaces || !_pInterfaces->size() )
return nullptr;
return _pParentPool ? _pParentPool->FirstInterface() : (*_pInterfaces)[0];
}
const SfxSlot* SfxSlotPool::GetUnoSlot( const OUString& rName )
{
const SfxSlot *pSlot = nullptr;
for (sal_uInt16 nInterface = 0; _pInterfaces && nInterface < _pInterfaces->size(); ++nInterface)
{
pSlot = (*_pInterfaces)[nInterface]->GetSlot( rName );
if ( pSlot )
break;
}
if ( !pSlot && _pParentPool )
pSlot = _pParentPool->GetUnoSlot( rName );
return pSlot;
}
SfxSlotPool& SfxSlotPool::GetSlotPool( SfxViewFrame *pFrame )
{
SfxModule *pMod = SfxModule::GetActiveModule( pFrame );
if ( pMod && pMod->GetSlotPool() )
return *pMod->GetSlotPool();
else
return *SfxGetpApp()->Get_Impl()->pSlotPool;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|