1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <com/sun/star/uno/Sequence.hxx>
11 #include <com/sun/star/beans/PropertyValue.hpp>
12 #include <comphelper/propertyvalue.hxx>
13 #include <svl/memberid.h>
14 #include <svx/statusitem.hxx>
16 constexpr OUStringLiteral STATUS_PARAM_VALUE
= u
"Value";
17 constexpr OUStringLiteral STATUS_PARAM_TYPE
= u
"Type";
18 constexpr int STATUS_PARAMS
= 2;
20 SvxStatusItem::SvxStatusItem(TypedWhichId
<SvxStatusItem
> nWhich
, const OUString
& rString
,
21 StatusCategory eCategory
)
22 : SfxStringItem(nWhich
, rString
)
23 , m_eCategory(eCategory
)
27 bool SvxStatusItem::operator==(const SfxPoolItem
& rItem
) const
29 return SfxStringItem::operator==(rItem
)
30 && static_cast<const SvxStatusItem
&>(rItem
).m_eCategory
== m_eCategory
;
33 bool SvxStatusItem::QueryValue(css::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
35 nMemberId
&= ~CONVERT_TWIPS
;
41 css::uno::Sequence
<css::beans::PropertyValue
> aSeq
{
42 comphelper::makePropertyValue(STATUS_PARAM_VALUE
, GetValue()),
43 comphelper::makePropertyValue(STATUS_PARAM_TYPE
,
44 static_cast<sal_Int16
>(m_eCategory
))
46 assert(aSeq
.getLength() == STATUS_PARAMS
);
54 rVal
<<= static_cast<sal_Int16
>(m_eCategory
);
63 bool SvxStatusItem::PutValue(const css::uno::Any
& rVal
, sal_uInt8 nMemberId
)
65 nMemberId
&= ~CONVERT_TWIPS
;
71 css::uno::Sequence
<css::beans::PropertyValue
> aSeq
;
72 if ((rVal
>>= aSeq
) && (aSeq
.getLength() == STATUS_PARAMS
))
75 sal_Int16
nTypeTmp(0);
76 bool bAllConverted(true);
77 sal_Int16
nConvertedCount(0);
78 for (const auto& rProp
: std::as_const(aSeq
))
80 if (rProp
.Name
== STATUS_PARAM_VALUE
)
82 bAllConverted
&= (rProp
.Value
>>= sValueTmp
);
85 else if (rProp
.Name
== STATUS_PARAM_TYPE
)
87 bAllConverted
&= (rProp
.Value
>>= nTypeTmp
);
92 if (bAllConverted
&& nConvertedCount
== STATUS_PARAMS
)
95 m_eCategory
= static_cast<StatusCategory
>(nTypeTmp
);
104 bRet
= (rVal
>>= nCategory
);
106 m_eCategory
= static_cast<StatusCategory
>(nCategory
);
112 bRet
= (rVal
>>= aStr
);
124 SvxStatusItem
* SvxStatusItem::Clone(SfxItemPool
* /*pPool*/) const
126 return new SvxStatusItem(*this);
129 SfxPoolItem
* SvxStatusItem::CreateDefault()
131 return new SvxStatusItem(TypedWhichId
<SvxStatusItem
>(0), OUString(), StatusCategory::NONE
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */