OInterfaceContainerHelper3 needs to be thread-safe
[LibreOffice.git] / svl / source / items / intitem.cxx
blob072de0501f40b21f4dca4769e544e78151e5b490
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 <svl/metitem.hxx>
26 #include <libxml/xmlwriter.h>
27 #include <boost/property_tree/json_parser.hpp>
32 SfxPoolItem* SfxByteItem::CreateDefault()
34 return new SfxByteItem();
37 SfxPoolItem* SfxInt16Item::CreateDefault()
39 return new SfxInt16Item();
42 // virtual
43 bool SfxInt16Item::operator ==(const SfxPoolItem & rItem) const
45 assert(SfxPoolItem::operator==(rItem));
46 return m_nValue == static_cast< const SfxInt16Item * >(&rItem)->
47 m_nValue;
50 // virtual
51 bool SfxInt16Item::GetPresentation(SfxItemPresentation,
52 MapUnit, MapUnit,
53 OUString & rText,
54 const IntlWrapper&) const
56 rText = OUString::number(m_nValue);
57 return true;
61 boost::property_tree::ptree SfxInt16Item::dumpAsJSON() const
63 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
64 aTree.put("state", GetValue());
65 return aTree;
69 // virtual
70 bool SfxInt16Item::QueryValue(css::uno::Any& rVal, sal_uInt8) const
72 sal_Int16 nValue = m_nValue;
73 rVal <<= nValue;
74 return true;
77 // virtual
78 bool SfxInt16Item::PutValue(const css::uno::Any& rVal, sal_uInt8 )
80 sal_Int16 nValue = sal_Int16();
81 if (rVal >>= nValue)
83 m_nValue = nValue;
84 return true;
87 OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" );
88 return false;
91 SfxInt16Item* SfxInt16Item::Clone(SfxItemPool *) const
93 return new SfxInt16Item(*this);
96 SfxPoolItem* SfxUInt16Item::CreateDefault()
98 return new SfxUInt16Item();
101 void SfxUInt16Item::dumpAsXml(xmlTextWriterPtr pWriter) const
103 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxUInt16Item"));
104 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
105 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
106 xmlTextWriterEndElement(pWriter);
109 boost::property_tree::ptree SfxUInt16Item::dumpAsJSON() const
111 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
112 aTree.put("state", GetValue());
113 return aTree;
119 SfxPoolItem* SfxInt32Item::CreateDefault()
121 return new SfxInt32Item();
124 void SfxInt32Item::dumpAsXml(xmlTextWriterPtr pWriter) const
126 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxInt32Item"));
127 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
128 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
129 xmlTextWriterEndElement(pWriter);
132 boost::property_tree::ptree SfxInt32Item::dumpAsJSON() const
134 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
135 aTree.put("state", GetValue());
136 return aTree;
142 SfxPoolItem* SfxUInt32Item::CreateDefault()
144 return new SfxUInt32Item();
147 void SfxUInt32Item::dumpAsXml(xmlTextWriterPtr pWriter) const
149 xmlTextWriterStartElement(pWriter, BAD_CAST("SfxUInt32Item"));
150 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
151 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::number(GetValue()).getStr()));
152 xmlTextWriterEndElement(pWriter);
155 boost::property_tree::ptree SfxUInt32Item::dumpAsJSON() const
157 boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
158 aTree.put("state", GetValue());
159 return aTree;
162 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue):
163 SfxInt32Item(which, nValue)
167 // virtual
168 void SfxMetricItem::ScaleMetrics(tools::Long nMult, tools::Long nDiv)
170 BigInt aTheValue(GetValue());
171 aTheValue *= nMult;
172 aTheValue += nDiv / 2;
173 aTheValue /= nDiv;
174 SetValue(aTheValue);
177 // virtual
178 bool SfxMetricItem::HasMetrics() const
180 return true;
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */