lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svl / source / items / intitem.cxx
blobafa9923265eae154c20263d22d22c2db10331470
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 SfxPoolItem* SfxByteItem::CreateDefault()
35 return new SfxByteItem();
38 // virtual
39 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const
41 short nValue = 0;
42 rStream.ReadInt16( nValue );
43 return new SfxByteItem(Which(), sal_uInt8(nValue));
46 SfxPoolItem* SfxInt16Item::CreateDefault()
48 return new SfxInt16Item();
51 SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream):
52 SfxPoolItem(which)
54 short nTheValue = 0;
55 rStream.ReadInt16( nTheValue );
56 m_nValue = nTheValue;
59 // virtual
60 bool SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
62 assert(SfxPoolItem::operator==(rItem));
63 return m_nValue == static_cast< const SfxInt16Item * >(&rItem)->
64 m_nValue;
67 // virtual
68 bool SfxInt16Item::GetPresentation(SfxItemPresentation,
69 MapUnit, MapUnit,
70 OUString & rText,
71 const IntlWrapper&) const
73 rText = OUString::number(m_nValue);
74 return true;
78 boost::property_tree::ptree SfxInt16Item::dumpAsJSON() const
80 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
81 aTree.put("state", GetValue());
82 return aTree;
86 // virtual
87 bool SfxInt16Item::QueryValue(css::uno::Any& rVal, sal_uInt8) const
89 sal_Int16 nValue = m_nValue;
90 rVal <<= nValue;
91 return true;
94 // virtual
95 bool SfxInt16Item::PutValue(const css::uno::Any& rVal, sal_uInt8 )
97 sal_Int16 nValue = sal_Int16();
98 if (rVal >>= nValue)
100 m_nValue = nValue;
101 return true;
104 OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" );
105 return false;
108 // virtual
109 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const
111 return new SfxInt16Item(Which(), rStream);
114 // virtual
115 SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const
117 rStream.WriteInt16( short(m_nValue) );
118 return rStream;
121 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const
123 return new SfxInt16Item(*this);
126 // class SfxUInt16Item
127 SfxPoolItem* SfxUInt16Item::CreateDefault()
129 return new SfxUInt16Item();
132 void SfxUInt16Item::dumpAsXml(xmlTextWriterPtr pWriter) const
134 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxUInt16Item"));
135 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
136 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
137 xmlTextWriterEndElement(pWriter);
140 boost::property_tree::ptree SfxUInt16Item::dumpAsJSON() const
142 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
143 aTree.put("state", GetValue());
144 return aTree;
148 // class SfxInt32Item
151 SfxPoolItem* SfxInt32Item::CreateDefault()
153 return new SfxInt32Item();
156 boost::property_tree::ptree SfxInt32Item::dumpAsJSON() const
158 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
159 aTree.put("state", GetValue());
160 return aTree;
164 // class SfxUInt32Item
167 SfxPoolItem* SfxUInt32Item::CreateDefault()
169 return new SfxUInt32Item();
172 boost::property_tree::ptree SfxUInt32Item::dumpAsJSON() const
174 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
175 aTree.put("state", GetValue());
176 return aTree;
179 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue):
180 SfxInt32Item(which, nValue)
184 // virtual
185 void SfxMetricItem::ScaleMetrics(long nMult, long nDiv)
187 BigInt aTheValue(GetValue());
188 aTheValue *= nMult;
189 aTheValue += nDiv / 2;
190 aTheValue /= nDiv;
191 SetValue(aTheValue);
194 // virtual
195 bool SfxMetricItem::HasMetrics() const
197 return true;
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */