1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdlib.h> 32*cdf0e10cSrcweir #include <tools/rcid.h> 33*cdf0e10cSrcweir #ifndef GCC 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir #include <tools/stream.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <sfx2/module.hxx> 38*cdf0e10cSrcweir #include <sfx2/objface.hxx> 39*cdf0e10cSrcweir #include <sfx2/msg.hxx> 40*cdf0e10cSrcweir #include <sfx2/app.hxx> 41*cdf0e10cSrcweir #include <sfx2/msgpool.hxx> 42*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 43*cdf0e10cSrcweir #include <sfx2/minarray.hxx> 44*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir DBG_NAME(SfxInterface) 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //==================================================================== 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir EXTERN_C 51*cdf0e10cSrcweir #if defined( PM2 ) && (!defined( CSET ) && !defined ( MTW ) && !defined( WTC )) 52*cdf0e10cSrcweir int _stdcall 53*cdf0e10cSrcweir #else 54*cdf0e10cSrcweir #ifdef WNT 55*cdf0e10cSrcweir int _cdecl 56*cdf0e10cSrcweir #else 57*cdf0e10cSrcweir int 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir #endif 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir SfxCompareSlots_Impl( const void* pSmaller, const void* pBigger ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir DBG_MEMTEST(); 64*cdf0e10cSrcweir return ( (int) ((SfxSlot*)pSmaller)->GetSlotId() ) - 65*cdf0e10cSrcweir ( (int) ((SfxSlot*)pBigger)->GetSlotId() ); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //========================================================================= 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir struct SfxObjectUI_Impl 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir sal_uInt16 nPos; 73*cdf0e10cSrcweir ResId aResId; 74*cdf0e10cSrcweir sal_Bool bVisible; 75*cdf0e10cSrcweir sal_Bool bContext; 76*cdf0e10cSrcweir String* pName; 77*cdf0e10cSrcweir sal_uInt32 nFeature; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir SfxObjectUI_Impl(sal_uInt16 n, const ResId& rResId, sal_Bool bVis, sal_uInt32 nFeat) : 80*cdf0e10cSrcweir nPos(n), 81*cdf0e10cSrcweir aResId(rResId.GetId(), *rResId.GetResMgr()), 82*cdf0e10cSrcweir bVisible(bVis), 83*cdf0e10cSrcweir bContext(sal_False), 84*cdf0e10cSrcweir pName(0), 85*cdf0e10cSrcweir nFeature(nFeat) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir aResId.SetRT(rResId.GetRT()); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir ~SfxObjectUI_Impl() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir delete pName; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir DECL_PTRARRAY(SfxObjectUIArr_Impl, SfxObjectUI_Impl*, 2, 2) 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir struct SfxInterface_Impl 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir SfxObjectUIArr_Impl* pObjectBars; // registered ObjectBars 101*cdf0e10cSrcweir SfxObjectUIArr_Impl* pChildWindows; // registered ChildWindows 102*cdf0e10cSrcweir ResId aPopupRes; // registered PopupMenu 103*cdf0e10cSrcweir ResId aStatBarRes; // registered StatusBar 104*cdf0e10cSrcweir SfxModule* pModule; 105*cdf0e10cSrcweir sal_Bool bRegistered; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir SfxInterface_Impl() : 108*cdf0e10cSrcweir aPopupRes(0,*SfxApplication::GetOrCreate()->GetSfxResManager()), 109*cdf0e10cSrcweir aStatBarRes(0,*SfxApplication::GetOrCreate()->GetSfxResManager()) 110*cdf0e10cSrcweir , bRegistered(sal_False) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir pObjectBars = new SfxObjectUIArr_Impl; 113*cdf0e10cSrcweir pChildWindows = new SfxObjectUIArr_Impl; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir ~SfxInterface_Impl() 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir sal_uInt16 n; 119*cdf0e10cSrcweir for (n=0; n<pObjectBars->Count(); n++) 120*cdf0e10cSrcweir delete (*pObjectBars)[n]; 121*cdf0e10cSrcweir delete pObjectBars; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir for (n=0; n<pChildWindows->Count(); n++) 124*cdf0e10cSrcweir delete (*pChildWindows)[n]; 125*cdf0e10cSrcweir delete pChildWindows; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir }; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir static SfxObjectUI_Impl* CreateObjectBarUI_Impl( sal_uInt16 nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir //==================================================================== 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //==================================================================== 134*cdf0e10cSrcweir // ctor, registeres a new unit 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir SfxInterface::SfxInterface( const char *pClassName, 137*cdf0e10cSrcweir const ResId& rNameResId, 138*cdf0e10cSrcweir SfxInterfaceId nId, 139*cdf0e10cSrcweir const SfxInterface* pParent, 140*cdf0e10cSrcweir SfxSlot &rSlotMap, sal_uInt16 nSlotCount ): 141*cdf0e10cSrcweir pName(pClassName), 142*cdf0e10cSrcweir pGenoType(pParent), 143*cdf0e10cSrcweir nClassId(nId), 144*cdf0e10cSrcweir aNameResId(rNameResId.GetId(),*rNameResId.GetResMgr()), 145*cdf0e10cSrcweir pImpData(0) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir pImpData = new SfxInterface_Impl; 148*cdf0e10cSrcweir SetSlotMap( rSlotMap, nSlotCount ); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir void SfxInterface::Register( SfxModule* pMod ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir pImpData->bRegistered = sal_True; 154*cdf0e10cSrcweir pImpData->pModule = pMod; 155*cdf0e10cSrcweir if ( pMod ) 156*cdf0e10cSrcweir pMod->GetSlotPool()->RegisterInterface(*this); 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir SFX_APP()->GetAppSlotPool_Impl().RegisterInterface(*this); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir void SfxInterface::SetSlotMap( SfxSlot& rSlotMap, sal_uInt16 nSlotCount ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir pSlots = &rSlotMap; 164*cdf0e10cSrcweir nCount = nSlotCount; 165*cdf0e10cSrcweir SfxSlot* pIter = pSlots; 166*cdf0e10cSrcweir if ( 1 == nCount && !pIter->pNextSlot ) 167*cdf0e10cSrcweir pIter->pNextSlot = pIter; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if ( !pIter->pNextSlot ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir // sort the SfxSlots by id 172*cdf0e10cSrcweir qsort( pSlots, nCount, sizeof(SfxSlot), SfxCompareSlots_Impl ); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // link masters and slaves 175*cdf0e10cSrcweir sal_uInt16 nIter = 1; 176*cdf0e10cSrcweir for ( pIter = pSlots; nIter <= nCount; ++pIter, ++nIter ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir //! hier bitte sinnvoll pruefen 179*cdf0e10cSrcweir //! DBG_ASSERT(!(pIter->IsMode(SFX_SLOT_CACHABLE) && 180*cdf0e10cSrcweir //! pIter->IsMode(SFX_SLOT_VOLATILE)), 181*cdf0e10cSrcweir //! "invalid Flags" ); 182*cdf0e10cSrcweir DBG_ASSERT( nIter == nCount || 183*cdf0e10cSrcweir pIter->GetSlotId() != (pIter+1)->GetSlotId(), 184*cdf0e10cSrcweir "doppelte SID" ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // jeder Master verweist auf seinen ersten Slave (ENUM), alle 187*cdf0e10cSrcweir // Slaves auf ihren Master. 188*cdf0e10cSrcweir // Slaves verweisen im Ring auf die anderen mit gleichem Master 189*cdf0e10cSrcweir if ( pIter->GetKind() == SFX_KIND_ENUM ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir pIter->pLinkedSlot = GetSlot( pIter->nMasterSlotId ); 192*cdf0e10cSrcweir DBG_ASSERT( pIter->pLinkedSlot, "slave without master" ); 193*cdf0e10cSrcweir if ( !pIter->pLinkedSlot->pLinkedSlot ) 194*cdf0e10cSrcweir ( (SfxSlot*) pIter->pLinkedSlot)->pLinkedSlot = pIter; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if ( 0 == pIter->GetNextSlot() ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir SfxSlot *pLastSlot = pIter; 199*cdf0e10cSrcweir for ( sal_uInt16 n = nIter; n < Count(); ++n ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir SfxSlot *pCurSlot = (pSlots+n); 202*cdf0e10cSrcweir if ( pCurSlot->nMasterSlotId == pIter->nMasterSlotId ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir pLastSlot->pNextSlot = pCurSlot; 205*cdf0e10cSrcweir pLastSlot = pCurSlot; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir pLastSlot->pNextSlot = pIter; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir else if ( 0 == pIter->GetNextSlot() ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir // Slots verweisen im Ring auf den n"achten mit derselben Statusmethode 214*cdf0e10cSrcweir SfxSlot *pLastSlot = pIter; 215*cdf0e10cSrcweir for ( sal_uInt16 n = nIter; n < Count(); ++n ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir SfxSlot *pCurSlot = (pSlots+n); 218*cdf0e10cSrcweir if ( pCurSlot->GetStateFnc() == pIter->GetStateFnc() ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir pLastSlot->pNextSlot = pCurSlot; 221*cdf0e10cSrcweir pLastSlot = pCurSlot; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir pLastSlot->pNextSlot = pIter; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir #ifdef DBG_UTIL 229*cdf0e10cSrcweir else 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir sal_uInt16 nIter = 1; 232*cdf0e10cSrcweir for ( SfxSlot *pNext = pIter+1; nIter < nCount; ++pNext, ++nIter ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir if ( pNext->GetSlotId() <= pIter->GetSlotId() ) 236*cdf0e10cSrcweir DBG_ERROR ("Falsche Reihenfolge!"); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir if ( pIter->GetKind() == SFX_KIND_ENUM ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir const SfxSlot *pMasterSlot = GetSlot(pIter->nMasterSlotId); 241*cdf0e10cSrcweir const SfxSlot *pFirstSlave = pMasterSlot->pLinkedSlot; 242*cdf0e10cSrcweir const SfxSlot *pSlave = pFirstSlave; 243*cdf0e10cSrcweir do 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir if ( pSlave->pLinkedSlot != pMasterSlot ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir ByteString aStr("Falsche Master/Slave-Verkettung : "); 248*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pMasterSlot->GetSlotId()); 249*cdf0e10cSrcweir aStr += " , "; 250*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pSlave->GetSlotId()); 251*cdf0e10cSrcweir DBG_ERROR(aStr.GetBuffer()); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir if ( pSlave->nMasterSlotId != pMasterSlot->GetSlotId() ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir ByteString aStr("Falsche Master/Slave-Ids : "); 257*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pMasterSlot->GetSlotId()); 258*cdf0e10cSrcweir aStr += " , "; 259*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pSlave->GetSlotId()); 260*cdf0e10cSrcweir DBG_ERROR(aStr.GetBuffer()); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir pSlave = pSlave->pNextSlot; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir while ( pSlave != pFirstSlave ); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir else 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir if ( pIter->pLinkedSlot ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir if ( pIter->pLinkedSlot->GetKind() != SFX_KIND_ENUM ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir ByteString aStr("Slave ist kein enum : "); 274*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pIter->GetSlotId()); 275*cdf0e10cSrcweir aStr += " , "; 276*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pIter->pLinkedSlot->GetSlotId()); 277*cdf0e10cSrcweir DBG_ERROR(aStr.GetBuffer()); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir const SfxSlot *pCurSlot = pIter; 282*cdf0e10cSrcweir do 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir pCurSlot = pCurSlot->pNextSlot; 285*cdf0e10cSrcweir if ( pCurSlot->GetStateFnc() != pIter->GetStateFnc() ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir ByteString aStr("Verkettete Slots mit verschiedenen StateMethods : "); 288*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pCurSlot->GetSlotId()); 289*cdf0e10cSrcweir aStr += " , "; 290*cdf0e10cSrcweir aStr += ByteString::CreateFromInt32(pIter->GetSlotId()); 291*cdf0e10cSrcweir DBG_ERROR(aStr.GetBuffer()); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir while ( pCurSlot != pIter ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir pIter = pNext; 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir #endif 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //-------------------------------------------------------------------- 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir SfxInterface::~SfxInterface() 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir SfxModule *pMod = pImpData->pModule; 311*cdf0e10cSrcweir sal_Bool bRegistered = pImpData->bRegistered; 312*cdf0e10cSrcweir delete pImpData; 313*cdf0e10cSrcweir DBG_ASSERT( bRegistered, "Interface not registered!" ); 314*cdf0e10cSrcweir if ( bRegistered ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir if ( pMod ) 317*cdf0e10cSrcweir pMod->GetSlotPool()->ReleaseInterface(*this); 318*cdf0e10cSrcweir else 319*cdf0e10cSrcweir SFX_APP()->GetAppSlotPool_Impl().ReleaseInterface(*this); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir //-------------------------------------------------------------------- 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // searches for the specified func 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir const SfxSlot* SfxInterface::GetSlot( sal_uInt16 nFuncId ) const 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir DBG_MEMTEST(); 331*cdf0e10cSrcweir DBG_CHKTHIS(SfxInterface, 0); 332*cdf0e10cSrcweir DBG_ASSERT( this && pSlots && nCount, "" ); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir // find the id using binary search 335*cdf0e10cSrcweir void* p = bsearch( &nFuncId, pSlots, nCount, sizeof(SfxSlot), 336*cdf0e10cSrcweir SfxCompareSlots_Impl ); 337*cdf0e10cSrcweir if ( !p && pGenoType ) 338*cdf0e10cSrcweir return pGenoType->GetSlot( nFuncId ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir return p ? (const SfxSlot*)p : 0; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir const SfxSlot* SfxInterface::GetSlot( const String& rCommand ) const 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir static const char UNO_COMMAND[] = ".uno:"; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir String aCommand( rCommand ); 348*cdf0e10cSrcweir if ( aCommand.SearchAscii( UNO_COMMAND ) == 0 ) 349*cdf0e10cSrcweir aCommand.Erase( 0, sizeof( UNO_COMMAND )-1 ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nCount; n++ ) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir if ( (pSlots+n)->pUnoName && 354*cdf0e10cSrcweir aCommand.CompareIgnoreCaseToAscii( (pSlots+n)->GetUnoName() ) == COMPARE_EQUAL ) 355*cdf0e10cSrcweir return pSlots+n; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir return pGenoType ? pGenoType->GetSlot( aCommand ) : NULL; 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //-------------------------------------------------------------------- 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir const SfxSlot* SfxInterface::GetRealSlot( const SfxSlot *pSlot ) const 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir DBG_MEMTEST(); 367*cdf0e10cSrcweir DBG_CHKTHIS(SfxInterface, 0); 368*cdf0e10cSrcweir DBG_ASSERT( this && pSlots && nCount, "" ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir if ( !ContainsSlot_Impl(pSlot) ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir if(pGenoType) 373*cdf0e10cSrcweir return pGenoType->GetRealSlot(pSlot); 374*cdf0e10cSrcweir DBG_ERROR("fremder Slot"); 375*cdf0e10cSrcweir return 0; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir return pSlot->pLinkedSlot; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir //-------------------------------------------------------------------- 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir const SfxSlot* SfxInterface::GetRealSlot( sal_uInt16 nSlotId ) const 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir DBG_MEMTEST(); 387*cdf0e10cSrcweir DBG_CHKTHIS(SfxInterface, 0); 388*cdf0e10cSrcweir DBG_ASSERT( this && pSlots && nCount, "" ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir const SfxSlot *pSlot = GetSlot(nSlotId); 391*cdf0e10cSrcweir if ( !pSlot ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir if(pGenoType) 394*cdf0e10cSrcweir return pGenoType->GetRealSlot(nSlotId); 395*cdf0e10cSrcweir DBG_ERROR("fremder Slot"); 396*cdf0e10cSrcweir return 0; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir return pSlot->pLinkedSlot; 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir //-------------------------------------------------------------------- 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir void SfxInterface::RegisterPopupMenu( const ResId& rResId ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir DBG_CHKTHIS(SfxInterface, 0); 408*cdf0e10cSrcweir pImpData->aPopupRes = rResId; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir //-------------------------------------------------------------------- 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir void SfxInterface::RegisterObjectBar( sal_uInt16 nPos, const ResId& rResId, 414*cdf0e10cSrcweir const String *pStr ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir RegisterObjectBar( nPos, rResId, 0UL, pStr ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void SfxInterface::RegisterObjectBar( sal_uInt16 nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir SfxObjectUI_Impl* pUI = CreateObjectBarUI_Impl( nPos, rResId, nFeature, pStr ); 423*cdf0e10cSrcweir if ( pUI ) 424*cdf0e10cSrcweir pImpData->pObjectBars->Append(pUI); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir SfxObjectUI_Impl* CreateObjectBarUI_Impl( sal_uInt16 nPos, const ResId& rResId, sal_uInt32 nFeature, const String *pStr ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir if ((nPos & SFX_VISIBILITY_MASK) == 0) 430*cdf0e10cSrcweir nPos |= SFX_VISIBILITY_STANDARD; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(nPos, rResId, sal_True, nFeature); 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if (pStr == 0) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir ResId aResId(rResId); 437*cdf0e10cSrcweir aResId.SetRT(RSC_STRING); 438*cdf0e10cSrcweir aResId.SetResMgr(rResId.GetResMgr()); 439*cdf0e10cSrcweir if( ! aResId.GetResMgr() ) 440*cdf0e10cSrcweir aResId.SetResMgr( SfxApplication::GetOrCreate()->GetOffResManager_Impl() ); 441*cdf0e10cSrcweir if ( !aResId.GetResMgr()->IsAvailable(aResId) ) 442*cdf0e10cSrcweir pUI->pName = new String (DEFINE_CONST_UNICODE("NoName")); 443*cdf0e10cSrcweir else 444*cdf0e10cSrcweir pUI->pName = new String(aResId); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir else 447*cdf0e10cSrcweir pUI->pName = new String(*pStr); 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir return pUI; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir const ResId& SfxInterface::GetObjectBarResId( sal_uInt16 nNo ) const 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir sal_Bool bGenoType = (pGenoType != 0 && !pGenoType->HasName()); 455*cdf0e10cSrcweir if ( bGenoType ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir // Gibt es Toolbars in der Superklasse ? 458*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount(); 459*cdf0e10cSrcweir if ( nNo < nBaseCount ) 460*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 461*cdf0e10cSrcweir return pGenoType->GetObjectBarResId( nNo ); 462*cdf0e10cSrcweir else 463*cdf0e10cSrcweir nNo = nNo - nBaseCount; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir #ifdef DBG_UTIL 467*cdf0e10cSrcweir sal_uInt16 nObjBarCount = pImpData->pObjectBars->Count(); 468*cdf0e10cSrcweir DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" ); 469*cdf0e10cSrcweir #endif 470*cdf0e10cSrcweir return (*pImpData->pObjectBars)[nNo]->aResId; 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir //-------------------------------------------------------------------- 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir sal_uInt16 SfxInterface::GetObjectBarPos( sal_uInt16 nNo ) const 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir sal_Bool bGenoType = (pGenoType != 0 && !pGenoType->HasName()); 479*cdf0e10cSrcweir if ( bGenoType ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir // Gibt es Toolbars in der Superklasse ? 482*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount(); 483*cdf0e10cSrcweir if ( nNo < nBaseCount ) 484*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 485*cdf0e10cSrcweir return pGenoType->GetObjectBarPos( nNo ); 486*cdf0e10cSrcweir else 487*cdf0e10cSrcweir nNo = nNo - nBaseCount; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir #ifdef DBG_UTIL 491*cdf0e10cSrcweir sal_uInt16 nObjBarCount = pImpData->pObjectBars->Count(); 492*cdf0e10cSrcweir DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" ); 493*cdf0e10cSrcweir #endif 494*cdf0e10cSrcweir return (*pImpData->pObjectBars)[nNo]->nPos; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir //-------------------------------------------------------------------- 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir sal_uInt16 SfxInterface::GetObjectBarCount() const 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir if (pGenoType && ! pGenoType->HasName()) 503*cdf0e10cSrcweir return pImpData->pObjectBars->Count() + pGenoType->GetObjectBarCount(); 504*cdf0e10cSrcweir else 505*cdf0e10cSrcweir return pImpData->pObjectBars->Count(); 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir //-------------------------------------------------------------------- 509*cdf0e10cSrcweir void SfxInterface::RegisterChildWindow(sal_uInt16 nId, sal_Bool bContext, const String* pChildWinName) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir RegisterChildWindow( nId, bContext, 0UL, pChildWinName ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir void SfxInterface::RegisterChildWindow(sal_uInt16 nId, sal_Bool bContext, sal_uInt32 nFeature, const String*) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(0, ResId(nId, *SfxApplication::GetOrCreate()->GetOffResManager_Impl()), sal_True, nFeature); 517*cdf0e10cSrcweir pUI->bContext = bContext; 518*cdf0e10cSrcweir pImpData->pChildWindows->Append(pUI); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir void SfxInterface::RegisterStatusBar(const ResId& rResId) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir pImpData->aStatBarRes = rResId; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir sal_uInt32 SfxInterface::GetChildWindowId (sal_uInt16 nNo) const 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir if ( pGenoType ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir // Gibt es ChildWindows in der Superklasse ? 532*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetChildWindowCount(); 533*cdf0e10cSrcweir if ( nNo < nBaseCount ) 534*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 535*cdf0e10cSrcweir return pGenoType->GetChildWindowId( nNo ); 536*cdf0e10cSrcweir else 537*cdf0e10cSrcweir nNo = nNo - nBaseCount; 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir #ifdef DBG_UTIL 541*cdf0e10cSrcweir sal_uInt16 nCWCount = pImpData->pChildWindows->Count(); 542*cdf0e10cSrcweir DBG_ASSERT( nNo<nCWCount,"ChildWindow ist unbekannt!" ); 543*cdf0e10cSrcweir #endif 544*cdf0e10cSrcweir sal_uInt32 nRet = (*pImpData->pChildWindows)[nNo]->aResId.GetId(); 545*cdf0e10cSrcweir if ( (*pImpData->pChildWindows)[nNo]->bContext ) 546*cdf0e10cSrcweir nRet += sal_uInt32( nClassId ) << 16; 547*cdf0e10cSrcweir return nRet; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir sal_uInt32 SfxInterface::GetChildWindowFeature (sal_uInt16 nNo) const 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir if ( pGenoType ) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir // Gibt es ChildWindows in der Superklasse ? 555*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetChildWindowCount(); 556*cdf0e10cSrcweir if ( nNo < nBaseCount ) 557*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 558*cdf0e10cSrcweir return pGenoType->GetChildWindowFeature( nNo ); 559*cdf0e10cSrcweir else 560*cdf0e10cSrcweir nNo = nNo - nBaseCount; 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir #ifdef DBG_UTIL 564*cdf0e10cSrcweir sal_uInt16 nCWCount = pImpData->pChildWindows->Count(); 565*cdf0e10cSrcweir DBG_ASSERT( nNo<nCWCount,"ChildWindow ist unbekannt!" ); 566*cdf0e10cSrcweir #endif 567*cdf0e10cSrcweir return (*pImpData->pChildWindows)[nNo]->nFeature; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir //-------------------------------------------------------------------- 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir sal_uInt16 SfxInterface::GetChildWindowCount() const 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir if (pGenoType) 576*cdf0e10cSrcweir return pImpData->pChildWindows->Count() + pGenoType->GetChildWindowCount(); 577*cdf0e10cSrcweir else 578*cdf0e10cSrcweir return pImpData->pChildWindows->Count(); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir const ResId& SfxInterface::GetPopupMenuResId() const 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir return pImpData->aPopupRes; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir const ResId& SfxInterface::GetStatusBarResId() const 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir if (pImpData->aStatBarRes.GetId() == 0 && pGenoType) 591*cdf0e10cSrcweir return pGenoType->GetStatusBarResId(); 592*cdf0e10cSrcweir else 593*cdf0e10cSrcweir return pImpData->aStatBarRes; 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir const String* SfxInterface::GetObjectBarName ( sal_uInt16 nNo ) const 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir sal_Bool bGenoType = (pGenoType != 0 && !pGenoType->HasName()); 601*cdf0e10cSrcweir if ( bGenoType ) 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir // Gibt es Toolbars in der Superklasse ? 604*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount(); 605*cdf0e10cSrcweir if ( nNo < nBaseCount ) 606*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 607*cdf0e10cSrcweir return pGenoType->GetObjectBarName( nNo ); 608*cdf0e10cSrcweir else 609*cdf0e10cSrcweir nNo = nNo - nBaseCount; 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir #ifdef DBG_UTIL 613*cdf0e10cSrcweir sal_uInt16 nObjBarCount = pImpData->pObjectBars->Count(); 614*cdf0e10cSrcweir DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" ); 615*cdf0e10cSrcweir #endif 616*cdf0e10cSrcweir return (*pImpData->pObjectBars)[nNo]->pName; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir sal_uInt32 SfxInterface::GetObjectBarFeature ( sal_uInt16 nNo ) const 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir sal_Bool bGenoType = (pGenoType != 0 && !pGenoType->HasName()); 622*cdf0e10cSrcweir if ( bGenoType ) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir // Gibt es Toolbars in der Superklasse ? 625*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount(); 626*cdf0e10cSrcweir if ( nNo < nBaseCount ) 627*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 628*cdf0e10cSrcweir return pGenoType->GetObjectBarFeature( nNo ); 629*cdf0e10cSrcweir else 630*cdf0e10cSrcweir nNo = nNo - nBaseCount; 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir #ifdef DBG_UTIL 634*cdf0e10cSrcweir sal_uInt16 nObjBarCount = pImpData->pObjectBars->Count(); 635*cdf0e10cSrcweir DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" ); 636*cdf0e10cSrcweir #endif 637*cdf0e10cSrcweir return (*pImpData->pObjectBars)[nNo]->nFeature; 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir sal_Bool SfxInterface::IsObjectBarVisible(sal_uInt16 nNo) const 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir sal_Bool bGenoType = (pGenoType != 0 && !pGenoType->HasName()); 643*cdf0e10cSrcweir if ( bGenoType ) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir // Gibt es Toolbars in der Superklasse ? 646*cdf0e10cSrcweir sal_uInt16 nBaseCount = pGenoType->GetObjectBarCount(); 647*cdf0e10cSrcweir if ( nNo < nBaseCount ) 648*cdf0e10cSrcweir // Die der Superklasse kommen zuerst 649*cdf0e10cSrcweir return pGenoType->IsObjectBarVisible( nNo ); 650*cdf0e10cSrcweir else 651*cdf0e10cSrcweir nNo = nNo - nBaseCount; 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir #ifdef DBG_UTIL 655*cdf0e10cSrcweir sal_uInt16 nObjBarCount = pImpData->pObjectBars->Count(); 656*cdf0e10cSrcweir DBG_ASSERT( nNo<nObjBarCount,"Objectbar ist unbekannt!" ); 657*cdf0e10cSrcweir #endif 658*cdf0e10cSrcweir return (*pImpData->pObjectBars)[nNo]->bVisible; 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir const SfxInterface* SfxInterface::GetRealInterfaceForSlot( const SfxSlot *pRealSlot ) const 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir DBG_ASSERT( pImpData->bRegistered, "Interface not registered!" ); 664*cdf0e10cSrcweir const SfxInterface* pInterface = this; 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir // Der Slot k"onnte auch aus dem Interface einer Shell-Basisklasse stammen 667*cdf0e10cSrcweir do 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir const SfxSlot *pLastSlot = (*pInterface)[pInterface->Count()-1]; 670*cdf0e10cSrcweir const SfxSlot *pFirstSlot = (*pInterface)[0]; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir // Ist pInterface der Owner von pRealSlot ? 673*cdf0e10cSrcweir if ( pFirstSlot <= pRealSlot && pRealSlot <= pLastSlot ) 674*cdf0e10cSrcweir break; 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir // Sonst Interface der Superklasse probieren 677*cdf0e10cSrcweir pInterface = pInterface->pGenoType; 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir while ( pInterface ); 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir return pInterface; 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir 686