bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / accessibility / DescriptionGenerator.cxx
blob2a473ed40563669ea761c3027e129a44eb8fd299
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 <vcl/svapp.hxx>
28 // Includes for string resources.
29 #include <svx/strings.hrc>
30 #include <svx/dialmgr.hxx>
32 #include "lookupcolorname.hxx"
34 using namespace ::com::sun::star;
36 namespace accessibility
38 DescriptionGenerator::DescriptionGenerator(const uno::Reference<drawing::XShape>& xShape)
39 : mxShape(xShape)
40 , mxSet(mxShape, uno::UNO_QUERY)
41 , mbIsFirstProperty(true)
45 DescriptionGenerator::~DescriptionGenerator() {}
47 void DescriptionGenerator::Initialize(const char* pResourceId)
49 // Get the string from the resource for the specified id.
50 OUString sPrefix;
52 SolarMutexGuard aGuard;
53 sPrefix = SvxResId(pResourceId);
56 // Forward the call with the resulting string.
57 Initialize(sPrefix);
60 void DescriptionGenerator::Initialize(const OUString& sPrefix)
62 msDescription = sPrefix;
63 if (!mxSet.is())
64 return;
67 SolarMutexGuard aGuard;
69 msDescription.append(' ');
70 msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH));
71 msDescription.append(' ');
73 msDescription.append(SvxResId(RID_SVXSTR_A11Y_STYLE));
74 msDescription.append('=');
77 try
79 if (mxSet.is())
81 uno::Any aValue = mxSet->getPropertyValue("Style");
82 uno::Reference<container::XNamed> xStyle(aValue, uno::UNO_QUERY);
83 if (xStyle.is())
84 msDescription.append(xStyle->getName());
86 else
87 msDescription.append("<no style>");
89 catch (const css::beans::UnknownPropertyException&)
91 msDescription.append("<unknown>");
95 OUString DescriptionGenerator::operator()()
97 msDescription.append('.');
98 return msDescription.makeStringAndClear();
101 void DescriptionGenerator::AddProperty(const OUString& sPropertyName, PropertyType aType)
103 uno::Reference<beans::XPropertyState> xState(mxShape, uno::UNO_QUERY);
104 if (!xState.is()
105 || xState->getPropertyState(sPropertyName) == beans::PropertyState_DEFAULT_VALUE)
106 return;
108 if (!mxSet.is())
109 return;
111 // Append a separator from previous Properties.
112 if (!mbIsFirstProperty)
113 msDescription.append(',');
114 else
116 SolarMutexGuard aGuard;
118 msDescription.append(' ');
119 msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND));
120 msDescription.append(' ');
121 mbIsFirstProperty = false;
124 // Delegate to type specific property handling.
125 switch (aType)
127 case PropertyType::Color:
128 AddColor(sPropertyName);
129 break;
130 case PropertyType::Integer:
131 AddInteger(sPropertyName);
132 break;
136 void DescriptionGenerator::AppendString(std::u16string_view sString)
138 msDescription.append(sString);
141 /** Search for the given color in the global color table. If found append
142 its name to the description. Otherwise append its RGB tuple.
144 void DescriptionGenerator::AddColor(const OUString& sPropertyName)
146 msDescription.append('=');
150 tools::Long nValue(0);
151 if (mxSet.is())
153 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
154 aValue >>= nValue;
157 msDescription.append(lookUpColorName(nValue));
159 catch (const css::beans::UnknownPropertyException&)
161 msDescription.append("<unknown>");
165 void DescriptionGenerator::AddInteger(const OUString& sPropertyName)
167 msDescription.append('=');
171 if (mxSet.is())
173 uno::Any aValue = mxSet->getPropertyValue(sPropertyName);
174 tools::Long nValue = 0;
175 aValue >>= nValue;
176 msDescription.append(nValue);
179 catch (const css::beans::UnknownPropertyException&)
181 msDescription.append("<unknown>");
185 } // end of namespace accessibility
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */