1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <rscflag.hxx>
27 RscFlag::RscFlag( Atom nId
, sal_uInt32 nTypeId
)
28 : RscConst( nId
, nTypeId
)
32 sal_uInt32
RscFlag::Size()
34 return ALIGNED_SIZE( sizeof( RscFlagInst
) *
35 ( 1 + (nEntries
-1) / (sizeof( sal_uInt32
) * 8) ) );
38 ERRTYPE
RscFlag::SetNotConst( const RSCINST
& rInst
, Atom nConst
)
42 if( nEntries
!= (i
= GetConstPos( nConst
)) )
44 sal_uInt32 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
46 i
= i
/ (sizeof( sal_uInt32
) * 8);
47 reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nFlags
&= ~nFlag
;
48 reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nDfltFlags
&= ~nFlag
;
55 ERRTYPE
RscFlag::SetConst( const RSCINST
& rInst
, Atom nConst
, sal_Int32
/*nVal*/ )
59 if( nEntries
!= (i
= GetConstPos( nConst
)) )
61 sal_uInt32 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
63 i
= i
/ (sizeof( sal_uInt32
) * 8);
64 reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nFlags
|= nFlag
;
65 reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nDfltFlags
&= ~nFlag
;
72 RSCINST
RscFlag::CreateBasic( RSCINST
* pInst
)
79 aInst
.pData
= static_cast<CLASS_DATA
>(rtl_allocateMemory( Size() ));
87 RSCINST
RscFlag::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, bool bOwnClass
)
89 RSCINST aInst
= CreateBasic( pInst
);
91 if( !bOwnClass
&& rDflt
.IsInst() )
92 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
95 memmove( aInst
.pData
, rDflt
.pData
, Size() );
98 for( sal_uInt32 i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
100 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nFlags
= 0;
101 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nDfltFlags
= 0xFFFFFFFF;
108 RSCINST
RscFlag::CreateClient( RSCINST
* pInst
, const RSCINST
& rDfltI
,
109 bool bOwnClass
, Atom nConstId
)
111 RSCINST aInst
= CreateBasic( pInst
);
114 if( !bOwnClass
&& rDfltI
.IsInst() )
115 bOwnClass
= rDfltI
.pClass
->InHierarchy( this );
117 if( nEntries
!= (i
= GetConstPos( nConstId
)) )
119 sal_uInt32 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
120 i
= i
/ (sizeof( sal_uInt32
) * 8);
123 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nFlags
&=
124 ~nFlag
| reinterpret_cast<RscFlagInst
*>(rDfltI
.pData
)[ i
].nFlags
;
125 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nDfltFlags
&=
126 ~nFlag
| reinterpret_cast<RscFlagInst
*>(rDfltI
.pData
)[ i
].nDfltFlags
;
130 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nFlags
&= ~nFlag
;
131 reinterpret_cast<RscFlagInst
*>(aInst
.pData
)[ i
].nDfltFlags
|= nFlag
;
138 void RscFlag::SetToDefault( const RSCINST
& rInst
)
142 for( i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
143 reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nDfltFlags
= 0xFFFFFFFF;
146 bool RscFlag::IsDefault( const RSCINST
& rInst
)
150 for( i
= 0; i
< Size() / sizeof( RscFlagInst
); i
++ )
152 if( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nDfltFlags
!= 0xFFFFFFFF )
158 bool RscFlag::IsDefault( const RSCINST
& rInst
, Atom nConstId
)
160 sal_uInt32 i
= 0, nFlag
= 0;
162 if( nEntries
!= (i
= GetConstPos( nConstId
)) )
164 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
165 i
= i
/ (sizeof( sal_uInt32
) * 8);
167 if( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nDfltFlags
& nFlag
)
175 bool RscFlag::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
,
178 sal_uInt32 i
= 0, nFlag
= 0;
180 if( nEntries
!= (i
= GetConstPos( nConstId
)) )
182 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
183 i
= i
/ (sizeof( sal_uInt32
) * 8);
187 if( (reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nFlags
& nFlag
) ==
188 (reinterpret_cast<RscFlagInst
*>(pDef
)[ i
].nFlags
& nFlag
) )
198 bool RscFlag::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
202 sal_uInt32 Flag
= 0, nIndex
= 0;
205 for( sal_uInt32 i
= 0; i
< nEntries
; i
++ )
207 nIndex
= i
/ (sizeof( sal_uInt32
) * 8);
209 if( (reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ nIndex
].nFlags
& Flag
) !=
210 (reinterpret_cast<RscFlagInst
*>(pDef
)[ nIndex
].nFlags
& Flag
) )
225 bool RscFlag::IsSet( const RSCINST
& rInst
, Atom nConstId
)
227 sal_uInt32 i
= 0, nFlag
= 0;
229 if( nEntries
!= (i
= GetConstPos( nConstId
)) )
231 nFlag
= 1 << (i
% (sizeof( sal_uInt32
) * 8) );
232 i
= i
/ (sizeof( sal_uInt32
) * 8);
234 if( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ i
].nFlags
& nFlag
)
242 void RscFlag::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
243 RscTypCont
*, sal_uInt32
, const char * )
245 sal_uInt32 i
= 0, Flag
= 0, nIndex
= 0;
249 for( i
= 0; i
< nEntries
; i
++ )
251 nIndex
= i
/ (sizeof( sal_uInt32
) * 8);
252 if( !( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ nIndex
].nDfltFlags
& Flag
) )
255 fprintf( fOutput
, ", " );
257 if( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ nIndex
].nFlags
& Flag
)
258 fprintf( fOutput
, "%s", pHS
->getString( pVarArray
[ i
].nId
).getStr() );
261 fprintf( fOutput
, "not " );
262 fprintf( fOutput
, "%s", pHS
->getString( pVarArray
[ i
].nId
).getStr() );
272 ERRTYPE
RscFlag::WriteRc( const RSCINST
& rInst
, RscWriteRc
& aMem
,
273 RscTypCont
*, sal_uInt32
, bool )
276 sal_uInt32 i
= 0, Flag
= 0, nIndex
= 0;
279 for( i
= 0; i
< nEntries
; i
++ )
281 nIndex
= i
/ (sizeof( sal_uInt32
) * 8);
283 if( reinterpret_cast<RscFlagInst
*>(rInst
.pData
)[ nIndex
].nFlags
& Flag
)
284 lVal
|= pVarArray
[ i
].lValue
;
291 aMem
.Put( (sal_Int32
)lVal
);
295 RscClient::RscClient( Atom nId
, sal_uInt32 nTypeId
, RscFlag
* pClass
,
297 : RscTop ( nId
, nTypeId
)
300 nConstId
= nConstantId
;
303 RSCCLASS_TYPE
RscClient::GetClassType() const
305 return RSCCLASS_BOOL
;
308 void RscClient::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
309 RscTypCont
*, sal_uInt32
, const char * )
311 if( pRefClass
->IsSet( rInst
, nConstId
) )
312 fprintf( fOutput
, "TRUE" );
314 fprintf( fOutput
, "FALSE" );
317 RSCINST
RscClient::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
320 RSCINST aTmpI
, aDfltI
;
324 aTmpI
.pClass
= pRefClass
;
325 aTmpI
.pData
= pInst
->pData
;
328 if( !bOwnClass
&& rDflt
.IsInst() )
330 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
333 aDfltI
.pClass
= pRefClass
;
334 aDfltI
.pData
= rDflt
.pData
;
339 aTmpI
= pRefClass
->CreateClient( &aTmpI
, aDfltI
,
340 bOwnClass
, nConstId
);
342 aTmpI
= pRefClass
->CreateClient( NULL
, aDfltI
,
343 bOwnClass
, nConstId
);
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */