Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <stdlib.h>
22 : #include <stdio.h>
23 : #include <string.h>
24 :
25 : #include <rscrange.hxx>
26 :
27 6260 : RscRange::RscRange( Atom nId, sal_uInt32 nTypeId )
28 6260 : : RscTop( nId, nTypeId )
29 : {
30 6260 : nMin = nMax = 0;
31 6260 : nSize = ALIGNED_SIZE( sizeof( RscRangeInst ) );
32 6260 : }
33 :
34 0 : RSCCLASS_TYPE RscRange::GetClassType() const
35 : {
36 0 : return RSCCLASS_NUMBER;
37 : }
38 :
39 6260 : ERRTYPE RscRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum )
40 : {
41 6260 : if( nMinimum > nMaximum )
42 : {
43 0 : nMin = nMaximum;
44 0 : nMax = nMinimum;
45 : }
46 : else
47 : {
48 6260 : nMax = nMaximum;
49 6260 : nMin = nMinimum;
50 : };
51 :
52 6260 : return ERR_OK;
53 : }
54 :
55 2294 : bool RscRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
56 : {
57 2294 : if( pDef )
58 : {
59 2294 : if( ((RscRangeInst*)rInst.pData)->nValue ==
60 : ((RscRangeInst*)pDef)->nValue )
61 : {
62 469 : return true;
63 : }
64 : }
65 :
66 1825 : return false;
67 : }
68 :
69 10181 : ERRTYPE RscRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
70 : {
71 10181 : if( nMax < nValue || nMin > nValue )
72 0 : return ERR_RSCRANGE_OUTDEFSET;
73 :
74 10181 : ((RscRangeInst *)rInst.pData)->nValue = (sal_uInt16)( nValue - nMin );
75 10181 : ((RscRangeInst *)rInst.pData)->bDflt = false;
76 10181 : return ERR_OK;
77 : }
78 :
79 4365 : ERRTYPE RscRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN )
80 : {
81 4365 : *pN = ((RscRangeInst *)rInst.pData)->nValue + nMin;
82 4365 : return ERR_OK;
83 : }
84 :
85 70373 : RSCINST RscRange::Create( RSCINST * pInst, const RSCINST & rDflt,
86 : bool bOwnClass )
87 : {
88 70373 : RSCINST aInst;
89 :
90 70373 : if( !pInst )
91 : {
92 10709 : aInst.pClass = this;
93 10709 : aInst.pData = (CLASS_DATA)rtl_allocateMemory( sizeof( RscRangeInst ) );
94 : }
95 : else
96 59664 : aInst = *pInst;
97 :
98 70373 : if( !bOwnClass && rDflt.IsInst() )
99 42 : bOwnClass = rDflt.pClass->InHierarchy( this );
100 :
101 70373 : if( bOwnClass )
102 42 : memmove( aInst.pData, rDflt.pData, sizeof( RscRangeInst ) );
103 : else
104 : {
105 70331 : if( 0L >= nMin && 0L <= nMax )
106 70331 : ((RscRangeInst *)aInst.pData)->nValue = (sal_uInt16)(0L - nMin);
107 : else
108 0 : ((RscRangeInst *)aInst.pData)->nValue = 0;
109 :
110 70331 : ((RscRangeInst *)aInst.pData)->bDflt = true;
111 : }
112 :
113 70373 : return aInst;
114 : }
115 :
116 2901 : void RscRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
117 : RscTypCont *, sal_uInt32, const char * )
118 : {
119 2901 : fprintf( fOutput, "%ld", long( ((RscRangeInst *)rInst.pData)->nValue + nMin ) );
120 2901 : }
121 :
122 103945 : ERRTYPE RscRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
123 : RscTypCont *, sal_uInt32, bool )
124 : {
125 103945 : if( nMin >= 0 )
126 : {
127 : sal_uInt16 n;
128 4386 : n = (sal_uInt16)(((RscRangeInst *)rInst.pData)->nValue + nMin);
129 4386 : aMem.Put( n );
130 : }
131 : else
132 : {
133 : sal_Int16 n;
134 99559 : n = (sal_Int16)(((RscRangeInst *)rInst.pData)->nValue + nMin);
135 99559 : aMem.Put( n );
136 : }
137 :
138 103945 : return ERR_OK;
139 : }
140 :
141 1252 : RscLongRange::RscLongRange( Atom nId, sal_uInt32 nTypeId )
142 1252 : : RscTop( nId, nTypeId )
143 : {
144 1252 : nMin = nMax = 0;
145 1252 : nSize = ALIGNED_SIZE( sizeof( RscLongRangeInst ) );
146 1252 : }
147 :
148 0 : RSCCLASS_TYPE RscLongRange::GetClassType() const
149 : {
150 0 : return RSCCLASS_NUMBER;
151 : }
152 :
153 1252 : ERRTYPE RscLongRange::SetRange( sal_Int32 nMinimum, sal_Int32 nMaximum )
154 : {
155 1252 : if( nMinimum > nMaximum )
156 : {
157 0 : nMin = nMaximum;
158 0 : nMax = nMinimum;
159 : }
160 : else
161 : {
162 1252 : nMax = nMaximum;
163 1252 : nMin = nMinimum;
164 : };
165 :
166 1252 : return ERR_OK;
167 : }
168 :
169 1183 : bool RscLongRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
170 : {
171 1183 : if( pDef )
172 : return 0 == memcmp( &((RscLongRangeInst*)rInst.pData)->nValue,
173 : &((RscLongRangeInst*)pDef)->nValue,
174 1183 : sizeof( sal_Int32 ) );
175 :
176 0 : return false;
177 : }
178 :
179 51212 : ERRTYPE RscLongRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
180 : {
181 51212 : if( nMax < nValue || nMin > nValue )
182 0 : return( ERR_RSCRANGE_OUTDEFSET );
183 :
184 51212 : void * pData = &((RscLongRangeInst*)rInst.pData)->nValue;
185 51212 : memcpy( pData, &nValue, sizeof( sal_Int32 ) );
186 51212 : ((RscLongRangeInst *)rInst.pData)->bDflt = false;
187 51212 : return ERR_OK;
188 : }
189 :
190 52528 : ERRTYPE RscLongRange::GetNumber( const RSCINST & rInst, sal_Int32 * pN )
191 : {
192 : memmove( pN, &((RscLongRangeInst*)rInst.pData)->nValue,
193 52528 : sizeof( sal_Int32 ) );
194 52528 : return ERR_OK;
195 : }
196 :
197 70478 : RSCINST RscLongRange::Create( RSCINST * pInst, const RSCINST & rDflt,
198 : bool bOwnClass )
199 : {
200 70478 : RSCINST aInst;
201 :
202 70478 : if( !pInst )
203 : {
204 51 : aInst.pClass = this;
205 51 : aInst.pData = (CLASS_DATA) rtl_allocateMemory( sizeof( RscLongRangeInst ) );
206 : }
207 : else
208 70427 : aInst = *pInst;
209 :
210 70478 : if( !bOwnClass && rDflt.IsInst() )
211 172 : bOwnClass = rDflt.pClass->InHierarchy( this );
212 :
213 70478 : if( bOwnClass )
214 172 : memmove( aInst.pData, rDflt.pData, sizeof( RscLongRangeInst ) );
215 : else
216 : {
217 : sal_Int32 lDflt;
218 70306 : if( 0L >= nMin && 0L <= nMax )
219 70306 : lDflt = 0;
220 : else
221 0 : lDflt = nMin;
222 :
223 70306 : void * pData = &((RscLongRangeInst*)aInst.pData)->nValue;
224 70306 : memcpy( pData, &lDflt, sizeof( sal_Int32 ) );
225 70306 : ((RscLongRangeInst *)aInst.pData)->bDflt = true;
226 : }
227 :
228 70478 : return aInst;
229 : }
230 :
231 25280 : void RscLongRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
232 : RscTypCont *, sal_uInt32, const char * )
233 : {
234 : sal_Int32 lVal;
235 25280 : GetNumber( rInst, &lVal );
236 25280 : fprintf( fOutput, "%d", static_cast<int>(lVal) );
237 25280 : }
238 :
239 2824 : ERRTYPE RscLongRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
240 : RscTypCont *, sal_uInt32, bool )
241 : {
242 : sal_Int32 lVal;
243 :
244 2824 : GetNumber( rInst, &lVal );
245 2824 : aMem.Put( (sal_Int32)lVal );
246 :
247 2824 : return ERR_OK;
248 : }
249 :
250 626 : RscLongEnumRange::RscLongEnumRange( Atom nId, sal_uInt32 nTypeId )
251 626 : : RscLongRange( nId, nTypeId )
252 : {
253 626 : }
254 :
255 51 : ERRTYPE RscLongEnumRange::SetConst( const RSCINST & rInst, Atom /*nConst*/,
256 : sal_Int32 nValue )
257 : {
258 51 : return SetNumber( rInst, nValue );
259 : }
260 :
261 1878 : RscIdRange::RscIdRange( Atom nId, sal_uInt32 nTypeId )
262 1878 : : RscTop( nId, nTypeId )
263 : {
264 1878 : nSize = ALIGNED_SIZE( sizeof( RscId ) );
265 1878 : nMin = nMax = 0;
266 1878 : }
267 :
268 0 : RSCCLASS_TYPE RscIdRange::GetClassType() const
269 : {
270 0 : return RSCCLASS_NUMBER;
271 : }
272 :
273 14406 : RSCINST RscIdRange::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
274 : {
275 14406 : RSCINST aInst;
276 : RscId * pClassData;
277 :
278 14406 : if( !pInst )
279 : {
280 909 : aInst.pClass = this;
281 909 : aInst.pData = (CLASS_DATA)rtl_allocateMemory( sizeof( RscId ) );
282 : }
283 : else
284 13497 : aInst = *pInst;
285 :
286 :
287 14406 : if( !bOwnClass && rDflt.IsInst() )
288 0 : bOwnClass = rDflt.pClass->InHierarchy( this );
289 :
290 14406 : pClassData = (RscId *)aInst.pData;
291 :
292 14406 : pClassData->Create();
293 :
294 14406 : if( bOwnClass )
295 0 : *pClassData = *(RscId *)rDflt.pData;
296 : else
297 : {
298 14406 : *pClassData = RscId();
299 14406 : if( 0 >= nMin && 0 <= nMax )
300 5571 : *pClassData = RscId( (sal_Int32)0 );
301 : else
302 8835 : *pClassData = RscId( nMin );
303 :
304 : //cUnused wird fuer Defaultkennung verwendet
305 14406 : ((RscId *)aInst.pData)->aExp.cUnused = true;
306 : }
307 :
308 14406 : return aInst;
309 : }
310 :
311 14406 : void RscIdRange :: Destroy( const RSCINST & rInst )
312 : {
313 14406 : ((RscId *)rInst.pData)->Destroy();
314 14406 : }
315 :
316 4779 : bool RscIdRange::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
317 : {
318 4779 : if( pDef )
319 : {
320 9558 : if( ((RscId*)rInst.pData)->aExp.IsNumber() &&
321 4779 : ((RscId*)pDef)->aExp.IsNumber() )
322 : {
323 9558 : if( ((RscId*)rInst.pData)->GetNumber() ==
324 4779 : ((RscId*)pDef)->GetNumber() )
325 : {
326 125 : return true;
327 : }
328 : }
329 : }
330 :
331 4654 : return false;
332 : }
333 :
334 10140 : ERRTYPE RscIdRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
335 : {
336 10140 : if( nMax < nValue || nMin > nValue )
337 0 : return ERR_RSCRANGE_OUTDEFSET;
338 :
339 10140 : *(RscId *)rInst.pData = RscId( nValue );
340 10140 : ((RscId *)rInst.pData)->aExp.cUnused = false;
341 10140 : return ERR_OK;
342 : }
343 :
344 0 : ERRTYPE RscIdRange::GetNumber( const RSCINST & rInst, sal_Int32 * plValue )
345 : {
346 0 : *plValue = ((RscId *)rInst.pData)->GetNumber();
347 0 : return ERR_OK;
348 : }
349 :
350 10140 : ERRTYPE RscIdRange::SetRef( const RSCINST & rInst, const RscId & rRscId )
351 : {
352 10140 : ERRTYPE aError;
353 10140 : if( rRscId.IsId() )
354 : {
355 10140 : aError = SetNumber( rInst, rRscId );
356 10140 : if( aError.IsOk() )
357 : {
358 10140 : *(RscId *)rInst.pData = rRscId;
359 10140 : ((RscId *)rInst.pData)->aExp.cUnused = false;
360 : }
361 : }
362 : else
363 0 : aError = ERR_RSCRANGE_OUTDEFSET;
364 :
365 10140 : return aError;
366 : }
367 :
368 703 : ERRTYPE RscIdRange::GetRef( const RSCINST & rInst, RscId * pRscId )
369 : {
370 703 : *pRscId = *(RscId *)rInst.pData;
371 :
372 703 : return ERR_OK;
373 : }
374 :
375 5357 : void RscIdRange::WriteSrc( const RSCINST & rInst, FILE * fOutput,
376 : RscTypCont *, sal_uInt32, const char * )
377 : {
378 5357 : fprintf( fOutput, "%s", ((RscId *)rInst.pData)->GetName().getStr() );
379 5357 : }
380 :
381 4654 : ERRTYPE RscIdRange::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
382 : RscTypCont *, sal_uInt32, bool )
383 : {
384 4654 : sal_Int32 lVal = ((RscId*)rInst.pData)->GetNumber();
385 :
386 4654 : aMem.Put( (sal_Int32)lVal );
387 :
388 4654 : return ERR_OK;
389 : }
390 :
391 0 : bool RscIdRange::IsConsistent( const RSCINST & rInst )
392 : {
393 0 : long nValue = ((RscId *)rInst.pData)->GetNumber();
394 :
395 0 : return (nMax >= nValue) && (nMin <= nValue);
396 :
397 : }
398 :
399 626 : RscBool::RscBool( Atom nId, sal_uInt32 nTypeId )
400 626 : : RscRange( nId, nTypeId )
401 : {
402 626 : RscRange::SetRange( 0, 1 );
403 626 : }
404 :
405 0 : RSCCLASS_TYPE RscBool::GetClassType() const
406 : {
407 0 : return RSCCLASS_BOOL;
408 : }
409 :
410 727 : void RscBool::WriteSrc( const RSCINST & rInst, FILE * fOutput,
411 : RscTypCont *, sal_uInt32, const char * )
412 : {
413 : sal_Int32 l;
414 :
415 727 : GetNumber( rInst, &l );
416 727 : if( l )
417 727 : fprintf( fOutput, "TRUE" );
418 : else
419 0 : fprintf( fOutput, "FALSE" );
420 727 : }
421 :
422 626 : RscBreakRange :: RscBreakRange( Atom nId, sal_uInt32 nTypeId )
423 626 : : RscRange( nId, nTypeId )
424 : {
425 626 : nOutRange = 0xFFFFFFFF;
426 626 : }
427 :
428 0 : ERRTYPE RscBreakRange::SetNumber( const RSCINST & rInst, sal_Int32 nValue )
429 : {
430 0 : if( nValue == nOutRange )
431 0 : return ERR_RSCRANGE_OUTDEFSET;
432 : else
433 0 : return RscRange::SetNumber( rInst, nValue );
434 : }
435 :
436 0 : RSCINST RscBreakRange::Create( RSCINST * pInst, const RSCINST & rDflt,
437 : bool bOwnClass )
438 : {
439 0 : RSCINST aInst;
440 : sal_Int32 l;
441 :
442 0 : aInst = RscRange::Create( pInst, rDflt, bOwnClass );
443 :
444 0 : GetNumber( aInst, &l );
445 0 : if( l == nOutRange )
446 0 : ((RscRangeInst *)aInst.pData)->nValue++;
447 :
448 0 : return aInst;
449 : }
450 :
451 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|