1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <vcl/svapp.hxx>
29 // Includes for string resources.
30 #include <svx/strings.hrc>
31 #include <svx/dialmgr.hxx>
33 #include "lookupcolorname.hxx"
35 using namespace ::com::sun::star
;
37 namespace accessibility
39 DescriptionGenerator::DescriptionGenerator(uno::Reference
<drawing::XShape
> xShape
)
40 : mxShape(std::move(xShape
))
41 , mxSet(mxShape
, uno::UNO_QUERY
)
42 , mbIsFirstProperty(true)
46 DescriptionGenerator::~DescriptionGenerator() {}
48 void DescriptionGenerator::Initialize(TranslateId pResourceId
)
50 // Get the string from the resource for the specified id.
53 SolarMutexGuard aGuard
;
54 sPrefix
= SvxResId(pResourceId
);
57 // Forward the call with the resulting string.
61 void DescriptionGenerator::Initialize(std::u16string_view sPrefix
)
63 msDescription
= sPrefix
;
68 SolarMutexGuard aGuard
;
70 msDescription
.append(' ');
71 msDescription
.append(SvxResId(RID_SVXSTR_A11Y_WITH
));
72 msDescription
.append(' ');
74 msDescription
.append(SvxResId(RID_SVXSTR_A11Y_STYLE
));
75 msDescription
.append('=');
82 uno::Any aValue
= mxSet
->getPropertyValue(u
"Style"_ustr
);
83 uno::Reference
<container::XNamed
> xStyle(aValue
, uno::UNO_QUERY
);
85 msDescription
.append(xStyle
->getName());
88 msDescription
.append("<no style>");
90 catch (const css::beans::UnknownPropertyException
&)
92 msDescription
.append("<unknown>");
96 OUString
DescriptionGenerator::operator()()
98 msDescription
.append('.');
99 return msDescription
.makeStringAndClear();
102 void DescriptionGenerator::AddProperty(const OUString
& sPropertyName
, PropertyType aType
)
104 uno::Reference
<beans::XPropertyState
> xState(mxShape
, uno::UNO_QUERY
);
106 || xState
->getPropertyState(sPropertyName
) == beans::PropertyState_DEFAULT_VALUE
)
112 // Append a separator from previous Properties.
113 if (!mbIsFirstProperty
)
114 msDescription
.append(',');
117 SolarMutexGuard aGuard
;
119 msDescription
.append(' ');
120 msDescription
.append(SvxResId(RID_SVXSTR_A11Y_AND
));
121 msDescription
.append(' ');
122 mbIsFirstProperty
= false;
125 // Delegate to type specific property handling.
128 case PropertyType::Color
:
129 AddColor(sPropertyName
);
131 case PropertyType::Integer
:
132 AddInteger(sPropertyName
);
137 void DescriptionGenerator::AppendString(std::u16string_view sString
)
139 msDescription
.append(sString
);
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.
145 void DescriptionGenerator::AddColor(const OUString
& sPropertyName
)
147 msDescription
.append('=');
151 tools::Long
nValue(0);
154 uno::Any aValue
= mxSet
->getPropertyValue(sPropertyName
);
158 msDescription
.append(lookUpColorName(nValue
));
160 catch (const css::beans::UnknownPropertyException
&)
162 msDescription
.append("<unknown>");
166 void DescriptionGenerator::AddInteger(const OUString
& sPropertyName
)
168 msDescription
.append('=');
174 uno::Any aValue
= mxSet
->getPropertyValue(sPropertyName
);
175 tools::Long nValue
= 0;
177 msDescription
.append(nValue
);
180 catch (const css::beans::UnknownPropertyException
&)
182 msDescription
.append("<unknown>");
186 } // end of namespace accessibility
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */