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 <rscrange.hxx>
27 RscRange::RscRange( Atom nId
, sal_uInt32 nTypeId
)
28 : RscTop( nId
, nTypeId
)
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
)
55 bool RscRange::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
59 if( reinterpret_cast<RscRangeInst
*>(rInst
.pData
)->nValue
==
60 reinterpret_cast<RscRangeInst
*>(pDef
)->nValue
)
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;
79 ERRTYPE
RscRange::GetNumber( const RSCINST
& rInst
, sal_Int32
* pN
)
81 *pN
= reinterpret_cast<RscRangeInst
*>(rInst
.pData
)->nValue
+ nMin
;
85 RSCINST
RscRange::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
93 aInst
.pData
= static_cast<CLASS_DATA
>(rtl_allocateMemory( sizeof( RscRangeInst
) ));
98 if( !bOwnClass
&& rDflt
.IsInst() )
99 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
102 memmove( aInst
.pData
, rDflt
.pData
, sizeof( RscRangeInst
) );
105 if( 0L >= nMin
&& 0L <= nMax
)
106 reinterpret_cast<RscRangeInst
*>(aInst
.pData
)->nValue
= (sal_uInt16
)(0L - nMin
);
108 reinterpret_cast<RscRangeInst
*>(aInst
.pData
)->nValue
= 0;
110 reinterpret_cast<RscRangeInst
*>(aInst
.pData
)->bDflt
= true;
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 )
128 n
= (sal_uInt16
)(reinterpret_cast<RscRangeInst
*>(rInst
.pData
)->nValue
+ nMin
);
134 n
= (sal_Int16
)(reinterpret_cast<RscRangeInst
*>(rInst
.pData
)->nValue
+ nMin
);
141 RscLongRange::RscLongRange( Atom nId
, sal_uInt32 nTypeId
)
142 : RscTop( nId
, nTypeId
)
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
)
169 bool RscLongRange::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
172 return 0 == memcmp( &reinterpret_cast<RscLongRangeInst
*>(rInst
.pData
)->nValue
,
173 &reinterpret_cast<RscLongRangeInst
*>(pDef
)->nValue
,
174 sizeof( sal_Int32
) );
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;
190 ERRTYPE
RscLongRange::GetNumber( const RSCINST
& rInst
, sal_Int32
* pN
)
192 memmove( pN
, &reinterpret_cast<RscLongRangeInst
*>(rInst
.pData
)->nValue
,
193 sizeof( sal_Int32
) );
197 RSCINST
RscLongRange::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
205 aInst
.pData
= static_cast<CLASS_DATA
>(rtl_allocateMemory( sizeof( RscLongRangeInst
) ));
210 if( !bOwnClass
&& rDflt
.IsInst() )
211 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
214 memmove( aInst
.pData
, rDflt
.pData
, sizeof( RscLongRangeInst
) );
218 if( 0L >= nMin
&& 0L <= nMax
)
223 void * pData
= &reinterpret_cast<RscLongRangeInst
*>(aInst
.pData
)->nValue
;
224 memcpy( pData
, &lDflt
, sizeof( sal_Int32
) );
225 reinterpret_cast<RscLongRangeInst
*>(aInst
.pData
)->bDflt
= true;
231 void RscLongRange::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
232 RscTypCont
*, sal_uInt32
, const char * )
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 )
244 GetNumber( rInst
, &lVal
);
245 aMem
.Put( (sal_Int32
)lVal
);
250 RscLongEnumRange::RscLongEnumRange( Atom nId
, sal_uInt32 nTypeId
)
251 : RscLongRange( nId
, nTypeId
)
255 ERRTYPE
RscLongEnumRange::SetConst( const RSCINST
& rInst
, Atom
/*nConst*/,
258 return SetNumber( rInst
, nValue
);
261 RscIdRange::RscIdRange( Atom nId
, sal_uInt32 nTypeId
)
262 : RscTop( nId
, nTypeId
)
264 nSize
= ALIGNED_SIZE( sizeof( RscId
) );
268 RSCCLASS_TYPE
RscIdRange::GetClassType() const
270 return RSCCLASS_NUMBER
;
273 RSCINST
RscIdRange::Create( RSCINST
* pInst
, const RSCINST
& rDflt
, bool bOwnClass
)
281 aInst
.pData
= static_cast<CLASS_DATA
>(rtl_allocateMemory( sizeof( RscId
) ));
287 if( !bOwnClass
&& rDflt
.IsInst() )
288 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
290 pClassData
= reinterpret_cast<RscId
*>(aInst
.pData
);
292 pClassData
->Create();
295 *pClassData
= *reinterpret_cast<RscId
*>(rDflt
.pData
);
298 *pClassData
= RscId();
299 if( 0 >= nMin
&& 0 <= nMax
)
300 *pClassData
= RscId( (sal_Int32
)0 );
302 *pClassData
= RscId( nMin
);
304 //cUnused wird fuer Defaultkennung verwendet
305 reinterpret_cast<RscId
*>(aInst
.pData
)->aExp
.cUnused
= true;
311 void RscIdRange :: Destroy( const RSCINST
& rInst
)
313 reinterpret_cast<RscId
*>(rInst
.pData
)->Destroy();
316 bool RscIdRange::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA 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() )
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;
344 ERRTYPE
RscIdRange::GetNumber( const RSCINST
& rInst
, sal_Int32
* plValue
)
346 *plValue
= reinterpret_cast<RscId
*>(rInst
.pData
)->GetNumber();
350 ERRTYPE
RscIdRange::SetRef( const RSCINST
& rInst
, const RscId
& rRscId
)
355 aError
= SetNumber( rInst
, rRscId
);
358 *reinterpret_cast<RscId
*>(rInst
.pData
) = rRscId
;
359 reinterpret_cast<RscId
*>(rInst
.pData
)->aExp
.cUnused
= false;
363 aError
= ERR_RSCRANGE_OUTDEFSET
;
368 ERRTYPE
RscIdRange::GetRef( const RSCINST
& rInst
, RscId
* pRscId
)
370 *pRscId
= *reinterpret_cast<RscId
*>(rInst
.pData
);
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
);
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 * )
415 GetNumber( rInst
, &l
);
417 fprintf( fOutput
, "TRUE" );
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
;
433 return RscRange::SetNumber( rInst
, nValue
);
436 RSCINST
RscBreakRange::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
442 aInst
= RscRange::Create( pInst
, rDflt
, bOwnClass
);
444 GetNumber( aInst
, &l
);
446 reinterpret_cast<RscRangeInst
*>(aInst
.pData
)->nValue
++;
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */