Update ooo320-m1
[ooovba.git] / rsc / source / res / rscmgr.cxx
blob790df1c70b580b3788919486a28c8ff614f3c8bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscmgr.cxx,v $
10 * $Revision: 1.9 $
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.
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <ctype.h>
41 // Programmabhaengige Includes.
42 #include <rscmgr.hxx>
43 #include <rscdb.hxx>
45 /****************** C O D E **********************************************/
46 /****************** R s c M g r ******************************************/
47 /*************************************************************************
49 |* RscMgr::RscMgr()
51 |* Beschreibung
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 /*************************************************************************
63 |* RscMgr::Size()
65 |* Beschreibung
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 /*************************************************************************
77 |* RscMgr::Create()
79 |* Beschreibung
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 ){
85 RSCINST aInst;
86 RscMgrInst * pClassData;
88 if( !pInst ){
89 aInst.pClass = this;
90 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
92 else
93 aInst = *pInst;
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();
102 if( bOwnClass ){
103 RscMgrInst * pDfltData = (RscMgrInst *)(rDflt.pData + RscClass::Size());
104 *pClassData = *pDfltData;
107 return( aInst );
110 /*************************************************************************
112 |* RscMgr::Destroy()
114 |* Beschreibung
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()
132 |* Beschreibung
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()
151 |* Beschreibung
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 )
161 return( FALSE );
163 return( RscClass::IsDefault( rInst ) );
166 /*************************************************************************
168 |* RscMgr::IsValueDefault()
170 |* Beschreibung
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 ) )
180 return FALSE;
182 if( pDef ){
183 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
184 pDfltData = (RscMgrInst *)(pDef + RscClass::Size());
186 if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() ){
187 return TRUE;
191 return FALSE;
195 /*************************************************************************
197 |* RscMgr::WriteSrcHeader()
199 |* Beschreibung
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;
209 sal_uInt32 i;
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() );
218 else
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()
239 |* Beschreibung
240 |* Ersterstellung MM 08.04.91
241 |* Letzte Aenderung MM 08.04.91
243 *************************************************************************/
244 void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32,
245 const char * )
249 /*************************************************************************
251 |* RscMgr::WriteRcHeader()
253 |* Beschreibung
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;
263 ERRTYPE aError;
264 ObjNode * pObjNode = NULL;
266 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
268 if( pClassData->aRefId.IsId() )
270 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
271 nDeep++;
272 if( nDeep > nRefDeep )
273 aError = ERR_REFTODEEP;
274 else
275 pObjNode = rInst.pClass->GetRefClass()->
276 GetObjNode( pClassData->aRefId );
277 if( !pObjNode && pTC )
279 ByteString aMsg( pHS->getString( rInst.pClass->GetId() ).getStr() );
280 aMsg += ' ';
281 aMsg += pClassData->aRefId.GetName();
282 aError = WRN_MGR_REFNOTFOUND;
283 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
287 if( aError.IsOk() )
289 if( pObjNode )
291 RSCINST aRefI;
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 );
300 else
302 RSCINST aRefInst = rInst.pClass->Create( NULL, aRefI );
303 aError = aRefI.pClass->WriteRcHeader( aRefInst, rMem, pTC,
304 rId, nDeep, bExtra );
305 pTmpRefClass->Destroy( aRefInst );
308 else
310 sal_uInt32 nOldSize;
311 sal_uInt32 nLocalSize;
313 nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
315 aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep, bExtra );
316 if( aError.IsOk() )
317 aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
318 nLocalSize = rMem.Size();
320 if( aError.IsOk() )
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) );
343 return( aError );
346 /*************************************************************************
348 |* RscMgr::WriteRc()
350 |* Beschreibung
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 )
359 return( ERR_OK );
363 static ByteString MakeSmartName( const ByteString & rDefName )
365 ByteString aSmartName;
366 if( rDefName.Len() )
368 char * pStr = (char *)rDefName.GetBuffer();
369 aSmartName = (char)toupper( *pStr );
370 while( *++pStr )
372 if( '_' == *pStr )
374 if( *++pStr )
375 aSmartName += (char)toupper( *pStr );
376 else
377 break;
379 else
380 aSmartName += (char)tolower( *pStr );
383 return aSmartName;
386 static ByteString MakeName( RscTypCont * pTypCon, RscTop * pClass,
387 const ByteString & rName )
389 ByteString aRet;
390 if( !pTypCon->IsSmart() || isdigit( rName.GetChar(0) ) )
392 aRet += pHS->getString( pClass->GetId() ).getStr();
393 aRet += rName;
395 else
396 aRet += MakeSmartName( rName );
397 return aRet;
400 /*************************************************************************
402 |* RscMgr::WriteHxxHeader()
404 |* Beschreibung
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;
413 ERRTYPE aError;
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() );
424 aMsg += ' ';
425 aMsg += pClassData->aRefId.GetName();
426 aError = WRN_MGR_REFNOTFOUND;
427 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
431 if( pObjNode )
433 RSCINST aRefI;
435 aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
436 aError = aRefI.pClass->WriteHxxHeader( aRefI, fOutput, pTC,
437 rId );
439 else if (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" );
456 if( aError.IsOk() )
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" );
466 return aError;
469 /*************************************************************************
471 |* RscMgr::WriteHxx()
473 |* Beschreibung
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() );
485 return ERR_OK;
488 /*************************************************************************
490 |* RscClass::WriteCxxHeader()
492 |* Beschreibung
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;
501 ERRTYPE aError;
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() );
512 aMsg += ' ';
513 aMsg += pClassData->aRefId.GetName();
514 aError = WRN_MGR_REFNOTFOUND;
515 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
519 if( pObjNode )
521 RSCINST aRefI;
523 aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
524 aError = aRefI.pClass->WriteCxxHeader( aRefI, fOutput, pTC,
525 rId );
527 else if (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" );
560 else
562 fprintf( fOutput,
563 " // No subresources, automatic free resource\n" );
565 fprintf( fOutput, "}\n\n" );
567 return aError;
570 /*************************************************************************
572 |* RscClass::WriteCxx()
574 |* Beschreibung
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() );
587 return ERR_OK;
590 /*************************************************************************
592 |* RscArray::IsConsistent()
594 |* Beschreibung
595 |* Ersterstellung MM 23.09.91
596 |* Letzte Aenderung MM 23.09.91
598 *************************************************************************/
599 BOOL RscMgr::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
601 BOOL bRet;
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()) )
612 if( pList )
613 pList->Insert(
614 new RscInconsistent( pClassData->aRefId,
615 pClassData->aRefId ) );
616 bRet = FALSE;
619 return( bRet );
622 /*************************************************************************
624 |* RscMgr::GetRef()
626 |* Beschreibung
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;
636 return ERR_OK;
639 /*************************************************************************
641 |* RscMgr::IsToDeep()
643 |* Beschreibung
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;
651 RscId aOldId, aId;
652 ERRTYPE aError;
653 RSCINST aTmpI = rInst;
654 ObjNode * pObjNode;
656 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
658 while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() )
660 // Referenz holen
661 aTmpI.pClass->GetRef( aTmpI, &aId );
662 // Referenziertes Objekt holen
663 pObjNode = aTmpI.pClass->GetObjNode( aId );
664 // Referenzierte Objekt gefunden ?
665 if( pObjNode )
667 aTmpI.pData = pObjNode->GetRscObj();
668 nDeep++;
670 else //aTmpI.IsInst() wird FALSE, Schleife beenden
671 aTmpI.pData = NULL;
674 if( nDeep >= nRefDeep )
676 pClassData->aRefId = aOldId;
677 aError = ERR_REFTODEEP;
680 return( aError );
683 /*************************************************************************
685 |* RscMgr::SetRef()
687 |* Beschreibung
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;
695 RscId aOldId, aId;
696 ERRTYPE aError;
697 RSCINST aTmpI = rInst;
699 if( rRefId.IsId() &&
700 ((rRefId.GetNumber() < 1) || (rRefId.GetNumber() > 0x7FFF)) )
702 aError = ERR_IDRANGE;
704 else
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 );
713 if( aError.IsOk() )
714 pClassData->bDflt = FALSE;
715 else
716 pClassData->aRefId = aOldId;
719 return( aError );