bump product version to 4.1.6.2
[LibreOffice.git] / svl / source / items / cintitem.cxx
blob430bdb3c148f4c10f63a70c221bda061ca9cade7
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 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <tools/stream.hxx>
22 #include <svl/cintitem.hxx>
24 //============================================================================
26 // class CntByteItem
28 //============================================================================
30 DBG_NAME(CntByteItem)
32 //============================================================================
33 TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem);
35 //============================================================================
36 // virtual
37 int CntByteItem::operator ==(const SfxPoolItem & rItem) const
39 DBG_CHKTHIS(CntByteItem, 0);
40 DBG_ASSERT(rItem.ISA(CntByteItem),
41 "CntByteItem::operator ==(): Bad type");
42 return m_nValue == (static_cast< const CntByteItem * >(&rItem))->m_nValue;
45 //============================================================================
46 // virtual
47 int CntByteItem::Compare(const SfxPoolItem & rWith) const
49 DBG_CHKTHIS(CntByteItem, 0);
50 DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type");
51 return (static_cast< const CntByteItem * >(&rWith))->m_nValue < m_nValue ?
52 -1 :
53 (static_cast< const CntByteItem * >(&rWith))->m_nValue
54 == m_nValue ?
55 0 : 1;
58 //============================================================================
59 // virtual
60 SfxItemPresentation CntByteItem::GetPresentation(SfxItemPresentation,
61 SfxMapUnit, SfxMapUnit,
62 OUString & rText,
63 const IntlWrapper *) const
65 DBG_CHKTHIS(CntByteItem, 0);
66 rText = OUString::number( m_nValue );
67 return SFX_ITEM_PRESENTATION_NAMELESS;
70 //============================================================================
71 // virtual
72 bool CntByteItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
74 sal_Int8 nValue = m_nValue;
75 rVal <<= nValue;
76 return true;
79 //============================================================================
80 // virtual
81 bool CntByteItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
83 sal_Int8 nValue = sal_Int8();
84 if (rVal >>= nValue)
86 m_nValue = nValue;
87 return true;
90 OSL_FAIL( "CntByteItem::PutValue - Wrong type!" );
91 return false;
94 //============================================================================
95 // virtual
96 SfxPoolItem * CntByteItem::Create(SvStream & rStream, sal_uInt16) const
98 DBG_CHKTHIS(CntByteItem, 0);
99 short nTheValue = 0;
100 rStream >> nTheValue;
101 return new CntByteItem(Which(), sal_uInt8(nTheValue));
104 //============================================================================
105 // virtual
106 SvStream & CntByteItem::Store(SvStream & rStream, sal_uInt16) const
108 DBG_CHKTHIS(CntByteItem, 0);
109 rStream << short(m_nValue);
110 return rStream;
113 //============================================================================
114 // virtual
115 SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const
117 DBG_CHKTHIS(CntByteItem, 0);
118 return new CntByteItem(*this);
121 //============================================================================
122 // virtual
123 sal_uInt8 CntByteItem::GetMin() const
125 DBG_CHKTHIS(CntByteItem, 0);
126 return 0;
129 //============================================================================
130 // virtual
131 sal_uInt8 CntByteItem::GetMax() const
133 DBG_CHKTHIS(CntByteItem, 0);
134 return 255;
137 //============================================================================
138 // virtual
139 SfxFieldUnit CntByteItem::GetUnit() const
141 DBG_CHKTHIS(CntByteItem, 0);
142 return SFX_FUNIT_NONE;
145 //============================================================================
147 // class CntUInt16Item
149 //============================================================================
151 DBG_NAME(CntUInt16Item);
153 //============================================================================
154 TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem);
156 //============================================================================
157 CntUInt16Item::CntUInt16Item(sal_uInt16 which, SvStream & rStream) :
158 SfxPoolItem(which)
160 DBG_CTOR(CntUInt16Item, 0);
161 sal_uInt16 nTheValue = 0;
162 rStream >> nTheValue;
163 m_nValue = nTheValue;
166 //============================================================================
167 // virtual
168 int CntUInt16Item::operator ==(const SfxPoolItem & rItem) const
170 DBG_CHKTHIS(CntUInt16Item, 0);
171 DBG_ASSERT(rItem.ISA(CntUInt16Item),
172 "CntUInt16Item::operator ==(): Bad type");
173 return m_nValue == (static_cast< const CntUInt16Item * >(&rItem))->
174 m_nValue;
177 //============================================================================
178 // virtual
179 int CntUInt16Item::Compare(const SfxPoolItem & rWith) const
181 DBG_CHKTHIS(CntUInt16Item, 0);
182 DBG_ASSERT(rWith.ISA(CntUInt16Item),
183 "CntUInt16Item::Compare(): Bad type");
184 return (static_cast< const CntUInt16Item * >(&rWith))->m_nValue
185 < m_nValue ?
186 -1 :
187 (static_cast< const CntUInt16Item * >(&rWith))->m_nValue
188 == m_nValue ?
189 0 : 1;
192 //============================================================================
193 // virtual
194 SfxItemPresentation CntUInt16Item::GetPresentation(SfxItemPresentation,
195 SfxMapUnit, SfxMapUnit,
196 OUString & rText,
197 const IntlWrapper *)
198 const
200 DBG_CHKTHIS(CntUInt16Item, 0);
201 rText = OUString::number( m_nValue );
202 return SFX_ITEM_PRESENTATION_NAMELESS;
205 //============================================================================
206 // virtual
207 bool CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
209 sal_Int32 nValue = m_nValue;
210 rVal <<= nValue;
211 return true;
214 //============================================================================
215 // virtual
216 bool CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
218 sal_Int32 nValue = 0;
219 if (rVal >>= nValue)
221 DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!");
222 m_nValue = (sal_uInt16)nValue;
223 return true;
226 OSL_FAIL( "CntUInt16Item::PutValue - Wrong type!" );
227 return false;
230 //============================================================================
231 // virtual
232 SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, sal_uInt16) const
234 DBG_CHKTHIS(CntUInt16Item, 0);
235 return new CntUInt16Item(Which(), rStream);
238 //============================================================================
239 // virtual
240 SvStream & CntUInt16Item::Store(SvStream &rStream, sal_uInt16) const
242 DBG_CHKTHIS(CntUInt16Item, 0);
243 rStream << sal_uInt16(m_nValue);
244 return rStream;
247 //============================================================================
248 // virtual
249 SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const
251 DBG_CHKTHIS(CntUInt16Item, 0);
252 return new CntUInt16Item(*this);
255 //============================================================================
256 // virtual
257 sal_uInt16 CntUInt16Item::GetMin() const
259 DBG_CHKTHIS(CntUInt16Item, 0);
260 return 0;
263 //============================================================================
264 // virtual
265 sal_uInt16 CntUInt16Item::GetMax() const
267 DBG_CHKTHIS(CntUInt16Item, 0);
268 return 65535;
271 //============================================================================
272 // virtual
273 SfxFieldUnit CntUInt16Item::GetUnit() const
275 DBG_CHKTHIS(CntUInt16Item, 0);
276 return SFX_FUNIT_NONE;
279 //============================================================================
281 // class CntInt32Item
283 //============================================================================
285 DBG_NAME(CntInt32Item);
287 //============================================================================
288 TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem);
290 //============================================================================
291 CntInt32Item::CntInt32Item(sal_uInt16 which, SvStream & rStream) :
292 SfxPoolItem(which)
294 DBG_CTOR(CntInt32Item, 0);
295 //fdo#39428 SvStream no longer supports operator>>(long&)
296 rStream >> m_nValue;
299 //============================================================================
300 // virtual
301 int CntInt32Item::operator ==(const SfxPoolItem & rItem) const
303 DBG_CHKTHIS(CntInt32Item, 0);
304 DBG_ASSERT(rItem.ISA(CntInt32Item),
305 "CntInt32Item::operator ==(): Bad type");
306 return m_nValue == (static_cast< const CntInt32Item * >(&rItem))->
307 m_nValue;
310 //============================================================================
311 // virtual
312 int CntInt32Item::Compare(const SfxPoolItem & rWith) const
314 DBG_CHKTHIS(CntInt32Item, 0);
315 DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type");
316 return (static_cast< const CntInt32Item * >(&rWith))->m_nValue
317 < m_nValue ?
318 -1 :
319 (static_cast< const CntInt32Item * >(&rWith))->m_nValue
320 == m_nValue ?
321 0 : 1;
324 //============================================================================
325 // virtual
326 SfxItemPresentation CntInt32Item::GetPresentation(SfxItemPresentation,
327 SfxMapUnit, SfxMapUnit,
328 OUString & rText,
329 const IntlWrapper *) const
331 DBG_CHKTHIS(CntInt32Item, 0);
332 rText = OUString::number( m_nValue );
333 return SFX_ITEM_PRESENTATION_NAMELESS;
336 //============================================================================
337 // virtual
338 bool CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
340 sal_Int32 nValue = m_nValue;
341 rVal <<= nValue;
342 return true;
345 //============================================================================
346 // virtual
347 bool CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
349 sal_Int32 nValue = 0;
350 if (rVal >>= nValue)
352 m_nValue = nValue;
353 return true;
356 OSL_FAIL( "CntInt32Item::PutValue - Wrong type!" );
357 return false;
360 //============================================================================
361 // virtual
362 SfxPoolItem * CntInt32Item::Create(SvStream & rStream, sal_uInt16) const
364 DBG_CHKTHIS(CntInt32Item, 0);
365 return new CntInt32Item(Which(), rStream);
368 //============================================================================
369 // virtual
370 SvStream & CntInt32Item::Store(SvStream &rStream, sal_uInt16) const
372 DBG_CHKTHIS(CntInt32Item, 0);
373 //fdo#39428 SvStream no longer supports operator<<(long)
374 rStream << m_nValue;
375 return rStream;
378 //============================================================================
379 // virtual
380 SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const
382 DBG_CHKTHIS(CntInt32Item, 0);
383 return new CntInt32Item(*this);
386 //============================================================================
387 // virtual
388 sal_Int32 CntInt32Item::GetMin() const
390 DBG_CHKTHIS(CntInt32Item, 0);
391 return sal_Int32(0x80000000);
394 //============================================================================
395 // virtual
396 sal_Int32 CntInt32Item::GetMax() const
398 DBG_CHKTHIS(CntInt32Item, 0);
399 return 0x7FFFFFFF;
402 //============================================================================
403 // virtual
404 SfxFieldUnit CntInt32Item::GetUnit() const
406 DBG_CHKTHIS(CntInt32Item, 0);
407 return SFX_FUNIT_NONE;
410 //============================================================================
412 // class CntUInt32Item
414 //============================================================================
416 DBG_NAME(CntUInt32Item);
418 //============================================================================
419 TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem);
421 //============================================================================
422 CntUInt32Item::CntUInt32Item(sal_uInt16 which, SvStream & rStream) :
423 SfxPoolItem(which)
425 DBG_CTOR(CntUInt32Item, 0);
426 sal_uInt32 nTheValue = 0;
427 rStream >> nTheValue;
428 m_nValue = nTheValue;
431 //============================================================================
432 // virtual
433 int CntUInt32Item::operator ==(const SfxPoolItem & rItem) const
435 DBG_CHKTHIS(CntUInt32Item, 0);
436 DBG_ASSERT(rItem.ISA(CntUInt32Item),
437 "CntUInt32Item::operator ==(): Bad type");
438 return m_nValue == (static_cast< const CntUInt32Item * >(&rItem))->
439 m_nValue;
442 //============================================================================
443 // virtual
444 int CntUInt32Item::Compare(const SfxPoolItem & rWith) const
446 DBG_CHKTHIS(CntUInt32Item, 0);
447 DBG_ASSERT(rWith.ISA(CntUInt32Item),
448 "CntUInt32Item::operator ==(): Bad type");
449 return (static_cast< const CntUInt32Item * >(&rWith))->m_nValue
450 < m_nValue ?
451 -1 :
452 (static_cast< const CntUInt32Item * >(&rWith))->m_nValue
453 == m_nValue ?
454 0 : 1;
457 //============================================================================
458 // virtual
459 SfxItemPresentation CntUInt32Item::GetPresentation(SfxItemPresentation,
460 SfxMapUnit, SfxMapUnit,
461 OUString & rText,
462 const IntlWrapper *)
463 const
465 DBG_CHKTHIS(CntUInt32Item, 0);
466 rText = OUString::number(m_nValue);
467 return SFX_ITEM_PRESENTATION_NAMELESS;
470 //============================================================================
471 // virtual
472 bool CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
474 sal_Int32 nValue = m_nValue;
475 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
476 rVal <<= nValue;
477 return true;
480 //============================================================================
481 // virtual
482 bool CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
484 sal_Int32 nValue = 0;
485 if (rVal >>= nValue)
487 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
488 m_nValue = nValue;
489 return true;
492 OSL_FAIL( "CntUInt32Item::PutValue - Wrong type!" );
493 return false;
496 //============================================================================
497 // virtual
498 SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, sal_uInt16) const
500 DBG_CHKTHIS(CntUInt32Item, 0);
501 return new CntUInt32Item(Which(), rStream);
504 //============================================================================
505 // virtual
506 SvStream & CntUInt32Item::Store(SvStream &rStream, sal_uInt16) const
508 DBG_CHKTHIS(CntUInt32Item, 0);
509 rStream << static_cast<sal_uInt32>(m_nValue);
510 return rStream;
513 //============================================================================
514 // virtual
515 SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const
517 DBG_CHKTHIS(CntUInt32Item, 0);
518 return new CntUInt32Item(*this);
521 //============================================================================
522 // virtual
523 sal_uInt32 CntUInt32Item::GetMin() const
525 DBG_CHKTHIS(CntUInt32Item, 0);
526 return 0;
529 //============================================================================
530 // virtual
531 sal_uInt32 CntUInt32Item::GetMax() const
533 DBG_CHKTHIS(CntUInt32Item, 0);
534 return 0xFFFFFFFF;
537 //============================================================================
538 // virtual
539 SfxFieldUnit CntUInt32Item::GetUnit() const
541 DBG_CHKTHIS(CntUInt32Item, 0);
542 return SFX_FUNIT_NONE;
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */