CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / res / rscflag.cxx
blob48c583a3ff8e7982f88c28740976337c11326d86
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
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 **************************************/
32 // C and C++ Includes.
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include <rscflag.hxx>
39 /****************** C O D E **********************************************/
40 /****************** R s c F l a g ****************************************/
41 /*************************************************************************
43 |* RscFlag::RscFlag()
45 |* Beschreibung
46 |* Ersterstellung MM 03.04.91
47 |* Letzte Aenderung MM 03.04.91
49 *************************************************************************/
50 RscFlag::RscFlag( Atom nId, sal_uInt32 nTypeId )
51 : RscConst( nId, nTypeId )
54 /*************************************************************************
56 |* RscFlag::Size()
58 |* Beschreibung Die Groe�e der Instanzdaten richtet sich nach
59 |* der Anzahl der Flags
60 |* Ersterstellung MM 03.04.91
61 |* Letzte Aenderung MM 03.04.91
63 *************************************************************************/
64 sal_uInt32 RscFlag::Size()
66 return( ALIGNED_SIZE( sizeof( RscFlagInst ) *
67 ( 1 + (nEntries -1) / (sizeof( sal_uInt32 ) * 8) ) ) );
70 /*************************************************************************
72 |* RscFlag::SetNotConst()
74 |* Beschreibung
75 |* Ersterstellung MM 03.04.91
76 |* Letzte Aenderung MM 03.04.91
78 *************************************************************************/
79 ERRTYPE RscFlag::SetNotConst( const RSCINST & rInst, Atom nConst )
81 sal_uInt32 i = 0, nFlag = 0;
83 if( nEntries != (i = GetConstPos( nConst )) ){
84 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
85 i = i / (sizeof( sal_uInt32 ) * 8);
86 ((RscFlagInst *)rInst.pData)[ i ].nFlags &= ~nFlag;
87 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
88 return( ERR_OK );
91 return( ERR_RSCFLAG );
94 /*************************************************************************
96 |* RscFlag::SetConst()
98 |* Beschreibung
99 |* Ersterstellung MM 03.04.91
100 |* Letzte Aenderung MM 03.04.91
102 *************************************************************************/
103 ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
105 sal_uInt32 i = 0, nFlag = 0;
107 if( nEntries != (i = GetConstPos( nConst )) ){
108 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
109 i = i / (sizeof( sal_uInt32 ) * 8);
110 ((RscFlagInst *)rInst.pData)[ i ].nFlags |= nFlag;
111 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
112 return( ERR_OK );
115 return( ERR_RSCFLAG );
118 /*************************************************************************
120 |* RscFlag::CreateBasic()
122 |* Beschreibung
123 |* Ersterstellung MM 16.01.92
124 |* Letzte Aenderung MM 16.01.92
126 *************************************************************************/
127 RSCINST RscFlag::CreateBasic( RSCINST * pInst )
129 RSCINST aInst;
131 if( !pInst ){
132 aInst.pClass = this;
133 aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
135 else
136 aInst = *pInst;
138 return( aInst );
141 /*************************************************************************
143 |* RscFlag::Create()
145 |* Beschreibung
146 |* Ersterstellung MM 03.04.91
147 |* Letzte Aenderung MM 16.01.92
149 *************************************************************************/
150 RSCINST RscFlag::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass )
152 RSCINST aInst = CreateBasic( pInst );
153 sal_uInt32 i = 0;
155 if( !bOwnClass && rDflt.IsInst() )
156 bOwnClass = rDflt.pClass->InHierarchy( this );
158 if( bOwnClass )
159 memmove( aInst.pData, rDflt.pData, Size() );
160 else
162 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
164 ((RscFlagInst *)aInst.pData)[ i ].nFlags = 0;
165 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
169 return( aInst );
172 /*************************************************************************
174 |* RscFlag::CreateClient()
176 |* Beschreibung
177 |* Ersterstellung MM 16.01.92
178 |* Letzte Aenderung MM 16.01.92
180 *************************************************************************/
181 RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI,
182 sal_Bool bOwnClass, Atom nConstId )
184 RSCINST aInst = CreateBasic( pInst );
185 sal_uInt32 i = 0, nFlag = 0;
187 if( !bOwnClass && rDfltI.IsInst() )
188 bOwnClass = rDfltI.pClass->InHierarchy( this );
190 if( nEntries != (i = GetConstPos( nConstId )) ){
191 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
192 i = i / (sizeof( sal_uInt32 ) * 8);
193 if( bOwnClass ){
194 ((RscFlagInst *)aInst.pData)[ i ].nFlags &=
195 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nFlags;
196 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags &=
197 ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nDfltFlags;
199 else{
200 ((RscFlagInst *)aInst.pData)[ i ].nFlags &= ~nFlag;
201 ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags |= nFlag;
205 return( aInst );
208 /*************************************************************************
210 |* RscFlag::SetToDefault()
212 |* Beschreibung
213 |* Ersterstellung MM 03.04.91
214 |* Letzte Aenderung MM 03.04.91
216 *************************************************************************/
217 void RscFlag::SetToDefault( const RSCINST & rInst )
219 sal_uInt32 i = 0;
221 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
222 ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
225 /*************************************************************************
227 |* RscFlag::IsDlft()
229 |* Beschreibung
230 |* Ersterstellung MM 03.04.91
231 |* Letzte Aenderung MM 03.04.91
233 *************************************************************************/
234 sal_Bool RscFlag::IsDefault( const RSCINST & rInst )
236 sal_uInt32 i = 0;
238 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
239 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF )
240 return( sal_False );
241 return( sal_True );
244 sal_Bool RscFlag::IsDefault( const RSCINST & rInst, Atom nConstId )
246 sal_uInt32 i = 0, nFlag = 0;
248 if( nEntries != (i = GetConstPos( nConstId )) ){
249 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
250 i = i / (sizeof( sal_uInt32 ) * 8);
251 if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags & nFlag )
252 return( sal_True );
253 else
254 return( sal_False );
256 return( sal_True );
259 /*************************************************************************
261 |* RscFlag::IsValueDefault()
263 |* Beschreibung
264 |* Ersterstellung MM 25.04.91
265 |* Letzte Aenderung MM 25.04.91
267 *************************************************************************/
268 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef,
269 Atom nConstId )
271 sal_uInt32 i = 0, nFlag = 0;
273 if( nEntries != (i = GetConstPos( nConstId )) ){
274 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
275 i = i / (sizeof( sal_uInt32 ) * 8);
277 if( pDef ){
278 if( (((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag)
279 == (((RscFlagInst *)pDef)[ i ].nFlags & nFlag) )
281 return sal_True;
286 return sal_False;
289 sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
291 sal_uInt32 i = 0;
293 if( pDef ){
294 sal_uInt32 Flag = 0, nIndex = 0;
296 Flag = 1;
297 for( i = 0; i < nEntries; i++ ){
298 nIndex = i / (sizeof( sal_uInt32 ) * 8);
299 if( (((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag)
300 != (((RscFlagInst *)pDef)[ nIndex ].nFlags & Flag) )
302 return sal_False;
304 Flag <<= 1;
305 if( !Flag )
306 Flag = 1;
309 else
310 return sal_False;
312 return sal_True;
315 /*************************************************************************
317 |* RscFlag::IsSet()
319 |* Beschreibung
320 |* Ersterstellung MM 10.04.91
321 |* Letzte Aenderung MM 10.04.91
323 *************************************************************************/
324 sal_Bool RscFlag::IsSet( const RSCINST & rInst, Atom nConstId )
326 sal_uInt32 i = 0, nFlag = 0;
328 if( nEntries != (i = GetConstPos( nConstId )) ){
329 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
330 i = i / (sizeof( sal_uInt32 ) * 8);
331 if( ((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag )
332 return( sal_True );
333 else
334 return( sal_False );
336 return( sal_True );
339 /*************************************************************************
341 |* RscFlag::WriteSrc()
343 |* Beschreibung
344 |* Ersterstellung MM 08.04.91
345 |* Letzte Aenderung MM 08.04.91
347 *************************************************************************/
348 void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput,
349 RscTypCont *, sal_uInt32, const char * )
351 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
352 sal_Bool bComma = sal_False;
354 Flag = 1;
355 for( i = 0; i < nEntries; i++ ){
356 nIndex = i / (sizeof( sal_uInt32 ) * 8);
357 if( !( ((RscFlagInst *)rInst.pData)[ nIndex ].nDfltFlags & Flag) ){
358 if( bComma )
359 fprintf( fOutput, ", " );
360 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
361 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
362 else{
363 fprintf( fOutput, "not " );
364 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
366 bComma = sal_True;
368 Flag <<= 1;
369 if( !Flag )
370 Flag = 1;
374 /*************************************************************************
376 |* RscFlag::WriteRc()
378 |* Beschreibung
379 |* Ersterstellung MM 15.04.91
380 |* Letzte Aenderung MM 15.04.91
382 *************************************************************************/
383 ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
384 RscTypCont *, sal_uInt32, sal_Bool )
386 sal_Int32 lVal = 0;
387 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
389 Flag = 1;
390 for( i = 0; i < nEntries; i++ ){
391 nIndex = i / (sizeof( sal_uInt32 ) * 8);
392 if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
393 lVal |= pVarArray[ i ].lValue;
395 Flag <<= 1;
396 if( !Flag )
397 Flag = 1;
400 aMem.Put( (sal_Int32)lVal );
401 return( ERR_OK );
404 /*************************************************************************
406 |* RscClient::RscClient()
408 |* Beschreibung
409 |* Ersterstellung MM 08.04.91
410 |* Letzte Aenderung MM 08.04.91
412 *************************************************************************/
413 RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass,
414 Atom nConstantId )
415 : RscTop ( nId, nTypeId )
417 pRefClass = pClass;
418 nConstId = nConstantId;
421 /*************************************************************************
423 |* RscClient::GetClassType()
425 |* Beschreibung
426 |* Ersterstellung MM 08.04.91
427 |* Letzte Aenderung MM 08.04.91
429 *************************************************************************/
430 RSCCLASS_TYPE RscClient::GetClassType() const
432 return RSCCLASS_BOOL;
435 /*************************************************************************
437 |* RscClient::WriteSrc()
439 |* Beschreibung
440 |* Ersterstellung MM 08.04.91
441 |* Letzte Aenderung MM 08.04.91
443 *************************************************************************/
444 void RscClient::WriteSrc( const RSCINST & rInst, FILE * fOutput,
445 RscTypCont *, sal_uInt32, const char * )
447 if( pRefClass->IsSet( rInst, nConstId ) )
448 fprintf( fOutput, "TRUE" );
449 else
450 fprintf( fOutput, "FALSE" );
453 /*************************************************************************
455 |* RscClient::Create()
457 |* Beschreibung
458 |* Ersterstellung MM 08.04.91
459 |* Letzte Aenderung MM 08.04.91
461 *************************************************************************/
462 RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt,
463 sal_Bool bOwnClass )
465 RSCINST aTmpI, aDfltI;
467 if( pInst ){
468 aTmpI.pClass = pRefClass;
469 aTmpI.pData = pInst->pData;
472 if( !bOwnClass && rDflt.IsInst() ){
473 bOwnClass = rDflt.pClass->InHierarchy( this );
474 if( bOwnClass ){
475 aDfltI.pClass = pRefClass;
476 aDfltI.pData = rDflt.pData;
480 if( pInst )
481 aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI,
482 bOwnClass, nConstId );
483 else
484 aTmpI = pRefClass->CreateClient( NULL, aDfltI,
485 bOwnClass, nConstId );
486 aTmpI.pClass = this;
488 return( aTmpI );