update credits
[LibreOffice.git] / rsc / source / res / rscconst.cxx
blob2564c69f9e15c91f5618ec5265fe937e9ef17c58
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <cstdlib>
21 #include <cstdio>
22 #include <cstring>
24 #include <rscconst.hxx>
25 #include <rscall.h>
26 #include <rschash.hxx>
27 #include <tools/resid.hxx>
29 RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
30 : RscTop( nId, nTypeId )
32 pVarArray = NULL;
33 nEntries = 0;
36 RscConst::~RscConst()
38 if( pVarArray )
39 rtl_freeMemory( (void *)pVarArray );
42 RSCCLASS_TYPE RscConst::GetClassType() const
44 return RSCCLASS_CONST;
47 ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue ){
48 if( pVarArray )
49 pVarArray = (VarEle *)
50 rtl_reallocateMemory( (void *)pVarArray,
51 ((nEntries +1) * sizeof( VarEle )) );
52 else
53 pVarArray = (VarEle *)
54 rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
55 pVarArray[ nEntries ].nId = nVarName;
56 pVarArray[ nEntries ].lValue = lValue;
57 nEntries++;
59 return( ERR_OK );
62 Atom RscConst::GetConstant( sal_uInt32 nPos ){
63 if( nPos < nEntries )
64 return pVarArray[ nPos ].nId;
65 return( InvalidAtom );
68 sal_Bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
70 sal_uInt32 i = 0;
72 for( i = 0; i < nEntries; i++ )
73 if( pVarArray[ i ].nId == nConst )
75 *pValue = pVarArray[ i ].lValue;
76 return sal_True;
78 return sal_False;
81 sal_Bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
83 sal_uInt32 i = 0;
85 for( i = 0; i < nEntries; i++ )
86 if( pVarArray[ i ].lValue == lValue )
88 *pConst = pVarArray[ i ].nId;
89 return sal_True;
91 return sal_False;
94 sal_uInt32 RscConst::GetConstPos( Atom nConst )
96 sal_uInt32 i = 0;
98 for( i = 0; i < nEntries; i++ )
100 if( pVarArray[ i ].nId == nConst )
101 return( i );
104 return( nEntries );
107 RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
108 : RscConst( nId, nTypeId )
110 nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
113 ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
115 sal_uInt32 i = 0;
117 if( nEntries != (i = GetConstPos( nConst )) )
119 ((RscEnumInst *)rInst.pData)->nValue = i;
120 ((RscEnumInst *)rInst.pData)->bDflt = sal_False;
121 return( ERR_OK );
124 return( ERR_RSCENUM );
127 ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
129 sal_uInt32 i = 0;
131 for( i = 0; i < nEntries; i++ ){
132 if( (sal_Int32)pVarArray[ i ].lValue == lValue )
133 return( SetConst( rInst, pVarArray[ i ].nId, lValue ) );
136 return( ERR_RSCENUM );
139 ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH ){
140 *pH = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId;
141 return( ERR_OK );
144 ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){
145 *pNumber = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue;
146 return( ERR_OK );
149 RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass ){
150 RSCINST aInst;
152 if( !pInst ){
153 aInst.pClass = this;
154 aInst.pData = (CLASS_DATA)
155 rtl_allocateMemory( sizeof( RscEnumInst ) );
157 else
158 aInst = *pInst;
159 if( !bOwnClass && rDflt.IsInst() )
160 bOwnClass = rDflt.pClass->InHierarchy( this );
162 if( bOwnClass )
163 memmove( aInst.pData, rDflt.pData, Size() );
164 else{
165 ((RscEnumInst *)aInst.pData)->nValue = 0;
166 ((RscEnumInst *)aInst.pData)->bDflt = sal_True;
169 return( aInst );
172 sal_Bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
173 if( pDef ){
174 if( ((RscEnumInst*)rInst.pData)->nValue ==
175 ((RscEnumInst*)pDef)->nValue )
177 return sal_True;
181 return sal_False;
184 void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
185 RscTypCont *, sal_uInt32, const char * )
187 fprintf( fOutput, "%s", pHS->getString(
188 pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId ).getStr() );
191 ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
192 RscTypCont *, sal_uInt32, sal_Bool )
194 aMem.Put( (sal_Int32)pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue );
195 return( ERR_OK );
198 RscLangEnum::RscLangEnum()
199 : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
200 mnLangId( 0x400 )
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */