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