bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / cintitem.cxx
blob0fde0d94003e6975602dd4e81f81c298b427aafd
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 <osl/diagnose.h>
22 #include <tools/stream.hxx>
23 #include <svl/cintitem.hxx>
25 TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem);
27 // virtual
28 bool CntByteItem::operator ==(const SfxPoolItem & rItem) const
30 DBG_ASSERT(rItem.ISA(CntByteItem),
31 "CntByteItem::operator ==(): Bad type");
32 return m_nValue == (static_cast< const CntByteItem * >(&rItem))->m_nValue;
35 // virtual
36 int CntByteItem::Compare(const SfxPoolItem & rWith) const
38 DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type");
39 return (static_cast< const CntByteItem * >(&rWith))->m_nValue < m_nValue ?
40 -1 :
41 (static_cast< const CntByteItem * >(&rWith))->m_nValue
42 == m_nValue ?
43 0 : 1;
46 // virtual
47 bool CntByteItem::GetPresentation(SfxItemPresentation,
48 SfxMapUnit, SfxMapUnit,
49 OUString & rText,
50 const IntlWrapper *) const
52 rText = OUString::number( m_nValue );
53 return true;
56 // virtual
57 bool CntByteItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
59 sal_Int8 nValue = m_nValue;
60 rVal <<= nValue;
61 return true;
64 // virtual
65 bool CntByteItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
67 sal_Int8 nValue = sal_Int8();
68 if (rVal >>= nValue)
70 m_nValue = nValue;
71 return true;
74 OSL_FAIL( "CntByteItem::PutValue - Wrong type!" );
75 return false;
78 // virtual
79 SfxPoolItem * CntByteItem::Create(SvStream & rStream, sal_uInt16) const
81 short nTheValue = 0;
82 rStream.ReadInt16( nTheValue );
83 return new CntByteItem(Which(), sal_uInt8(nTheValue));
86 // virtual
87 SvStream & CntByteItem::Store(SvStream & rStream, sal_uInt16) const
89 rStream.WriteInt16( short(m_nValue) );
90 return rStream;
93 // virtual
94 SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const
96 return new CntByteItem(*this);
99 TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem);
101 CntUInt16Item::CntUInt16Item(sal_uInt16 which, SvStream & rStream) :
102 SfxPoolItem(which)
104 sal_uInt16 nTheValue = 0;
105 rStream.ReadUInt16( nTheValue );
106 m_nValue = nTheValue;
109 // virtual
110 bool CntUInt16Item::operator ==(const SfxPoolItem & rItem) const
112 DBG_ASSERT(rItem.ISA(CntUInt16Item),
113 "CntUInt16Item::operator ==(): Bad type");
114 return m_nValue == (static_cast< const CntUInt16Item * >(&rItem))->
115 m_nValue;
118 // virtual
119 int CntUInt16Item::Compare(const SfxPoolItem & rWith) const
121 DBG_ASSERT(rWith.ISA(CntUInt16Item),
122 "CntUInt16Item::Compare(): Bad type");
123 return (static_cast< const CntUInt16Item * >(&rWith))->m_nValue
124 < m_nValue ?
125 -1 :
126 (static_cast< const CntUInt16Item * >(&rWith))->m_nValue
127 == m_nValue ?
128 0 : 1;
131 // virtual
132 bool CntUInt16Item::GetPresentation(SfxItemPresentation,
133 SfxMapUnit, SfxMapUnit,
134 OUString & rText,
135 const IntlWrapper *)
136 const
138 rText = OUString::number( m_nValue );
139 return true;
142 // virtual
143 bool CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
145 sal_Int32 nValue = m_nValue;
146 rVal <<= nValue;
147 return true;
150 // virtual
151 bool CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
153 sal_Int32 nValue = 0;
154 if (rVal >>= nValue)
156 DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!");
157 m_nValue = (sal_uInt16)nValue;
158 return true;
161 OSL_FAIL( "CntUInt16Item::PutValue - Wrong type!" );
162 return false;
165 // virtual
166 SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, sal_uInt16) const
168 return new CntUInt16Item(Which(), rStream);
171 // virtual
172 SvStream & CntUInt16Item::Store(SvStream &rStream, sal_uInt16) const
174 rStream.WriteUInt16( m_nValue );
175 return rStream;
178 // virtual
179 SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const
181 return new CntUInt16Item(*this);
184 TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem);
186 CntInt32Item::CntInt32Item(sal_uInt16 which, SvStream & rStream)
187 : SfxPoolItem(which)
188 , m_nValue(0)
190 rStream.ReadInt32( m_nValue );
193 // virtual
194 bool CntInt32Item::operator ==(const SfxPoolItem & rItem) const
196 DBG_ASSERT(rItem.ISA(CntInt32Item),
197 "CntInt32Item::operator ==(): Bad type");
198 return m_nValue == (static_cast< const CntInt32Item * >(&rItem))->
199 m_nValue;
202 // virtual
203 int CntInt32Item::Compare(const SfxPoolItem & rWith) const
205 DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type");
206 return (static_cast< const CntInt32Item * >(&rWith))->m_nValue
207 < m_nValue ?
208 -1 :
209 (static_cast< const CntInt32Item * >(&rWith))->m_nValue
210 == m_nValue ?
211 0 : 1;
214 // virtual
215 bool CntInt32Item::GetPresentation(SfxItemPresentation,
216 SfxMapUnit, SfxMapUnit,
217 OUString & rText,
218 const IntlWrapper *) const
220 rText = OUString::number( m_nValue );
221 return true;
224 // virtual
225 bool CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
227 sal_Int32 nValue = m_nValue;
228 rVal <<= nValue;
229 return true;
232 // virtual
233 bool CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
235 sal_Int32 nValue = 0;
236 if (rVal >>= nValue)
238 m_nValue = nValue;
239 return true;
242 OSL_FAIL( "CntInt32Item::PutValue - Wrong type!" );
243 return false;
246 // virtual
247 SfxPoolItem * CntInt32Item::Create(SvStream & rStream, sal_uInt16) const
249 return new CntInt32Item(Which(), rStream);
252 // virtual
253 SvStream & CntInt32Item::Store(SvStream &rStream, sal_uInt16) const
255 rStream.WriteInt32( m_nValue );
256 return rStream;
259 // virtual
260 SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const
262 return new CntInt32Item(*this);
265 TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem);
267 CntUInt32Item::CntUInt32Item(sal_uInt16 which, SvStream & rStream) :
268 SfxPoolItem(which)
270 sal_uInt32 nTheValue = 0;
271 rStream.ReadUInt32( nTheValue );
272 m_nValue = nTheValue;
275 // virtual
276 bool CntUInt32Item::operator ==(const SfxPoolItem & rItem) const
278 DBG_ASSERT(rItem.ISA(CntUInt32Item),
279 "CntUInt32Item::operator ==(): Bad type");
280 return m_nValue == (static_cast< const CntUInt32Item * >(&rItem))->
281 m_nValue;
284 // virtual
285 int CntUInt32Item::Compare(const SfxPoolItem & rWith) const
287 DBG_ASSERT(rWith.ISA(CntUInt32Item),
288 "CntUInt32Item::operator ==(): Bad type");
289 return (static_cast< const CntUInt32Item * >(&rWith))->m_nValue
290 < m_nValue ?
291 -1 :
292 (static_cast< const CntUInt32Item * >(&rWith))->m_nValue
293 == m_nValue ?
294 0 : 1;
297 // virtual
298 bool CntUInt32Item::GetPresentation(SfxItemPresentation,
299 SfxMapUnit, SfxMapUnit,
300 OUString & rText,
301 const IntlWrapper *)
302 const
304 rText = OUString::number(m_nValue);
305 return true;
308 // virtual
309 bool CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
311 sal_Int32 nValue = m_nValue;
312 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
313 rVal <<= nValue;
314 return true;
317 // virtual
318 bool CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
320 sal_Int32 nValue = 0;
321 if (rVal >>= nValue)
323 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
324 m_nValue = nValue;
325 return true;
328 OSL_FAIL( "CntUInt32Item::PutValue - Wrong type!" );
329 return false;
332 // virtual
333 SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, sal_uInt16) const
335 return new CntUInt32Item(Which(), rStream);
338 // virtual
339 SvStream & CntUInt32Item::Store(SvStream &rStream, sal_uInt16) const
341 rStream.WriteUInt32( m_nValue );
342 return rStream;
345 // virtual
346 SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const
348 return new CntUInt32Item(*this);
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */