Update ooo320-m1
[ooovba.git] / svtools / source / items / intitem.cxx
blob31196d325eddfe620727666f34cd150c39d261de
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: intitem.cxx,v $
10 * $Revision: 1.9 $
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"
34 #include <svtools/intitem.hxx>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <tools/bigint.hxx>
37 #include <tools/stream.hxx>
38 #include <svtools/metitem.hxx>
40 //============================================================================
42 // class SfxByteItem
44 //============================================================================
46 TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem);
48 //============================================================================
49 // virtual
50 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, USHORT) const
52 short nValue = 0;
53 rStream >> nValue;
54 return new SfxByteItem(Which(), BYTE(nValue));
57 //============================================================================
59 // class SfxInt16Item
61 //============================================================================
63 DBG_NAME(SfxInt16Item);
65 //============================================================================
66 TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem);
68 //============================================================================
69 SfxInt16Item::SfxInt16Item(USHORT which, SvStream & rStream):
70 SfxPoolItem(which)
72 DBG_CTOR(SfxInt16Item, 0);
73 short nTheValue = 0;
74 rStream >> nTheValue;
75 m_nValue = nTheValue;
78 //============================================================================
79 // virtual
80 int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
82 DBG_CHKTHIS(SfxInt16Item, 0);
83 DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type");
84 return m_nValue == SAL_STATIC_CAST(const SfxInt16Item *, &rItem)->
85 m_nValue;
88 //============================================================================
89 // virtual
90 int SfxInt16Item::Compare(const SfxPoolItem & rWith) const
92 DBG_CHKTHIS(SfxInt16Item, 0);
93 DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type");
94 return SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue
95 < m_nValue ?
96 -1 :
97 SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue
98 == m_nValue ?
99 0 : 1;
102 //============================================================================
103 // virtual
104 SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation,
105 SfxMapUnit, SfxMapUnit,
106 XubString & rText,
107 const IntlWrapper *) const
109 DBG_CHKTHIS(SfxInt16Item, 0);
110 rText = UniString::CreateFromInt32(m_nValue);
111 return SFX_ITEM_PRESENTATION_NAMELESS;
115 //============================================================================
116 // virtual
117 BOOL SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, BYTE) const
119 sal_Int16 nValue = m_nValue;
120 rVal <<= nValue;
121 return TRUE;
124 //============================================================================
125 // virtual
126 BOOL SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, BYTE )
128 sal_Int16 nValue = sal_Int16();
129 if (rVal >>= nValue)
131 m_nValue = nValue;
132 return TRUE;
135 DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" );
136 return FALSE;
139 //============================================================================
140 // virtual
141 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, USHORT) const
143 DBG_CHKTHIS(SfxInt16Item, 0);
144 return new SfxInt16Item(Which(), rStream);
147 //============================================================================
148 // virtual
149 SvStream & SfxInt16Item::Store(SvStream & rStream, USHORT) const
151 DBG_CHKTHIS(SfxInt16Item, 0);
152 rStream << short(m_nValue);
153 return rStream;
156 //============================================================================
157 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const
159 DBG_CHKTHIS(SfxInt16Item, 0);
160 return new SfxInt16Item(*this);
163 //============================================================================
164 INT16 SfxInt16Item::GetMin() const
166 DBG_CHKTHIS(SfxInt16Item, 0);
167 return -32768;
170 //============================================================================
171 INT16 SfxInt16Item::GetMax() const
173 DBG_CHKTHIS(SfxInt16Item, 0);
174 return 32767;
177 //============================================================================
178 SfxFieldUnit SfxInt16Item::GetUnit() const
180 DBG_CHKTHIS(SfxInt16Item, 0);
181 return SFX_FUNIT_NONE;
184 //============================================================================
186 // class SfxUInt16Item
188 //============================================================================
190 TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item);
193 //============================================================================
195 // class SfxInt32Item
197 //============================================================================
199 TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item);
202 //============================================================================
204 // class SfxUInt32Item
206 //============================================================================
208 TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item);
211 //============================================================================
213 // class SfxMetricItem
215 //============================================================================
217 DBG_NAME(SfxMetricItem);
219 //============================================================================
220 TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item);
222 //============================================================================
223 SfxMetricItem::SfxMetricItem(USHORT which, UINT32 nValue):
224 SfxInt32Item(which, nValue)
226 DBG_CTOR(SfxMetricItem, 0);
229 //============================================================================
230 SfxMetricItem::SfxMetricItem(USHORT which, SvStream & rStream):
231 SfxInt32Item(which, rStream)
233 DBG_CTOR(SfxMetricItem, 0);
236 //============================================================================
237 SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem):
238 SfxInt32Item(rItem)
240 DBG_CTOR(SfxMetricItem, 0);
243 //============================================================================
244 // virtual
245 int SfxMetricItem::ScaleMetrics(long nMult, long nDiv)
247 BigInt aTheValue(GetValue());
248 aTheValue *= nMult;
249 aTheValue += nDiv / 2;
250 aTheValue /= nDiv;
251 SetValue(aTheValue);
252 return 1;
255 //============================================================================
256 // virtual
257 int SfxMetricItem::HasMetrics() const
259 return 1;