tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / svx / source / accessibility / DescriptionGenerator.cxx
blob3bb2a2db0dea290bd6cf29b3ea1164f6caf421ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <utility>
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.
51 OUString sPrefix;
53 SolarMutexGuard aGuard;
54 sPrefix = SvxResId(pResourceId);
57 // Forward the call with the resulting string.
58 Initialize(sPrefix);
61 void DescriptionGenerator::Initialize(std::u16string_view sPrefix)
63 msDescription = sPrefix;
64 if (!mxSet.is())
65 return;
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('=');
78 try
80 if (mxSet.is())
82 uno::Any aValue = mxSet->getPropertyValue(u"Style"_ustr);
83 uno::Reference<container::XNamed> xStyle(aValue, uno::UNO_QUERY);
84 if (xStyle.is())
85 msDescription.append(xStyle->getName());
87 else
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);
105 if (!xState.is()
106 || xState->getPropertyState(sPropertyName) == beans::PropertyState_DEFAULT_VALUE)
107 return;
109 if (!mxSet.is())
110 return;
112 // Append a separator from previous Properties.
113 if (!mbIsFirstProperty)
114 msDescription.append(',');
115 else
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.
126 switch (aType)
128 case PropertyType::Color:
129 AddColor(sPropertyName);
130 break;
131 case PropertyType::Integer:
132 AddInteger(sPropertyName);
133 break;
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);
152 if (mxSet.is())
154 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
155 aValue >>= nValue;
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('=');
172 if (mxSet.is())
174 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
175 tools::Long nValue = 0;
176 aValue >>= nValue;
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: */