1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
32 bool SfxEnumItemInterface::operator ==(const SfxPoolItem
& rItem
) const
34 SFX_ASSERT(SfxPoolItem::operator ==(rItem
), Which(), "unequal type");
36 == static_cast< const SfxEnumItemInterface
* >(&rItem
)->
41 bool SfxEnumItemInterface::GetPresentation(SfxItemPresentation
, SfxMapUnit
,
42 SfxMapUnit
, OUString
& rText
,
43 const IntlWrapper
*) const
45 rText
= OUString::number( GetEnumValue() );
50 bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any
& rVal
, sal_uInt8
)
53 rVal
<<= sal_Int32(GetEnumValue());
58 bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any
& rVal
,
61 sal_Int32 nTheValue
= 0;
63 if ( ::cppu::enum2int( nTheValue
, rVal
) )
65 SetEnumValue(sal_uInt16(nTheValue
));
68 OSL_FAIL("SfxEnumItemInterface::PutValue(): Wrong type");
72 OUString
SfxEnumItemInterface::GetValueTextByPos(sal_uInt16
) const
74 DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
79 sal_uInt16
SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos
) const
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
)
94 bool SfxEnumItemInterface::IsEnabled(sal_uInt16
) const
100 bool SfxEnumItemInterface::HasBoolValue() const
106 bool SfxEnumItemInterface::GetBoolValue() const
112 void SfxEnumItemInterface::SetBoolValue(bool)
115 SfxEnumItem::SfxEnumItem(sal_uInt16
const nWhich
, SvStream
& rStream
)
116 : SfxEnumItemInterface(nWhich
)
119 rStream
.ReadUInt16( m_nValue
);
122 TYPEINIT1(SfxEnumItem
, SfxEnumItemInterface
)
125 SvStream
& SfxEnumItem::Store(SvStream
& rStream
, sal_uInt16
) const
127 rStream
.WriteUInt16( m_nValue
);
132 sal_uInt16
SfxEnumItem::GetEnumValue() const
138 void SfxEnumItem::SetEnumValue(sal_uInt16
const 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
)
155 rStream
.ReadCharAsBool( tmp
);
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
;
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;
176 bool SfxBoolItem::GetPresentation(SfxItemPresentation
,
177 SfxMapUnit
, SfxMapUnit
,
179 const IntlWrapper
*) const
181 rText
= GetValueTextByVal(m_bValue
);
186 bool SfxBoolItem::QueryValue(com::sun::star::uno::Any
& rVal
, sal_uInt8
) const
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
;
201 OSL_FAIL("SfxBoolItem::PutValue(): Wrong type");
206 SfxPoolItem
* SfxBoolItem::Create(SvStream
& rStream
, sal_uInt16
) const
208 return new SfxBoolItem(Which(), rStream
);
212 SvStream
& SfxBoolItem::Store(SvStream
& rStream
, sal_uInt16
) const
214 rStream
.WriteBool( m_bValue
); // not bool for serialization!
219 SfxPoolItem
* SfxBoolItem::Clone(SfxItemPool
*) const
221 return new SfxBoolItem(*this);
225 OUString
SfxBoolItem::GetValueTextByVal(bool bTheValue
) const
227 return bTheValue
? OUString("TRUE") : OUString("FALSE");
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */