1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscconst.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
41 #include <tools/solar.h>
43 // Programmabhaengige Includes.
44 #include <rscconst.hxx>
46 #include <rschash.hxx>
47 #include <tools/resid.hxx>
49 /****************** C O D E **********************************************/
50 /****************** R s c C o n s t **************************************/
51 /*************************************************************************
53 |* RscConst::RscConst()
56 |* Ersterstellung MM 03.05.91
57 |* Letzte Aenderung MM 03.05.91
59 *************************************************************************/
60 RscConst::RscConst( Atom nId
, sal_uInt32 nTypeId
)
61 : RscTop( nId
, nTypeId
)
67 /*************************************************************************
69 |* RscConst::~RscConst()
72 |* Ersterstellung MM 03.05.91
73 |* Letzte Aenderung MM 03.05.91
75 *************************************************************************/
79 rtl_freeMemory( (void *)pVarArray
);
82 /*************************************************************************
84 |* RscConst::GetClassType()
87 |* Ersterstellung MM 03.05.91
88 |* Letzte Aenderung MM 03.05.91
90 *************************************************************************/
91 RSCCLASS_TYPE
RscConst::GetClassType() const
93 return RSCCLASS_CONST
;
96 /*************************************************************************
98 |* RscConst::SetConstance()
101 |* Ersterstellung MM 03.04.91
102 |* Letzte Aenderung MM 03.04.91
104 *************************************************************************/
105 ERRTYPE
RscConst::SetConstant( Atom nVarName
, INT32 lValue
){
107 pVarArray
= (VarEle
*)
108 rtl_reallocateMemory( (void *)pVarArray
,
109 ((nEntries
+1) * sizeof( VarEle
)) );
111 pVarArray
= (VarEle
*)
112 rtl_allocateMemory( ((nEntries
+1) * sizeof( VarEle
)) );
113 pVarArray
[ nEntries
].nId
= nVarName
;
114 pVarArray
[ nEntries
].lValue
= lValue
;
120 /*************************************************************************
122 |* RscConst::GetConstance()
125 |* Ersterstellung MM 15.05.91
126 |* Letzte Aenderung MM 15.05.91
128 *************************************************************************/
129 Atom
RscConst::GetConstant( sal_uInt32 nPos
){
130 if( nPos
< nEntries
)
131 return pVarArray
[ nPos
].nId
;
132 return( InvalidAtom
);
135 /*************************************************************************
137 |* RscConst::GetConstValue()
140 |* Ersterstellung MM 15.05.91
141 |* Letzte Aenderung MM 15.05.91
143 *************************************************************************/
144 BOOL
RscConst::GetConstValue( Atom nConst
, INT32
* pValue
) const
148 for( i
= 0; i
< nEntries
; i
++ )
149 if( pVarArray
[ i
].nId
== nConst
)
151 *pValue
= pVarArray
[ i
].lValue
;
157 /*************************************************************************
159 |* RscConst::GetValueConst()
162 |* Ersterstellung MM 15.05.91
163 |* Letzte Aenderung MM 15.05.91
165 *************************************************************************/
166 BOOL
RscConst::GetValueConst( INT32 lValue
, Atom
* pConst
) const
170 for( i
= 0; i
< nEntries
; i
++ )
171 if( pVarArray
[ i
].lValue
== lValue
)
173 *pConst
= pVarArray
[ i
].nId
;
179 /*************************************************************************
181 |* RscConst::GetConstPos()
183 |* Beschreibung Sucht die Position der Konstanten
184 |* Return = nEntries, nicht gefunden
185 |* Return = Position im Feld
186 |* Ersterstellung MM 03.04.91
187 |* Letzte Aenderung MM 03.04.91
189 *************************************************************************/
190 sal_uInt32
RscConst::GetConstPos( Atom nConst
)
194 for( i
= 0; i
< nEntries
; i
++ )
196 if( pVarArray
[ i
].nId
== nConst
)
203 /*************************************************************************
205 |* RscEnum::WriteSyntax()
208 |* Ersterstellung MM 29.05.91
209 |* Letzte Aenderung MM 29.05.91
211 *************************************************************************/
212 void RscConst::WriteSyntax( FILE * fOutput
, RscTypCont
* pTC
)
214 RscTop::WriteSyntax( fOutput
, pTC
);
217 // Wenn eine Variable Maskierung hat, dann Maskenfeld
218 fprintf( fOutput
, "\t" );
219 for( i
= 0; i
< nEntries
; i
++ )
221 fprintf( fOutput
, "%s, ", pHS
->getString( pVarArray
[ i
].nId
).getStr() );
222 if( 3 == (i
% 4) && i
< sal_uInt32(nEntries
-1) )
223 fprintf( fOutput
, "\n\t" );
225 fprintf( fOutput
, "\n" );
228 //==================================================================
229 void RscConst::WriteRcAccess
232 RscTypCont
* /*pTC*/,
236 fprintf( fOutput
, "\t\tSet%s( %s( ", pName
, pHS
->getString( GetId() ).getStr() );
237 fprintf( fOutput
, "*(short*)(pResData+nOffset) ) );\n" );
238 fprintf( fOutput
, "\t\tnOffset += sizeof( short );\n" );
241 /****************** R s c E n u m ****************************************/
242 /*************************************************************************
244 |* RscEnum::RscEnum()
247 |* Ersterstellung MM 03.04.91
248 |* Letzte Aenderung MM 03.04.91
250 *************************************************************************/
251 RscEnum::RscEnum( Atom nId
, sal_uInt32 nTypeId
)
252 : RscConst( nId
, nTypeId
)
254 nSize
= ALIGNED_SIZE( sizeof( RscEnumInst
) );
257 /*************************************************************************
259 |* RscEnum::SetConst()
262 |* Ersterstellung MM 03.04.91
263 |* Letzte Aenderung MM 03.04.91
265 *************************************************************************/
266 ERRTYPE
RscEnum::SetConst( const RSCINST
& rInst
, Atom nConst
, INT32
/*nVal*/ )
270 if( nEntries
!= (i
= GetConstPos( nConst
)) )
272 ((RscEnumInst
*)rInst
.pData
)->nValue
= i
;
273 ((RscEnumInst
*)rInst
.pData
)->bDflt
= FALSE
;
277 return( ERR_RSCENUM
);
280 /*************************************************************************
282 |* RscEnum::SetNumber()
285 |* Ersterstellung MM 18.07.91
286 |* Letzte Aenderung MM 18.07.91
288 *************************************************************************/
289 ERRTYPE
RscEnum::SetNumber( const RSCINST
& rInst
, INT32 lValue
)
293 for( i
= 0; i
< nEntries
; i
++ ){
294 if( (INT32
)pVarArray
[ i
].lValue
== lValue
)
295 return( SetConst( rInst
, pVarArray
[ i
].nId
, lValue
) );
298 return( ERR_RSCENUM
);
301 /*************************************************************************
303 |* RscEnum::GetConst()
306 |* Ersterstellung MM 03.04.91
307 |* Letzte Aenderung MM 03.04.91
309 *************************************************************************/
310 ERRTYPE
RscEnum::GetConst( const RSCINST
& rInst
, Atom
* pH
){
311 *pH
= pVarArray
[ ((RscEnumInst
*)rInst
.pData
)->nValue
].nId
;
315 /*************************************************************************
317 |* RscEnum::GetNumber()
320 |* Ersterstellung MM 16.09.91
321 |* Letzte Aenderung MM 16.09.91
323 *************************************************************************/
324 ERRTYPE
RscEnum::GetNumber( const RSCINST
& rInst
, INT32
* pNumber
){
325 *pNumber
= pVarArray
[ ((RscEnumInst
*)rInst
.pData
)->nValue
].lValue
;
329 /*************************************************************************
334 |* Ersterstellung MM 03.04.91
335 |* Letzte Aenderung MM 03.04.91
337 *************************************************************************/
338 RSCINST
RscEnum::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, BOOL bOwnClass
){
343 aInst
.pData
= (CLASS_DATA
)
344 rtl_allocateMemory( sizeof( RscEnumInst
) );
348 if( !bOwnClass
&& rDflt
.IsInst() )
349 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
352 memmove( aInst
.pData
, rDflt
.pData
, Size() );
354 ((RscEnumInst
*)aInst
.pData
)->nValue
= 0;
355 ((RscEnumInst
*)aInst
.pData
)->bDflt
= TRUE
;
361 /*************************************************************************
363 |* RscEnum::IsValueDefault()
366 |* Ersterstellung MM 15.01.92
367 |* Letzte Aenderung MM 15.01.92
369 *************************************************************************/
370 BOOL
RscEnum::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
){
372 if( ((RscEnumInst
*)rInst
.pData
)->nValue
==
373 ((RscEnumInst
*)pDef
)->nValue
)
382 /*************************************************************************
384 |* RscEnum::WriteSrc()
387 |* Ersterstellung MM 08.04.91
388 |* Letzte Aenderung MM 08.04.91
390 *************************************************************************/
391 void RscEnum::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
392 RscTypCont
*, sal_uInt32
, const char * )
394 fprintf( fOutput
, "%s", pHS
->getString(
395 pVarArray
[ ((RscEnumInst
*)rInst
.pData
)->nValue
].nId
).getStr() );
398 /*************************************************************************
400 |* RscEnum::WriteRc()
403 |* Ersterstellung MM 15.04.91
404 |* Letzte Aenderung MM 15.04.91
406 *************************************************************************/
407 ERRTYPE
RscEnum::WriteRc( const RSCINST
& rInst
, RscWriteRc
& aMem
,
408 RscTypCont
*, sal_uInt32
, BOOL
)
410 aMem
.Put( (INT32
)pVarArray
[ ((RscEnumInst
*)rInst
.pData
)->nValue
].lValue
);
414 RscLangEnum::RscLangEnum()
415 : RscEnum( pHS
->getID( "LangEnum" ), RSC_NOTYPE
),