update dev300-m58
[ooovba.git] / rsc / source / res / rscflag.cxx
blob4fc5ebd93127e093ffa3dbfd003eb63d62e97edc
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: rscflag.cxx,v $
10 * $Revision: 1.8 $
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 <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
40 #include <rscflag.hxx>
42 /****************** C O D E **********************************************/
43 /****************** R s c F l a g ****************************************/
44 /*************************************************************************
46 |* RscFlag::RscFlag()
48 |* Beschreibung
49 |* Ersterstellung MM 03.04.91
50 |* Letzte Aenderung MM 03.04.91
52 *************************************************************************/
53 RscFlag::RscFlag( Atom nId, sal_uInt32 nTypeId )
54 : RscConst( nId, nTypeId )
57 /*************************************************************************
59 |* RscFlag::Size()
61 |* Beschreibung Die Groe�e der Instanzdaten richtet sich nach
62 |* der Anzahl der Flags
63 |* Ersterstellung MM 03.04.91
64 |* Letzte Aenderung MM 03.04.91
66 *************************************************************************/
67 sal_uInt32 RscFlag::Size()
69 return( ALIGNED_SIZE( sizeof( RscFlagInst ) *
70 ( 1 + (nEntries -1) / (sizeof( sal_uInt32 ) * 8) ) ) );
73 /*************************************************************************
75 |* RscFlag::SetNotConst()
77 |* Beschreibung
78 |* Ersterstellung MM 03.04.91
79 |* Letzte Aenderung MM 03.04.91
81 *************************************************************************/
82 ERRTYPE RscFlag::SetNotConst( const RSCINST & rInst, Atom nConst )
84 sal_uInt32 i = 0, nFlag = 0;
86 if( nEntries != (i = GetConstPos( nConst )) ){
87 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
88 i = i / (sizeof( sal_uInt32 ) * 8);
89 ((RscFlagInst *)rInst.pData)[ i ].nFlags &= ~nFlag;
90 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
91 return( ERR_OK );
94 return( ERR_RSCFLAG );
97 /*************************************************************************
99 |* RscFlag::SetConst()
101 |* Beschreibung
102 |* Ersterstellung MM 03.04.91
103 |* Letzte Aenderung MM 03.04.91
105 *************************************************************************/
106 ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, INT32 /*nVal*/ )
108 sal_uInt32 i = 0, nFlag = 0;
110 if( nEntries != (i = GetConstPos( nConst )) ){
111 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
112 i = i / (sizeof( sal_uInt32 ) * 8);
113 ((RscFlagInst *)rInst.pData)[ i ].nFlags |= nFlag;
114 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
115 return( ERR_OK );
118 return( ERR_RSCFLAG );
121 /*************************************************************************
123 |* RscFlag::CreateBasic()
125 |* Beschreibung
126 |* Ersterstellung MM 16.01.92
127 |* Letzte Aenderung MM 16.01.92
129 *************************************************************************/
130 RSCINST RscFlag::CreateBasic( RSCINST * pInst )
132 RSCINST aInst;
134 if( !pInst ){
135 aInst.pClass = this;
136 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
138 else
139 aInst = *pInst;
141 return( aInst );
144 /*************************************************************************
146 |* RscFlag::Create()
148 |* Beschreibung
149 |* Ersterstellung MM 03.04.91
150 |* Letzte Aenderung MM 16.01.92
152 *************************************************************************/
153 RSCINST RscFlag::Create( RSCINST * pInst, const RSCINST & rDflt, BOOL bOwnClass )
155 RSCINST aInst = CreateBasic( pInst );
156 sal_uInt32 i = 0;
158 if( !bOwnClass && rDflt.IsInst() )
159 bOwnClass = rDflt.pClass->InHierarchy( this );
161 if( bOwnClass )
162 memmove( aInst.pData, rDflt.pData, Size() );
163 else
165 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
167 ((RscFlagInst *)aInst.pData)[ i ].nFlags = 0;
168 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
172 return( aInst );
175 /*************************************************************************
177 |* RscFlag::CreateClient()
179 |* Beschreibung
180 |* Ersterstellung MM 16.01.92
181 |* Letzte Aenderung MM 16.01.92
183 *************************************************************************/
184 RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI,
185 BOOL bOwnClass, Atom nConstId )
187 RSCINST aInst = CreateBasic( pInst );
188 sal_uInt32 i = 0, nFlag = 0;
190 if( !bOwnClass && rDfltI.IsInst() )
191 bOwnClass = rDfltI.pClass->InHierarchy( this );
193 if( nEntries != (i = GetConstPos( nConstId )) ){
194 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
195 i = i / (sizeof( sal_uInt32 ) * 8);
196 if( bOwnClass ){
197 ((RscFlagInst *)aInst.pData)[ i ].nFlags &=
198 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nFlags;
199 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags &=
200 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nDfltFlags;
202 else{
203 ((RscFlagInst *)aInst.pData)[ i ].nFlags &= ~nFlag;
204 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags |= nFlag;
208 return( aInst );
211 /*************************************************************************
213 |* RscFlag::SetToDefault()
215 |* Beschreibung
216 |* Ersterstellung MM 03.04.91
217 |* Letzte Aenderung MM 03.04.91
219 *************************************************************************/
220 void RscFlag::SetToDefault( const RSCINST & rInst )
222 sal_uInt32 i = 0;
224 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
225 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
228 /*************************************************************************
230 |* RscFlag::IsDlft()
232 |* Beschreibung
233 |* Ersterstellung MM 03.04.91
234 |* Letzte Aenderung MM 03.04.91
236 *************************************************************************/
237 BOOL RscFlag::IsDefault( const RSCINST & rInst )
239 sal_uInt32 i = 0;
241 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
242 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF )
243 return( FALSE );
244 return( TRUE );
247 BOOL RscFlag::IsDefault( const RSCINST & rInst, Atom nConstId )
249 sal_uInt32 i = 0, nFlag = 0;
251 if( nEntries != (i = GetConstPos( nConstId )) ){
252 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
253 i = i / (sizeof( sal_uInt32 ) * 8);
254 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags & nFlag )
255 return( TRUE );
256 else
257 return( FALSE );
259 return( TRUE );
262 /*************************************************************************
264 |* RscFlag::IsValueDefault()
266 |* Beschreibung
267 |* Ersterstellung MM 25.04.91
268 |* Letzte Aenderung MM 25.04.91
270 *************************************************************************/
271 BOOL RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef,
272 Atom nConstId )
274 sal_uInt32 i = 0, nFlag = 0;
276 if( nEntries != (i = GetConstPos( nConstId )) ){
277 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
278 i = i / (sizeof( sal_uInt32 ) * 8);
280 if( pDef ){
281 if( (((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag)
282 == (((RscFlagInst *)pDef)[ i ].nFlags & nFlag) )
284 return TRUE;
289 return FALSE;
292 BOOL RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
294 sal_uInt32 i = 0;
296 if( pDef ){
297 sal_uInt32 Flag = 0, nIndex = 0;
299 Flag = 1;
300 for( i = 0; i < nEntries; i++ ){
301 nIndex = i / (sizeof( sal_uInt32 ) * 8);
302 if( (((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag)
303 != (((RscFlagInst *)pDef)[ nIndex ].nFlags & Flag) )
305 return FALSE;
307 Flag <<= 1;
308 if( !Flag )
309 Flag = 1;
312 else
313 return FALSE;
315 return TRUE;
318 /*************************************************************************
320 |* RscFlag::IsSet()
322 |* Beschreibung
323 |* Ersterstellung MM 10.04.91
324 |* Letzte Aenderung MM 10.04.91
326 *************************************************************************/
327 BOOL RscFlag::IsSet( const RSCINST & rInst, Atom nConstId )
329 sal_uInt32 i = 0, nFlag = 0;
331 if( nEntries != (i = GetConstPos( nConstId )) ){
332 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
333 i = i / (sizeof( sal_uInt32 ) * 8);
334 if( ((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag )
335 return( TRUE );
336 else
337 return( FALSE );
339 return( TRUE );
342 /*************************************************************************
344 |* RscFlag::WriteSrc()
346 |* Beschreibung
347 |* Ersterstellung MM 08.04.91
348 |* Letzte Aenderung MM 08.04.91
350 *************************************************************************/
351 void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput,
352 RscTypCont *, sal_uInt32, const char * )
354 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
355 BOOL bComma = FALSE;
357 Flag = 1;
358 for( i = 0; i < nEntries; i++ ){
359 nIndex = i / (sizeof( sal_uInt32 ) * 8);
360 if( !( ((RscFlagInst *)rInst.pData)[ nIndex ].nDfltFlags & Flag) ){
361 if( bComma )
362 fprintf( fOutput, ", " );
363 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
364 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
365 else{
366 fprintf( fOutput, "not " );
367 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
369 bComma = TRUE;
371 Flag <<= 1;
372 if( !Flag )
373 Flag = 1;
377 /*************************************************************************
379 |* RscFlag::WriteRc()
381 |* Beschreibung
382 |* Ersterstellung MM 15.04.91
383 |* Letzte Aenderung MM 15.04.91
385 *************************************************************************/
386 ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
387 RscTypCont *, sal_uInt32, BOOL )
389 INT32 lVal = 0;
390 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
392 Flag = 1;
393 for( i = 0; i < nEntries; i++ ){
394 nIndex = i / (sizeof( sal_uInt32 ) * 8);
395 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
396 lVal |= pVarArray[ i ].lValue;
398 Flag <<= 1;
399 if( !Flag )
400 Flag = 1;
403 aMem.Put( (INT32)lVal );
404 return( ERR_OK );
407 /*************************************************************************
409 |* RscClient::RscClient()
411 |* Beschreibung
412 |* Ersterstellung MM 08.04.91
413 |* Letzte Aenderung MM 08.04.91
415 *************************************************************************/
416 RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass,
417 Atom nConstantId )
418 : RscTop ( nId, nTypeId )
420 pRefClass = pClass;
421 nConstId = nConstantId;
424 /*************************************************************************
426 |* RscClient::GetClassType()
428 |* Beschreibung
429 |* Ersterstellung MM 08.04.91
430 |* Letzte Aenderung MM 08.04.91
432 *************************************************************************/
433 RSCCLASS_TYPE RscClient::GetClassType() const
435 return RSCCLASS_BOOL;
438 /*************************************************************************
440 |* RscClient::WriteSrc()
442 |* Beschreibung
443 |* Ersterstellung MM 08.04.91
444 |* Letzte Aenderung MM 08.04.91
446 *************************************************************************/
447 void RscClient::WriteSrc( const RSCINST & rInst, FILE * fOutput,
448 RscTypCont *, sal_uInt32, const char * )
450 if( pRefClass->IsSet( rInst, nConstId ) )
451 fprintf( fOutput, "TRUE" );
452 else
453 fprintf( fOutput, "FALSE" );
456 /*************************************************************************
458 |* RscClient::Create()
460 |* Beschreibung
461 |* Ersterstellung MM 08.04.91
462 |* Letzte Aenderung MM 08.04.91
464 *************************************************************************/
465 RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt,
466 BOOL bOwnClass )
468 RSCINST aTmpI, aDfltI;
470 if( pInst ){
471 aTmpI.pClass = pRefClass;
472 aTmpI.pData = pInst->pData;
475 if( !bOwnClass && rDflt.IsInst() ){
476 bOwnClass = rDflt.pClass->InHierarchy( this );
477 if( bOwnClass ){
478 aDfltI.pClass = pRefClass;
479 aDfltI.pData = rDflt.pData;
483 if( pInst )
484 aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI,
485 bOwnClass, nConstId );
486 else
487 aTmpI = pRefClass->CreateClient( NULL, aDfltI,
488 bOwnClass, nConstId );
489 aTmpI.pClass = this;
491 return( aTmpI );