1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #include <rscconst.hxx>
26 #include <rschash.hxx>
27 #include <tools/resid.hxx>
29 RscConst::RscConst( Atom nId
, sal_uInt32 nTypeId
)
30 : RscTop( nId
, nTypeId
)
39 rtl_freeMemory( (void *)pVarArray
);
42 RSCCLASS_TYPE
RscConst::GetClassType() const
44 return RSCCLASS_CONST
;
47 ERRTYPE
RscConst::SetConstant( Atom nVarName
, sal_Int32 lValue
)
50 pVarArray
= static_cast<VarEle
*>(rtl_reallocateMemory( (void *)pVarArray
,
51 ((nEntries
+1) * sizeof( VarEle
)) ));
53 pVarArray
= static_cast<VarEle
*>(rtl_allocateMemory( ((nEntries
+1) * sizeof( VarEle
)) ));
54 pVarArray
[ nEntries
].nId
= nVarName
;
55 pVarArray
[ nEntries
].lValue
= lValue
;
61 Atom
RscConst::GetConstant( sal_uInt32 nPos
)
64 return pVarArray
[ nPos
].nId
;
68 bool RscConst::GetConstValue( Atom nConst
, sal_Int32
* pValue
) const
72 for( i
= 0; i
< nEntries
; i
++ )
74 if( pVarArray
[ i
].nId
== nConst
)
76 *pValue
= pVarArray
[ i
].lValue
;
83 bool RscConst::GetValueConst( sal_Int32 lValue
, Atom
* pConst
) const
87 for( i
= 0; i
< nEntries
; i
++ )
89 if( pVarArray
[ i
].lValue
== lValue
)
91 *pConst
= pVarArray
[ i
].nId
;
98 sal_uInt32
RscConst::GetConstPos( Atom nConst
)
102 for( i
= 0; i
< nEntries
; i
++ )
104 if( pVarArray
[ i
].nId
== nConst
)
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*/ )
121 if( nEntries
!= (i
= GetConstPos( nConst
)) )
123 reinterpret_cast<RscEnumInst
*>(rInst
.pData
)->nValue
= i
;
124 reinterpret_cast<RscEnumInst
*>(rInst
.pData
)->bDflt
= false;
131 ERRTYPE
RscEnum::SetNumber( const RSCINST
& rInst
, sal_Int32 lValue
)
135 for( i
= 0; i
< nEntries
; i
++ )
137 if( (sal_Int32
)pVarArray
[ i
].lValue
== lValue
)
138 return SetConst( rInst
, pVarArray
[ i
].nId
, lValue
);
144 ERRTYPE
RscEnum::GetConst( const RSCINST
& rInst
, Atom
* pH
)
146 *pH
= pVarArray
[ reinterpret_cast<RscEnumInst
*>(rInst
.pData
)->nValue
].nId
;
150 ERRTYPE
RscEnum::GetNumber( const RSCINST
& rInst
, sal_Int32
* pNumber
){
151 *pNumber
= pVarArray
[ reinterpret_cast<RscEnumInst
*>(rInst
.pData
)->nValue
].lValue
;
155 RSCINST
RscEnum::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, bool bOwnClass
)
162 aInst
.pData
= static_cast<CLASS_DATA
>(
163 rtl_allocateMemory( sizeof( RscEnumInst
) ));
168 if( !bOwnClass
&& rDflt
.IsInst() )
169 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
172 memmove( aInst
.pData
, rDflt
.pData
, Size() );
175 reinterpret_cast<RscEnumInst
*>(aInst
.pData
)->nValue
= 0;
176 reinterpret_cast<RscEnumInst
*>(aInst
.pData
)->bDflt
= true;
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
);
201 RscLangEnum::RscLangEnum()
202 : RscEnum( pHS
->getID( "LangEnum" ), RSC_NOTYPE
),
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */