bump product version to 5.0.4.1
[LibreOffice.git] / rsc / source / res / rscflag.cxx
blobd0f1573e1b3a9060764dd6e2963f460b205bbe40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
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 )
40 sal_uInt32 i = 0;
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;
49 return ERR_OK;
52 return ERR_RSCFLAG;
55 ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
57 sal_uInt32 i = 0;
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;
66 return ERR_OK;
69 return ERR_RSCFLAG;
72 RSCINST RscFlag::CreateBasic( RSCINST * pInst )
74 RSCINST aInst;
76 if( !pInst )
78 aInst.pClass = this;
79 aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( Size() ));
81 else
82 aInst = *pInst;
84 return aInst;
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 );
94 if( bOwnClass )
95 memmove( aInst.pData, rDflt.pData, Size() );
96 else
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;
105 return aInst;
108 RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI,
109 bool bOwnClass, Atom nConstId )
111 RSCINST aInst = CreateBasic( pInst );
112 sal_uInt32 i = 0;
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);
121 if( bOwnClass )
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;
128 else
130 reinterpret_cast<RscFlagInst *>(aInst.pData)[ i ].nFlags &= ~nFlag;
131 reinterpret_cast<RscFlagInst *>(aInst.pData)[ i ].nDfltFlags |= nFlag;
135 return aInst;
138 void RscFlag::SetToDefault( const RSCINST & rInst )
140 sal_uInt32 i = 0;
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 )
148 sal_uInt32 i = 0;
150 for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
152 if( reinterpret_cast<RscFlagInst *>(rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF )
153 return false;
155 return true;
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 )
168 return true ;
169 else
170 return false;
172 return true;
175 bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef,
176 Atom nConstId )
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);
185 if( pDef )
187 if( (reinterpret_cast<RscFlagInst *>(rInst.pData)[ i ].nFlags & nFlag) ==
188 (reinterpret_cast<RscFlagInst *>(pDef)[ i ].nFlags & nFlag) )
190 return true;
195 return false;
198 bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
200 if( pDef )
202 sal_uInt32 Flag = 0, nIndex = 0;
204 Flag = 1;
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) )
212 return false;
214 Flag <<= 1;
215 if( !Flag )
216 Flag = 1;
219 else
220 return false;
222 return true;
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 )
235 return true;
236 else
237 return false;
239 return true;
242 void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput,
243 RscTypCont *, sal_uInt32, const char * )
245 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
246 bool bComma = false;
248 Flag = 1;
249 for( i = 0; i < nEntries; i++ )
251 nIndex = i / (sizeof( sal_uInt32 ) * 8);
252 if( !( reinterpret_cast<RscFlagInst *>(rInst.pData)[ nIndex ].nDfltFlags & Flag) )
254 if( bComma )
255 fprintf( fOutput, ", " );
257 if( reinterpret_cast<RscFlagInst *>(rInst.pData)[ nIndex ].nFlags & Flag )
258 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
259 else
261 fprintf( fOutput, "not " );
262 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
264 bComma = true;
266 Flag <<= 1;
267 if( !Flag )
268 Flag = 1;
272 ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
273 RscTypCont *, sal_uInt32, bool )
275 sal_Int32 lVal = 0;
276 sal_uInt32 i = 0, Flag = 0, nIndex = 0;
278 Flag = 1;
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;
286 Flag <<= 1;
287 if( !Flag )
288 Flag = 1;
291 aMem.Put( (sal_Int32)lVal );
292 return ERR_OK;
295 RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass,
296 Atom nConstantId )
297 : RscTop ( nId, nTypeId )
299 pRefClass = pClass;
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" );
313 else
314 fprintf( fOutput, "FALSE" );
317 RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt,
318 bool bOwnClass )
320 RSCINST aTmpI, aDfltI;
322 if( pInst )
324 aTmpI.pClass = pRefClass;
325 aTmpI.pData = pInst->pData;
328 if( !bOwnClass && rDflt.IsInst() )
330 bOwnClass = rDflt.pClass->InHierarchy( this );
331 if( bOwnClass )
333 aDfltI.pClass = pRefClass;
334 aDfltI.pData = rDflt.pData;
338 if( pInst )
339 aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI,
340 bOwnClass, nConstId );
341 else
342 aTmpI = pRefClass->CreateClient( NULL, aDfltI,
343 bOwnClass, nConstId );
344 aTmpI.pClass = this;
346 return aTmpI;
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */