1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscflag.cxx,v $
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.
40 #include <rscflag.hxx>
42 /****************** C O D E **********************************************/
43 /****************** R s c F l a g ****************************************/
44 /*************************************************************************
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 /*************************************************************************
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()
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
;
94 return( ERR_RSCFLAG
);
97 /*************************************************************************
99 |* RscFlag::SetConst()
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
;
118 return( ERR_RSCFLAG
);
121 /*************************************************************************
123 |* RscFlag::CreateBasic()
126 |* Ersterstellung MM 16.01.92
127 |* Letzte Aenderung MM 16.01.92
129 *************************************************************************/
130 RSCINST
RscFlag::CreateBasic( RSCINST
* pInst
)
136 aInst
.pData
= (CLASS_DATA
) rtl_allocateMemory( Size() );
144 /*************************************************************************
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
);
158 if( !bOwnClass
&& rDflt
.IsInst() )
159 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
162 memmove( aInst
.pData
, rDflt
.pData
, Size() );
165 for( i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
167 ((RscFlagInst
*)aInst
.pData
)[ i
].nFlags
= 0;
168 ((RscFlagInst
*)aInst
.pData
)[ i
].nDfltFlags
= 0xFFFFFFFF;
175 /*************************************************************************
177 |* RscFlag::CreateClient()
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);
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
;
203 ((RscFlagInst
*)aInst
.pData
)[ i
].nFlags
&= ~nFlag
;
204 ((RscFlagInst
*)aInst
.pData
)[ i
].nDfltFlags
|= nFlag
;
211 /*************************************************************************
213 |* RscFlag::SetToDefault()
216 |* Ersterstellung MM 03.04.91
217 |* Letzte Aenderung MM 03.04.91
219 *************************************************************************/
220 void RscFlag::SetToDefault( const RSCINST
& rInst
)
224 for( i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
225 ((RscFlagInst
*)rInst
.pData
)[ i
].nDfltFlags
= 0xFFFFFFFF;
228 /*************************************************************************
233 |* Ersterstellung MM 03.04.91
234 |* Letzte Aenderung MM 03.04.91
236 *************************************************************************/
237 BOOL
RscFlag::IsDefault( const RSCINST
& rInst
)
241 for( i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
242 if( ((RscFlagInst
*)rInst
.pData
)[ i
].nDfltFlags
!= 0xFFFFFFFF )
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
)
262 /*************************************************************************
264 |* RscFlag::IsValueDefault()
267 |* Ersterstellung MM 25.04.91
268 |* Letzte Aenderung MM 25.04.91
270 *************************************************************************/
271 BOOL
RscFlag::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
,
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);
281 if( (((RscFlagInst
*)rInst
.pData
)[ i
].nFlags
& nFlag
)
282 == (((RscFlagInst
*)pDef
)[ i
].nFlags
& nFlag
) )
292 BOOL
RscFlag::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
297 sal_uInt32 Flag
= 0, nIndex
= 0;
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
) )
318 /*************************************************************************
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
)
342 /*************************************************************************
344 |* RscFlag::WriteSrc()
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;
358 for( i
= 0; i
< nEntries
; i
++ ){
359 nIndex
= i
/ (sizeof( sal_uInt32
) * 8);
360 if( !( ((RscFlagInst
*)rInst
.pData
)[ nIndex
].nDfltFlags
& Flag
) ){
362 fprintf( fOutput
, ", " );
363 if( ((RscFlagInst
*)rInst
.pData
)[ nIndex
].nFlags
& Flag
)
364 fprintf( fOutput
, "%s", pHS
->getString( pVarArray
[ i
].nId
).getStr() );
366 fprintf( fOutput
, "not " );
367 fprintf( fOutput
, "%s", pHS
->getString( pVarArray
[ i
].nId
).getStr() );
377 /*************************************************************************
379 |* RscFlag::WriteRc()
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
)
390 sal_uInt32 i
= 0, Flag
= 0, nIndex
= 0;
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
;
403 aMem
.Put( (INT32
)lVal
);
407 /*************************************************************************
409 |* RscClient::RscClient()
412 |* Ersterstellung MM 08.04.91
413 |* Letzte Aenderung MM 08.04.91
415 *************************************************************************/
416 RscClient::RscClient( Atom nId
, sal_uInt32 nTypeId
, RscFlag
* pClass
,
418 : RscTop ( nId
, nTypeId
)
421 nConstId
= nConstantId
;
424 /*************************************************************************
426 |* RscClient::GetClassType()
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()
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" );
453 fprintf( fOutput
, "FALSE" );
456 /*************************************************************************
458 |* RscClient::Create()
461 |* Ersterstellung MM 08.04.91
462 |* Letzte Aenderung MM 08.04.91
464 *************************************************************************/
465 RSCINST
RscClient::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
468 RSCINST aTmpI
, aDfltI
;
471 aTmpI
.pClass
= pRefClass
;
472 aTmpI
.pData
= pInst
->pData
;
475 if( !bOwnClass
&& rDflt
.IsInst() ){
476 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
478 aDfltI
.pClass
= pRefClass
;
479 aDfltI
.pData
= rDflt
.pData
;
484 aTmpI
= pRefClass
->CreateClient( &aTmpI
, aDfltI
,
485 bOwnClass
, nConstId
);
487 aTmpI
= pRefClass
->CreateClient( NULL
, aDfltI
,
488 bOwnClass
, nConstId
);