Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / statusitem.cxx
blob3b326f39ebe00fb6bfddc59c2ff5ac66536f8e60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
8 */
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;
37 switch (nMemberId)
39 case 0:
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);
47 rVal <<= aSeq;
48 break;
50 case MID_VALUE:
51 rVal <<= GetValue();
52 break;
53 case MID_TYPE:
54 rVal <<= static_cast<sal_Int16>(m_eCategory);
55 break;
56 default:
57 return false;
60 return true;
63 bool SvxStatusItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId)
65 nMemberId &= ~CONVERT_TWIPS;
66 bool bRet;
67 switch (nMemberId)
69 case 0:
71 css::uno::Sequence<css::beans::PropertyValue> aSeq;
72 if ((rVal >>= aSeq) && (aSeq.getLength() == STATUS_PARAMS))
74 OUString sValueTmp;
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);
83 ++nConvertedCount;
85 else if (rProp.Name == STATUS_PARAM_TYPE)
87 bAllConverted &= (rProp.Value >>= nTypeTmp);
88 ++nConvertedCount;
92 if (bAllConverted && nConvertedCount == STATUS_PARAMS)
94 SetValue(sValueTmp);
95 m_eCategory = static_cast<StatusCategory>(nTypeTmp);
96 return true;
99 return false;
101 case MID_TYPE:
103 sal_Int16 nCategory;
104 bRet = (rVal >>= nCategory);
105 if (bRet)
106 m_eCategory = static_cast<StatusCategory>(nCategory);
107 break;
109 case MID_VALUE:
111 OUString aStr;
112 bRet = (rVal >>= aStr);
113 if (bRet)
114 SetValue(aStr);
115 break;
117 default:
118 return false;
121 return bRet;
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: */