xref: /AOO41X/main/basic/source/sbx/sbxarray.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_basic.hxx"
30*cdf0e10cSrcweir #include <tools/stream.hxx>
31*cdf0e10cSrcweir #include <basic/sbx.hxx>
32*cdf0e10cSrcweir #include "runtime.hxx"
33*cdf0e10cSrcweir #include <vector>
34*cdf0e10cSrcweir using namespace std;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir struct SbxDim {                 // eine Array-Dimension:
37*cdf0e10cSrcweir 	SbxDim* pNext;              // Link
38*cdf0e10cSrcweir 	sal_Int32 nLbound, nUbound;     // Begrenzungen
39*cdf0e10cSrcweir 	sal_Int32 nSize;                // Anzahl Elemente
40*cdf0e10cSrcweir };
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir class SbxVarEntry : public SbxVariableRef {
43*cdf0e10cSrcweir public:
44*cdf0e10cSrcweir 	XubString* pAlias;
45*cdf0e10cSrcweir 	SbxVarEntry() : SbxVariableRef(), pAlias( NULL ) {}
46*cdf0e10cSrcweir    ~SbxVarEntry() { delete pAlias; }
47*cdf0e10cSrcweir };
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir typedef SbxVarEntry* SbxVarEntryPtr;
50*cdf0e10cSrcweir typedef vector< SbxVarEntryPtr > SbxVarEntryPtrVector;
51*cdf0e10cSrcweir class SbxVarRefs : public SbxVarEntryPtrVector
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir public:
54*cdf0e10cSrcweir     SbxVarRefs( void ) {}
55*cdf0e10cSrcweir };
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir TYPEINIT1(SbxArray,SbxBase)
59*cdf0e10cSrcweir TYPEINIT1(SbxDimArray,SbxArray)
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
62*cdf0e10cSrcweir //
63*cdf0e10cSrcweir //  SbxArray
64*cdf0e10cSrcweir //
65*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir SbxArray::SbxArray( SbxDataType t ) : SbxBase()
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	pData = new SbxVarRefs;
70*cdf0e10cSrcweir 	eType = t;
71*cdf0e10cSrcweir 	if( t != SbxVARIANT )
72*cdf0e10cSrcweir 		SetFlag( SBX_FIXED );
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir SbxArray::SbxArray( const SbxArray& rArray ) :
76*cdf0e10cSrcweir     SvRefBase( rArray ), SbxBase()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	pData = new SbxVarRefs;
79*cdf0e10cSrcweir 	if( rArray.eType != SbxVARIANT )
80*cdf0e10cSrcweir 		SetFlag( SBX_FIXED );
81*cdf0e10cSrcweir 	*this = rArray;
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir SbxArray& SbxArray::operator=( const SbxArray& rArray )
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	if( &rArray != this )
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		eType = rArray.eType;
89*cdf0e10cSrcweir 		Clear();
90*cdf0e10cSrcweir 		SbxVarRefs* pSrc = rArray.pData;
91*cdf0e10cSrcweir 		for( sal_uInt32 i = 0; i < pSrc->size(); i++ )
92*cdf0e10cSrcweir 		{
93*cdf0e10cSrcweir 			SbxVarEntryPtr pSrcRef = (*pSrc)[i];
94*cdf0e10cSrcweir 			const SbxVariable* pSrc_ = *pSrcRef;
95*cdf0e10cSrcweir 			if( !pSrc_ )
96*cdf0e10cSrcweir 				continue;
97*cdf0e10cSrcweir 			SbxVarEntryPtr pDstRef = new SbxVarEntry;
98*cdf0e10cSrcweir 			*((SbxVariableRef*) pDstRef) = *((SbxVariableRef*) pSrcRef);
99*cdf0e10cSrcweir 			if( pSrcRef->pAlias )
100*cdf0e10cSrcweir 				pDstRef->pAlias = new XubString( *pSrcRef->pAlias );
101*cdf0e10cSrcweir 			if( eType != SbxVARIANT )
102*cdf0e10cSrcweir 				// Keine Objekte konvertieren
103*cdf0e10cSrcweir 				if( eType != SbxOBJECT || pSrc_->GetClass() != SbxCLASS_OBJECT )
104*cdf0e10cSrcweir 					((SbxVariable*) pSrc_)->Convert( eType );
105*cdf0e10cSrcweir 			pData->push_back( pDstRef );
106*cdf0e10cSrcweir 		}
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir 	return *this;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir SbxArray::~SbxArray()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     Clear();
114*cdf0e10cSrcweir 	delete pData;
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir SbxDataType SbxArray::GetType() const
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	return (SbxDataType) ( eType | SbxARRAY );
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir SbxClassType SbxArray::GetClass() const
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	return SbxCLASS_ARRAY;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir void SbxArray::Clear()
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     sal_uInt32 nSize = pData->size();
130*cdf0e10cSrcweir 	for( sal_uInt32 i = 0 ; i < nSize ; i++ )
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         SbxVarEntry* pEntry = (*pData)[i];
133*cdf0e10cSrcweir 		delete pEntry;
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 	pData->clear();
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir sal_uInt32 SbxArray::Count32() const
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     return pData->size();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir sal_uInt16 SbxArray::Count() const
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     sal_uInt32 nCount = pData->size();
146*cdf0e10cSrcweir 	DBG_ASSERT( nCount <= SBX_MAXINDEX, "SBX: Array-Index > SBX_MAXINDEX" );
147*cdf0e10cSrcweir 	return (sal_uInt16)nCount;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir SbxVariableRef& SbxArray::GetRef32( sal_uInt32 nIdx )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	// Array ggf. vergroessern
153*cdf0e10cSrcweir 	DBG_ASSERT( nIdx <= SBX_MAXINDEX32, "SBX: Array-Index > SBX_MAXINDEX32" );
154*cdf0e10cSrcweir 	// Very Hot Fix
155*cdf0e10cSrcweir 	if( nIdx > SBX_MAXINDEX32 )
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS );
158*cdf0e10cSrcweir 		nIdx = 0;
159*cdf0e10cSrcweir 	}
160*cdf0e10cSrcweir 	while( pData->size() <= nIdx )
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir 		const SbxVarEntryPtr p = new SbxVarEntry;
163*cdf0e10cSrcweir 		pData->push_back( p );
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 	return *((*pData)[nIdx]);
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir SbxVariableRef& SbxArray::GetRef( sal_uInt16 nIdx )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	// Array ggf. vergroessern
171*cdf0e10cSrcweir 	DBG_ASSERT( nIdx <= SBX_MAXINDEX, "SBX: Array-Index > SBX_MAXINDEX" );
172*cdf0e10cSrcweir 	// Very Hot Fix
173*cdf0e10cSrcweir 	if( nIdx > SBX_MAXINDEX )
174*cdf0e10cSrcweir 	{
175*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS );
176*cdf0e10cSrcweir 		nIdx = 0;
177*cdf0e10cSrcweir 	}
178*cdf0e10cSrcweir 	while( pData->size() <= nIdx )
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		const SbxVarEntryPtr p = new SbxVarEntry;
181*cdf0e10cSrcweir 		pData->push_back( p );
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir 	return *((*pData)[nIdx]);
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir SbxVariable* SbxArray::Get32( sal_uInt32 nIdx )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	if( !CanRead() )
189*cdf0e10cSrcweir 	{
190*cdf0e10cSrcweir 		SetError( SbxERR_PROP_WRITEONLY );
191*cdf0e10cSrcweir 		return NULL;
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir 	SbxVariableRef& rRef = GetRef32( nIdx );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	if ( !rRef.Is() )
196*cdf0e10cSrcweir 		rRef = new SbxVariable( eType );
197*cdf0e10cSrcweir #ifdef DBG_UTIL
198*cdf0e10cSrcweir 	else
199*cdf0e10cSrcweir 		DBG_CHKOBJ( rRef, SbxBase, 0 );
200*cdf0e10cSrcweir #endif
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	return rRef;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir SbxVariable* SbxArray::Get( sal_uInt16 nIdx )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	if( !CanRead() )
208*cdf0e10cSrcweir 	{
209*cdf0e10cSrcweir 		SetError( SbxERR_PROP_WRITEONLY );
210*cdf0e10cSrcweir 		return NULL;
211*cdf0e10cSrcweir 	}
212*cdf0e10cSrcweir 	SbxVariableRef& rRef = GetRef( nIdx );
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	if ( !rRef.Is() )
215*cdf0e10cSrcweir 		rRef = new SbxVariable( eType );
216*cdf0e10cSrcweir #ifdef DBG_UTIL
217*cdf0e10cSrcweir 	else
218*cdf0e10cSrcweir 		DBG_CHKOBJ( rRef, SbxBase, 0 );
219*cdf0e10cSrcweir #endif
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	return rRef;
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir void SbxArray::Put32( SbxVariable* pVar, sal_uInt32 nIdx )
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir 	if( !CanWrite() )
227*cdf0e10cSrcweir 		SetError( SbxERR_PROP_READONLY );
228*cdf0e10cSrcweir 	else
229*cdf0e10cSrcweir 	{
230*cdf0e10cSrcweir 		if( pVar )
231*cdf0e10cSrcweir 			if( eType != SbxVARIANT )
232*cdf0e10cSrcweir 				// Keine Objekte konvertieren
233*cdf0e10cSrcweir 				if( eType != SbxOBJECT || pVar->GetClass() != SbxCLASS_OBJECT )
234*cdf0e10cSrcweir 					pVar->Convert( eType );
235*cdf0e10cSrcweir 		SbxVariableRef& rRef = GetRef32( nIdx );
236*cdf0e10cSrcweir 		if( (SbxVariable*) rRef != pVar )
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			rRef = pVar;
239*cdf0e10cSrcweir 			SetFlag( SBX_MODIFIED );
240*cdf0e10cSrcweir 		}
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void SbxArray::Put( SbxVariable* pVar, sal_uInt16 nIdx )
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir 	if( !CanWrite() )
247*cdf0e10cSrcweir 		SetError( SbxERR_PROP_READONLY );
248*cdf0e10cSrcweir 	else
249*cdf0e10cSrcweir 	{
250*cdf0e10cSrcweir 		if( pVar )
251*cdf0e10cSrcweir 			if( eType != SbxVARIANT )
252*cdf0e10cSrcweir 				// Keine Objekte konvertieren
253*cdf0e10cSrcweir 				if( eType != SbxOBJECT || pVar->GetClass() != SbxCLASS_OBJECT )
254*cdf0e10cSrcweir 					pVar->Convert( eType );
255*cdf0e10cSrcweir 		SbxVariableRef& rRef = GetRef( nIdx );
256*cdf0e10cSrcweir 		if( (SbxVariable*) rRef != pVar )
257*cdf0e10cSrcweir 		{
258*cdf0e10cSrcweir 			rRef = pVar;
259*cdf0e10cSrcweir 			SetFlag( SBX_MODIFIED );
260*cdf0e10cSrcweir 		}
261*cdf0e10cSrcweir 	}
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir const XubString& SbxArray::GetAlias( sal_uInt16 nIdx )
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	if( !CanRead() )
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		SetError( SbxERR_PROP_WRITEONLY );
269*cdf0e10cSrcweir 		return String::EmptyString();
270*cdf0e10cSrcweir 	}
271*cdf0e10cSrcweir 	SbxVarEntry& rRef = (SbxVarEntry&) GetRef( nIdx );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	if ( !rRef.pAlias )
274*cdf0e10cSrcweir 		return String::EmptyString();
275*cdf0e10cSrcweir #ifdef DBG_UTIL
276*cdf0e10cSrcweir 	else
277*cdf0e10cSrcweir 		DBG_CHKOBJ( rRef, SbxBase, 0 );
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	return *rRef.pAlias;
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir void SbxArray::PutAlias( const XubString& rAlias, sal_uInt16 nIdx )
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir 	if( !CanWrite() )
286*cdf0e10cSrcweir 		SetError( SbxERR_PROP_READONLY );
287*cdf0e10cSrcweir 	else
288*cdf0e10cSrcweir 	{
289*cdf0e10cSrcweir 		SbxVarEntry& rRef = (SbxVarEntry&) GetRef( nIdx );
290*cdf0e10cSrcweir 		if( !rRef.pAlias )
291*cdf0e10cSrcweir 			rRef.pAlias = new XubString( rAlias );
292*cdf0e10cSrcweir 		else
293*cdf0e10cSrcweir 			*rRef.pAlias = rAlias;
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir void SbxArray::Insert32( SbxVariable* pVar, sal_uInt32 nIdx )
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir 	DBG_ASSERT( pData->size() <= SBX_MAXINDEX32, "SBX: Array wird zu gross" );
300*cdf0e10cSrcweir 	if( pData->size() > SBX_MAXINDEX32 )
301*cdf0e10cSrcweir 			return;
302*cdf0e10cSrcweir 	SbxVarEntryPtr p = new SbxVarEntry;
303*cdf0e10cSrcweir 	*((SbxVariableRef*) p) = pVar;
304*cdf0e10cSrcweir     SbxVarEntryPtrVector::size_type nSize = pData->size();
305*cdf0e10cSrcweir 	if( nIdx > nSize )
306*cdf0e10cSrcweir 		nIdx = nSize;
307*cdf0e10cSrcweir 	if( eType != SbxVARIANT && pVar )
308*cdf0e10cSrcweir 		(*p)->Convert( eType );
309*cdf0e10cSrcweir 	if( nIdx == nSize )
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         pData->push_back( p );
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir     else
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir 	    pData->insert( pData->begin() + nIdx, p );
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 	SetFlag( SBX_MODIFIED );
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir void SbxArray::Insert( SbxVariable* pVar, sal_uInt16 nIdx )
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir 	DBG_ASSERT( pData->size() <= 0x3FF0, "SBX: Array wird zu gross" );
323*cdf0e10cSrcweir 	if( pData->size() > 0x3FF0 )
324*cdf0e10cSrcweir 			return;
325*cdf0e10cSrcweir     Insert32( pVar, nIdx );
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir void SbxArray::Remove32( sal_uInt32 nIdx )
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir 	if( nIdx < pData->size() )
331*cdf0e10cSrcweir 	{
332*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[nIdx];
333*cdf0e10cSrcweir 	    pData->erase( pData->begin() + nIdx );
334*cdf0e10cSrcweir 		delete pRef;
335*cdf0e10cSrcweir 		SetFlag( SBX_MODIFIED );
336*cdf0e10cSrcweir 	}
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir void SbxArray::Remove( sal_uInt16 nIdx )
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir 	if( nIdx < pData->size() )
342*cdf0e10cSrcweir 	{
343*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[nIdx];
344*cdf0e10cSrcweir 	    pData->erase( pData->begin() + nIdx );
345*cdf0e10cSrcweir 		delete pRef;
346*cdf0e10cSrcweir 		SetFlag( SBX_MODIFIED );
347*cdf0e10cSrcweir 	}
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void SbxArray::Remove( SbxVariable* pVar )
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir 	if( pVar )
353*cdf0e10cSrcweir 	{
354*cdf0e10cSrcweir 		for( sal_uInt32 i = 0; i < pData->size(); i++ )
355*cdf0e10cSrcweir 		{
356*cdf0e10cSrcweir 			SbxVariableRef* pRef = (*pData)[i];
357*cdf0e10cSrcweir 			// SbxVariableRef* pRef = pData->GetObject( i );
358*cdf0e10cSrcweir 			if( *pRef == pVar )
359*cdf0e10cSrcweir 			{
360*cdf0e10cSrcweir 				Remove32( i ); break;
361*cdf0e10cSrcweir 			}
362*cdf0e10cSrcweir 		}
363*cdf0e10cSrcweir 	}
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir // Uebernahme der Daten aus dem uebergebenen Array, wobei
367*cdf0e10cSrcweir // gleichnamige Variable ueberschrieben werden.
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir void SbxArray::Merge( SbxArray* p )
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir 	if( p )
372*cdf0e10cSrcweir 	{
373*cdf0e10cSrcweir 		sal_uInt32 nSize = p->Count();
374*cdf0e10cSrcweir 		for( sal_uInt32 i = 0; i < nSize; i++ )
375*cdf0e10cSrcweir 		{
376*cdf0e10cSrcweir 			SbxVarEntryPtr pRef1 = (*(p->pData))[i];
377*cdf0e10cSrcweir 			// Ist das Element by name schon drin?
378*cdf0e10cSrcweir 			// Dann ueberschreiben!
379*cdf0e10cSrcweir 			SbxVariable* pVar = *pRef1;
380*cdf0e10cSrcweir 			if( pVar )
381*cdf0e10cSrcweir 			{
382*cdf0e10cSrcweir 				XubString aName = pVar->GetName();
383*cdf0e10cSrcweir 				sal_uInt16 nHash = pVar->GetHashCode();
384*cdf0e10cSrcweir 				for( sal_uInt32 j = 0; j < pData->size(); j++ )
385*cdf0e10cSrcweir 				{
386*cdf0e10cSrcweir 					SbxVariableRef* pRef2 = (*pData)[j];
387*cdf0e10cSrcweir 					if( (*pRef2)->GetHashCode() == nHash
388*cdf0e10cSrcweir 					 && (*pRef2)->GetName().EqualsIgnoreCaseAscii( aName ) )
389*cdf0e10cSrcweir 					{
390*cdf0e10cSrcweir 						*pRef2 = pVar; pRef1 = NULL;
391*cdf0e10cSrcweir 						break;
392*cdf0e10cSrcweir 					}
393*cdf0e10cSrcweir 				}
394*cdf0e10cSrcweir 				if( pRef1 )
395*cdf0e10cSrcweir 				{
396*cdf0e10cSrcweir 					SbxVarEntryPtr pRef = new SbxVarEntry;
397*cdf0e10cSrcweir 					const SbxVarEntryPtr pTemp = pRef;
398*cdf0e10cSrcweir 					pData->push_back( pTemp );
399*cdf0e10cSrcweir 					*((SbxVariableRef*) pRef) = *((SbxVariableRef*) pRef1);
400*cdf0e10cSrcweir 					if( pRef1->pAlias )
401*cdf0e10cSrcweir 						pRef->pAlias = new XubString( *pRef1->pAlias );
402*cdf0e10cSrcweir 				}
403*cdf0e10cSrcweir 			}
404*cdf0e10cSrcweir 		}
405*cdf0e10cSrcweir 	}
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir // Suchen eines Elements ueber die Userdaten. Falls ein Element
409*cdf0e10cSrcweir // ein Objekt ist, wird dieses ebenfalls durchsucht.
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir SbxVariable* SbxArray::FindUserData( sal_uInt32 nData )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	SbxVariable* p = NULL;
414*cdf0e10cSrcweir 	for( sal_uInt32 i = 0; i < pData->size(); i++ )
415*cdf0e10cSrcweir 	{
416*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[i];
417*cdf0e10cSrcweir 		SbxVariable* pVar = *pRef;
418*cdf0e10cSrcweir 		if( pVar )
419*cdf0e10cSrcweir 		{
420*cdf0e10cSrcweir 			if( pVar->IsVisible() && pVar->GetUserData() == nData )
421*cdf0e10cSrcweir 			{
422*cdf0e10cSrcweir 				p = pVar;
423*cdf0e10cSrcweir 				p->ResetFlag( SBX_EXTFOUND );
424*cdf0e10cSrcweir 				break;	// JSM 06.10.95
425*cdf0e10cSrcweir 			}
426*cdf0e10cSrcweir 			// Haben wir ein Array/Objekt mit Extended Search?
427*cdf0e10cSrcweir 			else if( pVar->IsSet( SBX_EXTSEARCH ) )
428*cdf0e10cSrcweir 			{
429*cdf0e10cSrcweir 				switch( pVar->GetClass() )
430*cdf0e10cSrcweir 				{
431*cdf0e10cSrcweir 					case SbxCLASS_OBJECT:
432*cdf0e10cSrcweir 					{
433*cdf0e10cSrcweir 						// Objekte duerfen ihren Parent nicht durchsuchen
434*cdf0e10cSrcweir 						sal_uInt16 nOld = pVar->GetFlags();
435*cdf0e10cSrcweir 						pVar->ResetFlag( SBX_GBLSEARCH );
436*cdf0e10cSrcweir 						p = ((SbxObject*) pVar)->FindUserData( nData );
437*cdf0e10cSrcweir 						pVar->SetFlags( nOld );
438*cdf0e10cSrcweir 						break;
439*cdf0e10cSrcweir 					}
440*cdf0e10cSrcweir 					case SbxCLASS_ARRAY:
441*cdf0e10cSrcweir 						p = ((SbxArray*) pVar)->FindUserData( nData );
442*cdf0e10cSrcweir 						break;
443*cdf0e10cSrcweir 					default: break;
444*cdf0e10cSrcweir 				}
445*cdf0e10cSrcweir 				if( p )
446*cdf0e10cSrcweir 				{
447*cdf0e10cSrcweir 					p->SetFlag( SBX_EXTFOUND );
448*cdf0e10cSrcweir 					break;
449*cdf0e10cSrcweir 				}
450*cdf0e10cSrcweir 			}
451*cdf0e10cSrcweir 		}
452*cdf0e10cSrcweir 	}
453*cdf0e10cSrcweir 	return p;
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir // Suchen eines Elements ueber den Namen und den Typ. Falls ein Element
457*cdf0e10cSrcweir // ein Objekt ist, wird dieses ebenfalls durchsucht.
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir SbxVariable* SbxArray::Find( const XubString& rName, SbxClassType t )
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir 	SbxVariable* p = NULL;
462*cdf0e10cSrcweir 	sal_uInt32 nCount = pData->size();
463*cdf0e10cSrcweir 	if( !nCount )
464*cdf0e10cSrcweir 		return NULL;
465*cdf0e10cSrcweir 	sal_Bool bExtSearch = IsSet( SBX_EXTSEARCH );
466*cdf0e10cSrcweir 	sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
467*cdf0e10cSrcweir 	for( sal_uInt32 i = 0; i < nCount; i++ )
468*cdf0e10cSrcweir 	{
469*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[i];
470*cdf0e10cSrcweir 		SbxVariable* pVar = *pRef;
471*cdf0e10cSrcweir 		if( pVar && pVar->IsVisible() )
472*cdf0e10cSrcweir 		{
473*cdf0e10cSrcweir 			// Die ganz sichere Suche klappt auch, wenn es
474*cdf0e10cSrcweir 			// keinen Hascode gibt!
475*cdf0e10cSrcweir 			sal_uInt16 nVarHash = pVar->GetHashCode();
476*cdf0e10cSrcweir 			if( ( !nVarHash || nVarHash == nHash )
477*cdf0e10cSrcweir 				&& ( t == SbxCLASS_DONTCARE || pVar->GetClass() == t )
478*cdf0e10cSrcweir 				&& ( pVar->GetName().EqualsIgnoreCaseAscii( rName ) ) )
479*cdf0e10cSrcweir 			{
480*cdf0e10cSrcweir 				p = pVar;
481*cdf0e10cSrcweir 				p->ResetFlag( SBX_EXTFOUND );
482*cdf0e10cSrcweir 				break;
483*cdf0e10cSrcweir 			}
484*cdf0e10cSrcweir 			// Haben wir ein Array/Objekt mit Extended Search?
485*cdf0e10cSrcweir 			else if( bExtSearch && pVar->IsSet( SBX_EXTSEARCH ) )
486*cdf0e10cSrcweir 			{
487*cdf0e10cSrcweir 				switch( pVar->GetClass() )
488*cdf0e10cSrcweir 				{
489*cdf0e10cSrcweir 					case SbxCLASS_OBJECT:
490*cdf0e10cSrcweir 					{
491*cdf0e10cSrcweir 						// Objekte duerfen ihren Parent nicht durchsuchen
492*cdf0e10cSrcweir 						sal_uInt16 nOld = pVar->GetFlags();
493*cdf0e10cSrcweir 						pVar->ResetFlag( SBX_GBLSEARCH );
494*cdf0e10cSrcweir 						p = ((SbxObject*) pVar)->Find( rName, t );
495*cdf0e10cSrcweir 						pVar->SetFlags( nOld );
496*cdf0e10cSrcweir 						break;
497*cdf0e10cSrcweir 					}
498*cdf0e10cSrcweir 					case SbxCLASS_ARRAY:
499*cdf0e10cSrcweir 						p = ((SbxArray*) pVar)->Find( rName, t );
500*cdf0e10cSrcweir 						break;
501*cdf0e10cSrcweir 					default: break;
502*cdf0e10cSrcweir 				}
503*cdf0e10cSrcweir 				if( p )
504*cdf0e10cSrcweir 				{
505*cdf0e10cSrcweir 					p->SetFlag( SBX_EXTFOUND );
506*cdf0e10cSrcweir 					break;
507*cdf0e10cSrcweir 				}
508*cdf0e10cSrcweir 			}
509*cdf0e10cSrcweir 		}
510*cdf0e10cSrcweir 	}
511*cdf0e10cSrcweir 	return p;
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir sal_Bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 nVer )
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir 	sal_uInt16 nElem;
517*cdf0e10cSrcweir 	Clear();
518*cdf0e10cSrcweir 	sal_Bool bRes = sal_True;
519*cdf0e10cSrcweir 	sal_uInt16 f = nFlags;
520*cdf0e10cSrcweir 	nFlags |= SBX_WRITE;
521*cdf0e10cSrcweir 	rStrm >> nElem;
522*cdf0e10cSrcweir 	nElem &= 0x7FFF;
523*cdf0e10cSrcweir 	for( sal_uInt32 n = 0; n < nElem; n++ )
524*cdf0e10cSrcweir 	{
525*cdf0e10cSrcweir 		sal_uInt16 nIdx;
526*cdf0e10cSrcweir 		rStrm >> nIdx;
527*cdf0e10cSrcweir 		SbxVariable* pVar = (SbxVariable*) Load( rStrm );
528*cdf0e10cSrcweir 		if( pVar )
529*cdf0e10cSrcweir 		{
530*cdf0e10cSrcweir 			SbxVariableRef& rRef = GetRef( nIdx );
531*cdf0e10cSrcweir 			rRef = pVar;
532*cdf0e10cSrcweir 		}
533*cdf0e10cSrcweir 		else
534*cdf0e10cSrcweir 		{
535*cdf0e10cSrcweir 			bRes = sal_False; break;
536*cdf0e10cSrcweir 		}
537*cdf0e10cSrcweir 	}
538*cdf0e10cSrcweir 	if( bRes )
539*cdf0e10cSrcweir 		bRes = LoadPrivateData( rStrm, nVer );
540*cdf0e10cSrcweir 	nFlags = f;
541*cdf0e10cSrcweir 	return bRes;
542*cdf0e10cSrcweir }
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir sal_Bool SbxArray::StoreData( SvStream& rStrm ) const
545*cdf0e10cSrcweir {
546*cdf0e10cSrcweir 	sal_uInt32 nElem = 0;
547*cdf0e10cSrcweir 	sal_uInt32 n;
548*cdf0e10cSrcweir 	// Welche Elemente sind ueberhaupt definiert?
549*cdf0e10cSrcweir 	for( n = 0; n < pData->size(); n++ )
550*cdf0e10cSrcweir 	{
551*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[n];
552*cdf0e10cSrcweir 		SbxVariable* p = *pRef;
553*cdf0e10cSrcweir 		if( p && !( p->GetFlags() & SBX_DONTSTORE ) )
554*cdf0e10cSrcweir 			nElem++;
555*cdf0e10cSrcweir 	}
556*cdf0e10cSrcweir 	rStrm << (sal_uInt16) nElem;
557*cdf0e10cSrcweir 	for( n = 0; n < pData->size(); n++ )
558*cdf0e10cSrcweir 	{
559*cdf0e10cSrcweir 		SbxVariableRef* pRef = (*pData)[n];
560*cdf0e10cSrcweir 		SbxVariable* p = *pRef;
561*cdf0e10cSrcweir 		if( p && !( p->GetFlags() & SBX_DONTSTORE ) )
562*cdf0e10cSrcweir 		{
563*cdf0e10cSrcweir 			rStrm << (sal_uInt16) n;
564*cdf0e10cSrcweir 			if( !p->Store( rStrm ) )
565*cdf0e10cSrcweir 				return sal_False;
566*cdf0e10cSrcweir 		}
567*cdf0e10cSrcweir 	}
568*cdf0e10cSrcweir 	return StorePrivateData( rStrm );
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir // #100883 Method to set method directly to parameter array
572*cdf0e10cSrcweir void SbxArray::PutDirect( SbxVariable* pVar, sal_uInt32 nIdx )
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir 	SbxVariableRef& rRef = GetRef32( nIdx );
575*cdf0e10cSrcweir 	rRef = pVar;
576*cdf0e10cSrcweir }
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
580*cdf0e10cSrcweir //
581*cdf0e10cSrcweir //  SbxArray
582*cdf0e10cSrcweir //
583*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir SbxDimArray::SbxDimArray( SbxDataType t ) : SbxArray( t ), mbHasFixedSize( false )
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir 	pFirst = pLast = NULL;
588*cdf0e10cSrcweir 	nDim = 0;
589*cdf0e10cSrcweir }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir SbxDimArray::SbxDimArray( const SbxDimArray& rArray )
592*cdf0e10cSrcweir     : SvRefBase( rArray ), SbxArray( rArray.eType )
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir 	pFirst = pLast = NULL;
595*cdf0e10cSrcweir 	nDim = 0;
596*cdf0e10cSrcweir 	*this = rArray;
597*cdf0e10cSrcweir }
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir SbxDimArray& SbxDimArray::operator=( const SbxDimArray& rArray )
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir 	if( &rArray != this )
602*cdf0e10cSrcweir 	{
603*cdf0e10cSrcweir 		SbxArray::operator=( (const SbxArray&) rArray );
604*cdf0e10cSrcweir 		SbxDim* p = rArray.pFirst;
605*cdf0e10cSrcweir 		while( p )
606*cdf0e10cSrcweir 		{
607*cdf0e10cSrcweir 			AddDim32( p->nLbound, p->nUbound );
608*cdf0e10cSrcweir 			p = p->pNext;
609*cdf0e10cSrcweir 		}
610*cdf0e10cSrcweir 		this->mbHasFixedSize = rArray.mbHasFixedSize;
611*cdf0e10cSrcweir 	}
612*cdf0e10cSrcweir 	return *this;
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir SbxDimArray::~SbxDimArray()
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir 	Clear();
618*cdf0e10cSrcweir }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir void SbxDimArray::Clear()
621*cdf0e10cSrcweir {
622*cdf0e10cSrcweir 	SbxDim* p = pFirst;
623*cdf0e10cSrcweir 	while( p )
624*cdf0e10cSrcweir 	{
625*cdf0e10cSrcweir 		SbxDim* q = p->pNext;
626*cdf0e10cSrcweir 		delete p;
627*cdf0e10cSrcweir 		p = q;
628*cdf0e10cSrcweir 	}
629*cdf0e10cSrcweir 	pFirst = pLast = NULL;
630*cdf0e10cSrcweir 	nDim   = 0;
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir // Dimension hinzufuegen
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir void SbxDimArray::AddDimImpl32( sal_Int32 lb, sal_Int32 ub, sal_Bool bAllowSize0 )
636*cdf0e10cSrcweir {
637*cdf0e10cSrcweir 	SbxError eRes = SbxERR_OK;
638*cdf0e10cSrcweir 	if( ub < lb && !bAllowSize0 )
639*cdf0e10cSrcweir 	{
640*cdf0e10cSrcweir 		eRes = SbxERR_BOUNDS;
641*cdf0e10cSrcweir 		ub = lb;
642*cdf0e10cSrcweir 	}
643*cdf0e10cSrcweir 	SbxDim* p = new SbxDim;
644*cdf0e10cSrcweir 	p->nLbound = lb;
645*cdf0e10cSrcweir 	p->nUbound = ub;
646*cdf0e10cSrcweir 	p->nSize   = ub - lb + 1;
647*cdf0e10cSrcweir 	p->pNext   = NULL;
648*cdf0e10cSrcweir 	if( !pFirst )
649*cdf0e10cSrcweir 		pFirst = pLast = p;
650*cdf0e10cSrcweir 	else
651*cdf0e10cSrcweir 		pLast->pNext = p, pLast = p;
652*cdf0e10cSrcweir 	nDim++;
653*cdf0e10cSrcweir 	if( eRes )
654*cdf0e10cSrcweir 		SetError( eRes );
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir void SbxDimArray::AddDim( short lb, short ub )
658*cdf0e10cSrcweir {
659*cdf0e10cSrcweir 	AddDimImpl32( lb, ub, sal_False );
660*cdf0e10cSrcweir }
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir void SbxDimArray::unoAddDim( short lb, short ub )
663*cdf0e10cSrcweir {
664*cdf0e10cSrcweir 	AddDimImpl32( lb, ub, sal_True );
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir void SbxDimArray::AddDim32( sal_Int32 lb, sal_Int32 ub )
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir 	AddDimImpl32( lb, ub, sal_False );
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir void SbxDimArray::unoAddDim32( sal_Int32 lb, sal_Int32 ub )
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir 	AddDimImpl32( lb, ub, sal_True );
675*cdf0e10cSrcweir }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir // Dimensionsdaten auslesen
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir sal_Bool SbxDimArray::GetDim32( sal_Int32 n, sal_Int32& rlb, sal_Int32& rub ) const
681*cdf0e10cSrcweir {
682*cdf0e10cSrcweir 	if( n < 1 || n > nDim )
683*cdf0e10cSrcweir 	{
684*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); rub = rlb = 0; return sal_False;
685*cdf0e10cSrcweir 	}
686*cdf0e10cSrcweir 	SbxDim* p = pFirst;
687*cdf0e10cSrcweir 	while( --n )
688*cdf0e10cSrcweir 		p = p->pNext;
689*cdf0e10cSrcweir 	rub = p->nUbound;
690*cdf0e10cSrcweir 	rlb = p->nLbound;
691*cdf0e10cSrcweir 	return sal_True;
692*cdf0e10cSrcweir }
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir sal_Bool SbxDimArray::GetDim( short n, short& rlb, short& rub ) const
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir     sal_Int32 rlb32, rub32;
697*cdf0e10cSrcweir     sal_Bool bRet = GetDim32( n, rlb32, rub32 );
698*cdf0e10cSrcweir     if( bRet )
699*cdf0e10cSrcweir     {
700*cdf0e10cSrcweir 	    if( rlb32 < -SBX_MAXINDEX || rub32 > SBX_MAXINDEX )
701*cdf0e10cSrcweir 	    {
702*cdf0e10cSrcweir 		    SetError( SbxERR_BOUNDS );
703*cdf0e10cSrcweir             return sal_False;
704*cdf0e10cSrcweir         }
705*cdf0e10cSrcweir 	    rub = (short)rub32;
706*cdf0e10cSrcweir 	    rlb = (short)rlb32;
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir 	return bRet;
709*cdf0e10cSrcweir }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir // Element-Ptr anhand einer Index-Liste
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir sal_uInt32 SbxDimArray::Offset32( const sal_Int32* pIdx )
714*cdf0e10cSrcweir {
715*cdf0e10cSrcweir 	sal_uInt32 nPos = 0;
716*cdf0e10cSrcweir 	for( SbxDim* p = pFirst; p; p = p->pNext )
717*cdf0e10cSrcweir 	{
718*cdf0e10cSrcweir 		sal_Int32 nIdx = *pIdx++;
719*cdf0e10cSrcweir 		if( nIdx < p->nLbound || nIdx > p->nUbound )
720*cdf0e10cSrcweir 		{
721*cdf0e10cSrcweir 			nPos = (sal_uInt32)SBX_MAXINDEX32 + 1; break;
722*cdf0e10cSrcweir 		}
723*cdf0e10cSrcweir 		nPos = nPos * p->nSize + nIdx - p->nLbound;
724*cdf0e10cSrcweir 	}
725*cdf0e10cSrcweir 	if( nDim == 0 || nPos > SBX_MAXINDEX32 )
726*cdf0e10cSrcweir 	{
727*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); nPos = 0;
728*cdf0e10cSrcweir 	}
729*cdf0e10cSrcweir 	return nPos;
730*cdf0e10cSrcweir }
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir sal_uInt16 SbxDimArray::Offset( const short* pIdx )
733*cdf0e10cSrcweir {
734*cdf0e10cSrcweir 	long nPos = 0;
735*cdf0e10cSrcweir 	for( SbxDim* p = pFirst; p; p = p->pNext )
736*cdf0e10cSrcweir 	{
737*cdf0e10cSrcweir 		short nIdx = *pIdx++;
738*cdf0e10cSrcweir 		if( nIdx < p->nLbound || nIdx > p->nUbound )
739*cdf0e10cSrcweir 		{
740*cdf0e10cSrcweir 			nPos = SBX_MAXINDEX + 1; break;
741*cdf0e10cSrcweir 		}
742*cdf0e10cSrcweir 		nPos = nPos * p->nSize + nIdx - p->nLbound;
743*cdf0e10cSrcweir 	}
744*cdf0e10cSrcweir 	if( nDim == 0 || nPos > SBX_MAXINDEX )
745*cdf0e10cSrcweir 	{
746*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); nPos = 0;
747*cdf0e10cSrcweir 	}
748*cdf0e10cSrcweir 	return (sal_uInt16) nPos;
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir SbxVariableRef& SbxDimArray::GetRef( const short* pIdx )
752*cdf0e10cSrcweir {
753*cdf0e10cSrcweir 	return SbxArray::GetRef( Offset( pIdx ) );
754*cdf0e10cSrcweir }
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir SbxVariable* SbxDimArray::Get( const short* pIdx )
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir 	return SbxArray::Get( Offset( pIdx ) );
759*cdf0e10cSrcweir }
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir void SbxDimArray::Put( SbxVariable* p, const short* pIdx  )
762*cdf0e10cSrcweir {
763*cdf0e10cSrcweir 	SbxArray::Put( p, Offset( pIdx ) );
764*cdf0e10cSrcweir }
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir SbxVariableRef& SbxDimArray::GetRef32( const sal_Int32* pIdx )
767*cdf0e10cSrcweir {
768*cdf0e10cSrcweir 	return SbxArray::GetRef32( Offset32( pIdx ) );
769*cdf0e10cSrcweir }
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir SbxVariable* SbxDimArray::Get32( const sal_Int32* pIdx )
772*cdf0e10cSrcweir {
773*cdf0e10cSrcweir 	return SbxArray::Get32( Offset32( pIdx ) );
774*cdf0e10cSrcweir }
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir void SbxDimArray::Put32( SbxVariable* p, const sal_Int32* pIdx  )
777*cdf0e10cSrcweir {
778*cdf0e10cSrcweir 	SbxArray::Put32( p, Offset32( pIdx ) );
779*cdf0e10cSrcweir }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir // Element-Nr anhand eines Parameter-Arrays
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir sal_uInt32 SbxDimArray::Offset32( SbxArray* pPar )
785*cdf0e10cSrcweir {
786*cdf0e10cSrcweir 	if( nDim == 0 || !pPar || ( ( nDim != ( pPar->Count() - 1 ) ) && SbiRuntime::isVBAEnabled() ) )
787*cdf0e10cSrcweir 	{
788*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); return 0;
789*cdf0e10cSrcweir 	}
790*cdf0e10cSrcweir 	sal_uInt32 nPos = 0;
791*cdf0e10cSrcweir 	sal_uInt16 nOff = 1;	// Nicht Element 0!
792*cdf0e10cSrcweir 	for( SbxDim* p = pFirst; p && !IsError(); p = p->pNext )
793*cdf0e10cSrcweir 	{
794*cdf0e10cSrcweir 		sal_Int32 nIdx = pPar->Get( nOff++ )->GetLong();
795*cdf0e10cSrcweir 		if( nIdx < p->nLbound || nIdx > p->nUbound )
796*cdf0e10cSrcweir 		{
797*cdf0e10cSrcweir 			nPos = (sal_uInt32) SBX_MAXINDEX32+1; break;
798*cdf0e10cSrcweir 		}
799*cdf0e10cSrcweir 		nPos = nPos * p->nSize + nIdx - p->nLbound;
800*cdf0e10cSrcweir 	}
801*cdf0e10cSrcweir 	if( nPos > (sal_uInt32) SBX_MAXINDEX32 )
802*cdf0e10cSrcweir 	{
803*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); nPos = 0;
804*cdf0e10cSrcweir 	}
805*cdf0e10cSrcweir 	return nPos;
806*cdf0e10cSrcweir }
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir sal_uInt16 SbxDimArray::Offset( SbxArray* pPar )
809*cdf0e10cSrcweir {
810*cdf0e10cSrcweir     sal_uInt32 nPos = Offset32( pPar );
811*cdf0e10cSrcweir 	if( nPos > (long) SBX_MAXINDEX )
812*cdf0e10cSrcweir 	{
813*cdf0e10cSrcweir 		SetError( SbxERR_BOUNDS ); nPos = 0;
814*cdf0e10cSrcweir 	}
815*cdf0e10cSrcweir 	return (sal_uInt16) nPos;
816*cdf0e10cSrcweir }
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir SbxVariableRef& SbxDimArray::GetRef( SbxArray* pPar )
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	return SbxArray::GetRef32( Offset32( pPar ) );
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir SbxVariable* SbxDimArray::Get( SbxArray* pPar )
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir 	return SbxArray::Get32( Offset32( pPar ) );
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir void SbxDimArray::Put( SbxVariable* p, SbxArray* pPar  )
829*cdf0e10cSrcweir {
830*cdf0e10cSrcweir 	SbxArray::Put32( p, Offset32( pPar ) );
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir sal_Bool SbxDimArray::LoadData( SvStream& rStrm, sal_uInt16 nVer )
834*cdf0e10cSrcweir {
835*cdf0e10cSrcweir 	short nDimension;
836*cdf0e10cSrcweir 	rStrm >> nDimension;
837*cdf0e10cSrcweir 	for( short i = 0; i < nDimension && rStrm.GetError() == SVSTREAM_OK; i++ )
838*cdf0e10cSrcweir 	{
839*cdf0e10cSrcweir 		sal_Int16 lb, ub;
840*cdf0e10cSrcweir 		rStrm >> lb >> ub;
841*cdf0e10cSrcweir 		AddDim( lb, ub );
842*cdf0e10cSrcweir 	}
843*cdf0e10cSrcweir 	return SbxArray::LoadData( rStrm, nVer );
844*cdf0e10cSrcweir }
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir sal_Bool SbxDimArray::StoreData( SvStream& rStrm ) const
847*cdf0e10cSrcweir {
848*cdf0e10cSrcweir 	rStrm << (sal_Int16) nDim;
849*cdf0e10cSrcweir 	for( short i = 0; i < nDim; i++ )
850*cdf0e10cSrcweir 	{
851*cdf0e10cSrcweir 		short lb, ub;
852*cdf0e10cSrcweir 		GetDim( i, lb, ub );
853*cdf0e10cSrcweir 		rStrm << (sal_Int16) lb << (sal_Int16) ub;
854*cdf0e10cSrcweir 	}
855*cdf0e10cSrcweir 	return SbxArray::StoreData( rStrm );
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858