bump product version to 5.0.4.1
[LibreOffice.git] / rsc / source / res / rscrange.cxx
blob7820762502973b2556f27bd1bb7bba2bd9c33bdb
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 <rscrange.hxx>
27 RscRange::RscRange( Atom nId, sal_uInt32 nTypeId )
28 : RscTop( nId, nTypeId )
30 nMin = nMax = 0;
31 nSize = ALIGNED_SIZE( sizeof( RscRangeInst ) );
34 RSCCLASS_TYPE RscRange::GetClassType() const
36 return RSCCLASS_NUMBER;
39 ERRTYPE RscRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum )
41 if( nMinimum > nMaximum )
43 nMin = nMaximum;
44 nMax = nMinimum;
46 else
48 nMax = nMaximum;
49 nMin = nMinimum;
52 return ERR_OK;
55 bool RscRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
57 if( pDef )
59 if( reinterpret_cast<RscRangeInst*>(rInst.pData)->nValue ==
60 reinterpret_cast<RscRangeInst*>(pDef)->nValue )
62 return true;
66 return false;
69 ERRTYPE RscRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
71 if( nMax < nValue || nMin > nValue )
72 return ERR_RSCRANGE_OUTDEFSET;
74 reinterpret_cast<RscRangeInst *>(rInst.pData)->nValue = (sal_uInt16)( nValue - nMin );
75 reinterpret_cast<RscRangeInst *>(rInst.pData)->bDflt = false;
76 return ERR_OK;
79 ERRTYPE RscRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN )
81 *pN = reinterpret_cast<RscRangeInst *>(rInst.pData)->nValue + nMin;
82 return ERR_OK;
85 RSCINST RscRange::Create( RSCINST * pInst, const RSCINST & rDflt,
86 bool bOwnClass )
88 RSCINST aInst;
90 if( !pInst )
92 aInst.pClass = this;
93 aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( sizeof( RscRangeInst ) ));
95 else
96 aInst = *pInst;
98 if( !bOwnClass && rDflt.IsInst() )
99 bOwnClass = rDflt.pClass->InHierarchy( this );
101 if( bOwnClass )
102 memmove( aInst.pData, rDflt.pData, sizeof( RscRangeInst ) );
103 else
105 if( 0L >= nMin && 0L <= nMax )
106 reinterpret_cast<RscRangeInst *>(aInst.pData)->nValue = (sal_uInt16)(0L - nMin);
107 else
108 reinterpret_cast<RscRangeInst *>(aInst.pData)->nValue = 0;
110 reinterpret_cast<RscRangeInst *>(aInst.pData)->bDflt = true;
113 return aInst;
116 void RscRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
117 RscTypCont *, sal_uInt32, const char * )
119 fprintf( fOutput, "%ld", long( reinterpret_cast<RscRangeInst *>(rInst.pData)->nValue + nMin ) );
122 ERRTYPE RscRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
123 RscTypCont *, sal_uInt32, bool )
125 if( nMin >= 0 )
127 sal_uInt16 n;
128 n = (sal_uInt16)(reinterpret_cast<RscRangeInst *>(rInst.pData)->nValue + nMin);
129 aMem.Put( n );
131 else
133 sal_Int16 n;
134 n = (sal_Int16)(reinterpret_cast<RscRangeInst *>(rInst.pData)->nValue + nMin);
135 aMem.Put( n );
138 return ERR_OK;
141 RscLongRange::RscLongRange( Atom nId, sal_uInt32 nTypeId )
142 : RscTop( nId, nTypeId )
144 nMin = nMax = 0;
145 nSize = ALIGNED_SIZE( sizeof( RscLongRangeInst ) );
148 RSCCLASS_TYPE RscLongRange::GetClassType() const
150 return RSCCLASS_NUMBER;
153 ERRTYPE RscLongRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum )
155 if( nMinimum > nMaximum )
157 nMin = nMaximum;
158 nMax = nMinimum;
160 else
162 nMax = nMaximum;
163 nMin = nMinimum;
166 return ERR_OK;
169 bool RscLongRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
171 if( pDef )
172 return 0 == memcmp( &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue,
173 &reinterpret_cast<RscLongRangeInst*>(pDef)->nValue,
174 sizeof( sal_Int32 ) );
176 return false;
179 ERRTYPE RscLongRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
181 if( nMax < nValue || nMin > nValue )
182 return ERR_RSCRANGE_OUTDEFSET;
184 void * pData = &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue;
185 memcpy( pData, &nValue, sizeof( sal_Int32 ) );
186 reinterpret_cast<RscLongRangeInst *>(rInst.pData)->bDflt = false;
187 return ERR_OK;
190 ERRTYPE RscLongRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN )
192 memmove( pN, &reinterpret_cast<RscLongRangeInst*>(rInst.pData)->nValue,
193 sizeof( sal_Int32 ) );
194 return ERR_OK;
197 RSCINST RscLongRange::Create( RSCINST * pInst, const RSCINST & rDflt,
198 bool bOwnClass )
200 RSCINST aInst;
202 if( !pInst )
204 aInst.pClass = this;
205 aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( sizeof( RscLongRangeInst ) ));
207 else
208 aInst = *pInst;
210 if( !bOwnClass && rDflt.IsInst() )
211 bOwnClass = rDflt.pClass->InHierarchy( this );
213 if( bOwnClass )
214 memmove( aInst.pData, rDflt.pData, sizeof( RscLongRangeInst ) );
215 else
217 sal_Int32 lDflt;
218 if( 0L >= nMin && 0L <= nMax )
219 lDflt = 0;
220 else
221 lDflt = nMin;
223 void * pData = &reinterpret_cast<RscLongRangeInst*>(aInst.pData)->nValue;
224 memcpy( pData, &lDflt, sizeof( sal_Int32 ) );
225 reinterpret_cast<RscLongRangeInst *>(aInst.pData)->bDflt = true;
228 return aInst;
231 void RscLongRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
232 RscTypCont *, sal_uInt32, const char * )
234 sal_Int32 lVal;
235 GetNumber( rInst, &lVal );
236 fprintf( fOutput, "%d", static_cast<int>(lVal) );
239 ERRTYPE RscLongRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
240 RscTypCont *, sal_uInt32, bool )
242 sal_Int32 lVal;
244 GetNumber( rInst, &lVal );
245 aMem.Put( (sal_Int32)lVal );
247 return ERR_OK;
250 RscLongEnumRange::RscLongEnumRange( Atom nId, sal_uInt32 nTypeId )
251 : RscLongRange( nId, nTypeId )
255 ERRTYPE RscLongEnumRange::SetConst( const RSCINST & rInst, Atom /*nConst*/,
256 sal_Int32 nValue )
258 return SetNumber( rInst, nValue );
261 RscIdRange::RscIdRange( Atom nId, sal_uInt32 nTypeId )
262 : RscTop( nId, nTypeId )
264 nSize = ALIGNED_SIZE( sizeof( RscId ) );
265 nMin = nMax = 0;
268 RSCCLASS_TYPE RscIdRange::GetClassType() const
270 return RSCCLASS_NUMBER;
273 RSCINST RscIdRange::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
275 RSCINST aInst;
276 RscId * pClassData;
278 if( !pInst )
280 aInst.pClass = this;
281 aInst.pData = static_cast<CLASS_DATA>(rtl_allocateMemory( sizeof( RscId ) ));
283 else
284 aInst = *pInst;
287 if( !bOwnClass && rDflt.IsInst() )
288 bOwnClass = rDflt.pClass->InHierarchy( this );
290 pClassData = reinterpret_cast<RscId *>(aInst.pData);
292 pClassData->Create();
294 if( bOwnClass )
295 *pClassData = *reinterpret_cast<RscId *>(rDflt.pData);
296 else
298 *pClassData = RscId();
299 if( 0 >= nMin && 0 <= nMax )
300 *pClassData = RscId( (sal_Int32)0 );
301 else
302 *pClassData = RscId( nMin );
304 //cUnused wird fuer Defaultkennung verwendet
305 reinterpret_cast<RscId *>(aInst.pData)->aExp.cUnused = true;
308 return aInst;
311 void RscIdRange :: Destroy( const RSCINST & rInst )
313 reinterpret_cast<RscId *>(rInst.pData)->Destroy();
316 bool RscIdRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
318 if( pDef )
320 if( reinterpret_cast<RscId*>(rInst.pData)->aExp.IsNumber() &&
321 reinterpret_cast<RscId*>(pDef)->aExp.IsNumber() )
323 if( reinterpret_cast<RscId*>(rInst.pData)->GetNumber() ==
324 reinterpret_cast<RscId*>(pDef)->GetNumber() )
326 return true;
331 return false;
334 ERRTYPE RscIdRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
336 if( nMax < nValue || nMin > nValue )
337 return ERR_RSCRANGE_OUTDEFSET;
339 *reinterpret_cast<RscId *>(rInst.pData) = RscId( nValue );
340 reinterpret_cast<RscId *>(rInst.pData)->aExp.cUnused = false;
341 return ERR_OK;
344 ERRTYPE RscIdRange::GetNumber( const RSCINST & rInst, sal_Int32 * plValue )
346 *plValue = reinterpret_cast<RscId *>(rInst.pData)->GetNumber();
347 return ERR_OK;
350 ERRTYPE RscIdRange::SetRef( const RSCINST & rInst, const RscId & rRscId )
352 ERRTYPE aError;
353 if( rRscId.IsId() )
355 aError = SetNumber( rInst, rRscId );
356 if( aError.IsOk() )
358 *reinterpret_cast<RscId *>(rInst.pData) = rRscId;
359 reinterpret_cast<RscId *>(rInst.pData)->aExp.cUnused = false;
362 else
363 aError = ERR_RSCRANGE_OUTDEFSET;
365 return aError;
368 ERRTYPE RscIdRange::GetRef( const RSCINST & rInst, RscId * pRscId )
370 *pRscId = *reinterpret_cast<RscId *>(rInst.pData);
372 return ERR_OK;
375 void RscIdRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
376 RscTypCont *, sal_uInt32, const char * )
378 fprintf( fOutput, "%s", reinterpret_cast<RscId *>(rInst.pData)->GetName().getStr() );
381 ERRTYPE RscIdRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
382 RscTypCont *, sal_uInt32, bool )
384 sal_Int32 lVal = reinterpret_cast<RscId*>(rInst.pData)->GetNumber();
386 aMem.Put( (sal_Int32)lVal );
388 return ERR_OK;
391 bool RscIdRange::IsConsistent( const RSCINST & rInst )
393 long nValue = reinterpret_cast<RscId *>(rInst.pData)->GetNumber();
395 return (nMax >= nValue) && (nMin <= nValue);
399 RscBool::RscBool( Atom nId, sal_uInt32 nTypeId )
400 : RscRange( nId, nTypeId )
402 RscRange::SetRange( 0, 1 );
405 RSCCLASS_TYPE RscBool::GetClassType() const
407 return RSCCLASS_BOOL;
410 void RscBool::WriteSrc( const RSCINST & rInst, FILE * fOutput,
411 RscTypCont *, sal_uInt32, const char * )
413 sal_Int32 l;
415 GetNumber( rInst, &l );
416 if( l )
417 fprintf( fOutput, "TRUE" );
418 else
419 fprintf( fOutput, "FALSE" );
422 RscBreakRange :: RscBreakRange( Atom nId, sal_uInt32 nTypeId )
423 : RscRange( nId, nTypeId )
425 nOutRange = 0xFFFFFFFF;
428 ERRTYPE RscBreakRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
430 if( nValue == nOutRange )
431 return ERR_RSCRANGE_OUTDEFSET;
432 else
433 return RscRange::SetNumber( rInst, nValue );
436 RSCINST RscBreakRange::Create( RSCINST * pInst, const RSCINST & rDflt,
437 bool bOwnClass )
439 RSCINST aInst;
440 sal_Int32 l;
442 aInst = RscRange::Create( pInst, rDflt, bOwnClass );
444 GetNumber( aInst, &l );
445 if( l == nOutRange )
446 reinterpret_cast<RscRangeInst *>(aInst.pData)->nValue++;
448 return aInst;
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */