LibreOffice Module svx (master) 1
DescriptionGenerator.cxx
Go to the documentation of this file.
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
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
35using namespace ::com::sun::star;
36
37namespace accessibility
38{
39DescriptionGenerator::DescriptionGenerator(uno::Reference<drawing::XShape> xShape)
40 : mxShape(std::move(xShape))
41 , mxSet(mxShape, uno::UNO_QUERY)
42 , mbIsFirstProperty(true)
43{
44}
45
47
49{
50 // Get the string from the resource for the specified id.
51 OUString sPrefix;
52 {
53 SolarMutexGuard aGuard;
54 sPrefix = SvxResId(pResourceId);
55 }
56
57 // Forward the call with the resulting string.
59}
60
62{
64 if (!mxSet.is())
65 return;
66
67 {
68 SolarMutexGuard aGuard;
69
70 msDescription.append(' ');
71 msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH));
72 msDescription.append(' ');
73
74 msDescription.append(SvxResId(RID_SVXSTR_A11Y_STYLE));
75 msDescription.append('=');
76 }
77
78 try
79 {
80 if (mxSet.is())
81 {
82 uno::Any aValue = mxSet->getPropertyValue("Style");
83 uno::Reference<container::XNamed> xStyle(aValue, uno::UNO_QUERY);
84 if (xStyle.is())
85 msDescription.append(xStyle->getName());
86 }
87 else
88 msDescription.append("<no style>");
89 }
90 catch (const css::beans::UnknownPropertyException&)
91 {
92 msDescription.append("<unknown>");
93 }
94}
95
97{
98 msDescription.append('.');
99 return msDescription.makeStringAndClear();
100}
101
102void DescriptionGenerator::AddProperty(const OUString& sPropertyName, PropertyType aType)
103{
104 uno::Reference<beans::XPropertyState> xState(mxShape, uno::UNO_QUERY);
105 if (!xState.is()
106 || xState->getPropertyState(sPropertyName) == beans::PropertyState_DEFAULT_VALUE)
107 return;
108
109 if (!mxSet.is())
110 return;
111
112 // Append a separator from previous Properties.
114 msDescription.append(',');
115 else
116 {
117 SolarMutexGuard aGuard;
118
119 msDescription.append(' ');
120 msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND));
121 msDescription.append(' ');
122 mbIsFirstProperty = false;
123 }
124
125 // Delegate to type specific property handling.
126 switch (aType)
127 {
129 AddColor(sPropertyName);
130 break;
132 AddInteger(sPropertyName);
133 break;
134 }
135}
136
137void DescriptionGenerator::AppendString(std::u16string_view sString)
138{
139 msDescription.append(sString);
140}
141
145void DescriptionGenerator::AddColor(const OUString& sPropertyName)
146{
147 msDescription.append('=');
148
149 try
150 {
152 if (mxSet.is())
153 {
154 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
155 aValue >>= nValue;
156 }
157
159 }
160 catch (const css::beans::UnknownPropertyException&)
161 {
162 msDescription.append("<unknown>");
163 }
164}
165
166void DescriptionGenerator::AddInteger(const OUString& sPropertyName)
167{
168 msDescription.append('=');
169
170 try
171 {
172 if (mxSet.is())
173 {
174 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
176 aValue >>= nValue;
177 msDescription.append(nValue);
178 }
179 }
180 catch (const css::beans::UnknownPropertyException&)
181 {
182 msDescription.append("<unknown>");
183 }
184}
185
186} // end of namespace accessibility
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddProperty(const OUString &sPropertyName, PropertyType aType)
Add the given property name and its associated value to the description string.
void AddInteger(const OUString &sPropertyName)
Add a property value formatted as integer to the description string.
void Initialize(std::u16string_view sPrefix)
Initialize the description with the given prefix followed by the shape style in parentheses and a col...
OUStringBuffer msDescription
The description string that is build.
css::uno::Reference< css::drawing::XShape > mxShape
Reference to the shape from which the properties are extracted.
void AddColor(const OUString &sPropertyName)
Add a property value formatted as color to the description string.
css::uno::Reference< css::beans::XPropertySet > mxSet
Reference to the shape's property set.
bool mbIsFirstProperty
This flag is used to determine whether to insert a separator e.g.
OUString operator()(void)
Returns the description string and then resets it.
DescriptionGenerator(css::uno::Reference< css::drawing::XShape > xShape)
Creates a new description generator with an empty description string.
void AppendString(std::u16string_view sString)
Append the given string as is to the current description.
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
OUString sPrefix
OUString lookUpColorName(tools::Long color)
This is a color name lookup targeted to be used by the accessibility <type>DescriptionGenerator</type...
long Long
uno::Reference< drawing::XShape > const mxShape