merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items1 / cintitem.cxx
blob5c6bc3a1f399fd0c14afcc5beeb6caad2690ee6a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cintitem.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/uno/Any.hxx>
34 #include <tools/stream.hxx>
35 #include <svtools/cintitem.hxx>
37 //============================================================================
39 // class CntByteItem
41 //============================================================================
43 DBG_NAME(CntByteItem)
45 //============================================================================
46 TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem);
48 //============================================================================
49 CntByteItem::CntByteItem(USHORT which, SvStream & rStream):
50 SfxPoolItem(which)
52 DBG_CTOR(CntByteItem, 0);
53 rStream >> m_nValue;
56 //============================================================================
57 // virtual
58 int CntByteItem::operator ==(const SfxPoolItem & rItem) const
60 DBG_CHKTHIS(CntByteItem, 0);
61 DBG_ASSERT(rItem.ISA(CntByteItem),
62 "CntByteItem::operator ==(): Bad type");
63 return m_nValue == SAL_STATIC_CAST(const CntByteItem *, &rItem)->m_nValue;
66 //============================================================================
67 // virtual
68 int CntByteItem::Compare(const SfxPoolItem & rWith) const
70 DBG_CHKTHIS(CntByteItem, 0);
71 DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type");
72 return SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue < m_nValue ?
73 -1 :
74 SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue
75 == m_nValue ?
76 0 : 1;
79 //============================================================================
80 // virtual
81 SfxItemPresentation CntByteItem::GetPresentation(SfxItemPresentation,
82 SfxMapUnit, SfxMapUnit,
83 XubString & rText,
84 const IntlWrapper *) const
86 DBG_CHKTHIS(CntByteItem, 0);
87 rText = XubString::CreateFromInt32(m_nValue);
88 return SFX_ITEM_PRESENTATION_NAMELESS;
91 //============================================================================
92 // virtual
93 BOOL CntByteItem::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const
95 sal_Int8 nValue = m_nValue;
96 rVal <<= nValue;
97 return TRUE;
100 //============================================================================
101 // virtual
102 BOOL CntByteItem::PutValue(const com::sun::star::uno::Any& rVal,BYTE)
104 sal_Int8 nValue = sal_Int8();
105 if (rVal >>= nValue)
107 m_nValue = nValue;
108 return TRUE;
111 DBG_ERROR( "CntByteItem::PutValue - Wrong type!" );
112 return FALSE;
115 //============================================================================
116 // virtual
117 SfxPoolItem * CntByteItem::Create(SvStream & rStream, USHORT) const
119 DBG_CHKTHIS(CntByteItem, 0);
120 short nTheValue = 0;
121 rStream >> nTheValue;
122 return new CntByteItem(Which(), BYTE(nTheValue));
125 //============================================================================
126 // virtual
127 SvStream & CntByteItem::Store(SvStream & rStream, USHORT) const
129 DBG_CHKTHIS(CntByteItem, 0);
130 rStream << short(m_nValue);
131 return rStream;
134 //============================================================================
135 // virtual
136 SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const
138 DBG_CHKTHIS(CntByteItem, 0);
139 return new CntByteItem(*this);
142 //============================================================================
143 // virtual
144 BYTE CntByteItem::GetMin() const
146 DBG_CHKTHIS(CntByteItem, 0);
147 return 0;
150 //============================================================================
151 // virtual
152 BYTE CntByteItem::GetMax() const
154 DBG_CHKTHIS(CntByteItem, 0);
155 return 255;
158 //============================================================================
159 // virtual
160 SfxFieldUnit CntByteItem::GetUnit() const
162 DBG_CHKTHIS(CntByteItem, 0);
163 return SFX_FUNIT_NONE;
166 //============================================================================
168 // class CntUInt16Item
170 //============================================================================
172 DBG_NAME(CntUInt16Item);
174 //============================================================================
175 TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem);
177 //============================================================================
178 CntUInt16Item::CntUInt16Item(USHORT which, SvStream & rStream) :
179 SfxPoolItem(which)
181 DBG_CTOR(CntUInt16Item, 0);
182 USHORT nTheValue = 0;
183 rStream >> nTheValue;
184 m_nValue = nTheValue;
187 //============================================================================
188 // virtual
189 int CntUInt16Item::operator ==(const SfxPoolItem & rItem) const
191 DBG_CHKTHIS(CntUInt16Item, 0);
192 DBG_ASSERT(rItem.ISA(CntUInt16Item),
193 "CntUInt16Item::operator ==(): Bad type");
194 return m_nValue == SAL_STATIC_CAST(const CntUInt16Item *, &rItem)->
195 m_nValue;
198 //============================================================================
199 // virtual
200 int CntUInt16Item::Compare(const SfxPoolItem & rWith) const
202 DBG_CHKTHIS(CntUInt16Item, 0);
203 DBG_ASSERT(rWith.ISA(CntUInt16Item),
204 "CntUInt16Item::Compare(): Bad type");
205 return SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue
206 < m_nValue ?
207 -1 :
208 SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue
209 == m_nValue ?
210 0 : 1;
213 //============================================================================
214 // virtual
215 SfxItemPresentation CntUInt16Item::GetPresentation(SfxItemPresentation,
216 SfxMapUnit, SfxMapUnit,
217 XubString & rText,
218 const IntlWrapper *)
219 const
221 DBG_CHKTHIS(CntUInt16Item, 0);
222 rText = XubString::CreateFromInt32(m_nValue);
223 return SFX_ITEM_PRESENTATION_NAMELESS;
226 //============================================================================
227 // virtual
228 BOOL CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const
230 sal_Int32 nValue = m_nValue;
231 rVal <<= nValue;
232 return TRUE;
235 //============================================================================
236 // virtual
237 BOOL CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE)
239 sal_Int32 nValue = 0;
240 if (rVal >>= nValue)
242 DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!");
243 m_nValue = (sal_uInt16)nValue;
244 return TRUE;
247 DBG_ERROR( "CntUInt16Item::PutValue - Wrong type!" );
248 return FALSE;
251 //============================================================================
252 // virtual
253 SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, USHORT) const
255 DBG_CHKTHIS(CntUInt16Item, 0);
256 return new CntUInt16Item(Which(), rStream);
259 //============================================================================
260 // virtual
261 SvStream & CntUInt16Item::Store(SvStream &rStream, USHORT) const
263 DBG_CHKTHIS(CntUInt16Item, 0);
264 rStream << USHORT(m_nValue);
265 return rStream;
268 //============================================================================
269 // virtual
270 SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const
272 DBG_CHKTHIS(CntUInt16Item, 0);
273 return new CntUInt16Item(*this);
276 //============================================================================
277 // virtual
278 UINT16 CntUInt16Item::GetMin() const
280 DBG_CHKTHIS(CntUInt16Item, 0);
281 return 0;
284 //============================================================================
285 // virtual
286 UINT16 CntUInt16Item::GetMax() const
288 DBG_CHKTHIS(CntUInt16Item, 0);
289 return 65535;
292 //============================================================================
293 // virtual
294 SfxFieldUnit CntUInt16Item::GetUnit() const
296 DBG_CHKTHIS(CntUInt16Item, 0);
297 return SFX_FUNIT_NONE;
300 //============================================================================
302 // class CntInt32Item
304 //============================================================================
306 DBG_NAME(CntInt32Item);
308 //============================================================================
309 TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem);
311 //============================================================================
312 CntInt32Item::CntInt32Item(USHORT which, SvStream & rStream) :
313 SfxPoolItem(which)
315 DBG_CTOR(CntInt32Item, 0);
316 long nTheValue = 0;
317 rStream >> nTheValue;
318 m_nValue = nTheValue;
321 //============================================================================
322 // virtual
323 int CntInt32Item::operator ==(const SfxPoolItem & rItem) const
325 DBG_CHKTHIS(CntInt32Item, 0);
326 DBG_ASSERT(rItem.ISA(CntInt32Item),
327 "CntInt32Item::operator ==(): Bad type");
328 return m_nValue == SAL_STATIC_CAST(const CntInt32Item *, &rItem)->
329 m_nValue;
332 //============================================================================
333 // virtual
334 int CntInt32Item::Compare(const SfxPoolItem & rWith) const
336 DBG_CHKTHIS(CntInt32Item, 0);
337 DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type");
338 return SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue
339 < m_nValue ?
340 -1 :
341 SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue
342 == m_nValue ?
343 0 : 1;
346 //============================================================================
347 // virtual
348 SfxItemPresentation CntInt32Item::GetPresentation(SfxItemPresentation,
349 SfxMapUnit, SfxMapUnit,
350 XubString & rText,
351 const IntlWrapper *) const
353 DBG_CHKTHIS(CntInt32Item, 0);
354 rText = XubString::CreateFromInt32(m_nValue);
355 return SFX_ITEM_PRESENTATION_NAMELESS;
358 //============================================================================
359 // virtual
360 BOOL CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const
362 sal_Int32 nValue = m_nValue;
363 rVal <<= nValue;
364 return TRUE;
367 //============================================================================
368 // virtual
369 BOOL CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE)
371 sal_Int32 nValue = 0;
372 if (rVal >>= nValue)
374 m_nValue = nValue;
375 return TRUE;
378 DBG_ERROR( "CntInt32Item::PutValue - Wrong type!" );
379 return FALSE;
382 //============================================================================
383 // virtual
384 SfxPoolItem * CntInt32Item::Create(SvStream & rStream, USHORT) const
386 DBG_CHKTHIS(CntInt32Item, 0);
387 return new CntInt32Item(Which(), rStream);
390 //============================================================================
391 // virtual
392 SvStream & CntInt32Item::Store(SvStream &rStream, USHORT) const
394 DBG_CHKTHIS(CntInt32Item, 0);
395 rStream << long(m_nValue);
396 return rStream;
399 //============================================================================
400 // virtual
401 SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const
403 DBG_CHKTHIS(CntInt32Item, 0);
404 return new CntInt32Item(*this);
407 //============================================================================
408 // virtual
409 INT32 CntInt32Item::GetMin() const
411 DBG_CHKTHIS(CntInt32Item, 0);
412 return INT32(0x80000000);
415 //============================================================================
416 // virtual
417 INT32 CntInt32Item::GetMax() const
419 DBG_CHKTHIS(CntInt32Item, 0);
420 return 0x7FFFFFFF;
423 //============================================================================
424 // virtual
425 SfxFieldUnit CntInt32Item::GetUnit() const
427 DBG_CHKTHIS(CntInt32Item, 0);
428 return SFX_FUNIT_NONE;
431 //============================================================================
433 // class CntUInt32Item
435 //============================================================================
437 DBG_NAME(CntUInt32Item);
439 //============================================================================
440 TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem);
442 //============================================================================
443 CntUInt32Item::CntUInt32Item(USHORT which, SvStream & rStream) :
444 SfxPoolItem(which)
446 DBG_CTOR(CntUInt32Item, 0);
447 sal_uInt32 nTheValue = 0;
448 rStream >> nTheValue;
449 m_nValue = nTheValue;
452 //============================================================================
453 // virtual
454 int CntUInt32Item::operator ==(const SfxPoolItem & rItem) const
456 DBG_CHKTHIS(CntUInt32Item, 0);
457 DBG_ASSERT(rItem.ISA(CntUInt32Item),
458 "CntUInt32Item::operator ==(): Bad type");
459 return m_nValue == SAL_STATIC_CAST(const CntUInt32Item *, &rItem)->
460 m_nValue;
463 //============================================================================
464 // virtual
465 int CntUInt32Item::Compare(const SfxPoolItem & rWith) const
467 DBG_CHKTHIS(CntUInt32Item, 0);
468 DBG_ASSERT(rWith.ISA(CntUInt32Item),
469 "CntUInt32Item::operator ==(): Bad type");
470 return SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue
471 < m_nValue ?
472 -1 :
473 SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue
474 == m_nValue ?
475 0 : 1;
478 //============================================================================
479 // virtual
480 SfxItemPresentation CntUInt32Item::GetPresentation(SfxItemPresentation,
481 SfxMapUnit, SfxMapUnit,
482 XubString & rText,
483 const IntlWrapper *)
484 const
486 DBG_CHKTHIS(CntUInt32Item, 0);
487 rText = XubString::CreateFromInt64(m_nValue);
488 return SFX_ITEM_PRESENTATION_NAMELESS;
491 //============================================================================
492 // virtual
493 BOOL CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const
495 sal_Int32 nValue = m_nValue;
496 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
497 rVal <<= nValue;
498 return TRUE;
501 //============================================================================
502 // virtual
503 BOOL CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE)
505 sal_Int32 nValue = 0;
506 if (rVal >>= nValue)
508 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!");
509 m_nValue = nValue;
510 return TRUE;
513 DBG_ERROR( "CntUInt32Item::PutValue - Wrong type!" );
514 return FALSE;
517 //============================================================================
518 // virtual
519 SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, USHORT) const
521 DBG_CHKTHIS(CntUInt32Item, 0);
522 return new CntUInt32Item(Which(), rStream);
525 //============================================================================
526 // virtual
527 SvStream & CntUInt32Item::Store(SvStream &rStream, USHORT) const
529 DBG_CHKTHIS(CntUInt32Item, 0);
530 rStream << static_cast<sal_uInt32>(m_nValue);
531 return rStream;
534 //============================================================================
535 // virtual
536 SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const
538 DBG_CHKTHIS(CntUInt32Item, 0);
539 return new CntUInt32Item(*this);
542 //============================================================================
543 // virtual
544 UINT32 CntUInt32Item::GetMin() const
546 DBG_CHKTHIS(CntUInt32Item, 0);
547 return 0;
550 //============================================================================
551 // virtual
552 UINT32 CntUInt32Item::GetMax() const
554 DBG_CHKTHIS(CntUInt32Item, 0);
555 return 0xFFFFFFFF;
558 //============================================================================
559 // virtual
560 SfxFieldUnit CntUInt32Item::GetUnit() const
562 DBG_CHKTHIS(CntUInt32Item, 0);
563 return SFX_FUNIT_NONE;