/src/libreoffice/svx/source/items/statusitem.cxx
Line | Count | Source |
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> |
12 | | #include <comphelper/propertyvalue.hxx> |
13 | | #include <svl/memberid.h> |
14 | | #include <svx/statusitem.hxx> |
15 | | |
16 | | constexpr OUString STATUS_PARAM_VALUE = u"Value"_ustr; |
17 | | constexpr OUString STATUS_PARAM_TYPE = u"Type"_ustr; |
18 | | constexpr int STATUS_PARAMS = 2; |
19 | | |
20 | | SvxStatusItem::SvxStatusItem(TypedWhichId<SvxStatusItem> nWhich, const OUString& rString, |
21 | | StatusCategory eCategory) |
22 | 0 | : SfxStringItem(nWhich, rString) |
23 | 0 | , m_eCategory(eCategory) |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | | bool SvxStatusItem::operator==(const SfxPoolItem& rItem) const |
28 | 0 | { |
29 | 0 | return SfxStringItem::operator==(rItem) |
30 | 0 | && static_cast<const SvxStatusItem&>(rItem).m_eCategory == m_eCategory; |
31 | 0 | } |
32 | | |
33 | | bool SvxStatusItem::QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId) const |
34 | 0 | { |
35 | 0 | nMemberId &= ~CONVERT_TWIPS; |
36 | |
|
37 | 0 | switch (nMemberId) |
38 | 0 | { |
39 | 0 | case 0: |
40 | 0 | { |
41 | 0 | css::uno::Sequence<css::beans::PropertyValue> aSeq{ |
42 | 0 | comphelper::makePropertyValue(STATUS_PARAM_VALUE, GetValue()), |
43 | 0 | comphelper::makePropertyValue(STATUS_PARAM_TYPE, |
44 | 0 | static_cast<sal_Int16>(m_eCategory)) |
45 | 0 | }; |
46 | 0 | assert(aSeq.getLength() == STATUS_PARAMS); |
47 | 0 | rVal <<= aSeq; |
48 | 0 | break; |
49 | 0 | } |
50 | 0 | case MID_VALUE: |
51 | 0 | rVal <<= GetValue(); |
52 | 0 | break; |
53 | 0 | case MID_TYPE: |
54 | 0 | rVal <<= static_cast<sal_Int16>(m_eCategory); |
55 | 0 | break; |
56 | 0 | default: |
57 | 0 | return false; |
58 | 0 | } |
59 | | |
60 | 0 | return true; |
61 | 0 | } |
62 | | |
63 | | bool SvxStatusItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) |
64 | 0 | { |
65 | 0 | nMemberId &= ~CONVERT_TWIPS; |
66 | 0 | bool bRet; |
67 | 0 | switch (nMemberId) |
68 | 0 | { |
69 | 0 | case 0: |
70 | 0 | { |
71 | 0 | css::uno::Sequence<css::beans::PropertyValue> aSeq; |
72 | 0 | if ((rVal >>= aSeq) && (aSeq.getLength() == STATUS_PARAMS)) |
73 | 0 | { |
74 | 0 | OUString sValueTmp; |
75 | 0 | sal_Int16 nTypeTmp(0); |
76 | 0 | bool bAllConverted(true); |
77 | 0 | sal_Int16 nConvertedCount(0); |
78 | 0 | for (const auto& rProp : aSeq) |
79 | 0 | { |
80 | 0 | if (rProp.Name == STATUS_PARAM_VALUE) |
81 | 0 | { |
82 | 0 | bAllConverted &= (rProp.Value >>= sValueTmp); |
83 | 0 | ++nConvertedCount; |
84 | 0 | } |
85 | 0 | else if (rProp.Name == STATUS_PARAM_TYPE) |
86 | 0 | { |
87 | 0 | bAllConverted &= (rProp.Value >>= nTypeTmp); |
88 | 0 | ++nConvertedCount; |
89 | 0 | } |
90 | 0 | } |
91 | |
|
92 | 0 | if (bAllConverted && nConvertedCount == STATUS_PARAMS) |
93 | 0 | { |
94 | 0 | SetValue(sValueTmp); |
95 | 0 | m_eCategory = static_cast<StatusCategory>(nTypeTmp); |
96 | 0 | return true; |
97 | 0 | } |
98 | 0 | } |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | case MID_TYPE: |
102 | 0 | { |
103 | 0 | sal_Int16 nCategory; |
104 | 0 | bRet = (rVal >>= nCategory); |
105 | 0 | if (bRet) |
106 | 0 | m_eCategory = static_cast<StatusCategory>(nCategory); |
107 | 0 | break; |
108 | 0 | } |
109 | 0 | case MID_VALUE: |
110 | 0 | { |
111 | 0 | OUString aStr; |
112 | 0 | bRet = (rVal >>= aStr); |
113 | 0 | if (bRet) |
114 | 0 | SetValue(aStr); |
115 | 0 | break; |
116 | 0 | } |
117 | 0 | default: |
118 | 0 | return false; |
119 | 0 | } |
120 | | |
121 | 0 | return bRet; |
122 | 0 | } |
123 | | |
124 | | SvxStatusItem* SvxStatusItem::Clone(SfxItemPool* /*pPool*/) const |
125 | 0 | { |
126 | 0 | return new SvxStatusItem(*this); |
127 | 0 | } |
128 | | |
129 | | SfxPoolItem* SvxStatusItem::CreateDefault() |
130 | 0 | { |
131 | 0 | return new SvxStatusItem(TypedWhichId<SvxStatusItem>(0), OUString(), StatusCategory::NONE); |
132 | 0 | } |
133 | | |
134 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |