/src/libreoffice/svx/source/accessibility/DescriptionGenerator.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <DescriptionGenerator.hxx> |
21 | | #include <com/sun/star/beans/PropertyState.hpp> |
22 | | #include <com/sun/star/beans/XPropertySet.hpp> |
23 | | #include <com/sun/star/beans/XPropertyState.hpp> |
24 | | #include <com/sun/star/container/XNamed.hpp> |
25 | | #include <com/sun/star/drawing/XShape.hpp> |
26 | | #include <utility> |
27 | | #include <vcl/svapp.hxx> |
28 | | |
29 | | // Includes for string resources. |
30 | | #include <svx/strings.hrc> |
31 | | #include <svx/dialmgr.hxx> |
32 | | |
33 | | #include "lookupcolorname.hxx" |
34 | | |
35 | | using namespace ::com::sun::star; |
36 | | |
37 | | namespace accessibility |
38 | | { |
39 | | DescriptionGenerator::DescriptionGenerator(uno::Reference<drawing::XShape> xShape) |
40 | 0 | : mxShape(std::move(xShape)) |
41 | 0 | , mxSet(mxShape, uno::UNO_QUERY) |
42 | 0 | , mbIsFirstProperty(true) |
43 | 0 | { |
44 | 0 | } |
45 | | |
46 | 0 | DescriptionGenerator::~DescriptionGenerator() {} |
47 | | |
48 | | void DescriptionGenerator::Initialize(TranslateId pResourceId) |
49 | 0 | { |
50 | | // Get the string from the resource for the specified id. |
51 | 0 | OUString sPrefix; |
52 | 0 | { |
53 | 0 | SolarMutexGuard aGuard; |
54 | 0 | sPrefix = SvxResId(pResourceId); |
55 | 0 | } |
56 | | |
57 | | // Forward the call with the resulting string. |
58 | 0 | Initialize(sPrefix); |
59 | 0 | } |
60 | | |
61 | | void DescriptionGenerator::Initialize(std::u16string_view sPrefix) |
62 | 0 | { |
63 | 0 | msDescription = sPrefix; |
64 | 0 | if (!mxSet.is()) |
65 | 0 | return; |
66 | | |
67 | 0 | { |
68 | 0 | SolarMutexGuard aGuard; |
69 | |
|
70 | 0 | msDescription.append(' '); |
71 | 0 | msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH)); |
72 | 0 | msDescription.append(' '); |
73 | |
|
74 | 0 | msDescription.append(SvxResId(RID_SVXSTR_A11Y_STYLE)); |
75 | 0 | msDescription.append('='); |
76 | 0 | } |
77 | |
|
78 | 0 | try |
79 | 0 | { |
80 | 0 | if (mxSet.is()) |
81 | 0 | { |
82 | 0 | uno::Any aValue = mxSet->getPropertyValue(u"Style"_ustr); |
83 | 0 | uno::Reference<container::XNamed> xStyle(aValue, uno::UNO_QUERY); |
84 | 0 | if (xStyle.is()) |
85 | 0 | msDescription.append(xStyle->getName()); |
86 | 0 | } |
87 | 0 | else |
88 | 0 | msDescription.append("<no style>"); |
89 | 0 | } |
90 | 0 | catch (const css::beans::UnknownPropertyException&) |
91 | 0 | { |
92 | 0 | msDescription.append("<unknown>"); |
93 | 0 | } |
94 | 0 | } |
95 | | |
96 | | OUString DescriptionGenerator::operator()() |
97 | 0 | { |
98 | 0 | msDescription.append('.'); |
99 | 0 | return msDescription.makeStringAndClear(); |
100 | 0 | } |
101 | | |
102 | | void DescriptionGenerator::AddProperty(const OUString& sPropertyName, PropertyType aType) |
103 | 0 | { |
104 | 0 | uno::Reference<beans::XPropertyState> xState(mxShape, uno::UNO_QUERY); |
105 | 0 | if (!xState.is() |
106 | 0 | || xState->getPropertyState(sPropertyName) == beans::PropertyState_DEFAULT_VALUE) |
107 | 0 | return; |
108 | | |
109 | 0 | if (!mxSet.is()) |
110 | 0 | return; |
111 | | |
112 | | // Append a separator from previous Properties. |
113 | 0 | if (!mbIsFirstProperty) |
114 | 0 | msDescription.append(','); |
115 | 0 | else |
116 | 0 | { |
117 | 0 | SolarMutexGuard aGuard; |
118 | |
|
119 | 0 | msDescription.append(' '); |
120 | 0 | msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND)); |
121 | 0 | msDescription.append(' '); |
122 | 0 | mbIsFirstProperty = false; |
123 | 0 | } |
124 | | |
125 | | // Delegate to type specific property handling. |
126 | 0 | switch (aType) |
127 | 0 | { |
128 | 0 | case PropertyType::Color: |
129 | 0 | AddColor(sPropertyName); |
130 | 0 | break; |
131 | 0 | case PropertyType::Integer: |
132 | 0 | AddInteger(sPropertyName); |
133 | 0 | break; |
134 | 0 | } |
135 | 0 | } |
136 | | |
137 | | void DescriptionGenerator::AppendString(std::u16string_view sString) |
138 | 0 | { |
139 | 0 | msDescription.append(sString); |
140 | 0 | } |
141 | | |
142 | | /** Search for the given color in the global color table. If found append |
143 | | its name to the description. Otherwise append its RGB tuple. |
144 | | */ |
145 | | void DescriptionGenerator::AddColor(const OUString& sPropertyName) |
146 | 0 | { |
147 | 0 | msDescription.append('='); |
148 | |
|
149 | 0 | try |
150 | 0 | { |
151 | 0 | tools::Long nValue(0); |
152 | 0 | if (mxSet.is()) |
153 | 0 | { |
154 | 0 | uno::Any aValue = mxSet->getPropertyValue(sPropertyName); |
155 | 0 | aValue >>= nValue; |
156 | 0 | } |
157 | |
|
158 | 0 | msDescription.append(lookUpColorName(nValue)); |
159 | 0 | } |
160 | 0 | catch (const css::beans::UnknownPropertyException&) |
161 | 0 | { |
162 | 0 | msDescription.append("<unknown>"); |
163 | 0 | } |
164 | 0 | } |
165 | | |
166 | | void DescriptionGenerator::AddInteger(const OUString& sPropertyName) |
167 | 0 | { |
168 | 0 | msDescription.append('='); |
169 | |
|
170 | 0 | try |
171 | 0 | { |
172 | 0 | if (mxSet.is()) |
173 | 0 | { |
174 | 0 | uno::Any aValue = mxSet->getPropertyValue(sPropertyName); |
175 | 0 | tools::Long nValue = 0; |
176 | 0 | aValue >>= nValue; |
177 | 0 | msDescription.append(nValue); |
178 | 0 | } |
179 | 0 | } |
180 | 0 | catch (const css::beans::UnknownPropertyException&) |
181 | 0 | { |
182 | 0 | msDescription.append("<unknown>"); |
183 | 0 | } |
184 | 0 | } |
185 | | |
186 | | } // end of namespace accessibility |
187 | | |
188 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |