bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / intitem.cxx
blobe596d4a5a8f9cce6c052e5f25ecc4333b1aab3c5
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 <osl/diagnose.h>
24 #include <tools/bigint.hxx>
25 #include <tools/stream.hxx>
26 #include <svl/metitem.hxx>
27 #include <libxml/xmlwriter.h>
30 // class SfxByteItem
33 TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem);
35 // virtual
36 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const
38 short nValue = 0;
39 rStream.ReadInt16( nValue );
40 return new SfxByteItem(Which(), sal_uInt8(nValue));
43 TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem);
45 SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream):
46 SfxPoolItem(which)
48 short nTheValue = 0;
49 rStream.ReadInt16( nTheValue );
50 m_nValue = nTheValue;
53 // virtual
54 bool SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
56 DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type");
57 return m_nValue == (static_cast< const SfxInt16Item * >(&rItem))->
58 m_nValue;
61 // virtual
62 int SfxInt16Item::Compare(const SfxPoolItem & rWith) const
64 DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type");
65 return (static_cast< const SfxInt16Item * >(&rWith))->m_nValue
66 < m_nValue ?
67 -1 :
68 (static_cast< const SfxInt16Item * >(&rWith))->m_nValue
69 == m_nValue ?
70 0 : 1;
73 // virtual
74 bool SfxInt16Item::GetPresentation(SfxItemPresentation,
75 SfxMapUnit, SfxMapUnit,
76 OUString & rText,
77 const IntlWrapper *) const
79 rText = OUString::number(m_nValue);
80 return true;
84 // virtual
85 bool SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
87 sal_Int16 nValue = m_nValue;
88 rVal <<= nValue;
89 return true;
92 // virtual
93 bool SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 )
95 sal_Int16 nValue = sal_Int16();
96 if (rVal >>= nValue)
98 m_nValue = nValue;
99 return true;
102 OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" );
103 return false;
106 // virtual
107 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const
109 return new SfxInt16Item(Which(), rStream);
112 // virtual
113 SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const
115 rStream.WriteInt16( short(m_nValue) );
116 return rStream;
119 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const
121 return new SfxInt16Item(*this);
124 // class SfxUInt16Item
125 TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item);
127 void SfxUInt16Item::dumpAsXml(xmlTextWriterPtr pWriter) const
129 xmlTextWriterStartElement(pWriter, BAD_CAST("sfxUInt16Item"));
130 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
131 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
132 xmlTextWriterEndElement(pWriter);
136 // class SfxInt32Item
139 TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item);
143 // class SfxUInt32Item
146 TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item);
148 TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item);
150 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue):
151 SfxInt32Item(which, nValue)
155 SfxMetricItem::SfxMetricItem(sal_uInt16 which, SvStream & rStream):
156 SfxInt32Item(which, rStream)
160 SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem):
161 SfxInt32Item(rItem)
165 // virtual
166 bool SfxMetricItem::ScaleMetrics(long nMult, long nDiv)
168 BigInt aTheValue(GetValue());
169 aTheValue *= nMult;
170 aTheValue += nDiv / 2;
171 aTheValue /= nDiv;
172 SetValue(aTheValue);
173 return true;
176 // virtual
177 bool SfxMetricItem::HasMetrics() const
179 return true;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */