1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
29 RscMgr::RscMgr( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuperCl
)
30 : RscClass( nId
, nTypeId
, pSuperCl
)
34 sal_uInt32
RscMgr::Size()
36 return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst
) );
39 RSCINST
RscMgr::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, bool bOwnClass
)
42 RscMgrInst
* pClassData
;
47 aInst
.pData
= static_cast<CLASS_DATA
>(rtl_allocateMemory( Size() ));
52 if( !bOwnClass
&& rDflt
.IsInst() )
53 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
55 RscClass::Create( &aInst
, rDflt
, bOwnClass
);
57 pClassData
= reinterpret_cast<RscMgrInst
*>(aInst
.pData
+ RscClass::Size() );
62 RscMgrInst
* pDfltData
= reinterpret_cast<RscMgrInst
*>(rDflt
.pData
+ RscClass::Size());
63 *pClassData
= *pDfltData
;
69 void RscMgr::Destroy( const RSCINST
& rInst
)
71 RscMgrInst
* pClassData
;
73 RscClass::Destroy( rInst
);
75 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
76 pClassData
->Destroy();
79 void RscMgr::SetToDefault( const RSCINST
& rInst
)
81 RscMgrInst
* pClassData
;
83 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
84 pClassData
->bDflt
= true;
86 RscClass::SetToDefault( rInst
);
89 bool RscMgr::IsDefault( const RSCINST
& rInst
)
91 RscMgrInst
* pClassData
;
93 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
94 if( !pClassData
->bDflt
)
97 return RscClass::IsDefault( rInst
);
100 bool RscMgr::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
102 if( !RscClass::IsValueDefault( rInst
, pDef
) )
107 RscMgrInst
* pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
108 RscMgrInst
* pDfltData
= reinterpret_cast<RscMgrInst
*>(pDef
+ RscClass::Size());
110 if( !pClassData
->aRefId
.IsId() && !pDfltData
->aRefId
.IsId() )
120 void RscMgr::WriteSrcHeader( const RSCINST
& rInst
, FILE * fOutput
,
121 RscTypCont
* pTC
, sal_uInt32 nTab
,
122 const RscId
& rId
, const char * pVarName
)
124 RscMgrInst
* pClassData
;
127 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
129 fprintf( fOutput
, "%s %s",
130 pHS
->getString( rInst
.pClass
->GetId() ).getStr(),
131 (rId
.GetName()).getStr() );
133 if( pClassData
->aRefId
.IsId() )
134 fprintf( fOutput
, ",%s", pClassData
->aRefId
.GetName().getStr() );
137 fprintf( fOutput
, "\n" );
138 for( i
= 0; i
< nTab
; i
++ )
139 fputc( '\t', fOutput
);
141 fprintf( fOutput
, "{\n" );
143 rInst
.pClass
->WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
145 RscClass::WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
147 for( i
= 0; i
< nTab
; i
++ )
148 fputc( '\t', fOutput
);
150 fprintf( fOutput
, "}" );
154 void RscMgr::WriteSrc( const RSCINST
&, FILE *, RscTypCont
*, sal_uInt32
,
159 ERRTYPE
RscMgr::WriteRcHeader( const RSCINST
& rInst
, RscWriteRc
& rMem
,
160 RscTypCont
* pTC
, const RscId
&rId
,
161 sal_uInt32 nDeep
, bool bExtra
)
163 RscMgrInst
* pClassData
;
165 ObjNode
* pObjNode
= NULL
;
167 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
169 if( pClassData
->aRefId
.IsId() )
171 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
173 if( nDeep
> nRefDeep
)
174 aError
= ERR_REFTODEEP
;
176 pObjNode
= rInst
.pClass
->GetRefClass()->
177 GetObjNode( pClassData
->aRefId
);
179 if( !pObjNode
&& pTC
)
181 OStringBuffer
aMsg(pHS
->getString(rInst
.pClass
->GetId()));
182 aMsg
.append(' ').append(pClassData
->aRefId
.GetName());
183 aError
= WRN_MGR_REFNOTFOUND
;
184 pTC
->pEH
->Error(aError
, rInst
.pClass
, rId
, aMsg
.getStr());
193 RscTop
* pTmpRefClass
= rInst
.pClass
->GetRefClass();
195 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
196 if( pTmpRefClass
== rInst
.pClass
)
198 aError
= aRefI
.pClass
->WriteRcHeader( aRefI
, rMem
, pTC
,
199 rId
, nDeep
, bExtra
);
203 RSCINST aRefInst
= rInst
.pClass
->Create( NULL
, aRefI
);
204 aError
= aRefI
.pClass
->WriteRcHeader( aRefInst
, rMem
, pTC
,
205 rId
, nDeep
, bExtra
);
206 pTmpRefClass
->Destroy( aRefInst
);
212 sal_uInt32 nLocalSize
;
214 nOldSize
= rMem
.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
216 aError
= rInst
.pClass
->WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
218 aError
= WriteInstRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
219 nLocalSize
= rMem
.Size();
223 // RscClass wird uebersprungen
224 aError
= RscTop::WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
228 // Definition der Struktur, aus denen die Resource aufgebaut ist
229 struct RSHEADER_TYPE{
230 RESOURCE_TYPE nRT; // Resource Typ
231 sal_uInt32 nRT; // Resource Typ
232 sal_uInt32 nGlobOff; // Globaler Offset
233 sal_uInt32 nLocalOff; // Lokaler Offset
236 sal_uInt32 nID
= rId
;
237 rMem
.PutAt( nOldSize
, nID
);
238 rMem
.PutAt( nOldSize
+4, (sal_uInt32
)rInst
.pClass
->GetTypId() );
239 rMem
.PutAt( nOldSize
+8, (sal_uInt32
)(rMem
.Size() - nOldSize
) );
240 rMem
.PutAt( nOldSize
+12, (sal_uInt32
)(nLocalSize
- nOldSize
) );
247 ERRTYPE
RscMgr::WriteRc( const RSCINST
&, RscWriteRc
&,
248 RscTypCont
*, sal_uInt32
, bool )
254 bool RscMgr::IsConsistent( const RSCINST
& rInst
)
257 RscMgrInst
* pClassData
;
259 bRet
= RscClass::IsConsistent( rInst
);
261 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
262 if( pClassData
->aRefId
.IsId() &&
263 ((pClassData
->aRefId
.GetNumber() < 1) ||
264 (pClassData
->aRefId
.GetNumber() > 0x7FFF) ||
265 IsToDeep( rInst
).IsError()) )
273 ERRTYPE
RscMgr::GetRef( const RSCINST
& rInst
, RscId
* pRscId
)
275 RscMgrInst
* pClassData
;
277 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
278 *pRscId
= pClassData
->aRefId
;
282 ERRTYPE
RscMgr::IsToDeep( const RSCINST
& rInst
, sal_uInt32 nDeep
)
284 RscMgrInst
* pClassData
;
287 RSCINST aTmpI
= rInst
;
290 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
292 while( aTmpI
.IsInst() && (nDeep
< nRefDeep
) && aError
.IsOk() )
295 aTmpI
.pClass
->GetRef( aTmpI
, &aId
);
296 // Referenziertes Objekt holen
297 pObjNode
= aTmpI
.pClass
->GetObjNode( aId
);
298 // Referenzierte Objekt gefunden ?
301 aTmpI
.pData
= pObjNode
->GetRscObj();
304 else //aTmpI.IsInst() wird false, Schleife beenden
308 if( nDeep
>= nRefDeep
)
310 pClassData
->aRefId
= aOldId
;
311 aError
= ERR_REFTODEEP
;
317 ERRTYPE
RscMgr::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
)
319 RscMgrInst
* pClassData
;
324 ((rRefId
.GetNumber() < 1) ||
325 (rRefId
.GetNumber() > 0x7FFF)) )
327 aError
= ERR_IDRANGE
;
331 pClassData
= reinterpret_cast<RscMgrInst
*>(rInst
.pData
+ RscClass::Size());
332 aOldId
= pClassData
->aRefId
;// Alten Wert merken
333 pClassData
->aRefId
= rRefId
;// vorher eintragen,
334 // sonst Fehler bei rekursion
337 aError
= IsToDeep( rInst
);
339 pClassData
->bDflt
= false;
341 pClassData
->aRefId
= aOldId
;
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */