CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / res / rscmgr.cxx
blob69a989c1683bd6645b890d206886fa0bbdd321e4
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.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <ctype.h>
38 // Programmabhaengige Includes.
39 #include <rscmgr.hxx>
40 #include <rscdb.hxx>
42 /****************** C O D E **********************************************/
43 /****************** R s c M g r ******************************************/
44 /*************************************************************************
46 |* RscMgr::RscMgr()
48 |* Beschreibung
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 /*************************************************************************
60 |* RscMgr::Size()
62 |* Beschreibung
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 /*************************************************************************
74 |* RscMgr::Create()
76 |* Beschreibung
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 ){
82 RSCINST aInst;
83 RscMgrInst * pClassData;
85 if( !pInst ){
86 aInst.pClass = this;
87 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
89 else
90 aInst = *pInst;
91 if( !bOwnClass && rDflt.IsInst() )
92 bOwnClass = rDflt.pClass->InHierarchy( this );
94 RscClass::Create( &aInst, rDflt, bOwnClass );
96 pClassData = (RscMgrInst *)(aInst.pData + RscClass::Size() );
97 pClassData->Create();
99 if( bOwnClass ){
100 RscMgrInst * pDfltData = (RscMgrInst *)(rDflt.pData + RscClass::Size());
101 *pClassData = *pDfltData;
104 return( aInst );
107 /*************************************************************************
109 |* RscMgr::Destroy()
111 |* Beschreibung
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()
129 |* Beschreibung
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()
148 |* Beschreibung
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 )
158 return( sal_False );
160 return( RscClass::IsDefault( rInst ) );
163 /*************************************************************************
165 |* RscMgr::IsValueDefault()
167 |* Beschreibung
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 ) )
177 return sal_False;
179 if( pDef ){
180 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
181 pDfltData = (RscMgrInst *)(pDef + RscClass::Size());
183 if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() ){
184 return sal_True;
188 return sal_False;
192 /*************************************************************************
194 |* RscMgr::WriteSrcHeader()
196 |* Beschreibung
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;
206 sal_uInt32 i;
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() );
215 else
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()
236 |* Beschreibung
237 |* Ersterstellung MM 08.04.91
238 |* Letzte Aenderung MM 08.04.91
240 *************************************************************************/
241 void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32,
242 const char * )
246 /*************************************************************************
248 |* RscMgr::WriteRcHeader()
250 |* Beschreibung
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;
260 ERRTYPE aError;
261 ObjNode * pObjNode = NULL;
263 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
265 if( pClassData->aRefId.IsId() )
267 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
268 nDeep++;
269 if( nDeep > nRefDeep )
270 aError = ERR_REFTODEEP;
271 else
272 pObjNode = rInst.pClass->GetRefClass()->
273 GetObjNode( pClassData->aRefId );
274 if( !pObjNode && pTC )
276 ByteString aMsg( pHS->getString( rInst.pClass->GetId() ).getStr() );
277 aMsg += ' ';
278 aMsg += pClassData->aRefId.GetName();
279 aError = WRN_MGR_REFNOTFOUND;
280 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
284 if( aError.IsOk() )
286 if( pObjNode )
288 RSCINST aRefI;
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 );
297 else
299 RSCINST aRefInst = rInst.pClass->Create( NULL, aRefI );
300 aError = aRefI.pClass->WriteRcHeader( aRefInst, rMem, pTC,
301 rId, nDeep, bExtra );
302 pTmpRefClass->Destroy( aRefInst );
305 else
307 sal_uInt32 nOldSize;
308 sal_uInt32 nLocalSize;
310 nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
312 aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep, bExtra );
313 if( aError.IsOk() )
314 aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
315 nLocalSize = rMem.Size();
317 if( aError.IsOk() )
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) );
340 return( aError );
343 /*************************************************************************
345 |* RscMgr::WriteRc()
347 |* Beschreibung
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 )
356 return( ERR_OK );
360 static ByteString MakeSmartName( const ByteString & rDefName )
362 ByteString aSmartName;
363 if( rDefName.Len() )
365 char * pStr = (char *)rDefName.GetBuffer();
366 aSmartName = (char)toupper( *pStr );
367 while( *++pStr )
369 if( '_' == *pStr )
371 if( *++pStr )
372 aSmartName += (char)toupper( *pStr );
373 else
374 break;
376 else
377 aSmartName += (char)tolower( *pStr );
380 return aSmartName;
383 static ByteString MakeName( RscTypCont * pTypCon, RscTop * pClass,
384 const ByteString & rName )
386 ByteString aRet;
387 if( !pTypCon->IsSmart() || isdigit( rName.GetChar(0) ) )
389 aRet += pHS->getString( pClass->GetId() ).getStr();
390 aRet += rName;
392 else
393 aRet += MakeSmartName( rName );
394 return aRet;
397 /*************************************************************************
399 |* RscMgr::WriteHxxHeader()
401 |* Beschreibung
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;
410 ERRTYPE aError;
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() );
421 aMsg += ' ';
422 aMsg += pClassData->aRefId.GetName();
423 aError = WRN_MGR_REFNOTFOUND;
424 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
428 if( pObjNode )
430 RSCINST aRefI;
432 aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
433 aError = aRefI.pClass->WriteHxxHeader( aRefI, fOutput, pTC,
434 rId );
436 else if (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" );
453 if( aError.IsOk() )
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" );
463 return aError;
466 /*************************************************************************
468 |* RscMgr::WriteHxx()
470 |* Beschreibung
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() );
482 return ERR_OK;
485 /*************************************************************************
487 |* RscClass::WriteCxxHeader()
489 |* Beschreibung
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;
498 ERRTYPE aError;
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() );
509 aMsg += ' ';
510 aMsg += pClassData->aRefId.GetName();
511 aError = WRN_MGR_REFNOTFOUND;
512 pTC->pEH->Error( aError, rInst.pClass, rId, aMsg.GetBuffer() );
516 if( pObjNode )
518 RSCINST aRefI;
520 aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
521 aError = aRefI.pClass->WriteCxxHeader( aRefI, fOutput, pTC,
522 rId );
524 else if (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" );
557 else
559 fprintf( fOutput,
560 " // No subresources, automatic free resource\n" );
562 fprintf( fOutput, "}\n\n" );
564 return aError;
567 /*************************************************************************
569 |* RscClass::WriteCxx()
571 |* Beschreibung
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() );
584 return ERR_OK;
587 /*************************************************************************
589 |* RscArray::IsConsistent()
591 |* Beschreibung
592 |* Ersterstellung MM 23.09.91
593 |* Letzte Aenderung MM 23.09.91
595 *************************************************************************/
596 sal_Bool RscMgr::IsConsistent( const RSCINST & rInst, RscInconsList * pList )
598 sal_Bool bRet;
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()) )
609 if( pList )
610 pList->Insert(
611 new RscInconsistent( pClassData->aRefId,
612 pClassData->aRefId ) );
613 bRet = sal_False;
616 return( bRet );
619 /*************************************************************************
621 |* RscMgr::GetRef()
623 |* Beschreibung
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;
633 return ERR_OK;
636 /*************************************************************************
638 |* RscMgr::IsToDeep()
640 |* Beschreibung
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;
648 RscId aOldId, aId;
649 ERRTYPE aError;
650 RSCINST aTmpI = rInst;
651 ObjNode * pObjNode;
653 pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
655 while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() )
657 // Referenz holen
658 aTmpI.pClass->GetRef( aTmpI, &aId );
659 // Referenziertes Objekt holen
660 pObjNode = aTmpI.pClass->GetObjNode( aId );
661 // Referenzierte Objekt gefunden ?
662 if( pObjNode )
664 aTmpI.pData = pObjNode->GetRscObj();
665 nDeep++;
667 else //aTmpI.IsInst() wird sal_False, Schleife beenden
668 aTmpI.pData = NULL;
671 if( nDeep >= nRefDeep )
673 pClassData->aRefId = aOldId;
674 aError = ERR_REFTODEEP;
677 return( aError );
680 /*************************************************************************
682 |* RscMgr::SetRef()
684 |* Beschreibung
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;
692 RscId aOldId, aId;
693 ERRTYPE aError;
694 RSCINST aTmpI = rInst;
696 if( rRefId.IsId() &&
697 ((rRefId.GetNumber() < 1) || (rRefId.GetNumber() > 0x7FFF)) )
699 aError = ERR_IDRANGE;
701 else
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 );
710 if( aError.IsOk() )
711 pClassData->bDflt = sal_False;
712 else
713 pClassData->aRefId = aOldId;
716 return( aError );