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
){
49 pVarArray
= (VarEle
*)
50 rtl_reallocateMemory( (void *)pVarArray
,
51 ((nEntries
+1) * sizeof( VarEle
)) );
53 pVarArray
= (VarEle
*)
54 rtl_allocateMemory( ((nEntries
+1) * sizeof( VarEle
)) );
55 pVarArray
[ nEntries
].nId
= nVarName
;
56 pVarArray
[ nEntries
].lValue
= lValue
;
62 Atom
RscConst::GetConstant( sal_uInt32 nPos
){
64 return pVarArray
[ nPos
].nId
;
65 return( InvalidAtom
);
68 sal_Bool
RscConst::GetConstValue( Atom nConst
, sal_Int32
* pValue
) const
72 for( i
= 0; i
< nEntries
; i
++ )
73 if( pVarArray
[ i
].nId
== nConst
)
75 *pValue
= pVarArray
[ i
].lValue
;
81 sal_Bool
RscConst::GetValueConst( sal_Int32 lValue
, Atom
* pConst
) const
85 for( i
= 0; i
< nEntries
; i
++ )
86 if( pVarArray
[ i
].lValue
== lValue
)
88 *pConst
= pVarArray
[ i
].nId
;
94 sal_uInt32
RscConst::GetConstPos( Atom nConst
)
98 for( i
= 0; i
< nEntries
; i
++ )
100 if( pVarArray
[ i
].nId
== nConst
)
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*/ )
117 if( nEntries
!= (i
= GetConstPos( nConst
)) )
119 ((RscEnumInst
*)rInst
.pData
)->nValue
= i
;
120 ((RscEnumInst
*)rInst
.pData
)->bDflt
= sal_False
;
124 return( ERR_RSCENUM
);
127 ERRTYPE
RscEnum::SetNumber( const RSCINST
& rInst
, sal_Int32 lValue
)
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
;
144 ERRTYPE
RscEnum::GetNumber( const RSCINST
& rInst
, sal_Int32
* pNumber
){
145 *pNumber
= pVarArray
[ ((RscEnumInst
*)rInst
.pData
)->nValue
].lValue
;
149 RSCINST
RscEnum::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, sal_Bool bOwnClass
){
154 aInst
.pData
= (CLASS_DATA
)
155 rtl_allocateMemory( sizeof( RscEnumInst
) );
159 if( !bOwnClass
&& rDflt
.IsInst() )
160 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
163 memmove( aInst
.pData
, rDflt
.pData
, Size() );
165 ((RscEnumInst
*)aInst
.pData
)->nValue
= 0;
166 ((RscEnumInst
*)aInst
.pData
)->bDflt
= sal_True
;
172 sal_Bool
RscEnum::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
){
174 if( ((RscEnumInst
*)rInst
.pData
)->nValue
==
175 ((RscEnumInst
*)pDef
)->nValue
)
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
);
198 RscLangEnum::RscLangEnum()
199 : RscEnum( pHS
->getID( "LangEnum" ), RSC_NOTYPE
),
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */