xref: /AOO41X/main/rsc/source/res/rscclass.cxx (revision 477794c15c6b4ddeee1d73cab1de4160cfe6efef)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_rsc.hxx"
26 /****************** I N C L U D E S **************************************/
27 
28 // C and C++ Includes.
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 
33 // Programmabhaengige Includes.
34 #include <rscdb.hxx>
35 #include <rscclass.hxx>
36 
37 #include <tools/fsys.hxx>
38 #include <tools/rcid.h>
39 #include <tools/rc.h>
40 
41 /****************** C O D E **********************************************/
42 /****************** R s c C l a s s **************************************/
43 /*************************************************************************
44 |*
45 |*    RscClass::RscClass()
46 |*
47 |*    Beschreibung
48 |*    Ersterstellung    MM 25.05.91
49 |*    Letzte Aenderung  MM 25.05.91
50 |*
51 *************************************************************************/
RscClass(Atom nId,sal_uInt32 nTypeId,RscTop * pSuperCl)52 RscClass::RscClass( Atom nId, sal_uInt32 nTypeId, RscTop * pSuperCl )
53     : RscTop( nId, nTypeId, pSuperCl )
54 {
55     nEntries = 0;
56     pVarTypeList = NULL;
57     nSuperSize = RscTop::Size();
58     nSize = nSuperSize + ALIGNED_SIZE( sizeof( RscClassInst ) );
59 }
60 
61 /*************************************************************************
62 |*
63 |*    RscClass::Pre_dtor()
64 |*
65 |*    Beschreibung
66 |*    Ersterstellung    MM 25.05.91
67 |*    Letzte Aenderung  MM 25.05.91
68 |*
69 *************************************************************************/
Pre_dtor()70 void RscClass::Pre_dtor()
71 {
72     sal_uInt32  i;
73 
74     RscTop::Pre_dtor();
75 
76     for( i = 0; i < nEntries; i++ )
77     {
78         if( pVarTypeList[ i ].pDefault )
79         {
80             pVarTypeList[ i ].pClass->Destroy(
81                          RSCINST( pVarTypeList[ i ].pClass,
82                                   pVarTypeList[ i ].pDefault ) );
83             rtl_freeMemory( pVarTypeList[ i ].pDefault );
84             pVarTypeList[ i ].pDefault = NULL;
85         };
86     };
87 }
88 
89 /*************************************************************************
90 |*
91 |*    RscClass::~RscClass()
92 |*
93 |*    Beschreibung
94 |*    Ersterstellung    MM 25.05.91
95 |*    Letzte Aenderung  MM 25.05.91
96 |*
97 *************************************************************************/
~RscClass()98 RscClass::~RscClass()
99 {
100     if( pVarTypeList )
101         rtl_freeMemory( (void *)pVarTypeList );
102 }
103 
104 /*************************************************************************
105 |*
106 |*    RscClass::GetClassType()
107 |*
108 |*    Beschreibung
109 |*    Ersterstellung    MM 25.05.91
110 |*    Letzte Aenderung  MM 25.05.91
111 |*
112 *************************************************************************/
GetClassType() const113 RSCCLASS_TYPE RscClass::GetClassType() const
114 {
115     return RSCCLASS_COMPLEX;
116 }
117 
118 /*************************************************************************
119 |*
120 |*    RscClass::GetInstData()
121 |*
122 |*    Beschreibung
123 |*    Ersterstellung    MM 15.04.91
124 |*    Letzte Aenderung  MM 15.04.91
125 |*
126 *************************************************************************/
GetInstData(CLASS_DATA pData,sal_uInt32 nEle,sal_Bool bGetCopy)127 RSCINST RscClass::GetInstData
128 (
129     CLASS_DATA pData,
130     sal_uInt32 nEle,
131     sal_Bool bGetCopy
132 )
133 {
134     RSCINST aInst;
135 
136     aInst.pClass = pVarTypeList[ nEle ].pClass;
137     if( pData )
138     {
139         if( VAR_NODATAINST & pVarTypeList[ nEle ].nVarType )
140         {
141             RSCINST aTmpI;
142 
143             aTmpI.pClass = this;
144             aTmpI.pData = pData;
145             if( bGetCopy )
146                 aInst.pData = GetCopyVar(
147                                   aTmpI,
148                                   pVarTypeList[ nEle ].nDataBaseName
149                               ).pData;
150             else
151                 aInst.pData = GetVariable(
152                                   aTmpI,
153                                   pVarTypeList[ nEle ].nDataBaseName,
154                                   RSCINST()
155                               ).pData;
156         }
157         else if( VAR_POINTER & pVarTypeList[ nEle ].nVarType )
158         {
159             if( VAR_EXTENDABLE & pVarTypeList[ nEle ].nVarType )
160                 aInst = *(RSCINST *)
161                               (pData + pVarTypeList[ nEle ].nOffset);
162             else
163                 aInst.pData = *(CLASS_DATA *)
164                               (pData + pVarTypeList[ nEle ].nOffset);
165         }
166         else
167             aInst.pData = pData + pVarTypeList[ nEle ].nOffset;
168     };
169     return( aInst );
170 }
171 
172 /*************************************************************************
173 |*
174 |*    RscClass::GetInstDflt()
175 |*
176 |*    Beschreibung
177 |*
178 *************************************************************************/
GetDfltData(sal_uInt32 nEle)179 CLASS_DATA RscClass::GetDfltData( sal_uInt32 nEle )
180 {
181     if( pVarTypeList[ nEle ].pDefault )
182         return pVarTypeList[ nEle ].pDefault;
183 
184     return pVarTypeList[ nEle ].pClass->GetDefault().pData;
185 }
186 
187 /*************************************************************************
188 |*
189 |*    RscClass::SetVarDflt()
190 |*
191 |*    Beschreibung
192 |*    Ersterstellung    MM 22.07.91
193 |*    Letzte Aenderung  MM 22.07.91
194 |*
195 *************************************************************************/
SetVarDflt(CLASS_DATA pData,sal_uInt32 nEle,sal_Bool bSet)196 void RscClass::SetVarDflt( CLASS_DATA pData, sal_uInt32 nEle, sal_Bool bSet )
197 {
198     RscClassInst * pClass;
199 
200     pClass = (RscClassInst *)(pData + nSuperSize );
201     if( bSet )
202         pClass->nVarDflt |= ((sal_uLong)1 << nEle);
203     else
204         pClass->nVarDflt &= ~((sal_uLong)1 << nEle);
205 }
206 
207 /*************************************************************************
208 |*
209 |*    RscClass::IsDflt()
210 |*
211 |*    Beschreibung
212 |*    Ersterstellung    MM 22.07.91
213 |*    Letzte Aenderung  MM 08.01.92
214 |*
215 *************************************************************************/
IsDflt(CLASS_DATA pData,sal_uInt32 nEle)216 sal_Bool RscClass::IsDflt( CLASS_DATA pData, sal_uInt32 nEle )
217 {
218     RscClassInst *  pClass;
219     sal_Bool            bRet;
220 
221     pClass = (RscClassInst *)(pData + nSuperSize );
222     if( pClass->nVarDflt & ((sal_uLong)1 << nEle) )
223         bRet = sal_True;
224     else
225         bRet = sal_False;
226 /*  {
227         //Variablenname ist Default
228         RSCINST aTmpI;
229 
230         aTmpI = GetInstData( pData, nEle, sal_True );
231         if( aTmpI.IsInst() && !aTmpI.pClass->IsDefault( aTmpI ) )
232             bRet = sal_False;
233     }
234 */
235     return bRet;
236 }
237 
238 /*************************************************************************
239 |*
240 |*    RscClass::Create()
241 |*
242 |*    Beschreibung
243 |*    Ersterstellung    MM 03.04.91
244 |*    Letzte Aenderung  MM 03.04.91
245 |*
246 *************************************************************************/
Create(RSCINST * pInst,const RSCINST & rDflt,sal_Bool bOwnClass)247 RSCINST RscClass::Create
248 (
249     RSCINST * pInst,
250     const RSCINST & rDflt,
251     sal_Bool bOwnClass
252 )
253 {
254     sal_uInt32  i;
255     CLASS_DATA  * ppData;
256     RSCINST aInst;
257     RSCINST aMemInst, aDfltI;
258 
259     if( !pInst )
260     {
261         aInst.pClass = this;
262         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
263     }
264     else
265         aInst = *pInst;
266     if( !bOwnClass && rDflt.IsInst() )
267         bOwnClass = rDflt.pClass->InHierarchy( this );
268 
269     RscTop::Create( &aInst, rDflt, bOwnClass );
270 
271     if( bOwnClass )
272         ((RscClassInst *)(aInst.pData + nSuperSize))->nVarDflt =
273             ((RscClassInst *)(rDflt.pData + nSuperSize))->nVarDflt;
274     else
275         ((RscClassInst *)(aInst.pData + nSuperSize))->nVarDflt = ~((sal_uLong)0);
276 
277     for( i = 0; i < nEntries; i++ )
278     {
279         aDfltI = GetInstData( bOwnClass ? rDflt.pData : NULL, i, sal_True );
280 
281         if( (VAR_POINTER & pVarTypeList[ i ].nVarType)
282           && !(VAR_NODATAINST & pVarTypeList[ i ].nVarType) )
283         {
284             if( VAR_EXTENDABLE & pVarTypeList[ i ].nVarType )
285             {
286                 RSCINST * pInstance = (RSCINST *)
287                         (aInst.pData + pVarTypeList[ i ].nOffset );
288                 pInstance->pClass = pVarTypeList[ i ].pClass;
289                 ppData = &pInstance->pData;
290             }
291             else
292                 ppData = (CLASS_DATA* )
293                         (aInst.pData + pVarTypeList[ i ].nOffset );
294             *ppData = NULL;
295             if( aDfltI.IsInst() )
296             {
297                 aMemInst = pVarTypeList[ i ].pClass->Create( NULL, aDfltI );
298                 *ppData = aMemInst.pData;
299             };
300         }
301         else
302         {
303             aMemInst = GetInstData( aInst.pData, i, sal_True );
304             aMemInst = aMemInst.pClass->Create( &aMemInst, aDfltI );
305         };
306     }
307 
308     return( aInst );
309 }
310 
311 /*************************************************************************
312 |*
313 |*    RscClass::Destroy()
314 |*
315 |*    Beschreibung
316 |*
317 *************************************************************************/
Destroy(const RSCINST & rInst)318 void RscClass::Destroy( const RSCINST & rInst )
319 {
320     sal_uInt32  i;
321 
322     RscTop::Destroy( rInst );
323 
324     for( i = 0; i < nEntries; i++ )
325     {
326         if( !(pVarTypeList[ i ].nVarType & VAR_NODATAINST) )
327         {
328             RSCINST aTmpI;
329 
330             aTmpI = GetInstData( rInst.pData, i, sal_True );
331             if( aTmpI.IsInst() )
332             {
333                 // Objekt loeschen
334                 aTmpI.pClass->Destroy( aTmpI );
335                 if( pVarTypeList[ i ].nVarType & VAR_POINTER )
336                 {
337                     // Speicher freigeben
338                     rtl_freeMemory( aTmpI.pData );
339                 };
340             };
341         }
342     };
343 }
344 
345 /*************************************************************************
346 |*
347 |*    RscClass::SetVariable()
348 |*
349 |*    Beschreibung
350 |*
351 *************************************************************************/
SetVariable(Atom nVarName,RscTop * pClass,RSCINST * pDflt,RSCVAR nVarType,sal_uInt32 nMask,Atom nDataBaseName)352 ERRTYPE RscClass::SetVariable
353 (
354     Atom nVarName,
355     RscTop * pClass,
356     RSCINST * pDflt,
357     RSCVAR nVarType,
358     sal_uInt32 nMask,
359     Atom nDataBaseName
360 )
361 {
362     if( pVarTypeList )
363         pVarTypeList = (VARTYPE_STRUCT *)
364                  rtl_reallocateMemory( (void *)pVarTypeList,
365                  ((nEntries +1) * sizeof( VARTYPE_STRUCT )) );
366     else
367         pVarTypeList = (VARTYPE_STRUCT *)
368             rtl_allocateMemory( ((nEntries +1)
369                             * sizeof( VARTYPE_STRUCT )) );
370 
371     pVarTypeList[ nEntries ].nVarName       = nVarName;
372     pVarTypeList[ nEntries ].nMask          = nMask;
373     pVarTypeList[ nEntries ].pClass         = pClass;
374     pVarTypeList[ nEntries ].nOffset        = nSize;
375     pVarTypeList[ nEntries ].nDataBaseName  = nDataBaseName;
376     if( pDflt )
377         pVarTypeList[ nEntries ].pDefault = pDflt->pData;
378     else
379         pVarTypeList[ nEntries ].pDefault = NULL;
380 
381     pVarTypeList[ nEntries ].nVarType = ~VAR_POINTER & nVarType;
382     if( pClass->Size() > 10 || (nVarType & VAR_EXTENDABLE) )
383         pVarTypeList[ nEntries ].nVarType |= VAR_POINTER;
384 
385     if( !(pVarTypeList[ nEntries ].nVarType & VAR_NODATAINST) )
386     {
387         if( pVarTypeList[ nEntries ].nVarType & VAR_POINTER )
388         {
389             if( pVarTypeList[ nEntries ].nVarType & VAR_EXTENDABLE )
390                 nSize += sizeof( RSCINST );
391             else
392                 nSize += sizeof( CLASS_DATA );
393         }
394         else
395             nSize += pClass->Size();
396     }
397 
398     nEntries++;
399     if( nEntries > (sizeof( sal_uLong ) * 8) )
400     {
401         // Bereich fuer Default zu klein
402         RscExit( 16 );
403     };
404     return( ERR_OK );
405 }
406 
407 /*************************************************************************
408 |*
409 |*    RscClass::EnumVariable()
410 |*
411 |*    Beschreibung
412 |*
413 *************************************************************************/
EnumVariables(void * pData,VarEnumCallbackProc pProc)414 void RscClass::EnumVariables( void * pData, VarEnumCallbackProc pProc )
415 {
416     sal_uInt32 i;
417 
418     RscTop::EnumVariables( pData, pProc );
419     for( i = 0; i < nEntries; i ++ )
420     {
421         if( !(pVarTypeList[ i ].nVarType & VAR_NOENUM) )
422             (*pProc)( pData, pVarTypeList[ i ].pClass->GetClassType(),
423                         pVarTypeList[ i ].nVarName );
424     }
425 }
426 
427 /*************************************************************************
428 |*
429 |*    RscClass::GetVariable()
430 |*
431 |*    Beschreibung
432 |*
433 *************************************************************************/
GetVariable(const RSCINST & rInst,Atom nVarName,const RSCINST & rInitInst,sal_Bool bInitDflt,RscTop * pCreateClass)434 RSCINST RscClass::GetVariable
435 (
436     const RSCINST & rInst,
437     Atom nVarName,
438     const RSCINST & rInitInst,
439     sal_Bool bInitDflt,
440     RscTop * pCreateClass
441 )
442 {
443     sal_uInt32  i = 0;
444     RSCINST aTmpI;
445 
446     while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName )
447         i++;
448     if( i < nEntries )
449     {
450         if( VAR_NODATAINST & pVarTypeList[ i ].nVarType )
451         {
452             aTmpI = GetVariable( rInst,
453                                  pVarTypeList[ i ].nDataBaseName,
454                                  RSCINST() );
455             aTmpI.pClass = pVarTypeList[ i ].pClass;
456         }
457         else
458         {
459             // Default Instanz generieren
460             RSCINST aDefInst = rInitInst;
461             if( !aDefInst.IsInst() && bInitDflt )
462             {
463                 // mit dem Variablen-Default besetzen
464                 aDefInst.pData  = pVarTypeList[ i ].pDefault;
465                 aDefInst.pClass = pVarTypeList[ i ].pClass;
466             }
467 
468             aTmpI = GetInstData( rInst.pData, i );
469             if( aTmpI.IsInst() )
470             {
471                 if( aDefInst.IsInst() )
472                 {
473                     aTmpI.pClass->Destroy( aTmpI );
474                     aTmpI.pClass->Create( &aTmpI, aDefInst );
475                 }
476             }
477             else
478             { // Wird ueber Zeiger angegeben
479                 if( VAR_EXTENDABLE & pVarTypeList[ i ].nVarType )
480                 {
481                     RSCINST * pInst = (RSCINST *)
482                             (rInst.pData + pVarTypeList[ i ].nOffset );
483                     if( pCreateClass && pCreateClass->InHierarchy( aTmpI.pClass ) )
484                         *pInst = pCreateClass->Create( NULL, aDefInst );
485                     else
486                         *pInst = aTmpI.pClass->Create( NULL, aDefInst );
487                     aTmpI = *pInst;
488                 }
489                 else
490                 {
491                     CLASS_DATA  * ppData
492                         = (CLASS_DATA *)(rInst.pData + pVarTypeList[ i ].nOffset);
493                     aTmpI = aTmpI.pClass->Create( NULL, aDefInst );
494                     *ppData = aTmpI.pData;
495                 }
496             }
497         };
498         // auf nicht Default setzen
499         SetVarDflt( rInst.pData, i, sal_False );
500         return( aTmpI );
501     };
502 
503     return( RscTop::GetVariable( rInst, nVarName, rInitInst,
504                                 bInitDflt, pCreateClass ) );
505 }
506 
507 /*************************************************************************
508 |*
509 |*    RscClass::GetCopyVar()
510 |*
511 |*    Beschreibung
512 |*
513 *************************************************************************/
GetCopyVar(const RSCINST & rInst,Atom nVarName)514 RSCINST RscClass::GetCopyVar
515 (
516     const RSCINST & rInst,
517     Atom nVarName
518 )
519 {
520     sal_uInt32  i = 0;
521     RSCINST aVarI;
522 
523     while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName )
524         i++;
525 
526     if( i < nEntries )
527     {
528         if( VAR_NODATAINST & pVarTypeList[ i ].nVarType )
529         {
530             aVarI = GetCopyVar( rInst, pVarTypeList[ i ].nDataBaseName );
531             aVarI.pClass = pVarTypeList[ i ].pClass;
532         }
533         else
534         {
535             if( IsDflt( rInst.pData, i ) )
536             {
537                 // mit Variablen Default initialiaieren
538                 aVarI = GetVariable( rInst, nVarName, RSCINST(), sal_True );
539                 SetVarDflt( rInst.pData, i, sal_True );
540             }
541             else
542                 aVarI = GetInstData( rInst.pData, i, sal_True );
543 
544         };
545         return aVarI ;
546     };
547 
548     return RscTop::GetCopyVar( rInst, nVarName );
549 }
550 
551 /*************************************************************************
552 |*
553 |*    RscClass::IsConsistent()
554 |*
555 |*    Beschreibung
556 |*
557 *************************************************************************/
IsConsistent(const RSCINST & rInst,RscInconsList * pList)558 sal_Bool RscClass::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
559 {
560     sal_uInt32  i = 0;
561     RSCINST aTmpI;
562     sal_Bool    bRet;
563 
564     bRet = RscTop::IsConsistent( rInst, pList );
565 
566     for( i = 0; i < nEntries; i++ )
567     {
568         if( !(VAR_NODATAINST & pVarTypeList[ i ].nVarType) )
569         {
570             aTmpI = GetInstData( rInst.pData, i, sal_True );
571 
572             if( aTmpI.IsInst() )
573                 if( ! aTmpI.pClass->IsConsistent( aTmpI, pList ) )
574                     bRet = sal_False;
575         }
576     };
577 
578     return( bRet );
579 }
580 
581 /*************************************************************************
582 |*
583 |*    RscClass::SetToDefault()
584 |*
585 |*    Beschreibung
586 |*
587 *************************************************************************/
SetToDefault(const RSCINST & rInst)588 void RscClass::SetToDefault( const RSCINST & rInst )
589 {
590     sal_uInt32  i;
591     RSCINST aTmpI;
592     RscClassInst *  pClass;
593 
594     pClass = (RscClassInst *)(rInst.pData + nSuperSize );
595 
596     for( i = 0; i < nEntries; i++ )
597     {
598         // Variablen ohne eigenen Speicher werden vom "Datenserver"
599         // auf Default gesetzt
600         if( !(VAR_NODATAINST & pVarTypeList[ i ].nVarType) )
601         {
602             aTmpI = GetInstData( rInst.pData, i, sal_True );
603             if( aTmpI.IsInst() )
604                 aTmpI.pClass->SetToDefault( aTmpI );
605         }
606     }
607     pClass->nVarDflt = ~((sal_uLong)0); // alles auf Default
608 
609     RscTop::SetToDefault( rInst );
610 }
611 
612 /*************************************************************************
613 |*
614 |*    RscClass::IsDefault()
615 |*
616 |*    Beschreibung
617 |*
618 *************************************************************************/
IsDefault(const RSCINST & rInst)619 sal_Bool RscClass::IsDefault( const RSCINST & rInst )
620 {
621     sal_uInt32  i;
622     RSCINST aTmpI;
623 
624     for( i = 0; i < nEntries; i++ )
625     {
626         // Variablen ohne eigenen Speicher werden vom "Datenserver"
627         // auf Default untersucht
628         if( !(VAR_NODATAINST & pVarTypeList[ i ].nVarType) )
629             if( !IsDflt( rInst.pData, i ) )
630                 return( sal_False );
631     };
632 
633     return( RscTop::IsDefault( rInst ) );
634 }
635 
636 /*************************************************************************
637 |*
638 |*    RscClass::GetDefault()
639 |*
640 |*    Beschreibung
641 |*
642 *************************************************************************/
GetDefault(Atom nVarId)643 RSCINST RscClass::GetDefault( Atom nVarId )
644 {
645     sal_uInt32  i;
646 
647     i = 0;
648     while( i < nEntries && pVarTypeList[ i ].nVarName != nVarId )
649         i++;
650     if( i < nEntries )
651     {
652         RSCINST aTmpI;
653 
654         aTmpI.pClass = pVarTypeList[ i ].pClass;
655         aTmpI.pData  = GetDfltData( i );
656         return( aTmpI );
657     };
658 
659     return( RscTop::GetDefault( nVarId ) );
660 }
661 
662 /*************************************************************************
663 |*
664 |*    RscClass::IsValueDflt()
665 |*
666 |*    Beschreibung
667 |*
668 *************************************************************************/
IsValueDflt(CLASS_DATA pData,sal_uInt32 nEle)669 sal_Bool RscClass::IsValueDflt( CLASS_DATA pData, sal_uInt32 nEle )
670 {
671     RSCINST aTmpI;
672 
673     aTmpI = GetInstData( pData, nEle, sal_True );
674 
675     if( aTmpI.IsInst() )
676     {
677         if( VAR_SVDYNAMIC & pVarTypeList[ nEle ].nVarType )
678             return sal_False;
679 
680         if( aTmpI.pClass == pVarTypeList[ nEle ].pClass )
681             //sie haben auch die gleiche Klasse
682             return aTmpI.pClass->IsValueDefault( aTmpI, GetDfltData( nEle ) );
683         else
684             return sal_False;
685     }
686     return sal_True;
687 }
688 
689 /*************************************************************************
690 |*
691 |*    RscClass::IsValueDefault()
692 |*
693 |*    Beschreibung
694 |*
695 *************************************************************************/
IsValueDefault(const RSCINST & rInst,CLASS_DATA pDef)696 sal_Bool RscClass::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
697 {
698     sal_uInt32  i = 0;
699     RSCINST aTmpI;
700     RSCINST aDfltI;
701 
702     if( !RscTop::IsValueDefault( rInst, pDef ) )
703         return sal_False;
704 
705     if( pDef )
706     {
707         for( i = 0; i < nEntries; i++ )
708         {
709             aTmpI = GetInstData( rInst.pData, i, sal_True );
710             if( aTmpI.IsInst() )
711             {
712                 if( aTmpI.pClass != pVarTypeList[ i ].pClass )
713                     //sie haben nicht die gleiche Klasse
714                     return sal_False;
715 
716                 aDfltI = GetInstData( pDef, i, sal_True );
717                 if( !aDfltI.IsInst() )
718                     aDfltI.pData = GetDfltData( i );
719 
720                 if( !aTmpI.pClass->IsValueDefault( aTmpI, aDfltI.pData ) )
721                     return sal_False;
722             }
723         }
724     }
725     else
726         return sal_False;
727 
728     return sal_True;
729 }
730 
731 /*************************************************************************
732 |*
733 |*    RscClass::SetDefault()
734 |*
735 |*    Beschreibung
736 |*
737 *************************************************************************/
SetDefault(const RSCINST & rInst,Atom nVarName)738 void RscClass::SetDefault( const RSCINST & rInst, Atom nVarName )
739 {
740     sal_uInt32  i = 0;
741     RSCINST aTmpI;
742 
743     while( i < nEntries && pVarTypeList[ i ].nVarName != nVarName )
744         i++;
745 
746     if( i < nEntries )
747     {
748         aTmpI = GetInstData( rInst.pData, i, sal_True );
749         if( aTmpI.IsInst() )
750         {
751             aTmpI.pClass->Destroy( aTmpI );
752             aTmpI.pClass->Create( &aTmpI, RSCINST() );
753             SetVarDflt( rInst.pData, i, sal_True );
754         }
755     }
756     else //In Superklasse nach Variable suchen
757         RscTop::SetDefault( rInst, nVarName );
758 
759 }
760 
761 
762 /*************************************************************************
763 |*
764 |*    RscClass::WriteSrc()
765 |*
766 |*    Beschreibung
767 |*
768 *************************************************************************/
WriteSrc(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,sal_uInt32 nTab,const char * pVarName)769 void RscClass::WriteSrc
770 (
771     const RSCINST & rInst,
772     FILE * fOutput,
773     RscTypCont * pTC,
774     sal_uInt32 nTab,
775     const char * pVarName
776 )
777 {
778     sal_uInt32  i = 0, n = 0;
779     RSCINST aTmpI;
780 
781     RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
782 
783     for( i = 0; i < nEntries; i++ )
784     {
785         if( !(VAR_HIDDEN & pVarTypeList[ i ].nVarType) )
786         {
787             // Hack wegen Position und Dimensiuon
788             if( nRsc_XYMAPMODEId == pVarTypeList[ i ].nVarName
789               || nRsc_WHMAPMODEId == pVarTypeList[ i ].nVarName )
790             {
791                 if( !IsDflt( rInst.pData, i )     //MapUnit
792                   || !IsDflt( rInst.pData, i+1 )  //X, Width
793                   || !IsDflt( rInst.pData, i+2 ) )//Y, Height
794                 {// ein Wert ist nicht Default
795                     for( n = 0; n < nTab; n++ )
796                         fputc( '\t', fOutput );
797                     if( nRsc_XYMAPMODEId == pVarTypeList[ i ].nVarName )
798                         fprintf( fOutput, "Pos = " );
799                     else
800                         fprintf( fOutput, "Size = " );
801 
802                     if( !IsDflt( rInst.pData, i ) )
803                     {
804                         aTmpI = GetInstData( rInst.pData, i, sal_True );
805                         aTmpI.pClass->WriteSrcHeader(
806                               aTmpI, fOutput, pTC, nTab, RscId(), pVarName );
807                     }
808 
809                     fprintf( fOutput, "( " );
810                     aTmpI = GetInstData( rInst.pData, i+1, sal_True );
811                     if( !aTmpI.IsInst() )
812                         aTmpI.pData = GetDfltData( i+1 );
813                     aTmpI.pClass->WriteSrcHeader(
814                               aTmpI, fOutput, pTC, nTab, RscId(), pVarName );
815 
816                     fprintf( fOutput, ", " );
817                     aTmpI = GetInstData( rInst.pData, i+2, sal_True );
818                     if( !aTmpI.IsInst() )
819                         aTmpI.pData = GetDfltData( i+2 );
820                     aTmpI.pClass->WriteSrcHeader(
821                               aTmpI, fOutput, pTC, nTab, RscId(), pVarName );
822                     fprintf( fOutput, " );\n" );
823                 }
824                 i += 2; //_X, _Y oder _Widht, Height ueberlesen
825             }
826             else if( !IsDflt( rInst.pData, i )
827               && !IsValueDflt( rInst.pData, i ) )
828             {
829                 aTmpI = GetInstData( rInst.pData, i, sal_True );
830 
831                 if( aTmpI.IsInst() )
832                 {
833                     const char * pName = pHS->getString( pVarTypeList[ i ].nVarName ).getStr();
834 
835                     for( n = 0; n < nTab; n++ )
836                         fputc( '\t', fOutput );
837                     fprintf( fOutput, "%s", pName );
838                     fprintf( fOutput, " = " );
839                     aTmpI.pClass->WriteSrcHeader(
840                               aTmpI, fOutput, pTC, nTab, RscId(), pName );
841                     fprintf( fOutput, ";\n" );
842                 }
843             };
844         };
845     };
846 
847     return;
848 }
849 
850 /*************************************************************************
851 |*
852 |*    RscClass::WriteInstRc()
853 |*
854 |*    Beschreibung
855 |*
856 *************************************************************************/
GetCorrectValues(const RSCINST & rInst,sal_uInt32 nVarPos,sal_uInt32 nTupelIdx,RscTypCont * pTC)857 sal_Int32 RscClass::GetCorrectValues
858 (
859     const RSCINST & rInst,
860     sal_uInt32 nVarPos,
861     sal_uInt32 nTupelIdx,
862     RscTypCont * pTC
863 )
864 {
865     sal_Int32 nLang = 0;
866     sal_Int32 nBaseValue;
867 
868     // Basiswert holen
869     RSCINST aTmpI = GetInstData( rInst.pData, nVarPos, sal_True );
870     aTmpI.pClass->GetNumber( aTmpI, &nBaseValue );
871 
872     // Sprach Delta holen
873     aTmpI = rInst.pClass->GetVariable( rInst, nRsc_DELTALANG, RSCINST() );
874     if( aTmpI.IsInst() )
875     {
876         RscWriteRc aMem;
877         aTmpI.pClass->WriteRc( aTmpI, aMem, pTC, 0, sal_False );
878         nLang = (sal_Int32)aMem.GetShort( nTupelIdx * sizeof(sal_uInt16) );
879     }
880 
881     return nLang + nBaseValue;
882 }
883 
WriteInstRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra)884 ERRTYPE RscClass::WriteInstRc
885 (
886     const RSCINST & rInst,
887     RscWriteRc & rMem,
888     RscTypCont * pTC,
889     sal_uInt32 nDeep,
890     sal_Bool bExtra
891 )
892 {
893     sal_uInt32 i = 0;
894     ERRTYPE aError;
895     RSCINST aTmpI;
896     sal_uInt32  nMaskOff = 0;// Offset um Maskenfeld zu addressieren
897 
898     // Wenn eine Variable Maskierung hat, dann Maskenfeld
899     for( i = 0; i < nEntries; i++ )
900     {
901         if( pVarTypeList[ i ].nMask )
902         {
903             nMaskOff = rMem.Size();
904             rMem.Put( sal_uInt32(0) );
905             break;
906         }
907     };
908 
909     for( i = 0; i < nEntries && aError.IsOk(); i++ )
910     {
911         if( !((VAR_NODATAINST | VAR_NORC) & pVarTypeList[ i ].nVarType ))
912         {
913             if( pVarTypeList[ i ].nMask )
914             {
915                 if( !IsDflt( rInst.pData, i ) )
916                 {
917                     if( nRsc_X == pVarTypeList[ i ].nVarName )
918                     {
919                         sal_Int32 nVal = GetCorrectValues( rInst, i, 0, pTC );
920                         rMem.Put( nVal );
921                     }
922                     else if( nRsc_Y == pVarTypeList[ i ].nVarName )
923                     {
924                         sal_Int32 nVal = GetCorrectValues( rInst, i, 1, pTC );
925                         rMem.Put( nVal );
926                     }
927                     else if( nRsc_WIDTH == pVarTypeList[ i ].nVarName )
928                     {
929                         sal_Int32 nVal = GetCorrectValues( rInst, i, 2, pTC );
930                         rMem.Put( nVal );
931                     }
932                     else if( nRsc_HEIGHT == pVarTypeList[ i ].nVarName )
933                     {
934                         sal_Int32 nVal = GetCorrectValues( rInst, i, 3, pTC );
935                         rMem.Put( nVal );
936                     }
937                     else
938                     {
939                         aTmpI = GetInstData( rInst.pData, i, sal_True );
940                         // Nur an Variable Extradata bExtra nicht auf sal_False
941                         // setzen
942                         aError = aTmpI.pClass->
943                             WriteRcHeader( aTmpI, rMem, pTC,
944                                         RscId(), nDeep,
945                                         (nRsc_EXTRADATA
946                                         == pVarTypeList[ i ].nVarName)
947                                         ? bExtra : sal_False );
948                     }
949                     sal_uInt32 nMask = rMem.GetLong( nMaskOff );
950                     nMask |= pVarTypeList[ i ].nMask;
951                     rMem.PutAt( nMaskOff, nMask );
952                 }
953             }
954             else{
955                 if( IsDflt( rInst.pData, i ) )
956                 {
957                     aTmpI.pClass = pVarTypeList[ i ].pClass;
958                     aTmpI.pData  = GetDfltData( i );
959                 }
960                 else
961                     aTmpI = GetInstData( rInst.pData, i, sal_True );
962                 // Nur an Variable Extradata bExtra nicht auf sal_False
963                 // setzen
964                 aError = aTmpI.pClass->
965                             WriteRcHeader( aTmpI, rMem, pTC,
966                                         RscId(), nDeep,
967                                         (nRsc_EXTRADATA
968                                         == pVarTypeList[ i ].nVarName)
969                                         ? bExtra : sal_False );
970             }
971         }
972     }
973 
974     return( aError );
975 }
976 
977 /*************************************************************************
978 |*
979 |*    RscClass::WriteRc()
980 |*
981 |*    Beschreibung
982 |*
983 *************************************************************************/
WriteRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra)984 ERRTYPE RscClass::WriteRc
985 (
986     const RSCINST & rInst,
987     RscWriteRc & rMem,
988     RscTypCont * pTC,
989     sal_uInt32 nDeep,
990     sal_Bool bExtra
991 )
992 {
993     ERRTYPE aError;
994 
995     aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
996     if( aError.IsOk() )
997         aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
998 
999     return( aError );
1000 }
1001 
1002 /*************************************************************************
1003 |*
1004 |*    RscClass::WriteSyntax()
1005 |*
1006 |*    Beschreibung
1007 |*
1008 *************************************************************************/
WriteSyntax(FILE * fOutput,RscTypCont * pTC)1009 void RscClass::WriteSyntax( FILE * fOutput, RscTypCont * pTC )
1010 {
1011     RscTop::WriteSyntax( fOutput, pTC );
1012 
1013     sal_uInt32 i;
1014     // Wenn eine Variable Maskierung hat, dann Maskenfeld
1015     fprintf( fOutput, "\t//%s\n", pHS->getString( GetId() ).getStr() );
1016     for( i = 0; i < nEntries; i++ )
1017     {
1018         fprintf( fOutput, "\t%s", pHS->getString( pVarTypeList[ i ].nVarName ).getStr() );
1019         sal_uInt32 n = strlen( pHS->getString( pVarTypeList[ i ].nVarName ).getStr() );
1020         while( n < 20 )
1021         {
1022             putc( ' ', fOutput );
1023             n++;
1024         }
1025         fprintf( fOutput, " = %s;\n",
1026                 pHS->getString( pVarTypeList[ i ].pClass->GetId() ).getStr() );
1027     };
1028 }
1029 
1030 //==================================================================
WriteRcAccess(FILE * fOutput,RscTypCont *,const char * pName)1031 void RscClass::WriteRcAccess
1032 (
1033     FILE * fOutput,
1034     RscTypCont * /*pTC*/,
1035     const char * pName
1036 )
1037 {
1038     fprintf( fOutput, "\t\tSet%s( %s ", pName, pHS->getString( GetId() ).getStr() );
1039     fprintf( fOutput, "%s ", aCallPar2.GetBuffer() );
1040     fprintf( fOutput, "ResId( (RSHEADER_TYPE*)(pResData+nOffset) ) ) );\n" );
1041     fprintf( fOutput, "\t\tnOffset += GetObjSizeRes( (RSHEADER_TYPE*)(pResData+nOffset) );\n" );
1042 }
1043 
1044 //==================================================================
WriteRcCtor(FILE * fOutput,RscTypCont * pTC)1045 void RscClass::WriteRcCtor( FILE * fOutput, RscTypCont * pTC )
1046 {
1047     if( GetId() != InvalidAtom )
1048     {
1049         // Konstruktor
1050         fprintf( fOutput, "%s::%s%s bFreeResource )",
1051                 pHS->getString( GetId() ).getStr(),
1052                 pHS->getString( GetId() ).getStr(),
1053                 aCallParType.GetBuffer() );
1054         if( GetSuperClass() )
1055         {
1056             // Superaufruf
1057             fprintf( fOutput, "\n\t: %s", pHS->getString( GetSuperClass()->GetId() ).getStr() );
1058             fprintf( fOutput, "%s", GetSuperClass()->aCallPar1.GetBuffer() );
1059             fprintf( fOutput, " rResId.SetRT2( 0x%lx ) )",
1060                      sal::static_int_cast< unsigned long >(GetTypId()) );
1061         }
1062         fprintf( fOutput, "\n{\n" );
1063         fprintf( fOutput, "\tsal_uInt32\tnObjMask;\n" );
1064         fprintf( fOutput, "\tsal_uInt32\tnOffset = 0;\n" );
1065         fprintf( fOutput, "\tBYTE *\tpResData;\n\n" );
1066         fprintf( fOutput, "\tpResData = (tBYTE *)GetClassRes();\n\n" );
1067         fprintf( fOutput, "\tnObjMask = *(sal_uInt32*)pResData;\n" );
1068         fprintf( fOutput, "\tnOffset += 4;\n\n" );
1069 
1070         for( sal_uInt32 i = 0; i < nEntries; i++ )
1071         {
1072             if( !((VAR_NODATAINST | VAR_NORC) & pVarTypeList[ i ].nVarType ))
1073             {
1074                 fprintf( fOutput, "\tif( nObjMask & 0x%lx )\n\t{\n",
1075                          sal::static_int_cast< unsigned long >(
1076                              pVarTypeList[ i ].nMask) );
1077 
1078                 pVarTypeList[ i ].pClass->WriteRcAccess( fOutput, pTC,
1079                                     pHS->getString( pVarTypeList[ i ].nVarName ).getStr() );
1080 
1081                 fprintf( fOutput, "\t}\n" );
1082             }
1083         }
1084         fprintf( fOutput, "\tIncrementRes( nOffset );\n" );
1085         fprintf( fOutput, "\tif( bFreeResource )\n" );
1086         fprintf( fOutput, "\t\tFreeResource();\n" );
1087         fprintf( fOutput, "}\n\n" );
1088     }
1089 }
1090 
1091 /*************************************************************************
1092 |*
1093 |*    RscSysDepend::RscSysDepend()
1094 |*
1095 |*    Beschreibung
1096 |*
1097 *************************************************************************/
RscSysDepend(Atom nId,sal_uInt32 nTypeId,RscTop * pSuper)1098 RscSysDepend::RscSysDepend( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper )
1099             : RscClass( nId, nTypeId, pSuper )
1100 {}
1101 
1102 /*************************************************************************
1103 |*
1104 |*    RscSysDepend::WriteRc()
1105 |*
1106 |*    Beschreibung
1107 |*
1108 *************************************************************************/
WriteSysDependRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra,sal_Bool bFirst)1109 ERRTYPE RscSysDepend::WriteSysDependRc( const RSCINST & rInst, RscWriteRc & rMem,
1110                 RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra, sal_Bool bFirst )
1111 {
1112     sal_uInt32  nId = 0xFFFFFFFF;
1113     ERRTYPE     aError;
1114     RSCINST     aFileName;
1115 
1116     //Instanz mit dem Dateinamen "FILENAME" holen
1117     aFileName = RscClass::GetCopyVar( rInst, pHS->getID( "FILE", true ) );
1118     if( aFileName.IsInst() )
1119     {
1120         RscWriteRc aTmpMem;
1121         aError = aFileName.pClass->WriteRcHeader( aFileName, aTmpMem, pTC,
1122                                                   RscId(), nDeep, bExtra );
1123         // Obsolete - need changes in VCL
1124         rMem.Put( sal_uInt32(0) );
1125 
1126         // Identifier schreiben
1127         if( aTmpMem.Size() && pTC && (*aTmpMem.GetUTF8( 0 ) != '\0') )
1128         {
1129             nId = pTC->PutSysName( rInst.pClass->GetTypId(),
1130                                    aTmpMem.GetUTF8( 0 ),
1131                                    0, 0, bFirst );
1132         }
1133         rMem.Put( nId );
1134         aError = aFileName.pClass->WriteRcHeader( aFileName, rMem, pTC,
1135                                                   RscId(), nDeep, bExtra );
1136     }
1137     else
1138         aError = ERR_ERROR;
1139 
1140     return( aError );
1141 }
1142 
1143 /*************************************************************************
1144 |*
1145 |*    RscSysDepend::WriteRc()
1146 |*
1147 |*    Beschreibung
1148 |*
1149 *************************************************************************/
WriteRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra)1150 ERRTYPE RscSysDepend::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
1151                             RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
1152 {
1153     ERRTYPE     aError = RscClass::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
1154 
1155     if( this == rInst.pClass )
1156         // nur wenn es eigen Klasse ist
1157         aError = WriteSysDependRc( rInst, rMem, pTC, nDeep, bExtra );
1158     return aError;
1159 }
1160 
1161 /*************************************************************************
1162 |*
1163 |*    RscFirstSysDepend::RscFirstSysDepend()
1164 |*
1165 |*    Beschreibung
1166 |*
1167 *************************************************************************/
RscFirstSysDepend(Atom nId,sal_uInt32 nTypeId,RscTop * pSuper)1168 RscFirstSysDepend::RscFirstSysDepend( Atom nId, sal_uInt32 nTypeId,
1169                                         RscTop * pSuper )
1170             : RscSysDepend( nId, nTypeId, pSuper )
1171 {}
1172 
1173 /*************************************************************************
1174 |*
1175 |*    RscFirstSysDepend::WriteRc()
1176 |*
1177 |*    Beschreibung
1178 |*
1179 *************************************************************************/
WriteRc(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,sal_uInt32 nDeep,sal_Bool bExtra)1180 ERRTYPE RscFirstSysDepend::WriteRc( const RSCINST & rInst, RscWriteRc & rMem,
1181                             RscTypCont * pTC, sal_uInt32 nDeep, sal_Bool bExtra )
1182 {
1183     ERRTYPE aError = RscClass::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
1184     aError = WriteSysDependRc( rInst, rMem, pTC, nDeep, bExtra, sal_True );
1185     return aError;
1186 }
1187 
1188 /*************************************************************************
1189 |*
1190 |*    RscTupel::RscTupel()
1191 |*
1192 |*    Beschreibung
1193 |*
1194 *************************************************************************/
RscTupel(Atom nId,sal_uInt32 nTypeId,RscTop * pSuper)1195 RscTupel::RscTupel( Atom nId, sal_uInt32 nTypeId, RscTop * pSuper )
1196     : RscClass( nId, nTypeId, pSuper )
1197 {}
1198 
1199 /*************************************************************************
1200 |*
1201 |*    RscTupel::GetTupelVar()
1202 |*
1203 |*    Beschreibung
1204 |*
1205 *************************************************************************/
GetTupelVar(const RSCINST & rInst,sal_uInt32 nPos,const RSCINST & rInitInst)1206 RSCINST RscTupel::GetTupelVar( const RSCINST & rInst, sal_uInt32 nPos,
1207                                  const RSCINST & rInitInst )
1208 {
1209     if( nPos >= nEntries )
1210     {
1211         return RSCINST();
1212     }
1213     else
1214         return GetVariable( rInst, pVarTypeList[ nPos ].nVarName, rInitInst );
1215 }
1216 
1217 /*************************************************************************
1218 |*
1219 |*    RscTupel::WriteSrc()
1220 |*
1221 |*    Beschreibung
1222 |*
1223 *************************************************************************/
WriteSrc(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,sal_uInt32 nTab,const char * pVarName)1224 void RscTupel::WriteSrc( const RSCINST & rInst, FILE * fOutput,
1225                          RscTypCont * pTC, sal_uInt32 nTab,
1226                          const char * pVarName )
1227 {
1228     sal_uInt32  i = 0;
1229     RSCINST aTmpI;
1230 
1231     RscTop::WriteSrc( rInst, fOutput, pTC, nTab, pVarName );
1232 
1233     fprintf( fOutput, "< " );
1234     for( i = 0; i < nEntries; i++ )
1235     {
1236         if( !(VAR_HIDDEN & pVarTypeList[ i ].nVarType) )
1237         {
1238             if( !IsDflt( rInst.pData, i )
1239               && !IsValueDflt( rInst.pData, i ) )
1240             {
1241                 aTmpI = GetInstData( rInst.pData, i, sal_True );
1242 
1243                 if( aTmpI.IsInst() )
1244                     aTmpI.pClass->WriteSrcHeader(
1245                               aTmpI, fOutput, pTC, nTab, RscId(), pVarName );
1246                 else
1247                     fprintf( fOutput, "Default" );
1248             }
1249             else
1250                 fprintf( fOutput, "Default" );
1251             fprintf( fOutput, "; " );
1252         };
1253     };
1254     fprintf( fOutput, ">" );
1255 
1256     return;
1257 }
1258