update dev300-m58
[ooovba.git] / rsc / source / res / rscconst.cxx
blobfd267ded0bf420738d51f16d0f7694467aa2b1df
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscconst.cxx,v $
10 * $Revision: 1.12 $
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.
36 #include <cstdlib>
37 #include <cstdio>
38 #include <cstring>
40 // Solar Definitionen
41 #include <tools/solar.h>
43 // Programmabhaengige Includes.
44 #include <rscconst.hxx>
45 #include <rscall.h>
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()
55 |* Beschreibung
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 )
63 pVarArray = NULL;
64 nEntries = 0;
67 /*************************************************************************
69 |* RscConst::~RscConst()
71 |* Beschreibung
72 |* Ersterstellung MM 03.05.91
73 |* Letzte Aenderung MM 03.05.91
75 *************************************************************************/
76 RscConst::~RscConst()
78 if( pVarArray )
79 rtl_freeMemory( (void *)pVarArray );
82 /*************************************************************************
84 |* RscConst::GetClassType()
86 |* Beschreibung
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()
100 |* Beschreibung
101 |* Ersterstellung MM 03.04.91
102 |* Letzte Aenderung MM 03.04.91
104 *************************************************************************/
105 ERRTYPE RscConst::SetConstant( Atom nVarName, INT32 lValue ){
106 if( pVarArray )
107 pVarArray = (VarEle *)
108 rtl_reallocateMemory( (void *)pVarArray,
109 ((nEntries +1) * sizeof( VarEle )) );
110 else
111 pVarArray = (VarEle *)
112 rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
113 pVarArray[ nEntries ].nId = nVarName;
114 pVarArray[ nEntries ].lValue = lValue;
115 nEntries++;
117 return( ERR_OK );
120 /*************************************************************************
122 |* RscConst::GetConstance()
124 |* Beschreibung
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()
139 |* Beschreibung
140 |* Ersterstellung MM 15.05.91
141 |* Letzte Aenderung MM 15.05.91
143 *************************************************************************/
144 BOOL RscConst::GetConstValue( Atom nConst, INT32 * pValue ) const
146 sal_uInt32 i = 0;
148 for( i = 0; i < nEntries; i++ )
149 if( pVarArray[ i ].nId == nConst )
151 *pValue = pVarArray[ i ].lValue;
152 return TRUE;
154 return FALSE;
157 /*************************************************************************
159 |* RscConst::GetValueConst()
161 |* Beschreibung
162 |* Ersterstellung MM 15.05.91
163 |* Letzte Aenderung MM 15.05.91
165 *************************************************************************/
166 BOOL RscConst::GetValueConst( INT32 lValue, Atom * pConst ) const
168 sal_uInt32 i = 0;
170 for( i = 0; i < nEntries; i++ )
171 if( pVarArray[ i ].lValue == lValue )
173 *pConst = pVarArray[ i ].nId;
174 return TRUE;
176 return FALSE;
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 )
192 sal_uInt32 i = 0;
194 for( i = 0; i < nEntries; i++ )
196 if( pVarArray[ i ].nId == nConst )
197 return( i );
200 return( nEntries );
203 /*************************************************************************
205 |* RscEnum::WriteSyntax()
207 |* Beschreibung
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 );
216 sal_uInt32 i = 0;
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
231 FILE * fOutput,
232 RscTypCont * /*pTC*/,
233 const char * pName
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()
246 |* Beschreibung
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()
261 |* Beschreibung
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*/ )
268 sal_uInt32 i = 0;
270 if( nEntries != (i = GetConstPos( nConst )) )
272 ((RscEnumInst *)rInst.pData)->nValue = i;
273 ((RscEnumInst *)rInst.pData)->bDflt = FALSE;
274 return( ERR_OK );
277 return( ERR_RSCENUM );
280 /*************************************************************************
282 |* RscEnum::SetNumber()
284 |* Beschreibung
285 |* Ersterstellung MM 18.07.91
286 |* Letzte Aenderung MM 18.07.91
288 *************************************************************************/
289 ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, INT32 lValue )
291 sal_uInt32 i = 0;
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()
305 |* Beschreibung
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;
312 return( ERR_OK );
315 /*************************************************************************
317 |* RscEnum::GetNumber()
319 |* Beschreibung
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;
326 return( ERR_OK );
329 /*************************************************************************
331 |* RscEnum::Create()
333 |* Beschreibung
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 ){
339 RSCINST aInst;
341 if( !pInst ){
342 aInst.pClass = this;
343 aInst.pData = (CLASS_DATA)
344 rtl_allocateMemory( sizeof( RscEnumInst ) );
346 else
347 aInst = *pInst;
348 if( !bOwnClass && rDflt.IsInst() )
349 bOwnClass = rDflt.pClass->InHierarchy( this );
351 if( bOwnClass )
352 memmove( aInst.pData, rDflt.pData, Size() );
353 else{
354 ((RscEnumInst *)aInst.pData)->nValue = 0;
355 ((RscEnumInst *)aInst.pData)->bDflt = TRUE;
358 return( aInst );
361 /*************************************************************************
363 |* RscEnum::IsValueDefault()
365 |* Beschreibung
366 |* Ersterstellung MM 15.01.92
367 |* Letzte Aenderung MM 15.01.92
369 *************************************************************************/
370 BOOL RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
371 if( pDef ){
372 if( ((RscEnumInst*)rInst.pData)->nValue ==
373 ((RscEnumInst*)pDef)->nValue )
375 return TRUE;
379 return FALSE;
382 /*************************************************************************
384 |* RscEnum::WriteSrc()
386 |* Beschreibung
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()
402 |* Beschreibung
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 );
411 return( ERR_OK );
414 RscLangEnum::RscLangEnum()
415 : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
416 mnLangId( 0x400 )