xref: /trunk/main/rsc/source/res/rscmgr.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*477794c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*477794c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*477794c1SAndrew Rist  * distributed with this work for additional information
6*477794c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*477794c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*477794c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*477794c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*477794c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*477794c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*477794c1SAndrew Rist  * software distributed under the License is distributed on an
15*477794c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*477794c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*477794c1SAndrew Rist  * specific language governing permissions and limitations
18*477794c1SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*477794c1SAndrew Rist  *************************************************************/
21*477794c1SAndrew Rist 
22*477794c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir /****************** I N C L U D E S **************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // C and C++ Includes.
29cdf0e10cSrcweir #include <stdlib.h>
30cdf0e10cSrcweir #include <stdio.h>
31cdf0e10cSrcweir #include <string.h>
32cdf0e10cSrcweir #include <ctype.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // Programmabhaengige Includes.
35cdf0e10cSrcweir #include <rscmgr.hxx>
36cdf0e10cSrcweir #include <rscdb.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /****************** C O D E **********************************************/
39cdf0e10cSrcweir /****************** R s c M g r ******************************************/
40cdf0e10cSrcweir /*************************************************************************
41cdf0e10cSrcweir |*
42cdf0e10cSrcweir |*    RscMgr::RscMgr()
43cdf0e10cSrcweir |*
44cdf0e10cSrcweir |*    Beschreibung
45cdf0e10cSrcweir |*    Ersterstellung    MM 26.04.91
46cdf0e10cSrcweir |*    Letzte Aenderung  MM 26.04.91
47cdf0e10cSrcweir |*
48cdf0e10cSrcweir *************************************************************************/
RscMgr(Atom nId,sal_uInt32 nTypeId,RscTop * pSuperCl)49cdf0e10cSrcweir RscMgr::RscMgr( Atom nId, sal_uInt32 nTypeId, RscTop * pSuperCl )
50cdf0e10cSrcweir             : RscClass( nId, nTypeId, pSuperCl )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /*************************************************************************
55cdf0e10cSrcweir |*
56cdf0e10cSrcweir |*    RscMgr::Size()
57cdf0e10cSrcweir |*
58cdf0e10cSrcweir |*    Beschreibung
59cdf0e10cSrcweir |*    Ersterstellung    MM 26.04.91
60cdf0e10cSrcweir |*    Letzte Aenderung  MM 26.04.91
61cdf0e10cSrcweir |*
62cdf0e10cSrcweir *************************************************************************/
Size()63cdf0e10cSrcweir sal_uInt32 RscMgr::Size()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst ) );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /*************************************************************************
69cdf0e10cSrcweir |*
70cdf0e10cSrcweir |*    RscMgr::Create()
71cdf0e10cSrcweir |*
72cdf0e10cSrcweir |*    Beschreibung
73cdf0e10cSrcweir |*    Ersterstellung    MM 03.04.91
74cdf0e10cSrcweir |*    Letzte Aenderung  MM 03.04.91
75cdf0e10cSrcweir |*
76cdf0e10cSrcweir *************************************************************************/
Create(RSCINST * pInst,const RSCINST & rDflt,sal_Bool bOwnClass)77cdf0e10cSrcweir RSCINST RscMgr::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass ){
78cdf0e10cSrcweir     RSCINST aInst;
79cdf0e10cSrcweir     RscMgrInst * pClassData;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     if( !pInst ){
82cdf0e10cSrcweir         aInst.pClass = this;
83cdf0e10cSrcweir         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir     else
86cdf0e10cSrcweir         aInst = *pInst;
87cdf0e10cSrcweir     if( !bOwnClass && rDflt.IsInst() )
88cdf0e10cSrcweir         bOwnClass = rDflt.pClass->InHierarchy( this );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     RscClass::Create( &aInst, rDflt, bOwnClass );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     pClassData = (RscMgrInst *)(aInst.pData + RscClass::Size() );
93cdf0e10cSrcweir     pClassData->Create();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     if( bOwnClass ){
96cdf0e10cSrcweir         RscMgrInst * pDfltData = (RscMgrInst *)(rDflt.pData + RscClass::Size());
97cdf0e10cSrcweir         *pClassData = *pDfltData;
98cdf0e10cSrcweir     };
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     return( aInst );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir /*************************************************************************
104cdf0e10cSrcweir |*
105cdf0e10cSrcweir |*    RscMgr::Destroy()
106cdf0e10cSrcweir |*
107cdf0e10cSrcweir |*    Beschreibung
108cdf0e10cSrcweir |*    Ersterstellung    MM 21.06.91
109cdf0e10cSrcweir |*    Letzte Aenderung  MM 21.06.91
110cdf0e10cSrcweir |*
111cdf0e10cSrcweir *************************************************************************/
Destroy(const RSCINST & rInst)112cdf0e10cSrcweir void RscMgr::Destroy( const RSCINST & rInst ){
113cdf0e10cSrcweir     RscMgrInst * pClassData;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     RscClass::Destroy( rInst );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
118cdf0e10cSrcweir     pClassData->Destroy();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir /*************************************************************************
122cdf0e10cSrcweir |*
123cdf0e10cSrcweir |*    RscMgr::SetToDefault()
124cdf0e10cSrcweir |*
125cdf0e10cSrcweir |*    Beschreibung
126cdf0e10cSrcweir |*    Ersterstellung    MM 12.06.91
127cdf0e10cSrcweir |*    Letzte Aenderung  MM 12.06.91
128cdf0e10cSrcweir |*
129cdf0e10cSrcweir *************************************************************************/
SetToDefault(const RSCINST & rInst)130cdf0e10cSrcweir void RscMgr::SetToDefault( const RSCINST & rInst )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     RscMgrInst * pClassData;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
135cdf0e10cSrcweir     pClassData->bDflt = sal_True;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     RscClass::SetToDefault( rInst );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir /*************************************************************************
141cdf0e10cSrcweir |*
142cdf0e10cSrcweir |*    RscMgr::IsDefault()
143cdf0e10cSrcweir |*
144cdf0e10cSrcweir |*    Beschreibung
145cdf0e10cSrcweir |*    Ersterstellung    MM 12.06.91
146cdf0e10cSrcweir |*    Letzte Aenderung  MM 12.06.91
147cdf0e10cSrcweir |*
148cdf0e10cSrcweir *************************************************************************/
IsDefault(const RSCINST & rInst)149cdf0e10cSrcweir sal_Bool RscMgr::IsDefault( const RSCINST & rInst ){
150cdf0e10cSrcweir     RscMgrInst * pClassData;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
153cdf0e10cSrcweir     if( !pClassData->bDflt )
154cdf0e10cSrcweir         return( sal_False );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     return( RscClass::IsDefault( rInst ) );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir /*************************************************************************
160cdf0e10cSrcweir |*
161cdf0e10cSrcweir |*    RscMgr::IsValueDefault()
162cdf0e10cSrcweir |*
163cdf0e10cSrcweir |*    Beschreibung
164cdf0e10cSrcweir |*    Ersterstellung    MM 12.06.91
165cdf0e10cSrcweir |*    Letzte Aenderung  MM 12.06.91
166cdf0e10cSrcweir |*
167cdf0e10cSrcweir *************************************************************************/
IsValueDefault(const RSCINST & rInst,CLASS_DATA pDef)168cdf0e10cSrcweir sal_Bool RscMgr::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
169cdf0e10cSrcweir     RscMgrInst * pClassData;
170cdf0e10cSrcweir     RscMgrInst * pDfltData;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     if( !RscClass::IsValueDefault( rInst, pDef ) )
173cdf0e10cSrcweir         return sal_False;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if( pDef ){
176cdf0e10cSrcweir         pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
177cdf0e10cSrcweir         pDfltData  = (RscMgrInst *)(pDef + RscClass::Size());
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() ){
180cdf0e10cSrcweir             return sal_True;
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     return sal_False;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 
188cdf0e10cSrcweir /*************************************************************************
189cdf0e10cSrcweir |*
190cdf0e10cSrcweir |*    RscMgr::WriteSrcHeader()
191cdf0e10cSrcweir |*
192cdf0e10cSrcweir |*    Beschreibung
193cdf0e10cSrcweir |*    Ersterstellung    MM 08.04.91
194cdf0e10cSrcweir |*    Letzte Aenderung  MM 08.04.91
195cdf0e10cSrcweir |*
196cdf0e10cSrcweir *************************************************************************/
WriteSrcHeader(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,sal_uInt32 nTab,const RscId & rId,const char * pVarName)197cdf0e10cSrcweir void RscMgr::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput,
198cdf0e10cSrcweir                              RscTypCont * pTC, sal_uInt32 nTab,
199cdf0e10cSrcweir                              const RscId & rId, const char * pVarName )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     RscMgrInst * pClassData;
202cdf0e10cSrcweir     sal_uInt32       i;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     fprintf( fOutput, "%s %s",
207cdf0e10cSrcweir              pHS->getString( rInst.pClass->GetId() ).getStr(),
208cdf0e10cSrcweir              (rId.GetName()).GetBuffer() );
209cdf0e10cSrcweir     if( pClassData->aRefId.IsId() )
210cdf0e10cSrcweir         fprintf( fOutput, ",%s", pClassData->aRefId.GetName().GetBuffer() );
211cdf0e10cSrcweir     else
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         fprintf( fOutput, "\n" );
214cdf0e10cSrcweir         for( i = 0; i < nTab; i++ )
215cdf0e10cSrcweir             fputc( '\t', fOutput );
216cdf0e10cSrcweir         fprintf( fOutput, "{\n" );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         rInst.pClass->WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         RscClass::WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName);
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         for( i = 0; i < nTab; i++ )
223cdf0e10cSrcweir             fputc( '\t', fOutput );
224cdf0e10cSrcweir         fprintf( fOutput, "}" );
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir /*************************************************************************
229cdf0e10cSrcweir |*
230cdf0e10cSrcweir |*    RscMgr::WriteSrc()
231cdf0e10cSrcweir |*
232cdf0e10cSrcweir |*    Beschreibung
233cdf0e10cSrcweir |*    Ersterstellung    MM 08.04.91
234cdf0e10cSrcweir |*    Letzte Aenderung  MM 08.04.91
235cdf0e10cSrcweir |*
236cdf0e10cSrcweir *************************************************************************/
WriteSrc(const RSCINST &,FILE *,RscTypCont *,sal_uInt32,const char *)237cdf0e10cSrcweir void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32,
238cdf0e10cSrcweir                         const char * )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir /*************************************************************************
243cdf0e10cSrcweir |*
244cdf0e10cSrcweir |*    RscMgr::WriteRcHeader()
245cdf0e10cSrcweir |*
246cdf0e10cSrcweir |*    Beschreibung
247cdf0e10cSrcweir |*    Ersterstellung    MM 15.04.91
248cdf0e10cSrcweir |*    Letzte Aenderung  MM 15.04.91
249cdf0e10cSrcweir |*
250cdf0e10cSrcweir *************************************************************************/
WriteRcHeader(const RSCINST & rInst,RscWriteRc & rMem,RscTypCont * pTC,const RscId & rId,sal_uInt32 nDeep,sal_Bool bExtra)251cdf0e10cSrcweir ERRTYPE RscMgr::WriteRcHeader( const RSCINST & rInst, RscWriteRc & rMem,
252cdf0e10cSrcweir                                RscTypCont * pTC, const RscId &rId,
253cdf0e10cSrcweir                                sal_uInt32 nDeep, sal_Bool bExtra )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     RscMgrInst *    pClassData;
256cdf0e10cSrcweir     ERRTYPE         aError;
257cdf0e10cSrcweir     ObjNode *       pObjNode = NULL;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     if( pClassData->aRefId.IsId() )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         //Erhoehen und abfragen um Endlosrekusion zu vermeiden
264cdf0e10cSrcweir         nDeep++;
265cdf0e10cSrcweir         if( nDeep > nRefDeep )
266cdf0e10cSrcweir             aError = ERR_REFTODEEP;
267cdf0e10cSrcweir         else
268cdf0e10cSrcweir             pObjNode = rInst.pClass->GetRefClass()->
269cdf0e10cSrcweir                                         GetObjNode( pClassData->aRefId );
270cdf0e10cSrcweir         if( !pObjNode && pTC )
271cdf0e10cSrcweir         {
272cdf0e10cSrcweir             ByteString aMsg( pHS->getString( rInst.pClass->GetId() ).getStr() );
273cdf0e10cSrcweir             aMsg += ' ';
274cdf0e10cSrcweir             aMsg += pClassData->aRefId.GetName();
275cdf0e10cSrcweir             aError = WRN_MGR_REFNOTFOUND;
276cdf0e10cSrcweir             pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     if( aError.IsOk() )
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         if( pObjNode )
283cdf0e10cSrcweir         {
284cdf0e10cSrcweir             RSCINST     aRefI;
285cdf0e10cSrcweir             RscTop *    pTmpRefClass = rInst.pClass->GetRefClass();
286cdf0e10cSrcweir 
287cdf0e10cSrcweir             aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
288cdf0e10cSrcweir             if( pTmpRefClass == rInst.pClass )
289cdf0e10cSrcweir             {
290cdf0e10cSrcweir                 aError = aRefI.pClass->WriteRcHeader( aRefI, rMem, pTC,
291cdf0e10cSrcweir                                                        rId, nDeep, bExtra );
292cdf0e10cSrcweir             }
293cdf0e10cSrcweir             else
294cdf0e10cSrcweir             {
295cdf0e10cSrcweir                 RSCINST aRefInst = rInst.pClass->Create( NULL, aRefI );
296cdf0e10cSrcweir                 aError = aRefI.pClass->WriteRcHeader( aRefInst, rMem, pTC,
297cdf0e10cSrcweir                                                        rId, nDeep, bExtra );
298cdf0e10cSrcweir                 pTmpRefClass->Destroy( aRefInst );
299cdf0e10cSrcweir             }
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir         else
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir             sal_uInt32          nOldSize;
304cdf0e10cSrcweir             sal_uInt32          nLocalSize;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir             nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir             aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep, bExtra );
309cdf0e10cSrcweir             if( aError.IsOk() )
310cdf0e10cSrcweir                 aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
311cdf0e10cSrcweir             nLocalSize = rMem.Size();
312cdf0e10cSrcweir 
313cdf0e10cSrcweir             if( aError.IsOk() )
314cdf0e10cSrcweir             {
315cdf0e10cSrcweir                 // RscClass wird uebersprungen
316cdf0e10cSrcweir                 aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
317cdf0e10cSrcweir             };
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             /*
320cdf0e10cSrcweir             // Definition der Struktur, aus denen die Resource aufgebaut ist
321cdf0e10cSrcweir             struct RSHEADER_TYPE{
322cdf0e10cSrcweir                 RESOURCE_TYPE   nRT;        // Resource Typ
323cdf0e10cSrcweir                 sal_uInt32          nRT;        // Resource Typ
324cdf0e10cSrcweir                 sal_uInt32          nGlobOff;   // Globaler Offset
325cdf0e10cSrcweir                 sal_uInt32          nLocalOff;  // Lokaler Offset
326cdf0e10cSrcweir             };
327cdf0e10cSrcweir             */
328cdf0e10cSrcweir             sal_uInt32 nID = rId;
329cdf0e10cSrcweir             rMem.PutAt( nOldSize, nID );
330cdf0e10cSrcweir             rMem.PutAt( nOldSize +4, (sal_uInt32)rInst.pClass->GetTypId() );
331cdf0e10cSrcweir             rMem.PutAt( nOldSize +8, (sal_uInt32)(rMem.Size() - nOldSize) );
332cdf0e10cSrcweir             rMem.PutAt( nOldSize +12, (sal_uInt32)(nLocalSize - nOldSize) );
333cdf0e10cSrcweir         };
334cdf0e10cSrcweir     };
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     return( aError );
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir /*************************************************************************
340cdf0e10cSrcweir |*
341cdf0e10cSrcweir |*    RscMgr::WriteRc()
342cdf0e10cSrcweir |*
343cdf0e10cSrcweir |*    Beschreibung
344cdf0e10cSrcweir |*    Ersterstellung    MM 26.04.91
345cdf0e10cSrcweir |*    Letzte Aenderung  MM 26.04.91
346cdf0e10cSrcweir |*
347cdf0e10cSrcweir *************************************************************************/
WriteRc(const RSCINST &,RscWriteRc &,RscTypCont *,sal_uInt32,sal_Bool)348cdf0e10cSrcweir ERRTYPE RscMgr::WriteRc( const RSCINST &, RscWriteRc &,
349cdf0e10cSrcweir                          RscTypCont *, sal_uInt32, sal_Bool )
350cdf0e10cSrcweir 
351cdf0e10cSrcweir {
352cdf0e10cSrcweir     return( ERR_OK );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 
MakeSmartName(const ByteString & rDefName)356cdf0e10cSrcweir static ByteString MakeSmartName( const ByteString & rDefName )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir     ByteString aSmartName;
359cdf0e10cSrcweir     if( rDefName.Len() )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         char * pStr = (char *)rDefName.GetBuffer();
362cdf0e10cSrcweir         aSmartName = (char)toupper( *pStr );
363cdf0e10cSrcweir         while( *++pStr )
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             if( '_' == *pStr )
366cdf0e10cSrcweir             {
367cdf0e10cSrcweir                 if( *++pStr )
368cdf0e10cSrcweir                     aSmartName += (char)toupper( *pStr );
369cdf0e10cSrcweir                 else
370cdf0e10cSrcweir                     break;
371cdf0e10cSrcweir             }
372cdf0e10cSrcweir             else
373cdf0e10cSrcweir                 aSmartName += (char)tolower( *pStr );
374cdf0e10cSrcweir         }
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir     return aSmartName;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
MakeName(RscTypCont * pTypCon,RscTop * pClass,const ByteString & rName)379cdf0e10cSrcweir static ByteString MakeName( RscTypCont * pTypCon, RscTop * pClass,
380cdf0e10cSrcweir                             const ByteString & rName )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir     ByteString aRet;
383cdf0e10cSrcweir     if( !pTypCon->IsSmart() || isdigit( rName.GetChar(0) ) )
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         aRet += pHS->getString( pClass->GetId() ).getStr();
386cdf0e10cSrcweir         aRet += rName;
387cdf0e10cSrcweir     }
388cdf0e10cSrcweir     else
389cdf0e10cSrcweir         aRet += MakeSmartName( rName );
390cdf0e10cSrcweir     return aRet;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir /*************************************************************************
394cdf0e10cSrcweir |*
395cdf0e10cSrcweir |*    RscMgr::WriteHxxHeader()
396cdf0e10cSrcweir |*
397cdf0e10cSrcweir |*    Beschreibung
398cdf0e10cSrcweir |*    Ersterstellung    MM 29.05.91
399cdf0e10cSrcweir |*    Letzte Aenderung  MM 29.05.91
400cdf0e10cSrcweir |*
401cdf0e10cSrcweir *************************************************************************/
WriteHxxHeader(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,const RscId & rId)402cdf0e10cSrcweir ERRTYPE RscMgr::WriteHxxHeader( const RSCINST & rInst, FILE * fOutput,
403cdf0e10cSrcweir                                 RscTypCont * pTC, const RscId &rId )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     RscMgrInst *    pClassData;
406cdf0e10cSrcweir     ERRTYPE         aError;
407cdf0e10cSrcweir     ObjNode *       pObjNode = NULL;
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     if( pClassData->aRefId.IsId() )
412cdf0e10cSrcweir     {
413cdf0e10cSrcweir         pObjNode = rInst.pClass->GetObjNode( pClassData->aRefId );
414cdf0e10cSrcweir         if( !pObjNode && pTC )
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             ByteString  aMsg( pHS->getString( rInst.pClass->GetId() ).getStr() );
417cdf0e10cSrcweir             aMsg += ' ';
418cdf0e10cSrcweir             aMsg += pClassData->aRefId.GetName();
419cdf0e10cSrcweir             aError = WRN_MGR_REFNOTFOUND;
420cdf0e10cSrcweir             pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     if( pObjNode )
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         RSCINST     aRefI;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
429cdf0e10cSrcweir         aError = aRefI.pClass->WriteHxxHeader( aRefI, fOutput, pTC,
430cdf0e10cSrcweir                                                rId );
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir     else if (pTC)
433cdf0e10cSrcweir     {
434cdf0e10cSrcweir         fprintf( fOutput, "class %s",
435cdf0e10cSrcweir                           MakeName( pTC, rInst.pClass,
436cdf0e10cSrcweir                                     rId.GetName() ).GetBuffer() );
437cdf0e10cSrcweir         fprintf( fOutput, " : public %s",
438cdf0e10cSrcweir                  pHS->getString( rInst.pClass->GetId() ).getStr() );
439cdf0e10cSrcweir         fprintf( fOutput, "\n{\nprotected:\n" );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir         aError = RscClass::WriteHxx( rInst, fOutput, pTC, rId );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir         RSCINST aExtraInst = rInst.pClass->GetCopyVar( rInst, nRsc_EXTRADATA );
444cdf0e10cSrcweir         if( aExtraInst.IsInst() )
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir             if( aExtraInst.pClass->GetCount( aExtraInst ) )
447cdf0e10cSrcweir                 fprintf( fOutput, "    char * pExtraData;\n" );
448cdf0e10cSrcweir         }
449cdf0e10cSrcweir         if( aError.IsOk() )
450cdf0e10cSrcweir         {
451cdf0e10cSrcweir             fprintf( fOutput, "public:\n    " );
452cdf0e10cSrcweir             fprintf( fOutput, "%s%s bFreeRes = TRUE )",
453cdf0e10cSrcweir                      MakeName( pTC, rInst.pClass,
454cdf0e10cSrcweir                                rId.GetName() ).GetBuffer(),
455cdf0e10cSrcweir                      (rInst.pClass->aCallParType).GetBuffer() );
456cdf0e10cSrcweir             fprintf( fOutput, ";\n};\n\n" );
457cdf0e10cSrcweir         }
458cdf0e10cSrcweir     };
459cdf0e10cSrcweir     return aError;
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir /*************************************************************************
463cdf0e10cSrcweir |*
464cdf0e10cSrcweir |*    RscMgr::WriteHxx()
465cdf0e10cSrcweir |*
466cdf0e10cSrcweir |*    Beschreibung
467cdf0e10cSrcweir |*    Ersterstellung    MM 29.05.91
468cdf0e10cSrcweir |*    Letzte Aenderung  MM 29.05.91
469cdf0e10cSrcweir |*
470cdf0e10cSrcweir *************************************************************************/
WriteHxx(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,const RscId & rId)471cdf0e10cSrcweir ERRTYPE RscMgr::WriteHxx( const RSCINST & rInst, FILE * fOutput,
472cdf0e10cSrcweir                           RscTypCont * pTC, const RscId & rId )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     fprintf( fOutput, "    %s", pHS->getString( rInst.pClass->GetId() ).getStr() );
475cdf0e10cSrcweir     fprintf( fOutput, " a%s;\n",
476cdf0e10cSrcweir              MakeName( pTC, rInst.pClass, rId.GetName() ).GetBuffer() );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     return ERR_OK;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir /*************************************************************************
482cdf0e10cSrcweir |*
483cdf0e10cSrcweir |*    RscClass::WriteCxxHeader()
484cdf0e10cSrcweir |*
485cdf0e10cSrcweir |*    Beschreibung
486cdf0e10cSrcweir |*    Ersterstellung    MM 29.05.91
487cdf0e10cSrcweir |*    Letzte Aenderung  MM 29.05.91
488cdf0e10cSrcweir |*
489cdf0e10cSrcweir *************************************************************************/
WriteCxxHeader(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,const RscId & rId)490cdf0e10cSrcweir ERRTYPE RscMgr::WriteCxxHeader( const RSCINST & rInst, FILE * fOutput,
491cdf0e10cSrcweir                                 RscTypCont * pTC, const RscId & rId )
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     RscMgrInst *    pClassData;
494cdf0e10cSrcweir     ERRTYPE         aError;
495cdf0e10cSrcweir     ObjNode *       pObjNode = NULL;
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
498cdf0e10cSrcweir 
499cdf0e10cSrcweir     if( pClassData->aRefId.IsId() )
500cdf0e10cSrcweir     {
501cdf0e10cSrcweir         pObjNode = rInst.pClass->GetObjNode( pClassData->aRefId );
502cdf0e10cSrcweir         if( !pObjNode && pTC )
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir             ByteString  aMsg( pHS->getString( rInst.pClass->GetId() ).getStr() );
505cdf0e10cSrcweir             aMsg += ' ';
506cdf0e10cSrcweir             aMsg += pClassData->aRefId.GetName();
507cdf0e10cSrcweir             aError = WRN_MGR_REFNOTFOUND;
508cdf0e10cSrcweir             pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     if( pObjNode )
513cdf0e10cSrcweir     {
514cdf0e10cSrcweir         RSCINST     aRefI;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir         aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
517cdf0e10cSrcweir         aError = aRefI.pClass->WriteCxxHeader( aRefI, fOutput, pTC,
518cdf0e10cSrcweir                                                rId );
519cdf0e10cSrcweir     }
520cdf0e10cSrcweir     else if (pTC)
521cdf0e10cSrcweir     {
522cdf0e10cSrcweir         fprintf( fOutput, "%s::%s",
523cdf0e10cSrcweir                  MakeName( pTC, rInst.pClass, rId.GetName() ).GetBuffer(),
524cdf0e10cSrcweir                  MakeName( pTC, rInst.pClass, rId.GetName() ).GetBuffer() );
525cdf0e10cSrcweir         fprintf( fOutput, "%s", (rInst.pClass->aCallParType).GetBuffer() );
526cdf0e10cSrcweir         if( GetCount( rInst ) )
527cdf0e10cSrcweir             fprintf( fOutput, " bFreeRes" );
528cdf0e10cSrcweir         fprintf( fOutput, " )\n    : %s", pHS->getString( rInst.pClass->GetId() ).getStr() );
529cdf0e10cSrcweir         fprintf( fOutput, "%s", (rInst.pClass->aCallPar1).GetBuffer() );
530cdf0e10cSrcweir         fprintf( fOutput, " rResId )" );
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         aError = RscClass::WriteCxx( rInst, fOutput, pTC, rId );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir         fprintf( fOutput, "\n{\n" );
535cdf0e10cSrcweir         RSCINST aExtraInst = rInst.pClass->GetCopyVar( rInst, nRsc_EXTRADATA );
536cdf0e10cSrcweir         if( aExtraInst.IsInst() )
537cdf0e10cSrcweir         {
538cdf0e10cSrcweir             if( aExtraInst.pClass->GetCount( aExtraInst ) )
539cdf0e10cSrcweir             {
540cdf0e10cSrcweir                 fprintf( fOutput, "    //read extra data\n" );
541cdf0e10cSrcweir                 fprintf( fOutput, "    pExtraData = new char "
542cdf0e10cSrcweir                                 "[ GetRemainSizeRes() ];\n" );
543cdf0e10cSrcweir                 fprintf( fOutput, "    memcpy( pExtraData, "
544cdf0e10cSrcweir                                 "GetClassRes(), GetRemainSizeRes() );\n" );
545cdf0e10cSrcweir                 fprintf( fOutput, "    IncrementRes( GetRemainSizeRes() );\n" );
546cdf0e10cSrcweir             }
547cdf0e10cSrcweir         }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir         if( GetCount( rInst ) )
550cdf0e10cSrcweir         { // Es gibt UnterResourcen
551cdf0e10cSrcweir             fprintf( fOutput, "    if( bFreeRes ) FreeResource();\n" );
552cdf0e10cSrcweir         }
553cdf0e10cSrcweir         else
554cdf0e10cSrcweir         {
555cdf0e10cSrcweir             fprintf( fOutput,
556cdf0e10cSrcweir                     "    // No subresources, automatic free resource\n" );
557cdf0e10cSrcweir         }
558cdf0e10cSrcweir         fprintf( fOutput, "}\n\n" );
559cdf0e10cSrcweir     }
560cdf0e10cSrcweir     return aError;
561cdf0e10cSrcweir }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir /*************************************************************************
564cdf0e10cSrcweir |*
565cdf0e10cSrcweir |*    RscClass::WriteCxx()
566cdf0e10cSrcweir |*
567cdf0e10cSrcweir |*    Beschreibung
568cdf0e10cSrcweir |*    Ersterstellung    MM 29.05.91
569cdf0e10cSrcweir |*    Letzte Aenderung  MM 29.05.91
570cdf0e10cSrcweir |*
571cdf0e10cSrcweir *************************************************************************/
WriteCxx(const RSCINST & rInst,FILE * fOutput,RscTypCont * pTC,const RscId & rId)572cdf0e10cSrcweir ERRTYPE RscMgr::WriteCxx( const RSCINST & rInst, FILE * fOutput,
573cdf0e10cSrcweir                           RscTypCont * pTC, const RscId & rId )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir     fprintf( fOutput, ",\n    a%s",
576cdf0e10cSrcweir              MakeName( pTC, rInst.pClass, rId.GetName() ).GetBuffer() );
577cdf0e10cSrcweir     fprintf( fOutput, "%s", (rInst.pClass->aCallPar2).GetBuffer() );
578cdf0e10cSrcweir     fprintf( fOutput, " ResId( %s ) )", (rId.GetName()).GetBuffer() );
579cdf0e10cSrcweir 
580cdf0e10cSrcweir     return ERR_OK;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir 
583cdf0e10cSrcweir /*************************************************************************
584cdf0e10cSrcweir |*
585cdf0e10cSrcweir |*    RscArray::IsConsistent()
586cdf0e10cSrcweir |*
587cdf0e10cSrcweir |*    Beschreibung
588cdf0e10cSrcweir |*    Ersterstellung    MM 23.09.91
589cdf0e10cSrcweir |*    Letzte Aenderung  MM 23.09.91
590cdf0e10cSrcweir |*
591cdf0e10cSrcweir *************************************************************************/
IsConsistent(const RSCINST & rInst,RscInconsList * pList)592cdf0e10cSrcweir sal_Bool RscMgr::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
593cdf0e10cSrcweir {
594cdf0e10cSrcweir     sal_Bool    bRet;
595cdf0e10cSrcweir     RscMgrInst * pClassData;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir     bRet = RscClass::IsConsistent( rInst, pList );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
600cdf0e10cSrcweir     if( pClassData->aRefId.IsId() &&
601cdf0e10cSrcweir       ((pClassData->aRefId.GetNumber() < 1)
602cdf0e10cSrcweir         || (pClassData->aRefId.GetNumber() > 0x7FFF)
603cdf0e10cSrcweir         || IsToDeep( rInst ).IsError()) )
604cdf0e10cSrcweir     {
605cdf0e10cSrcweir         if( pList )
606cdf0e10cSrcweir             pList->Insert(
607cdf0e10cSrcweir                 new RscInconsistent( pClassData->aRefId,
608cdf0e10cSrcweir                                      pClassData->aRefId ) );
609cdf0e10cSrcweir         bRet = sal_False;
610cdf0e10cSrcweir     }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     return( bRet );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir 
615cdf0e10cSrcweir /*************************************************************************
616cdf0e10cSrcweir |*
617cdf0e10cSrcweir |*    RscMgr::GetRef()
618cdf0e10cSrcweir |*
619cdf0e10cSrcweir |*    Beschreibung
620cdf0e10cSrcweir |*    Ersterstellung    MM 15.05.91
621cdf0e10cSrcweir |*    Letzte Aenderung  MM 15.05.91
622cdf0e10cSrcweir |*
623cdf0e10cSrcweir *************************************************************************/
GetRef(const RSCINST & rInst,RscId * pRscId)624cdf0e10cSrcweir ERRTYPE RscMgr::GetRef( const RSCINST & rInst, RscId * pRscId ){
625cdf0e10cSrcweir     RscMgrInst * pClassData;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
628cdf0e10cSrcweir     *pRscId = pClassData->aRefId;
629cdf0e10cSrcweir     return ERR_OK;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir /*************************************************************************
633cdf0e10cSrcweir |*
634cdf0e10cSrcweir |*    RscMgr::IsToDeep()
635cdf0e10cSrcweir |*
636cdf0e10cSrcweir |*    Beschreibung
637cdf0e10cSrcweir |*    Ersterstellung    MM 15.05.91
638cdf0e10cSrcweir |*    Letzte Aenderung  MM 15.05.91
639cdf0e10cSrcweir |*
640cdf0e10cSrcweir *************************************************************************/
IsToDeep(const RSCINST & rInst,sal_uInt32 nDeep)641cdf0e10cSrcweir ERRTYPE RscMgr::IsToDeep( const RSCINST & rInst, sal_uInt32 nDeep )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     RscMgrInst *    pClassData;
644cdf0e10cSrcweir     RscId           aOldId, aId;
645cdf0e10cSrcweir     ERRTYPE         aError;
646cdf0e10cSrcweir     RSCINST         aTmpI = rInst;
647cdf0e10cSrcweir     ObjNode *       pObjNode;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
650cdf0e10cSrcweir 
651cdf0e10cSrcweir     while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() )
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         // Referenz holen
654cdf0e10cSrcweir         aTmpI.pClass->GetRef( aTmpI, &aId );
655cdf0e10cSrcweir         // Referenziertes Objekt holen
656cdf0e10cSrcweir         pObjNode = aTmpI.pClass->GetObjNode( aId );
657cdf0e10cSrcweir         // Referenzierte Objekt gefunden ?
658cdf0e10cSrcweir         if( pObjNode )
659cdf0e10cSrcweir         {
660cdf0e10cSrcweir             aTmpI.pData = pObjNode->GetRscObj();
661cdf0e10cSrcweir             nDeep++;
662cdf0e10cSrcweir         }
663cdf0e10cSrcweir         else //aTmpI.IsInst() wird sal_False, Schleife beenden
664cdf0e10cSrcweir             aTmpI.pData = NULL;
665cdf0e10cSrcweir     }
666cdf0e10cSrcweir 
667cdf0e10cSrcweir     if( nDeep >= nRefDeep )
668cdf0e10cSrcweir     {
669cdf0e10cSrcweir         pClassData->aRefId = aOldId;
670cdf0e10cSrcweir         aError             = ERR_REFTODEEP;
671cdf0e10cSrcweir     }
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     return( aError );
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir /*************************************************************************
677cdf0e10cSrcweir |*
678cdf0e10cSrcweir |*    RscMgr::SetRef()
679cdf0e10cSrcweir |*
680cdf0e10cSrcweir |*    Beschreibung
681cdf0e10cSrcweir |*    Ersterstellung    MM 15.05.91
682cdf0e10cSrcweir |*    Letzte Aenderung  MM 15.05.91
683cdf0e10cSrcweir |*
684cdf0e10cSrcweir *************************************************************************/
SetRef(const RSCINST & rInst,const RscId & rRefId)685cdf0e10cSrcweir ERRTYPE RscMgr::SetRef( const RSCINST & rInst, const RscId & rRefId )
686cdf0e10cSrcweir {
687cdf0e10cSrcweir     RscMgrInst *    pClassData;
688cdf0e10cSrcweir     RscId           aOldId, aId;
689cdf0e10cSrcweir     ERRTYPE         aError;
690cdf0e10cSrcweir     RSCINST         aTmpI = rInst;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     if( rRefId.IsId() &&
693cdf0e10cSrcweir       ((rRefId.GetNumber() < 1) || (rRefId.GetNumber() > 0x7FFF)) )
694cdf0e10cSrcweir     {
695cdf0e10cSrcweir         aError = ERR_IDRANGE;
696cdf0e10cSrcweir     }
697cdf0e10cSrcweir     else
698cdf0e10cSrcweir     {
699cdf0e10cSrcweir         pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
700cdf0e10cSrcweir         aOldId = pClassData->aRefId;// Alten Wert merken
701cdf0e10cSrcweir         pClassData->aRefId = rRefId;// vorher eintragen,
702cdf0e10cSrcweir                                     // sonst Fehler bei rekursion
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 
705cdf0e10cSrcweir         aError = IsToDeep( rInst );
706cdf0e10cSrcweir         if( aError.IsOk() )
707cdf0e10cSrcweir             pClassData->bDflt  = sal_False;
708cdf0e10cSrcweir         else
709cdf0e10cSrcweir             pClassData->aRefId = aOldId;
710cdf0e10cSrcweir     }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir     return( aError );
713cdf0e10cSrcweir }
714