1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
32 // C and C++ Includes.
38 // Programmabhaengige Includes.
42 /****************** C O D E **********************************************/
43 /****************** R s c M g r ******************************************/
44 /*************************************************************************
49 |* Ersterstellung MM 26.04.91
50 |* Letzte Aenderung MM 26.04.91
52 *************************************************************************/
53 RscMgr::RscMgr( Atom nId
, sal_uInt32 nTypeId
, RscTop
* pSuperCl
)
54 : RscClass( nId
, nTypeId
, pSuperCl
)
58 /*************************************************************************
63 |* Ersterstellung MM 26.04.91
64 |* Letzte Aenderung MM 26.04.91
66 *************************************************************************/
67 sal_uInt32
RscMgr::Size()
69 return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst
) );
72 /*************************************************************************
77 |* Ersterstellung MM 03.04.91
78 |* Letzte Aenderung MM 03.04.91
80 *************************************************************************/
81 RSCINST
RscMgr::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, sal_Bool bOwnClass
){
83 RscMgrInst
* pClassData
;
87 aInst
.pData
= (CLASS_DATA
) rtl_allocateMemory( Size() );
91 if( !bOwnClass
&& rDflt
.IsInst() )
92 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
94 RscClass::Create( &aInst
, rDflt
, bOwnClass
);
96 pClassData
= (RscMgrInst
*)(aInst
.pData
+ RscClass::Size() );
100 RscMgrInst
* pDfltData
= (RscMgrInst
*)(rDflt
.pData
+ RscClass::Size());
101 *pClassData
= *pDfltData
;
107 /*************************************************************************
112 |* Ersterstellung MM 21.06.91
113 |* Letzte Aenderung MM 21.06.91
115 *************************************************************************/
116 void RscMgr::Destroy( const RSCINST
& rInst
){
117 RscMgrInst
* pClassData
;
119 RscClass::Destroy( rInst
);
121 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
122 pClassData
->Destroy();
125 /*************************************************************************
127 |* RscMgr::SetToDefault()
130 |* Ersterstellung MM 12.06.91
131 |* Letzte Aenderung MM 12.06.91
133 *************************************************************************/
134 void RscMgr::SetToDefault( const RSCINST
& rInst
)
136 RscMgrInst
* pClassData
;
138 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
139 pClassData
->bDflt
= sal_True
;
141 RscClass::SetToDefault( rInst
);
144 /*************************************************************************
146 |* RscMgr::IsDefault()
149 |* Ersterstellung MM 12.06.91
150 |* Letzte Aenderung MM 12.06.91
152 *************************************************************************/
153 sal_Bool
RscMgr::IsDefault( const RSCINST
& rInst
){
154 RscMgrInst
* pClassData
;
156 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
157 if( !pClassData
->bDflt
)
160 return( RscClass::IsDefault( rInst
) );
163 /*************************************************************************
165 |* RscMgr::IsValueDefault()
168 |* Ersterstellung MM 12.06.91
169 |* Letzte Aenderung MM 12.06.91
171 *************************************************************************/
172 sal_Bool
RscMgr::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
){
173 RscMgrInst
* pClassData
;
174 RscMgrInst
* pDfltData
;
176 if( !RscClass::IsValueDefault( rInst
, pDef
) )
180 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
181 pDfltData
= (RscMgrInst
*)(pDef
+ RscClass::Size());
183 if( !pClassData
->aRefId
.IsId() && !pDfltData
->aRefId
.IsId() ){
192 /*************************************************************************
194 |* RscMgr::WriteSrcHeader()
197 |* Ersterstellung MM 08.04.91
198 |* Letzte Aenderung MM 08.04.91
200 *************************************************************************/
201 void RscMgr::WriteSrcHeader( const RSCINST
& rInst
, FILE * fOutput
,
202 RscTypCont
* pTC
, sal_uInt32 nTab
,
203 const RscId
& rId
, const char * pVarName
)
205 RscMgrInst
* pClassData
;
208 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
210 fprintf( fOutput
, "%s %s",
211 pHS
->getString( rInst
.pClass
->GetId() ).getStr(),
212 (rId
.GetName()).GetBuffer() );
213 if( pClassData
->aRefId
.IsId() )
214 fprintf( fOutput
, ",%s", pClassData
->aRefId
.GetName().GetBuffer() );
217 fprintf( fOutput
, "\n" );
218 for( i
= 0; i
< nTab
; i
++ )
219 fputc( '\t', fOutput
);
220 fprintf( fOutput
, "{\n" );
222 rInst
.pClass
->WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
224 RscClass::WriteSrc( rInst
, fOutput
, pTC
, nTab
+1, pVarName
);
226 for( i
= 0; i
< nTab
; i
++ )
227 fputc( '\t', fOutput
);
228 fprintf( fOutput
, "}" );
232 /*************************************************************************
234 |* RscMgr::WriteSrc()
237 |* Ersterstellung MM 08.04.91
238 |* Letzte Aenderung MM 08.04.91
240 *************************************************************************/
241 void RscMgr::WriteSrc( const RSCINST
&, FILE *, RscTypCont
*, sal_uInt32
,
246 /*************************************************************************
248 |* RscMgr::WriteRcHeader()
251 |* Ersterstellung MM 15.04.91
252 |* Letzte Aenderung MM 15.04.91
254 *************************************************************************/
255 ERRTYPE
RscMgr::WriteRcHeader( const RSCINST
& rInst
, RscWriteRc
& rMem
,
256 RscTypCont
* pTC
, const RscId
&rId
,
257 sal_uInt32 nDeep
, sal_Bool bExtra
)
259 RscMgrInst
* pClassData
;
261 ObjNode
* pObjNode
= NULL
;
263 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
265 if( pClassData
->aRefId
.IsId() )
267 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
269 if( nDeep
> nRefDeep
)
270 aError
= ERR_REFTODEEP
;
272 pObjNode
= rInst
.pClass
->GetRefClass()->
273 GetObjNode( pClassData
->aRefId
);
274 if( !pObjNode
&& pTC
)
276 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
278 aMsg
+= pClassData
->aRefId
.GetName();
279 aError
= WRN_MGR_REFNOTFOUND
;
280 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
289 RscTop
* pTmpRefClass
= rInst
.pClass
->GetRefClass();
291 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
292 if( pTmpRefClass
== rInst
.pClass
)
294 aError
= aRefI
.pClass
->WriteRcHeader( aRefI
, rMem
, pTC
,
295 rId
, nDeep
, bExtra
);
299 RSCINST aRefInst
= rInst
.pClass
->Create( NULL
, aRefI
);
300 aError
= aRefI
.pClass
->WriteRcHeader( aRefInst
, rMem
, pTC
,
301 rId
, nDeep
, bExtra
);
302 pTmpRefClass
->Destroy( aRefInst
);
308 sal_uInt32 nLocalSize
;
310 nOldSize
= rMem
.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
312 aError
= rInst
.pClass
->WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
314 aError
= WriteInstRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
315 nLocalSize
= rMem
.Size();
319 // RscClass wird uebersprungen
320 aError
= RscTop::WriteRc( rInst
, rMem
, pTC
, nDeep
, bExtra
);
324 // Definition der Struktur, aus denen die Resource aufgebaut ist
325 struct RSHEADER_TYPE{
326 RESOURCE_TYPE nRT; // Resource Typ
327 sal_uInt32 nRT; // Resource Typ
328 sal_uInt32 nGlobOff; // Globaler Offset
329 sal_uInt32 nLocalOff; // Lokaler Offset
332 sal_uInt32 nID
= rId
;
333 rMem
.PutAt( nOldSize
, nID
);
334 rMem
.PutAt( nOldSize
+4, (sal_uInt32
)rInst
.pClass
->GetTypId() );
335 rMem
.PutAt( nOldSize
+8, (sal_uInt32
)(rMem
.Size() - nOldSize
) );
336 rMem
.PutAt( nOldSize
+12, (sal_uInt32
)(nLocalSize
- nOldSize
) );
343 /*************************************************************************
348 |* Ersterstellung MM 26.04.91
349 |* Letzte Aenderung MM 26.04.91
351 *************************************************************************/
352 ERRTYPE
RscMgr::WriteRc( const RSCINST
&, RscWriteRc
&,
353 RscTypCont
*, sal_uInt32
, sal_Bool
)
360 static ByteString
MakeSmartName( const ByteString
& rDefName
)
362 ByteString aSmartName
;
365 char * pStr
= (char *)rDefName
.GetBuffer();
366 aSmartName
= (char)toupper( *pStr
);
372 aSmartName
+= (char)toupper( *pStr
);
377 aSmartName
+= (char)tolower( *pStr
);
383 static ByteString
MakeName( RscTypCont
* pTypCon
, RscTop
* pClass
,
384 const ByteString
& rName
)
387 if( !pTypCon
->IsSmart() || isdigit( rName
.GetChar(0) ) )
389 aRet
+= pHS
->getString( pClass
->GetId() ).getStr();
393 aRet
+= MakeSmartName( rName
);
397 /*************************************************************************
399 |* RscMgr::WriteHxxHeader()
402 |* Ersterstellung MM 29.05.91
403 |* Letzte Aenderung MM 29.05.91
405 *************************************************************************/
406 ERRTYPE
RscMgr::WriteHxxHeader( const RSCINST
& rInst
, FILE * fOutput
,
407 RscTypCont
* pTC
, const RscId
&rId
)
409 RscMgrInst
* pClassData
;
411 ObjNode
* pObjNode
= NULL
;
413 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
415 if( pClassData
->aRefId
.IsId() )
417 pObjNode
= rInst
.pClass
->GetObjNode( pClassData
->aRefId
);
418 if( !pObjNode
&& pTC
)
420 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
422 aMsg
+= pClassData
->aRefId
.GetName();
423 aError
= WRN_MGR_REFNOTFOUND
;
424 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
432 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
433 aError
= aRefI
.pClass
->WriteHxxHeader( aRefI
, fOutput
, pTC
,
438 fprintf( fOutput
, "class %s",
439 MakeName( pTC
, rInst
.pClass
,
440 rId
.GetName() ).GetBuffer() );
441 fprintf( fOutput
, " : public %s",
442 pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
443 fprintf( fOutput
, "\n{\nprotected:\n" );
445 aError
= RscClass::WriteHxx( rInst
, fOutput
, pTC
, rId
);
447 RSCINST aExtraInst
= rInst
.pClass
->GetCopyVar( rInst
, nRsc_EXTRADATA
);
448 if( aExtraInst
.IsInst() )
450 if( aExtraInst
.pClass
->GetCount( aExtraInst
) )
451 fprintf( fOutput
, " char * pExtraData;\n" );
455 fprintf( fOutput
, "public:\n " );
456 fprintf( fOutput
, "%s%s bFreeRes = TRUE )",
457 MakeName( pTC
, rInst
.pClass
,
458 rId
.GetName() ).GetBuffer(),
459 (rInst
.pClass
->aCallParType
).GetBuffer() );
460 fprintf( fOutput
, ";\n};\n\n" );
466 /*************************************************************************
468 |* RscMgr::WriteHxx()
471 |* Ersterstellung MM 29.05.91
472 |* Letzte Aenderung MM 29.05.91
474 *************************************************************************/
475 ERRTYPE
RscMgr::WriteHxx( const RSCINST
& rInst
, FILE * fOutput
,
476 RscTypCont
* pTC
, const RscId
& rId
)
478 fprintf( fOutput
, " %s", pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
479 fprintf( fOutput
, " a%s;\n",
480 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
485 /*************************************************************************
487 |* RscClass::WriteCxxHeader()
490 |* Ersterstellung MM 29.05.91
491 |* Letzte Aenderung MM 29.05.91
493 *************************************************************************/
494 ERRTYPE
RscMgr::WriteCxxHeader( const RSCINST
& rInst
, FILE * fOutput
,
495 RscTypCont
* pTC
, const RscId
& rId
)
497 RscMgrInst
* pClassData
;
499 ObjNode
* pObjNode
= NULL
;
501 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
503 if( pClassData
->aRefId
.IsId() )
505 pObjNode
= rInst
.pClass
->GetObjNode( pClassData
->aRefId
);
506 if( !pObjNode
&& pTC
)
508 ByteString
aMsg( pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
510 aMsg
+= pClassData
->aRefId
.GetName();
511 aError
= WRN_MGR_REFNOTFOUND
;
512 pTC
->pEH
->Error( aError
, rInst
.pClass
, rId
, aMsg
.GetBuffer() );
520 aRefI
= RSCINST( rInst
.pClass
, pObjNode
->GetRscObj() );
521 aError
= aRefI
.pClass
->WriteCxxHeader( aRefI
, fOutput
, pTC
,
526 fprintf( fOutput
, "%s::%s",
527 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer(),
528 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
529 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallParType
).GetBuffer() );
530 if( GetCount( rInst
) )
531 fprintf( fOutput
, " bFreeRes" );
532 fprintf( fOutput
, " )\n : %s", pHS
->getString( rInst
.pClass
->GetId() ).getStr() );
533 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallPar1
).GetBuffer() );
534 fprintf( fOutput
, " rResId )" );
536 aError
= RscClass::WriteCxx( rInst
, fOutput
, pTC
, rId
);
538 fprintf( fOutput
, "\n{\n" );
539 RSCINST aExtraInst
= rInst
.pClass
->GetCopyVar( rInst
, nRsc_EXTRADATA
);
540 if( aExtraInst
.IsInst() )
542 if( aExtraInst
.pClass
->GetCount( aExtraInst
) )
544 fprintf( fOutput
, " //read extra data\n" );
545 fprintf( fOutput
, " pExtraData = new char "
546 "[ GetRemainSizeRes() ];\n" );
547 fprintf( fOutput
, " memcpy( pExtraData, "
548 "GetClassRes(), GetRemainSizeRes() );\n" );
549 fprintf( fOutput
, " IncrementRes( GetRemainSizeRes() );\n" );
553 if( GetCount( rInst
) )
554 { // Es gibt UnterResourcen
555 fprintf( fOutput
, " if( bFreeRes ) FreeResource();\n" );
560 " // No subresources, automatic free resource\n" );
562 fprintf( fOutput
, "}\n\n" );
567 /*************************************************************************
569 |* RscClass::WriteCxx()
572 |* Ersterstellung MM 29.05.91
573 |* Letzte Aenderung MM 29.05.91
575 *************************************************************************/
576 ERRTYPE
RscMgr::WriteCxx( const RSCINST
& rInst
, FILE * fOutput
,
577 RscTypCont
* pTC
, const RscId
& rId
)
579 fprintf( fOutput
, ",\n a%s",
580 MakeName( pTC
, rInst
.pClass
, rId
.GetName() ).GetBuffer() );
581 fprintf( fOutput
, "%s", (rInst
.pClass
->aCallPar2
).GetBuffer() );
582 fprintf( fOutput
, " ResId( %s ) )", (rId
.GetName()).GetBuffer() );
587 /*************************************************************************
589 |* RscArray::IsConsistent()
592 |* Ersterstellung MM 23.09.91
593 |* Letzte Aenderung MM 23.09.91
595 *************************************************************************/
596 sal_Bool
RscMgr::IsConsistent( const RSCINST
& rInst
, RscInconsList
* pList
)
599 RscMgrInst
* pClassData
;
601 bRet
= RscClass::IsConsistent( rInst
, pList
);
603 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
604 if( pClassData
->aRefId
.IsId() &&
605 ((pClassData
->aRefId
.GetNumber() < 1)
606 || (pClassData
->aRefId
.GetNumber() > 0x7FFF)
607 || IsToDeep( rInst
).IsError()) )
611 new RscInconsistent( pClassData
->aRefId
,
612 pClassData
->aRefId
) );
619 /*************************************************************************
624 |* Ersterstellung MM 15.05.91
625 |* Letzte Aenderung MM 15.05.91
627 *************************************************************************/
628 ERRTYPE
RscMgr::GetRef( const RSCINST
& rInst
, RscId
* pRscId
){
629 RscMgrInst
* pClassData
;
631 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
632 *pRscId
= pClassData
->aRefId
;
636 /*************************************************************************
638 |* RscMgr::IsToDeep()
641 |* Ersterstellung MM 15.05.91
642 |* Letzte Aenderung MM 15.05.91
644 *************************************************************************/
645 ERRTYPE
RscMgr::IsToDeep( const RSCINST
& rInst
, sal_uInt32 nDeep
)
647 RscMgrInst
* pClassData
;
650 RSCINST aTmpI
= rInst
;
653 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
655 while( aTmpI
.IsInst() && (nDeep
< nRefDeep
) && aError
.IsOk() )
658 aTmpI
.pClass
->GetRef( aTmpI
, &aId
);
659 // Referenziertes Objekt holen
660 pObjNode
= aTmpI
.pClass
->GetObjNode( aId
);
661 // Referenzierte Objekt gefunden ?
664 aTmpI
.pData
= pObjNode
->GetRscObj();
667 else //aTmpI.IsInst() wird sal_False, Schleife beenden
671 if( nDeep
>= nRefDeep
)
673 pClassData
->aRefId
= aOldId
;
674 aError
= ERR_REFTODEEP
;
680 /*************************************************************************
685 |* Ersterstellung MM 15.05.91
686 |* Letzte Aenderung MM 15.05.91
688 *************************************************************************/
689 ERRTYPE
RscMgr::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
)
691 RscMgrInst
* pClassData
;
694 RSCINST aTmpI
= rInst
;
697 ((rRefId
.GetNumber() < 1) || (rRefId
.GetNumber() > 0x7FFF)) )
699 aError
= ERR_IDRANGE
;
703 pClassData
= (RscMgrInst
*)(rInst
.pData
+ RscClass::Size());
704 aOldId
= pClassData
->aRefId
;// Alten Wert merken
705 pClassData
->aRefId
= rRefId
;// vorher eintragen,
706 // sonst Fehler bei rekursion
709 aError
= IsToDeep( rInst
);
711 pClassData
->bDflt
= sal_False
;
713 pClassData
->aRefId
= aOldId
;