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