1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscmgr.cxx,v $
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.
41 // Programmabhaengige Includes.
45 /****************** C O D E **********************************************/
46 /****************** R s c M g r ******************************************/
47 /*************************************************************************
52 |* Ersterstellung MM 26.04.91
53 |* Letzte Aenderung MM 26.04.91
55 *************************************************************************/
56 RscMgr::RscMgr( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuperCl
)
57 : RscClass( nId
, nTypeId
, pSuperCl
)
61 /*************************************************************************
66 |* Ersterstellung MM 26.04.91
67 |* Letzte Aenderung MM 26.04.91
69 *************************************************************************/
70 sal_uInt32
RscMgr::Size()
72 return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst
) );
75 /*************************************************************************
80 |* Ersterstellung MM 03.04.91
81 |* Letzte Aenderung MM 03.04.91
83 *************************************************************************/
84 RSCINST
RscMgr::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, BOOL bOwnClass
){
86 RscMgrInst
* pClassData
;
90 aInst
.pData
= (CLASS_DATA
) rtl_allocateMemory( Size() );
94 if( !bOwnClass
&& rDflt
.IsInst() )
95 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
97 RscClass::Create( &aInst
, rDflt
, bOwnClass
);
99 pClassData
= (RscMgrInst
*)(aInst
.pData
+ RscClass::Size() );
100 pClassData
->Create();
103 RscMgrInst
* pDfltData
= (RscMgrInst
*)(rDflt
.pData
+ RscClass::Size());
104 *pClassData
= *pDfltData
;
110 /*************************************************************************
115 |* Ersterstellung MM 21.06.91
116 |* Letzte Aenderung MM 21.06.91
118 *************************************************************************/
119 void RscMgr::Destroy( const RSCINST
& rInst
){
120 RscMgrInst
* pClassData
;
122 RscClass::Destroy( rInst
);
124 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
125 pClassData
->Destroy();
128 /*************************************************************************
130 |* RscMgr::SetToDefault()
133 |* Ersterstellung MM 12.06.91
134 |* Letzte Aenderung MM 12.06.91
136 *************************************************************************/
137 void RscMgr::SetToDefault( const RSCINST
& rInst
)
139 RscMgrInst
* pClassData
;
141 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
142 pClassData
->bDflt
= TRUE
;
144 RscClass::SetToDefault( rInst
);
147 /*************************************************************************
149 |* RscMgr::IsDefault()
152 |* Ersterstellung MM 12.06.91
153 |* Letzte Aenderung MM 12.06.91
155 *************************************************************************/
156 BOOL
RscMgr::IsDefault( const RSCINST
& rInst
){
157 RscMgrInst
* pClassData
;
159 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
160 if( !pClassData
->bDflt
)
163 return( RscClass::IsDefault( rInst
) );
166 /*************************************************************************
168 |* RscMgr::IsValueDefault()
171 |* Ersterstellung MM 12.06.91
172 |* Letzte Aenderung MM 12.06.91
174 *************************************************************************/
175 BOOL
RscMgr::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
){
176 RscMgrInst
* pClassData
;
177 RscMgrInst
* pDfltData
;
179 if( !RscClass::IsValueDefault( rInst
, pDef
) )
183 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
184 pDfltData
= (RscMgrInst
*)(pDef
+ RscClass::Size());
186 if( !pClassData
->aRefId
.IsId() && !pDfltData
->aRefId
.IsId() ){
195 /*************************************************************************
197 |* RscMgr::WriteSrcHeader()
200 |* Ersterstellung MM 08.04.91
201 |* Letzte Aenderung MM 08.04.91
203 *************************************************************************/
204 void RscMgr::WriteSrcHeader( const RSCINST
& rInst
, FILE * fOutput
,
205 RscTypCont
* pTC
, sal_uInt32 nTab
,
206 const RscId
& rId
, const char * pVarName
)
208 RscMgrInst
* pClassData
;
211 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
213 fprintf( fOutput
, "%s %s",
214 pHS
->getString( rInst
.pClass
->GetId() ).getStr(),
215 (rId
.GetName()).GetBuffer() );
216 if( pClassData
->aRefId
.IsId() )
217 fprintf( fOutput
, ",%s", pClassData
->aRefId
.GetName().GetBuffer() );
220 fprintf( fOutput
, "\n" );
221 for( i
= 0; i
< nTab
; i
++ )
222 fputc( '\t', fOutput
);
223 fprintf( fOutput
, "{\n" );
225 rInst
.pClass
->WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
227 RscClass::WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
229 for( i
= 0; i
< nTab
; i
++ )
230 fputc( '\t', fOutput
);
231 fprintf( fOutput
, "}" );
235 /*************************************************************************
237 |* RscMgr::WriteSrc()
240 |* Ersterstellung MM 08.04.91
241 |* Letzte Aenderung MM 08.04.91
243 *************************************************************************/
244 void RscMgr::WriteSrc( const RSCINST
&, FILE *, RscTypCont
*, sal_uInt32
,
249 /*************************************************************************
251 |* RscMgr::WriteRcHeader()
254 |* Ersterstellung MM 15.04.91
255 |* Letzte Aenderung MM 15.04.91
257 *************************************************************************/
258 ERRTYPE
RscMgr::WriteRcHeader( const RSCINST
& rInst
, RscWriteRc
& rMem
,
259 RscTypCont
* pTC
, const RscId
&rId
,
260 sal_uInt32 nDeep
, BOOL bExtra
)
262 RscMgrInst
* pClassData
;
264 ObjNode
* pObjNode
= NULL
;
266 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
268 if( pClassData
->aRefId
.IsId() )
270 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
272 if( nDeep
> nRefDeep
)
273 aError
= ERR_REFTODEEP
;
275 pObjNode
= rInst
.pClass
->GetRefClass()->
276 GetObjNode( pClassData
->aRefId
);
277 if( !pObjNode
&& pTC
)
279 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
281 aMsg
+= pClassData
->aRefId
.GetName();
282 aError
= WRN_MGR_REFNOTFOUND
;
283 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
292 RscTop
* pTmpRefClass
= rInst
.pClass
->GetRefClass();
294 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
295 if( pTmpRefClass
== rInst
.pClass
)
297 aError
= aRefI
.pClass
->WriteRcHeader( aRefI
, rMem
, pTC
,
298 rId
, nDeep
, bExtra
);
302 RSCINST aRefInst
= rInst
.pClass
->Create( NULL
, aRefI
);
303 aError
= aRefI
.pClass
->WriteRcHeader( aRefInst
, rMem
, pTC
,
304 rId
, nDeep
, bExtra
);
305 pTmpRefClass
->Destroy( aRefInst
);
311 sal_uInt32 nLocalSize
;
313 nOldSize
= rMem
.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
315 aError
= rInst
.pClass
->WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
317 aError
= WriteInstRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
318 nLocalSize
= rMem
.Size();
322 // RscClass wird uebersprungen
323 aError
= RscTop::WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
327 // Definition der Struktur, aus denen die Resource aufgebaut ist
328 struct RSHEADER_TYPE{
329 RESOURCE_TYPE nRT; // Resource Typ
330 sal_uInt32 nRT; // Resource Typ
331 sal_uInt32 nGlobOff; // Globaler Offset
332 sal_uInt32 nLocalOff; // Lokaler Offset
335 sal_uInt32 nID
= rId
;
336 rMem
.PutAt( nOldSize
, nID
);
337 rMem
.PutAt( nOldSize
+4, (sal_uInt32
)rInst
.pClass
->GetTypId() );
338 rMem
.PutAt( nOldSize
+8, (sal_uInt32
)(rMem
.Size() - nOldSize
) );
339 rMem
.PutAt( nOldSize
+12, (sal_uInt32
)(nLocalSize
- nOldSize
) );
346 /*************************************************************************
351 |* Ersterstellung MM 26.04.91
352 |* Letzte Aenderung MM 26.04.91
354 *************************************************************************/
355 ERRTYPE
RscMgr::WriteRc( const RSCINST
&, RscWriteRc
&,
356 RscTypCont
*, sal_uInt32
, BOOL
)
363 static ByteString
MakeSmartName( const ByteString
& rDefName
)
365 ByteString aSmartName
;
368 char * pStr
= (char *)rDefName
.GetBuffer();
369 aSmartName
= (char)toupper( *pStr
);
375 aSmartName
+= (char)toupper( *pStr
);
380 aSmartName
+= (char)tolower( *pStr
);
386 static ByteString
MakeName( RscTypCont
* pTypCon
, RscTop
* pClass
,
387 const ByteString
& rName
)
390 if( !pTypCon
->IsSmart() || isdigit( rName
.GetChar(0) ) )
392 aRet
+= pHS
->getString( pClass
->GetId() ).getStr();
396 aRet
+= MakeSmartName( rName
);
400 /*************************************************************************
402 |* RscMgr::WriteHxxHeader()
405 |* Ersterstellung MM 29.05.91
406 |* Letzte Aenderung MM 29.05.91
408 *************************************************************************/
409 ERRTYPE
RscMgr::WriteHxxHeader( const RSCINST
& rInst
, FILE * fOutput
,
410 RscTypCont
* pTC
, const RscId
&rId
)
412 RscMgrInst
* pClassData
;
414 ObjNode
* pObjNode
= NULL
;
416 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
418 if( pClassData
->aRefId
.IsId() )
420 pObjNode
= rInst
.pClass
->GetObjNode( pClassData
->aRefId
);
421 if( !pObjNode
&& pTC
)
423 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
425 aMsg
+= pClassData
->aRefId
.GetName();
426 aError
= WRN_MGR_REFNOTFOUND
;
427 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
435 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
436 aError
= aRefI
.pClass
->WriteHxxHeader( aRefI
, fOutput
, pTC
,
441 fprintf( fOutput
, "class %s",
442 MakeName( pTC
, rInst
.pClass
,
443 rId
.GetName() ).GetBuffer() );
444 fprintf( fOutput
, " : public %s",
445 pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
446 fprintf( fOutput
, "\n{\nprotected:\n" );
448 aError
= RscClass::WriteHxx( rInst
, fOutput
, pTC
, rId
);
450 RSCINST aExtraInst
= rInst
.pClass
->GetCopyVar( rInst
, nRsc_EXTRADATA
);
451 if( aExtraInst
.IsInst() )
453 if( aExtraInst
.pClass
->GetCount( aExtraInst
) )
454 fprintf( fOutput
, " char * pExtraData;\n" );
458 fprintf( fOutput
, "public:\n " );
459 fprintf( fOutput
, "%s%s bFreeRes = TRUE )",
460 MakeName( pTC
, rInst
.pClass
,
461 rId
.GetName() ).GetBuffer(),
462 (rInst
.pClass
->aCallParType
).GetBuffer() );
463 fprintf( fOutput
, ";\n};\n\n" );
469 /*************************************************************************
471 |* RscMgr::WriteHxx()
474 |* Ersterstellung MM 29.05.91
475 |* Letzte Aenderung MM 29.05.91
477 *************************************************************************/
478 ERRTYPE
RscMgr::WriteHxx( const RSCINST
& rInst
, FILE * fOutput
,
479 RscTypCont
* pTC
, const RscId
& rId
)
481 fprintf( fOutput
, " %s", pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
482 fprintf( fOutput
, " a%s;\n",
483 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
488 /*************************************************************************
490 |* RscClass::WriteCxxHeader()
493 |* Ersterstellung MM 29.05.91
494 |* Letzte Aenderung MM 29.05.91
496 *************************************************************************/
497 ERRTYPE
RscMgr::WriteCxxHeader( const RSCINST
& rInst
, FILE * fOutput
,
498 RscTypCont
* pTC
, const RscId
& rId
)
500 RscMgrInst
* pClassData
;
502 ObjNode
* pObjNode
= NULL
;
504 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
506 if( pClassData
->aRefId
.IsId() )
508 pObjNode
= rInst
.pClass
->GetObjNode( pClassData
->aRefId
);
509 if( !pObjNode
&& pTC
)
511 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
513 aMsg
+= pClassData
->aRefId
.GetName();
514 aError
= WRN_MGR_REFNOTFOUND
;
515 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
523 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
524 aError
= aRefI
.pClass
->WriteCxxHeader( aRefI
, fOutput
, pTC
,
529 fprintf( fOutput
, "%s::%s",
530 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer(),
531 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
532 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallParType
).GetBuffer() );
533 if( GetCount( rInst
) )
534 fprintf( fOutput
, " bFreeRes" );
535 fprintf( fOutput
, " )\n : %s", pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
536 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallPar1
).GetBuffer() );
537 fprintf( fOutput
, " rResId )" );
539 aError
= RscClass::WriteCxx( rInst
, fOutput
, pTC
, rId
);
541 fprintf( fOutput
, "\n{\n" );
542 RSCINST aExtraInst
= rInst
.pClass
->GetCopyVar( rInst
, nRsc_EXTRADATA
);
543 if( aExtraInst
.IsInst() )
545 if( aExtraInst
.pClass
->GetCount( aExtraInst
) )
547 fprintf( fOutput
, " //read extra data\n" );
548 fprintf( fOutput
, " pExtraData = new char "
549 "[ GetRemainSizeRes() ];\n" );
550 fprintf( fOutput
, " memcpy( pExtraData, "
551 "GetClassRes(), GetRemainSizeRes() );\n" );
552 fprintf( fOutput
, " IncrementRes( GetRemainSizeRes() );\n" );
556 if( GetCount( rInst
) )
557 { // Es gibt UnterResourcen
558 fprintf( fOutput
, " if( bFreeRes ) FreeResource();\n" );
563 " // No subresources, automatic free resource\n" );
565 fprintf( fOutput
, "}\n\n" );
570 /*************************************************************************
572 |* RscClass::WriteCxx()
575 |* Ersterstellung MM 29.05.91
576 |* Letzte Aenderung MM 29.05.91
578 *************************************************************************/
579 ERRTYPE
RscMgr::WriteCxx( const RSCINST
& rInst
, FILE * fOutput
,
580 RscTypCont
* pTC
, const RscId
& rId
)
582 fprintf( fOutput
, ",\n a%s",
583 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
584 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallPar2
).GetBuffer() );
585 fprintf( fOutput
, " ResId( %s ) )", (rId
.GetName()).GetBuffer() );
590 /*************************************************************************
592 |* RscArray::IsConsistent()
595 |* Ersterstellung MM 23.09.91
596 |* Letzte Aenderung MM 23.09.91
598 *************************************************************************/
599 BOOL
RscMgr::IsConsistent( const RSCINST
& rInst
, RscInconsList
* pList
)
602 RscMgrInst
* pClassData
;
604 bRet
= RscClass::IsConsistent( rInst
, pList
);
606 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
607 if( pClassData
->aRefId
.IsId() &&
608 ((pClassData
->aRefId
.GetNumber() < 1)
609 || (pClassData
->aRefId
.GetNumber() > 0x7FFF)
610 || IsToDeep( rInst
).IsError()) )
614 new RscInconsistent( pClassData
->aRefId
,
615 pClassData
->aRefId
) );
622 /*************************************************************************
627 |* Ersterstellung MM 15.05.91
628 |* Letzte Aenderung MM 15.05.91
630 *************************************************************************/
631 ERRTYPE
RscMgr::GetRef( const RSCINST
& rInst
, RscId
* pRscId
){
632 RscMgrInst
* pClassData
;
634 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
635 *pRscId
= pClassData
->aRefId
;
639 /*************************************************************************
641 |* RscMgr::IsToDeep()
644 |* Ersterstellung MM 15.05.91
645 |* Letzte Aenderung MM 15.05.91
647 *************************************************************************/
648 ERRTYPE
RscMgr::IsToDeep( const RSCINST
& rInst
, sal_uInt32 nDeep
)
650 RscMgrInst
* pClassData
;
653 RSCINST aTmpI
= rInst
;
656 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
658 while( aTmpI
.IsInst() && (nDeep
< nRefDeep
) && aError
.IsOk() )
661 aTmpI
.pClass
->GetRef( aTmpI
, &aId
);
662 // Referenziertes Objekt holen
663 pObjNode
= aTmpI
.pClass
->GetObjNode( aId
);
664 // Referenzierte Objekt gefunden ?
667 aTmpI
.pData
= pObjNode
->GetRscObj();
670 else //aTmpI.IsInst() wird FALSE, Schleife beenden
674 if( nDeep
>= nRefDeep
)
676 pClassData
->aRefId
= aOldId
;
677 aError
= ERR_REFTODEEP
;
683 /*************************************************************************
688 |* Ersterstellung MM 15.05.91
689 |* Letzte Aenderung MM 15.05.91
691 *************************************************************************/
692 ERRTYPE
RscMgr::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
)
694 RscMgrInst
* pClassData
;
697 RSCINST aTmpI
= rInst
;
700 ((rRefId
.GetNumber() < 1) || (rRefId
.GetNumber() > 0x7FFF)) )
702 aError
= ERR_IDRANGE
;
706 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
707 aOldId
= pClassData
->aRefId
;// Alten Wert merken
708 pClassData
->aRefId
= rRefId
;// vorher eintragen,
709 // sonst Fehler bei rekursion
712 aError
= IsToDeep( rInst
);
714 pClassData
->bDflt
= FALSE
;
716 pClassData
->aRefId
= aOldId
;