merge the formfield patch from ooo-build
[ooovba.git] / rsc / source / res / rscarray.cxx
blob11a36528d1e5d04ac46db359a58e6073dade8114
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscarray.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
40 // Programmabhaengige Includes.
41 #include <rscconst.hxx>
42 #ifndef _RSCSARRAY_HXX
43 #include <rscarray.hxx>
44 #endif
45 #include <rscdb.hxx>
47 /****************** C O D E **********************************************/
48 /****************** R s c I n s t N o d e ********************************/
49 /*************************************************************************
51 |* RscInstNode::RscInstNode()
53 |* Beschreibung
54 |* Ersterstellung MM 06.08.91
55 |* Letzte Aenderung MM 06.08.91
57 *************************************************************************/
58 RscInstNode::RscInstNode( sal_uInt32 nId )
60 nTypeId = nId;
63 /*************************************************************************
65 |* RscInstNode::~RscInstNode()
67 |* Beschreibung
68 |* Ersterstellung MM 06.08.91
69 |* Letzte Aenderung MM 06.08.91
71 *************************************************************************/
72 RscInstNode::~RscInstNode()
74 if( aInst.IsInst() )
76 aInst.pClass->Destroy( aInst );
77 rtl_freeMemory( aInst.pData );
81 /*************************************************************************
83 |* RscInstNode::GetId()
85 |* Beschreibung
86 |* Ersterstellung MM 06.08.91
87 |* Letzte Aenderung MM 06.08.91
89 *************************************************************************/
90 sal_uInt32 RscInstNode::GetId() const
92 return nTypeId;
95 /****************** R s c A r r a y *************************************/
96 /*************************************************************************
98 |* RscArray::RscArray()
100 |* Beschreibung
101 |* Ersterstellung MM 25.05.91
102 |* Letzte Aenderung MM 25.05.91
104 *************************************************************************/
105 RscArray::RscArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper, RscEnum * pTypeCl )
106 : RscTop( nId, nTypeId, pSuper )
108 pTypeClass = pTypeCl;
109 nOffInstData = RscTop::Size();
110 nSize = nOffInstData + ALIGNED_SIZE( sizeof( RscArrayInst ) );
113 /*************************************************************************
115 |* RscArray::~RscArray()
117 |* Beschreibung
118 |* Ersterstellung MM 25.05.91
119 |* Letzte Aenderung MM 25.05.91
121 *************************************************************************/
122 RscArray::~RscArray()
126 /*************************************************************************
128 |* RscArray::~RscArray()
130 |* Beschreibung
131 |* Ersterstellung MM 25.05.91
132 |* Letzte Aenderung MM 25.05.91
134 *************************************************************************/
135 RSCCLASS_TYPE RscArray::GetClassType() const
137 return RSCCLASS_ENUMARRAY;
140 /*************************************************************************
142 |* RscArray::GetIndexType()
144 |* Beschreibung
145 |* Ersterstellung MM 23.12.92
146 |* Letzte Aenderung MM
148 *************************************************************************/
149 RscTop * RscArray::GetTypeClass() const
151 return pTypeClass;
154 /*************************************************************************
156 |* RscArray::Create()
158 |* Beschreibung
159 |* Ersterstellung MM 26.04.91
160 |* Letzte Aenderung MM 26.04.91
162 *************************************************************************/
163 static RscInstNode * Create( RscInstNode * pNode )
165 RscInstNode * pRetNode = NULL;
166 RscInstNode * pTmpNode;
168 if( pNode )
170 pRetNode = new RscInstNode( pNode->GetId() );
171 pRetNode->aInst = pNode->aInst.pClass->Create( NULL, pNode->aInst );
172 if( (pTmpNode = Create( pNode->Left() )) != NULL )
173 pRetNode->Insert( pTmpNode );
174 if( (pTmpNode = Create( pNode->Right() )) != NULL )
175 pRetNode->Insert( pTmpNode );
178 return pRetNode;
181 RSCINST RscArray::Create( RSCINST * pInst, const RSCINST & rDflt,
182 BOOL bOwnClass )
184 RSCINST aInst;
185 RscArrayInst * pClassData;
187 if( !pInst )
189 aInst.pClass = this;
190 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
192 else
193 aInst = *pInst;
194 if( !bOwnClass && rDflt.IsInst() )
195 bOwnClass = rDflt.pClass->InHierarchy( this );
197 RscTop::Create( &aInst, rDflt, bOwnClass );
199 pClassData = (RscArrayInst *)(aInst.pData + nOffInstData);
200 pClassData->pNode = NULL;
201 if( bOwnClass )
203 RscArrayInst * pDfltClassData;
205 pDfltClassData = (RscArrayInst *)(rDflt.pData + nOffInstData);
207 pClassData->pNode = ::Create( pDfltClassData->pNode );
209 return( aInst );
212 /*************************************************************************
214 |* RscArray::Destroy()
216 |* Beschreibung
218 *************************************************************************/
219 static void Destroy( RscInstNode * pNode )
221 if( pNode )
223 Destroy( pNode->Left() );
224 Destroy( pNode->Right() );
225 delete pNode;
229 void RscArray::Destroy( const RSCINST & rInst )
231 RscArrayInst * pClassData;
233 RscTop::Destroy( rInst );
235 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
237 //Baum rekursiv loeschen
238 ::Destroy( pClassData->pNode );
241 /*************************************************************************
243 |* RscArray::GetValueEle()
245 |* Beschreibung
247 *************************************************************************/
248 ERRTYPE RscArray::GetValueEle
250 const RSCINST & rInst,
251 INT32 lValue,
252 RscTop * pCreateClass,
253 RSCINST * pGetInst
256 RscArrayInst * pClassData;
257 RscInstNode * pNode;
259 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
261 ERRTYPE aError;
263 Atom nId;
264 if( !pTypeClass->GetValueConst( sal_uInt32(lValue), &nId ) )
265 { // nicht gefunden
266 return ERR_ARRAY_INVALIDINDEX;
269 if( pClassData->pNode )
270 pNode = pClassData->pNode->Search( sal_uInt32(lValue) );
271 else
272 pNode = NULL;
275 if( pNode )
277 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) )
279 GetSuperClass()->Destroy( pNode->aInst );
280 GetSuperClass()->Create( &pNode->aInst, rInst );
281 pNode->aInst.pClass->SetToDefault( pNode->aInst );
284 else
286 if( !pNode )
288 pNode = new RscInstNode( sal_uInt32(lValue) );
289 if( pCreateClass && GetSuperClass()->InHierarchy( pCreateClass ) )
290 pNode->aInst = pCreateClass->Create( NULL, rInst );
291 else
292 pNode->aInst = GetSuperClass()->Create( NULL, rInst );
293 pNode->aInst.pClass->SetToDefault( pNode->aInst );
294 if( pClassData->pNode )
295 pClassData->pNode->Insert( pNode );
296 else
297 pClassData->pNode = pNode;
300 *pGetInst = pNode->aInst;
301 return aError;
304 /*************************************************************************
306 |* RscArray::GetArrayEle()
308 |* Beschreibung
310 *************************************************************************/
311 ERRTYPE RscArray::GetArrayEle
313 const RSCINST & rInst,
314 Atom nId,
315 RscTop * pCreateClass,
316 RSCINST * pGetInst
319 INT32 lValue;
320 if( !pTypeClass->GetConstValue( nId, &lValue ) )
321 { // nicht gefunden
322 return ERR_ARRAY_INVALIDINDEX;
325 return GetValueEle( rInst, lValue, pCreateClass, pGetInst );
328 /*************************************************************************
330 |* RscArray::IsConsistent()
332 |* Beschreibung
333 |* Ersterstellung MM 23.09.91
334 |* Letzte Aenderung MM 23.09.91
336 *************************************************************************/
337 static BOOL IsConsistent( RscInstNode * pNode, RscInconsList * pList )
339 BOOL bRet = TRUE;
341 if( pNode )
343 bRet = pNode->aInst.pClass->IsConsistent( pNode->aInst, pList );
344 if( !IsConsistent( pNode->Left(), pList ) )
345 bRet = FALSE;
346 if( !IsConsistent( pNode->Right(), pList ) )
347 bRet = FALSE;
349 return bRet;
352 BOOL RscArray::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
354 RscArrayInst * pClassData;
355 BOOL bRet;
357 bRet = RscTop::IsConsistent( rInst, pList );
359 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
360 if( !::IsConsistent( pClassData->pNode, pList ) )
361 bRet = FALSE;
363 return( bRet );
366 /*************************************************************************
368 |* RscArray::SetToDefault()
370 |* Beschreibung
371 |* Ersterstellung MM 25.04.91
372 |* Letzte Aenderung MM 25.04.91
374 *************************************************************************/
375 static void SetToDefault( RscInstNode * pNode )
377 if( pNode )
379 pNode->aInst.pClass->SetToDefault( pNode->aInst );
380 SetToDefault( pNode->Left() );
381 SetToDefault( pNode->Right() );
385 void RscArray::SetToDefault( const RSCINST & rInst )
387 RscArrayInst * pClassData;
389 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
391 ::SetToDefault( pClassData->pNode );
393 RscTop::SetToDefault( rInst );
396 /*************************************************************************
398 |* RscArray::IsDefault()
400 |* Beschreibung
401 |* Ersterstellung MM 25.04.91
402 |* Letzte Aenderung MM 25.04.91
404 *************************************************************************/
405 static BOOL IsDefault( RscInstNode * pNode )
407 BOOL bRet = TRUE;
409 if( pNode )
411 bRet = pNode->aInst.pClass->IsDefault( pNode->aInst );
412 if( bRet )
413 bRet = IsDefault( pNode->Left() );
414 if( bRet )
415 bRet = IsDefault( pNode->Right() );
417 return bRet;
420 BOOL RscArray::IsDefault( const RSCINST & rInst )
422 RscArrayInst * pClassData;
424 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
426 BOOL bRet = ::IsDefault( pClassData->pNode );
428 if( bRet )
429 bRet = RscTop::IsDefault( rInst );
430 return bRet;
433 /*************************************************************************
435 |* RscArray::IsValueDefault()
437 |* Beschreibung
438 |* Ersterstellung MM 25.04.91
439 |* Letzte Aenderung MM 15.01.92
441 *************************************************************************/
442 static BOOL IsValueDefault( RscInstNode * pNode, CLASS_DATA pDef )
444 BOOL bRet = TRUE;
446 if( pNode )
448 bRet = pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDef );
449 if( bRet )
450 bRet = IsValueDefault( pNode->Left(), pDef );
451 if( bRet )
452 bRet = IsValueDefault( pNode->Right(), pDef );
454 return bRet;
457 BOOL RscArray::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
459 RscArrayInst * pClassData;
460 BOOL bRet;
462 bRet = RscTop::IsValueDefault( rInst, pDef );
464 if( bRet )
466 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
468 bRet = ::IsValueDefault( pClassData->pNode, pDef );
470 return bRet;
473 /*************************************************************************
474 |* RscArray::WriteSrcHeader()
476 |* Beschreibung
477 *************************************************************************/
478 void RscArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput,
479 RscTypCont * pTC, sal_uInt32 nTab,
480 const RscId & aId, const char * pVarName )
482 RscArrayInst * pClassData;
484 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
486 if( pTC->IsSrsDefault() )
487 { // nur einen Wert schreiben
488 RscInstNode * pNode = NULL;
489 if( pClassData->pNode )
491 std::vector< sal_uInt32 >::const_iterator it;
492 for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it )
493 pNode = pClassData->pNode->Search( *it );
496 if( pNode )
498 if( pNode->aInst.pClass->IsDefault( pNode->aInst ) )
499 fprintf( fOutput, "Default" );
500 else
501 pNode->aInst.pClass->WriteSrcHeader(
502 pNode->aInst, fOutput,
503 pTC, nTab, aId, pVarName );
504 return;
508 if( IsDefault( rInst ) )
509 fprintf( fOutput, "Default" );
510 else
512 RSCINST aSuper( GetSuperClass(), rInst.pData );
513 aSuper.pClass->WriteSrcHeader( aSuper, fOutput, pTC,
514 nTab, aId, pVarName );
516 if( !pTC->IsSrsDefault() )
517 WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
520 /*************************************************************************
521 |* RscArray::WriteSrc()
523 |* Beschreibung
524 *************************************************************************/
525 static void WriteSrc( RscInstNode * pNode, FILE * fOutput, RscTypCont * pTC,
526 sal_uInt32 nTab, const char * pVarName,
527 CLASS_DATA pDfltData, RscConst * pTypeClass )
529 if( pNode )
531 WriteSrc( pNode->Left(), fOutput, pTC, nTab, pVarName,
532 pDfltData, pTypeClass );
533 if( !pNode->aInst.pClass->IsValueDefault( pNode->aInst, pDfltData ) )
535 fprintf( fOutput, ";\n" );
536 for( sal_uInt32 n = 0; n < nTab; n++ )
537 fputc( '\t', fOutput );
539 Atom nIdxId;
540 pTypeClass->GetValueConst( pNode->GetId(), &nIdxId );
541 fprintf( fOutput, "%s[ %s ] = ", pVarName, pHS->getString( nIdxId ).getStr() );
542 pNode->aInst.pClass->WriteSrcHeader( pNode->aInst, fOutput, pTC,
543 nTab, RscId(), pVarName );
545 WriteSrc( pNode->Right(), fOutput, pTC, nTab, pVarName,
546 pDfltData, pTypeClass );
550 void RscArray::WriteSrcArray( const RSCINST & rInst, FILE * fOutput,
551 RscTypCont * pTC, sal_uInt32 nTab,
552 const char * pVarName )
554 RscArrayInst * pClassData;
556 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
558 ::WriteSrc( pClassData->pNode, fOutput, pTC, nTab, pVarName,
559 rInst.pData, pTypeClass );
562 void RscArray::WriteSrc( const RSCINST & rInst, FILE * fOutput,
563 RscTypCont * pTC, sal_uInt32 nTab,
564 const char * pVarName )
566 WriteSrcArray( rInst, fOutput, pTC, nTab, pVarName );
569 /*************************************************************************
570 |* RscArray::WriteRc()
572 |* Beschreibung
573 *************************************************************************/
574 ERRTYPE RscArray::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
575 RscTypCont * pTC, sal_uInt32 nDeep, BOOL bExtra )
577 ERRTYPE aError;
578 RscArrayInst * pClassData;
579 RscInstNode * pNode = NULL;
581 pClassData = (RscArrayInst *)(rInst.pData + nOffInstData);
583 if( pClassData->pNode )
585 #if OSL_DEBUG_LEVEL > 2
586 fprintf( stderr, "RscArray::WriteRc: Fallback " );
587 #endif
588 std::vector< sal_uInt32 >::const_iterator it;
589 for( it = pTC->GetFallbacks().begin(); !pNode && it != pTC->GetFallbacks().end(); ++it )
591 pNode = pClassData->pNode->Search( *it );
592 #if OSL_DEBUG_LEVEL > 2
593 fprintf( stderr, " 0x%hx", *it );
594 #endif
596 #if OSL_DEBUG_LEVEL > 2
597 fprintf( stderr, "\n" );
598 #endif
601 if( pNode )
602 aError = pNode->aInst.pClass->WriteRc( pNode->aInst, rMem, pTC,
603 nDeep, bExtra );
604 else
605 aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
607 return aError;
610 //========================================================================
611 void RscArray::WriteRcAccess
613 FILE * fOutput,
614 RscTypCont * pTC,
615 const char * pName
618 GetSuperClass()->WriteRcAccess( fOutput, pTC, pName );
621 /*************************************************************************
623 |* RscClassArray::RscClassArray()
625 |* Beschreibung
626 |* Ersterstellung MM 25.05.91
627 |* Letzte Aenderung MM 25.05.91
629 *************************************************************************/
630 RscClassArray::RscClassArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper,
631 RscEnum * pTypeCl )
632 : RscArray( nId, nTypeId, pSuper, pTypeCl )
636 /*************************************************************************
638 |* RscClassArray::~RscClassArray()
640 |* Beschreibung
641 |* Ersterstellung MM 25.05.91
642 |* Letzte Aenderung MM 25.05.91
644 *************************************************************************/
645 RscClassArray::~RscClassArray()
649 /*************************************************************************
651 |* RscClassArray::WriteSrcHeader()
653 |* Beschreibung
654 |* Ersterstellung MM 25.05.91
655 |* Letzte Aenderung MM 25.05.91
657 *************************************************************************/
658 void RscClassArray::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput,
659 RscTypCont * pTC, sal_uInt32 nTab,
660 const RscId & aId, const char * pName )
662 RscArray::WriteSrcHeader( rInst, fOutput, pTC, nTab, aId, pName );
665 /*************************************************************************
667 |* RscClassArray::WriteSrc()
669 |* Beschreibung
670 |* Ersterstellung MM 25.05.91
671 |* Letzte Aenderung MM 25.05.91
673 *************************************************************************/
674 void RscClassArray::WriteSrc( const RSCINST & rInst, FILE * fOutput,
675 RscTypCont * pTC, sal_uInt32 nTab,
676 const char * pVarName )
678 RscArray::WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
681 /*************************************************************************
683 |* RscClassArray::WriteRcHeader()
685 |* Beschreibung
686 |* Ersterstellung MM 25.05.91
687 |* Letzte Aenderung MM 25.05.91
689 *************************************************************************/
690 ERRTYPE RscClassArray::WriteRcHeader( const RSCINST & rInst, RscWriteRc & aMem,
691 RscTypCont * pTC, const RscId & aId,
692 sal_uInt32 nDeep, BOOL bExtra )
694 // Eigenen Typ schreiben
695 return GetSuperClass()->WriteRcHeader( rInst, aMem, pTC, aId,
696 nDeep, bExtra );
699 /*************************************************************************
701 |* RscLangArray::RscLangArray()
703 |* Beschreibung
704 |* Ersterstellung MM 25.05.91
705 |* Letzte Aenderung MM 25.05.91
707 *************************************************************************/
708 RscLangArray::RscLangArray( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper,
709 RscEnum * pTypeCl )
710 : RscArray( nId, nTypeId, pSuper, pTypeCl )
714 /*************************************************************************
716 |* RscLangArray::RscLangArray()
718 |* Beschreibung
719 |* Ersterstellung MM 25.05.91
720 |* Letzte Aenderung MM 25.05.91
722 *************************************************************************/
723 RSCCLASS_TYPE RscLangArray::GetClassType() const
725 if( GetSuperClass() )
726 return GetSuperClass()->GetClassType();
727 else
728 return RscArray::GetClassType();