LibreOffice Module svx (master) 1
statusitem.cxx
Go to the documentation of this file.
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.
4 *
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 */
9
10#include <com/sun/star/uno/Sequence.hxx>
11#include <com/sun/star/beans/PropertyValue.hpp>
13#include <svl/memberid.h>
14#include <svx/statusitem.hxx>
15
16constexpr OUStringLiteral STATUS_PARAM_VALUE = u"Value";
17constexpr OUStringLiteral STATUS_PARAM_TYPE = u"Type";
18constexpr int STATUS_PARAMS = 2;
19
21 StatusCategory eCategory)
22 : SfxStringItem(nWhich, rString)
23 , m_eCategory(eCategory)
24{
25}
26
27bool SvxStatusItem::operator==(const SfxPoolItem& rItem) const
28{
29 return SfxStringItem::operator==(rItem)
30 && static_cast<const SvxStatusItem&>(rItem).m_eCategory == m_eCategory;
31}
32
33bool SvxStatusItem::QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId) const
34{
35 nMemberId &= ~CONVERT_TWIPS;
36
37 switch (nMemberId)
38 {
39 case 0:
40 {
41 css::uno::Sequence<css::beans::PropertyValue> aSeq{
44 static_cast<sal_Int16>(m_eCategory))
45 };
46 assert(aSeq.getLength() == STATUS_PARAMS);
47 rVal <<= aSeq;
48 break;
49 }
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;
58 }
59
60 return true;
61}
62
63bool SvxStatusItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId)
64{
65 nMemberId &= ~CONVERT_TWIPS;
66 bool bRet;
67 switch (nMemberId)
68 {
69 case 0:
70 {
71 css::uno::Sequence<css::beans::PropertyValue> aSeq;
72 if ((rVal >>= aSeq) && (aSeq.getLength() == STATUS_PARAMS))
73 {
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))
79 {
80 if (rProp.Name == STATUS_PARAM_VALUE)
81 {
82 bAllConverted &= (rProp.Value >>= sValueTmp);
83 ++nConvertedCount;
84 }
85 else if (rProp.Name == STATUS_PARAM_TYPE)
86 {
87 bAllConverted &= (rProp.Value >>= nTypeTmp);
88 ++nConvertedCount;
89 }
90 }
91
92 if (bAllConverted && nConvertedCount == STATUS_PARAMS)
93 {
94 SetValue(sValueTmp);
95 m_eCategory = static_cast<StatusCategory>(nTypeTmp);
96 return true;
97 }
98 }
99 return false;
100 }
101 case MID_TYPE:
102 {
103 sal_Int16 nCategory;
104 bRet = (rVal >>= nCategory);
105 if (bRet)
106 m_eCategory = static_cast<StatusCategory>(nCategory);
107 break;
108 }
109 case MID_VALUE:
110 {
111 OUString aStr;
112 bRet = (rVal >>= aStr);
113 if (bRet)
114 SetValue(aStr);
115 break;
116 }
117 default:
118 return false;
119 }
120
121 return bRet;
122}
123
125{
126 return new SvxStatusItem(*this);
127}
128
130{
132}
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
const OUString & GetValue() const
virtual bool operator==(const SfxPoolItem &rItem) const override
void SetValue(const OUString &rTheValue)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: statusitem.cxx:33
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: statusitem.cxx:63
StatusCategory m_eCategory
Definition: statusitem.hxx:29
virtual SvxStatusItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: statusitem.cxx:124
static SfxPoolItem * CreateDefault()
Definition: statusitem.cxx:129
SvxStatusItem(TypedWhichId< SvxStatusItem > nWhich, const OUString &rString, StatusCategory eStatusCategory)
Definition: statusitem.cxx:20
virtual bool operator==(const SfxPoolItem &rItem) const override
Definition: statusitem.cxx:27
float u
Sequence< sal_Int8 > aSeq
#define MID_TYPE
#define MID_VALUE
aStr
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral STATUS_PARAM_TYPE
Definition: statusitem.cxx:17
constexpr OUStringLiteral STATUS_PARAM_VALUE
Definition: statusitem.cxx:16
constexpr int STATUS_PARAMS
Definition: statusitem.cxx:18
StatusCategory
Definition: statusitem.hxx:15
unsigned char sal_uInt8