bump product version to 4.1.6.2
[LibreOffice.git] / svl / source / items / intitem.cxx
blob363afb9a9ec1b096cc2543d7b423d82a380384c7
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 .
21 #include <svl/intitem.hxx>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <tools/bigint.hxx>
24 #include <tools/stream.hxx>
25 #include <svl/metitem.hxx>
27 //============================================================================
29 // class SfxByteItem
31 //============================================================================
33 TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem);
35 //============================================================================
36 // virtual
37 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const
39 short nValue = 0;
40 rStream >> nValue;
41 return new SfxByteItem(Which(), sal_uInt8(nValue));
44 //============================================================================
46 // class SfxInt16Item
48 //============================================================================
50 DBG_NAME(SfxInt16Item);
52 //============================================================================
53 TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem);
55 //============================================================================
56 SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream):
57 SfxPoolItem(which)
59 DBG_CTOR(SfxInt16Item, 0);
60 short nTheValue = 0;
61 rStream >> nTheValue;
62 m_nValue = nTheValue;
65 //============================================================================
66 // virtual
67 int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
69 DBG_CHKTHIS(SfxInt16Item, 0);
70 DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type");
71 return m_nValue == (static_cast< const SfxInt16Item * >(&rItem))->
72 m_nValue;
75 //============================================================================
76 // virtual
77 int SfxInt16Item::Compare(const SfxPoolItem & rWith) const
79 DBG_CHKTHIS(SfxInt16Item, 0);
80 DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type");
81 return (static_cast< const SfxInt16Item * >(&rWith))->m_nValue
82 < m_nValue ?
83 -1 :
84 (static_cast< const SfxInt16Item * >(&rWith))->m_nValue
85 == m_nValue ?
86 0 : 1;
89 //============================================================================
90 // virtual
91 SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation,
92 SfxMapUnit, SfxMapUnit,
93 OUString & rText,
94 const IntlWrapper *) const
96 DBG_CHKTHIS(SfxInt16Item, 0);
97 rText = OUString::number(m_nValue);
98 return SFX_ITEM_PRESENTATION_NAMELESS;
102 //============================================================================
103 // virtual
104 bool SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
106 sal_Int16 nValue = m_nValue;
107 rVal <<= nValue;
108 return true;
111 //============================================================================
112 // virtual
113 bool SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 )
115 sal_Int16 nValue = sal_Int16();
116 if (rVal >>= nValue)
118 m_nValue = nValue;
119 return true;
122 OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" );
123 return false;
126 //============================================================================
127 // virtual
128 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const
130 DBG_CHKTHIS(SfxInt16Item, 0);
131 return new SfxInt16Item(Which(), rStream);
134 //============================================================================
135 // virtual
136 SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const
138 DBG_CHKTHIS(SfxInt16Item, 0);
139 rStream << short(m_nValue);
140 return rStream;
143 //============================================================================
144 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const
146 DBG_CHKTHIS(SfxInt16Item, 0);
147 return new SfxInt16Item(*this);
150 //============================================================================
151 sal_Int16 SfxInt16Item::GetMin() const
153 DBG_CHKTHIS(SfxInt16Item, 0);
154 return -32768;
157 //============================================================================
158 sal_Int16 SfxInt16Item::GetMax() const
160 DBG_CHKTHIS(SfxInt16Item, 0);
161 return 32767;
164 //============================================================================
165 SfxFieldUnit SfxInt16Item::GetUnit() const
167 DBG_CHKTHIS(SfxInt16Item, 0);
168 return SFX_FUNIT_NONE;
171 //============================================================================
173 // class SfxUInt16Item
175 //============================================================================
177 TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item);
180 //============================================================================
182 // class SfxInt32Item
184 //============================================================================
186 TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item);
189 //============================================================================
191 // class SfxUInt32Item
193 //============================================================================
195 TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item);
198 //============================================================================
200 // class SfxMetricItem
202 //============================================================================
204 DBG_NAME(SfxMetricItem);
206 //============================================================================
207 TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item);
209 //============================================================================
210 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue):
211 SfxInt32Item(which, nValue)
213 DBG_CTOR(SfxMetricItem, 0);
216 //============================================================================
217 SfxMetricItem::SfxMetricItem(sal_uInt16 which, SvStream & rStream):
218 SfxInt32Item(which, rStream)
220 DBG_CTOR(SfxMetricItem, 0);
223 //============================================================================
224 SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem):
225 SfxInt32Item(rItem)
227 DBG_CTOR(SfxMetricItem, 0);
230 //============================================================================
231 // virtual
232 bool SfxMetricItem::ScaleMetrics(long nMult, long nDiv)
234 BigInt aTheValue(GetValue());
235 aTheValue *= nMult;
236 aTheValue += nDiv / 2;
237 aTheValue /= nDiv;
238 SetValue(aTheValue);
239 return true;
242 //============================================================================
243 // virtual
244 bool SfxMetricItem::HasMetrics() const
246 return true;
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */