xref: /aoo41x/main/rsc/source/res/rscflag.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 <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 
33 #include <rscflag.hxx>
34 
35 /****************** C O D E **********************************************/
36 /****************** R s c F l a g ****************************************/
37 /*************************************************************************
38 |*
39 |*    RscFlag::RscFlag()
40 |*
41 |*    Beschreibung
42 |*    Ersterstellung    MM 03.04.91
43 |*    Letzte Aenderung  MM 03.04.91
44 |*
45 *************************************************************************/
RscFlag(Atom nId,sal_uInt32 nTypeId)46 RscFlag::RscFlag( Atom nId, sal_uInt32 nTypeId )
47 			: RscConst( nId, nTypeId )
48 {}
49 
50 /*************************************************************************
51 |*
52 |*    RscFlag::Size()
53 |*
54 |*    Beschreibung      Die Groe�e der Instanzdaten richtet sich nach
55 |*                      der Anzahl der Flags
56 |*    Ersterstellung    MM 03.04.91
57 |*    Letzte Aenderung  MM 03.04.91
58 |*
59 *************************************************************************/
Size()60 sal_uInt32 RscFlag::Size()
61 {
62     return( ALIGNED_SIZE( sizeof( RscFlagInst ) *
63             ( 1 + (nEntries -1) / (sizeof( sal_uInt32 ) * 8) ) ) );
64 }
65 
66 /*************************************************************************
67 |*
68 |*    RscFlag::SetNotConst()
69 |*
70 |*    Beschreibung
71 |*    Ersterstellung    MM 03.04.91
72 |*    Letzte Aenderung  MM 03.04.91
73 |*
74 *************************************************************************/
SetNotConst(const RSCINST & rInst,Atom nConst)75 ERRTYPE RscFlag::SetNotConst( const RSCINST & rInst, Atom nConst )
76 {
77     sal_uInt32 i = 0, nFlag = 0;
78 
79     if( nEntries != (i = GetConstPos( nConst )) ){
80         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
81         i = i / (sizeof( sal_uInt32 ) * 8);
82         ((RscFlagInst *)rInst.pData)[ i ].nFlags     &= ~nFlag;
83         ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
84         return( ERR_OK );
85     };
86 
87     return( ERR_RSCFLAG );
88 }
89 
90 /*************************************************************************
91 |*
92 |*    RscFlag::SetConst()
93 |*
94 |*    Beschreibung
95 |*    Ersterstellung    MM 03.04.91
96 |*    Letzte Aenderung  MM 03.04.91
97 |*
98 *************************************************************************/
SetConst(const RSCINST & rInst,Atom nConst,sal_Int32)99 ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
100 {
101     sal_uInt32 i = 0, nFlag = 0;
102 
103     if( nEntries != (i = GetConstPos( nConst )) ){
104         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
105         i = i / (sizeof( sal_uInt32 ) * 8);
106         ((RscFlagInst *)rInst.pData)[ i ].nFlags     |= nFlag;
107         ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
108         return( ERR_OK );
109     };
110 
111     return( ERR_RSCFLAG );
112 }
113 
114 /*************************************************************************
115 |*
116 |*    RscFlag::CreateBasic()
117 |*
118 |*    Beschreibung
119 |*    Ersterstellung    MM 16.01.92
120 |*    Letzte Aenderung  MM 16.01.92
121 |*
122 *************************************************************************/
CreateBasic(RSCINST * pInst)123 RSCINST RscFlag::CreateBasic( RSCINST * pInst )
124 {
125     RSCINST aInst;
126 
127     if( !pInst ){
128         aInst.pClass = this;
129         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
130     }
131     else
132         aInst = *pInst;
133 
134     return( aInst );
135 }
136 
137 /*************************************************************************
138 |*
139 |*    RscFlag::Create()
140 |*
141 |*    Beschreibung
142 |*    Ersterstellung    MM 03.04.91
143 |*    Letzte Aenderung  MM 16.01.92
144 |*
145 *************************************************************************/
Create(RSCINST * pInst,const RSCINST & rDflt,sal_Bool bOwnClass)146 RSCINST RscFlag::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass )
147 {
148     RSCINST aInst = CreateBasic( pInst );
149     sal_uInt32  i = 0;
150 
151     if( !bOwnClass && rDflt.IsInst() )
152         bOwnClass = rDflt.pClass->InHierarchy( this );
153 
154     if( bOwnClass )
155         memmove( aInst.pData, rDflt.pData, Size() );
156     else
157 	{
158         for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
159 		{
160             ((RscFlagInst *)aInst.pData)[ i ].nFlags = 0;
161             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
162         }
163     };
164 
165     return( aInst );
166 }
167 
168 /*************************************************************************
169 |*
170 |*    RscFlag::CreateClient()
171 |*
172 |*    Beschreibung
173 |*    Ersterstellung    MM 16.01.92
174 |*    Letzte Aenderung  MM 16.01.92
175 |*
176 *************************************************************************/
CreateClient(RSCINST * pInst,const RSCINST & rDfltI,sal_Bool bOwnClass,Atom nConstId)177 RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI,
178                                sal_Bool bOwnClass, Atom nConstId )
179 {
180     RSCINST aInst = CreateBasic( pInst );
181     sal_uInt32 i = 0, nFlag = 0;
182 
183     if( !bOwnClass && rDfltI.IsInst() )
184         bOwnClass = rDfltI.pClass->InHierarchy( this );
185 
186     if( nEntries != (i = GetConstPos( nConstId )) ){
187         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
188         i = i / (sizeof( sal_uInt32 ) * 8);
189         if( bOwnClass ){
190             ((RscFlagInst *)aInst.pData)[ i ].nFlags &=
191             ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nFlags;
192             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags &=
193             ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nDfltFlags;
194         }
195         else{
196             ((RscFlagInst *)aInst.pData)[ i ].nFlags &= ~nFlag;
197             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags |= nFlag;
198         }
199     }
200 
201     return( aInst );
202 }
203 
204 /*************************************************************************
205 |*
206 |*    RscFlag::SetToDefault()
207 |*
208 |*    Beschreibung
209 |*    Ersterstellung    MM 03.04.91
210 |*    Letzte Aenderung  MM 03.04.91
211 |*
212 *************************************************************************/
SetToDefault(const RSCINST & rInst)213 void RscFlag::SetToDefault( const RSCINST & rInst )
214 {
215 	sal_uInt32 i = 0;
216 
217 	for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
218 		((RscFlagInst *)rInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
219 }
220 
221 /*************************************************************************
222 |*
223 |*    RscFlag::IsDlft()
224 |*
225 |*    Beschreibung
226 |*    Ersterstellung    MM 03.04.91
227 |*    Letzte Aenderung  MM 03.04.91
228 |*
229 *************************************************************************/
IsDefault(const RSCINST & rInst)230 sal_Bool RscFlag::IsDefault( const RSCINST & rInst )
231 {
232     sal_uInt32 i = 0;
233 
234     for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
235         if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF )
236             return( sal_False );
237     return( sal_True );
238 }
239 
IsDefault(const RSCINST & rInst,Atom nConstId)240 sal_Bool RscFlag::IsDefault( const RSCINST & rInst, Atom nConstId )
241 {
242     sal_uInt32 i = 0, nFlag = 0;
243 
244     if( nEntries != (i = GetConstPos( nConstId )) ){
245         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
246         i = i / (sizeof( sal_uInt32 ) * 8);
247         if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags & nFlag )
248             return( sal_True );
249         else
250             return( sal_False );
251     };
252     return( sal_True );
253 }
254 
255 /*************************************************************************
256 |*
257 |*    RscFlag::IsValueDefault()
258 |*
259 |*    Beschreibung
260 |*    Ersterstellung    MM 25.04.91
261 |*    Letzte Aenderung  MM 25.04.91
262 |*
263 *************************************************************************/
IsValueDefault(const RSCINST & rInst,CLASS_DATA pDef,Atom nConstId)264 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef,
265                               Atom nConstId )
266 {
267     sal_uInt32 i = 0, nFlag = 0;
268 
269     if( nEntries != (i = GetConstPos( nConstId )) ){
270         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
271         i = i / (sizeof( sal_uInt32 ) * 8);
272 
273         if( pDef ){
274             if( (((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag)
275               == (((RscFlagInst *)pDef)[ i ].nFlags & nFlag) )
276             {
277                 return sal_True;
278             }
279         }
280     };
281 
282     return sal_False;
283 }
284 
IsValueDefault(const RSCINST & rInst,CLASS_DATA pDef)285 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
286 {
287     sal_uInt32 i = 0;
288 
289     if( pDef ){
290         sal_uInt32  Flag = 0, nIndex = 0;
291 
292         Flag = 1;
293         for( i = 0; i < nEntries; i++ ){
294             nIndex = i / (sizeof( sal_uInt32 ) * 8);
295             if( (((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag)
296               != (((RscFlagInst *)pDef)[ nIndex ].nFlags & Flag)  )
297             {
298                 return sal_False;
299             }
300             Flag <<= 1;
301             if( !Flag )
302                 Flag = 1;
303         };
304     }
305     else
306         return sal_False;
307 
308     return sal_True;
309 }
310 
311 /*************************************************************************
312 |*
313 |*    RscFlag::IsSet()
314 |*
315 |*    Beschreibung
316 |*    Ersterstellung    MM 10.04.91
317 |*    Letzte Aenderung  MM 10.04.91
318 |*
319 *************************************************************************/
IsSet(const RSCINST & rInst,Atom nConstId)320 sal_Bool RscFlag::IsSet( const RSCINST & rInst, Atom nConstId )
321 {
322     sal_uInt32 i = 0, nFlag = 0;
323 
324     if( nEntries != (i = GetConstPos( nConstId )) ){
325         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
326         i = i / (sizeof( sal_uInt32 ) * 8);
327         if( ((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag )
328             return( sal_True );
329         else
330             return( sal_False );
331     };
332     return( sal_True );
333 }
334 
335 /*************************************************************************
336 |*
337 |*    RscFlag::WriteSrc()
338 |*
339 |*    Beschreibung
340 |*    Ersterstellung    MM 08.04.91
341 |*    Letzte Aenderung  MM 08.04.91
342 |*
343 *************************************************************************/
WriteSrc(const RSCINST & rInst,FILE * fOutput,RscTypCont *,sal_uInt32,const char *)344 void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput,
345                         RscTypCont *, sal_uInt32, const char * )
346 {
347     sal_uInt32  i = 0, Flag = 0, nIndex = 0;
348     sal_Bool    bComma = sal_False;
349 
350     Flag = 1;
351     for( i = 0; i < nEntries; i++ ){
352         nIndex = i / (sizeof( sal_uInt32 ) * 8);
353         if( !( ((RscFlagInst *)rInst.pData)[ nIndex ].nDfltFlags & Flag) ){
354             if( bComma )
355                 fprintf( fOutput, ", " );
356             if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
357                 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
358             else{
359                 fprintf( fOutput, "not " );
360                 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
361             }
362             bComma = sal_True;
363         }
364         Flag <<= 1;
365         if( !Flag )
366             Flag = 1;
367     };
368 }
369 
370 /*************************************************************************
371 |*
372 |*    RscFlag::WriteRc()
373 |*
374 |*    Beschreibung
375 |*    Ersterstellung    MM 15.04.91
376 |*    Letzte Aenderung  MM 15.04.91
377 |*
378 *************************************************************************/
WriteRc(const RSCINST & rInst,RscWriteRc & aMem,RscTypCont *,sal_uInt32,sal_Bool)379 ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
380                           RscTypCont *, sal_uInt32, sal_Bool )
381 {
382     sal_Int32	lVal = 0;
383     sal_uInt32  i = 0, Flag = 0, nIndex = 0;
384 
385     Flag = 1;
386     for( i = 0; i < nEntries; i++ ){
387         nIndex = i / (sizeof( sal_uInt32 ) * 8);
388         if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
389             lVal |= pVarArray[ i ].lValue;
390 
391         Flag <<= 1;
392         if( !Flag )
393             Flag = 1;
394     };
395 
396 	aMem.Put( (sal_Int32)lVal );
397     return( ERR_OK );
398 }
399 
400 /*************************************************************************
401 |*
402 |*    RscClient::RscClient()
403 |*
404 |*    Beschreibung
405 |*    Ersterstellung    MM 08.04.91
406 |*    Letzte Aenderung  MM 08.04.91
407 |*
408 *************************************************************************/
RscClient(Atom nId,sal_uInt32 nTypeId,RscFlag * pClass,Atom nConstantId)409 RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass,
410 					   Atom nConstantId )
411 		   : RscTop ( nId, nTypeId )
412 {
413    pRefClass = pClass;
414    nConstId = nConstantId;
415 }
416 
417 /*************************************************************************
418 |*
419 |*    RscClient::GetClassType()
420 |*
421 |*    Beschreibung
422 |*    Ersterstellung    MM 08.04.91
423 |*    Letzte Aenderung  MM 08.04.91
424 |*
425 *************************************************************************/
GetClassType() const426 RSCCLASS_TYPE RscClient::GetClassType() const
427 {
428 	return RSCCLASS_BOOL;
429 }
430 
431 /*************************************************************************
432 |*
433 |*    RscClient::WriteSrc()
434 |*
435 |*    Beschreibung
436 |*    Ersterstellung    MM 08.04.91
437 |*    Letzte Aenderung  MM 08.04.91
438 |*
439 *************************************************************************/
WriteSrc(const RSCINST & rInst,FILE * fOutput,RscTypCont *,sal_uInt32,const char *)440 void RscClient::WriteSrc( const RSCINST & rInst, FILE * fOutput,
441                           RscTypCont *, sal_uInt32, const char * )
442 {
443     if( pRefClass->IsSet( rInst, nConstId ) )
444         fprintf( fOutput, "TRUE" );
445     else
446         fprintf( fOutput, "FALSE" );
447 }
448 
449 /*************************************************************************
450 |*
451 |*    RscClient::Create()
452 |*
453 |*    Beschreibung
454 |*    Ersterstellung    MM 08.04.91
455 |*    Letzte Aenderung  MM 08.04.91
456 |*
457 *************************************************************************/
Create(RSCINST * pInst,const RSCINST & rDflt,sal_Bool bOwnClass)458 RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt,
459                            sal_Bool bOwnClass )
460 {
461     RSCINST aTmpI, aDfltI;
462 
463     if( pInst ){
464         aTmpI.pClass = pRefClass;
465         aTmpI.pData  = pInst->pData;
466     }
467 
468     if( !bOwnClass && rDflt.IsInst() ){
469         bOwnClass = rDflt.pClass->InHierarchy( this );
470         if( bOwnClass ){
471             aDfltI.pClass = pRefClass;
472             aDfltI.pData = rDflt.pData;
473         }
474     }
475 
476     if( pInst )
477         aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI,
478                                          bOwnClass, nConstId );
479     else
480         aTmpI = pRefClass->CreateClient( NULL, aDfltI,
481                                          bOwnClass, nConstId );
482     aTmpI.pClass = this;
483 
484     return( aTmpI );
485 }
486 
487