bump product version to 5.0.4.1
[LibreOffice.git] / rsc / source / res / rscconst.cxx
blob77b67475516cf949cf4b414e43207496a4c9186d
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 )
49 if( pVarArray )
50 pVarArray = static_cast<VarEle *>(rtl_reallocateMemory( (void *)pVarArray,
51 ((nEntries +1) * sizeof( VarEle )) ));
52 else
53 pVarArray = static_cast<VarEle *>(rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) ));
54 pVarArray[ nEntries ].nId = nVarName;
55 pVarArray[ nEntries ].lValue = lValue;
56 nEntries++;
58 return ERR_OK;
61 Atom RscConst::GetConstant( sal_uInt32 nPos )
63 if( nPos < nEntries )
64 return pVarArray[ nPos ].nId;
65 return InvalidAtom;
68 bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
70 sal_uInt32 i = 0;
72 for( i = 0; i < nEntries; i++ )
74 if( pVarArray[ i ].nId == nConst )
76 *pValue = pVarArray[ i ].lValue;
77 return true;
80 return false;
83 bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
85 sal_uInt32 i = 0;
87 for( i = 0; i < nEntries; i++ )
89 if( pVarArray[ i ].lValue == lValue )
91 *pConst = pVarArray[ i ].nId;
92 return true;
95 return false;
98 sal_uInt32 RscConst::GetConstPos( Atom nConst )
100 sal_uInt32 i = 0;
102 for( i = 0; i < nEntries; i++ )
104 if( pVarArray[ i ].nId == nConst )
105 return i;
108 return nEntries;
111 RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
112 : RscConst( nId, nTypeId )
114 nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
117 ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
119 sal_uInt32 i = 0;
121 if( nEntries != (i = GetConstPos( nConst )) )
123 reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue = i;
124 reinterpret_cast<RscEnumInst *>(rInst.pData)->bDflt = false;
125 return ERR_OK;
128 return ERR_RSCENUM;
131 ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
133 sal_uInt32 i = 0;
135 for( i = 0; i < nEntries; i++ )
137 if( (sal_Int32)pVarArray[ i ].lValue == lValue )
138 return SetConst( rInst, pVarArray[ i ].nId, lValue );
141 return ERR_RSCENUM;
144 ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH )
146 *pH = pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].nId;
147 return ERR_OK;
150 ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){
151 *pNumber = pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue;
152 return ERR_OK;
155 RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
157 RSCINST aInst;
159 if( !pInst )
161 aInst.pClass = this;
162 aInst.pData = static_cast<CLASS_DATA>(
163 rtl_allocateMemory( sizeof( RscEnumInst ) ));
165 else
166 aInst = *pInst;
168 if( !bOwnClass && rDflt.IsInst() )
169 bOwnClass = rDflt.pClass->InHierarchy( this );
171 if( bOwnClass )
172 memmove( aInst.pData, rDflt.pData, Size() );
173 else
175 reinterpret_cast<RscEnumInst *>(aInst.pData)->nValue = 0;
176 reinterpret_cast<RscEnumInst *>(aInst.pData)->bDflt = true;
179 return aInst;
182 bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
184 return pDef && (reinterpret_cast<RscEnumInst*>(rInst.pData)->nValue == reinterpret_cast<RscEnumInst*>(pDef)->nValue );
187 void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
188 RscTypCont *, sal_uInt32, const char * )
190 fprintf( fOutput, "%s",
191 pHS->getString( pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].nId ).getStr() );
194 ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
195 RscTypCont *, sal_uInt32, bool )
197 aMem.Put( (sal_Int32)pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue );
198 return ERR_OK;
201 RscLangEnum::RscLangEnum()
202 : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
203 mnLangId( 0x400 )
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */