xref: /aoo41x/main/rsc/source/res/rscconst.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
31 
32 // C and C++ Includes.
33 #include <cstdlib>
34 #include <cstdio>
35 #include <cstring>
36 
37 // Solar Definitionen
38 #include <tools/solar.h>
39 
40 // Programmabhaengige Includes.
41 #include <rscconst.hxx>
42 #include <rscall.h>
43 #include <rschash.hxx>
44 #include <tools/resid.hxx>
45 
46 /****************** C O D E **********************************************/
47 /****************** R s c C o n s t **************************************/
48 /*************************************************************************
49 |*
50 |*    RscConst::RscConst()
51 |*
52 |*    Beschreibung
53 |*    Ersterstellung    MM 03.05.91
54 |*    Letzte Aenderung  MM 03.05.91
55 |*
56 *************************************************************************/
57 RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
58     : RscTop( nId, nTypeId )
59 {
60     pVarArray = NULL;
61     nEntries = 0;
62 }
63 
64 /*************************************************************************
65 |*
66 |*    RscConst::~RscConst()
67 |*
68 |*    Beschreibung
69 |*    Ersterstellung    MM 03.05.91
70 |*    Letzte Aenderung  MM 03.05.91
71 |*
72 *************************************************************************/
73 RscConst::~RscConst()
74 {
75     if( pVarArray )
76         rtl_freeMemory( (void *)pVarArray );
77 }
78 
79 /*************************************************************************
80 |*
81 |*    RscConst::GetClassType()
82 |*
83 |*    Beschreibung
84 |*    Ersterstellung    MM 03.05.91
85 |*    Letzte Aenderung  MM 03.05.91
86 |*
87 *************************************************************************/
88 RSCCLASS_TYPE RscConst::GetClassType() const
89 {
90 	return RSCCLASS_CONST;
91 }
92 
93 /*************************************************************************
94 |*
95 |*    RscConst::SetConstance()
96 |*
97 |*    Beschreibung
98 |*    Ersterstellung    MM 03.04.91
99 |*    Letzte Aenderung  MM 03.04.91
100 |*
101 *************************************************************************/
102 ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue ){
103     if( pVarArray )
104         pVarArray = (VarEle *)
105             rtl_reallocateMemory( (void *)pVarArray,
106                 ((nEntries +1) * sizeof( VarEle )) );
107     else
108         pVarArray = (VarEle *)
109             rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
110     pVarArray[ nEntries ].nId     = nVarName;
111     pVarArray[ nEntries ].lValue  = lValue;
112     nEntries++;
113 
114     return( ERR_OK );
115 }
116 
117 /*************************************************************************
118 |*
119 |*    RscConst::GetConstance()
120 |*
121 |*    Beschreibung
122 |*    Ersterstellung    MM 15.05.91
123 |*    Letzte Aenderung  MM 15.05.91
124 |*
125 *************************************************************************/
126 Atom RscConst::GetConstant( sal_uInt32 nPos ){
127      if( nPos < nEntries )
128         return pVarArray[ nPos ].nId;
129     return( InvalidAtom );
130 }
131 
132 /*************************************************************************
133 |*
134 |*    RscConst::GetConstValue()
135 |*
136 |*    Beschreibung
137 |*    Ersterstellung    MM 15.05.91
138 |*    Letzte Aenderung  MM 15.05.91
139 |*
140 *************************************************************************/
141 sal_Bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
142 {
143     sal_uInt32 i = 0;
144 
145     for( i = 0; i < nEntries; i++ )
146         if( pVarArray[ i ].nId == nConst )
147 		{
148             *pValue = pVarArray[ i ].lValue;
149 			return sal_True;
150 		}
151 	return sal_False;
152 }
153 
154 /*************************************************************************
155 |*
156 |*    RscConst::GetValueConst()
157 |*
158 |*    Beschreibung
159 |*    Ersterstellung    MM 15.05.91
160 |*    Letzte Aenderung  MM 15.05.91
161 |*
162 *************************************************************************/
163 sal_Bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
164 {
165     sal_uInt32 i = 0;
166 
167     for( i = 0; i < nEntries; i++ )
168         if( pVarArray[ i ].lValue == lValue )
169 		{
170             *pConst = pVarArray[ i ].nId;
171 			return sal_True;
172 		}
173 	return sal_False;
174 }
175 
176 /*************************************************************************
177 |*
178 |*    RscConst::GetConstPos()
179 |*
180 |*    Beschreibung      Sucht die Position der Konstanten
181 |*                      Return = nEntries, nicht gefunden
182 |*                      Return = Position im Feld
183 |*    Ersterstellung    MM 03.04.91
184 |*    Letzte Aenderung  MM 03.04.91
185 |*
186 *************************************************************************/
187 sal_uInt32 RscConst::GetConstPos( Atom nConst )
188 {
189     sal_uInt32 i = 0;
190 
191     for( i = 0; i < nEntries; i++ )
192 	{
193         if( pVarArray[ i ].nId == nConst )
194             return( i );
195 	}
196 
197     return( nEntries );
198 }
199 
200 /*************************************************************************
201 |*
202 |*    RscEnum::WriteSyntax()
203 |*
204 |*    Beschreibung
205 |*    Ersterstellung    MM 29.05.91
206 |*    Letzte Aenderung  MM 29.05.91
207 |*
208 *************************************************************************/
209 void RscConst::WriteSyntax( FILE * fOutput, RscTypCont * pTC )
210 {
211 	RscTop::WriteSyntax( fOutput, pTC );
212 
213 	sal_uInt32 i = 0;
214 	// Wenn eine Variable Maskierung hat, dann Maskenfeld
215 	fprintf( fOutput, "\t" );
216     for( i = 0; i < nEntries; i++ )
217 	{
218 		fprintf( fOutput, "%s, ", pHS->getString( pVarArray[ i ].nId ).getStr() );
219 		if( 3 == (i % 4) && i < sal_uInt32(nEntries -1) )
220 			fprintf( fOutput, "\n\t" );
221     };
222 	fprintf( fOutput, "\n" );
223 }
224 
225 //==================================================================
226 void RscConst::WriteRcAccess
227 (
228 	FILE * fOutput,
229 	RscTypCont * /*pTC*/,
230 	const char * pName
231 )
232 {
233     fprintf( fOutput, "\t\tSet%s( %s( ", pName, pHS->getString( GetId() ).getStr() );
234 	fprintf( fOutput, "*(short*)(pResData+nOffset) ) );\n" );
235     fprintf( fOutput, "\t\tnOffset += sizeof( short );\n" );
236 }
237 
238 /****************** R s c E n u m ****************************************/
239 /*************************************************************************
240 |*
241 |*    RscEnum::RscEnum()
242 |*
243 |*    Beschreibung
244 |*    Ersterstellung    MM 03.04.91
245 |*    Letzte Aenderung  MM 03.04.91
246 |*
247 *************************************************************************/
248 RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
249 			: RscConst( nId, nTypeId )
250 {
251 	nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
252 }
253 
254 /*************************************************************************
255 |*
256 |*    RscEnum::SetConst()
257 |*
258 |*    Beschreibung
259 |*    Ersterstellung    MM 03.04.91
260 |*    Letzte Aenderung  MM 03.04.91
261 |*
262 *************************************************************************/
263 ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
264 {
265     sal_uInt32 i = 0;
266 
267     if( nEntries != (i = GetConstPos( nConst )) )
268 	{
269         ((RscEnumInst *)rInst.pData)->nValue = i;
270         ((RscEnumInst *)rInst.pData)->bDflt = sal_False;
271         return( ERR_OK );
272     };
273 
274     return( ERR_RSCENUM );
275 }
276 
277 /*************************************************************************
278 |*
279 |*    RscEnum::SetNumber()
280 |*
281 |*    Beschreibung
282 |*    Ersterstellung    MM 18.07.91
283 |*    Letzte Aenderung  MM 18.07.91
284 |*
285 *************************************************************************/
286 ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
287 {
288     sal_uInt32  i = 0;
289 
290     for( i = 0; i < nEntries; i++ ){
291         if( (sal_Int32)pVarArray[ i ].lValue == lValue )
292             return( SetConst( rInst, pVarArray[ i ].nId, lValue ) );
293     };
294 
295     return( ERR_RSCENUM );
296 }
297 
298 /*************************************************************************
299 |*
300 |*    RscEnum::GetConst()
301 |*
302 |*    Beschreibung
303 |*    Ersterstellung    MM 03.04.91
304 |*    Letzte Aenderung  MM 03.04.91
305 |*
306 *************************************************************************/
307 ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH ){
308     *pH = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId;
309     return( ERR_OK );
310 }
311 
312 /*************************************************************************
313 |*
314 |*    RscEnum::GetNumber()
315 |*
316 |*    Beschreibung
317 |*    Ersterstellung    MM 16.09.91
318 |*    Letzte Aenderung  MM 16.09.91
319 |*
320 *************************************************************************/
321 ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){
322     *pNumber = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue;
323     return( ERR_OK );
324 }
325 
326 /*************************************************************************
327 |*
328 |*    RscEnum::Create()
329 |*
330 |*    Beschreibung
331 |*    Ersterstellung    MM 03.04.91
332 |*    Letzte Aenderung  MM 03.04.91
333 |*
334 *************************************************************************/
335 RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass ){
336     RSCINST aInst;
337 
338     if( !pInst ){
339         aInst.pClass = this;
340         aInst.pData = (CLASS_DATA)
341                       rtl_allocateMemory( sizeof( RscEnumInst ) );
342     }
343     else
344         aInst = *pInst;
345     if( !bOwnClass && rDflt.IsInst() )
346         bOwnClass = rDflt.pClass->InHierarchy( this );
347 
348     if( bOwnClass )
349         memmove( aInst.pData, rDflt.pData, Size() );
350     else{
351         ((RscEnumInst *)aInst.pData)->nValue = 0;
352         ((RscEnumInst *)aInst.pData)->bDflt = sal_True;
353     }
354 
355     return( aInst );
356 }
357 
358 /*************************************************************************
359 |*
360 |*    RscEnum::IsValueDefault()
361 |*
362 |*    Beschreibung
363 |*    Ersterstellung    MM 15.01.92
364 |*    Letzte Aenderung  MM 15.01.92
365 |*
366 *************************************************************************/
367 sal_Bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
368     if( pDef ){
369         if( ((RscEnumInst*)rInst.pData)->nValue ==
370           ((RscEnumInst*)pDef)->nValue )
371         {
372             return sal_True;
373         }
374     }
375 
376     return sal_False;
377 }
378 
379 /*************************************************************************
380 |*
381 |*    RscEnum::WriteSrc()
382 |*
383 |*    Beschreibung
384 |*    Ersterstellung    MM 08.04.91
385 |*    Letzte Aenderung  MM 08.04.91
386 |*
387 *************************************************************************/
388 void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
389                          RscTypCont *, sal_uInt32, const char * )
390 {
391     fprintf( fOutput, "%s", pHS->getString(
392              pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId ).getStr() );
393 }
394 
395 /*************************************************************************
396 |*
397 |*    RscEnum::WriteRc()
398 |*
399 |*    Beschreibung
400 |*    Ersterstellung    MM 15.04.91
401 |*    Letzte Aenderung  MM 15.04.91
402 |*
403 *************************************************************************/
404 ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
405                           RscTypCont *, sal_uInt32, sal_Bool )
406 {
407 	aMem.Put( (sal_Int32)pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue );
408     return( ERR_OK );
409 }
410 
411 RscLangEnum::RscLangEnum()
412         : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
413           mnLangId( 0x400 )
414 {
415 }
416