bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / cenumitm.cxx
bloba5525bedd27d368bbfa2987e964280195b79638d
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 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <osl/diagnose.h>
22 #include <tools/stream.hxx>
23 #include <svl/cenumitm.hxx>
24 #include <svl/eitem.hxx>
25 #include "whassert.hxx"
27 #include <comphelper/extract.hxx>
29 TYPEINIT1(SfxEnumItemInterface, SfxPoolItem)
31 // virtual
32 bool SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const
34 SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type");
35 return GetEnumValue()
36 == static_cast< const SfxEnumItemInterface * >(&rItem)->
37 GetEnumValue();
40 // virtual
41 bool SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit,
42 SfxMapUnit, OUString & rText,
43 const IntlWrapper *) const
45 rText = OUString::number( GetEnumValue() );
46 return true;
49 // virtual
50 bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8)
51 const
53 rVal <<= sal_Int32(GetEnumValue());
54 return true;
57 // virtual
58 bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal,
59 sal_uInt8)
61 sal_Int32 nTheValue = 0;
63 if ( ::cppu::enum2int( nTheValue, rVal ) )
65 SetEnumValue(sal_uInt16(nTheValue));
66 return true;
68 OSL_FAIL("SfxEnumItemInterface::PutValue(): Wrong type");
69 return false;
72 OUString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const
74 DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
75 return OUString();
78 // virtual
79 sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const
81 return nPos;
84 // virtual
85 sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const
87 sal_uInt16 nCount = GetValueCount();
88 for (sal_uInt16 i = 0; i < nCount; ++i)
89 if (GetValueByPos(i) == nValue)
90 return i;
91 return USHRT_MAX;
94 bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const
96 return true;
99 // virtual
100 bool SfxEnumItemInterface::HasBoolValue() const
102 return false;
105 // virtual
106 bool SfxEnumItemInterface::GetBoolValue() const
108 return false;
111 // virtual
112 void SfxEnumItemInterface::SetBoolValue(bool)
115 SfxEnumItem::SfxEnumItem(sal_uInt16 const nWhich, SvStream & rStream)
116 : SfxEnumItemInterface(nWhich)
118 m_nValue = 0;
119 rStream.ReadUInt16( m_nValue );
122 TYPEINIT1(SfxEnumItem, SfxEnumItemInterface)
124 // virtual
125 SvStream & SfxEnumItem::Store(SvStream & rStream, sal_uInt16) const
127 rStream.WriteUInt16( m_nValue );
128 return rStream;
131 // virtual
132 sal_uInt16 SfxEnumItem::GetEnumValue() const
134 return GetValue();
137 // virtual
138 void SfxEnumItem::SetEnumValue(sal_uInt16 const nTheValue)
140 SetValue(nTheValue);
143 void SfxEnumItem::SetValue(sal_uInt16 const nTheValue)
145 DBG_ASSERT(GetRefCount() == 0, "SfxEnumItem::SetValue(): Pooled item");
146 m_nValue = nTheValue;
149 TYPEINIT1_AUTOFACTORY(SfxBoolItem, SfxPoolItem);
151 SfxBoolItem::SfxBoolItem(sal_uInt16 const nWhich, SvStream & rStream)
152 : SfxPoolItem(nWhich)
154 bool tmp = false;
155 rStream.ReadCharAsBool( tmp );
156 m_bValue = tmp;
159 // virtual
160 bool SfxBoolItem::operator ==(const SfxPoolItem & rItem) const
162 DBG_ASSERT(rItem.ISA(SfxBoolItem),
163 "SfxBoolItem::operator ==(): Bad type");
164 return m_bValue == static_cast< SfxBoolItem const * >(&rItem)->m_bValue;
167 // virtual
168 int SfxBoolItem::Compare(const SfxPoolItem & rWith) const
170 DBG_ASSERT(rWith.ISA(SfxBoolItem), "SfxBoolItem::Compare(): Bad type");
171 return (m_bValue == static_cast<SfxBoolItem const*>(&rWith)->m_bValue) ?
172 0 : m_bValue ? -1 : 1;
175 // virtual
176 bool SfxBoolItem::GetPresentation(SfxItemPresentation,
177 SfxMapUnit, SfxMapUnit,
178 OUString & rText,
179 const IntlWrapper *) const
181 rText = GetValueTextByVal(m_bValue);
182 return true;
185 // virtual
186 bool SfxBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
188 rVal <<= m_bValue;
189 return true;
192 // virtual
193 bool SfxBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
195 bool bTheValue = bool();
196 if (rVal >>= bTheValue)
198 m_bValue = bTheValue;
199 return true;
201 OSL_FAIL("SfxBoolItem::PutValue(): Wrong type");
202 return false;
205 // virtual
206 SfxPoolItem * SfxBoolItem::Create(SvStream & rStream, sal_uInt16) const
208 return new SfxBoolItem(Which(), rStream);
211 // virtual
212 SvStream & SfxBoolItem::Store(SvStream & rStream, sal_uInt16) const
214 rStream.WriteBool( m_bValue ); // not bool for serialization!
215 return rStream;
218 // virtual
219 SfxPoolItem * SfxBoolItem::Clone(SfxItemPool *) const
221 return new SfxBoolItem(*this);
224 // virtual
225 OUString SfxBoolItem::GetValueTextByVal(bool bTheValue) const
227 return bTheValue ? OUString("TRUE") : OUString("FALSE");
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */