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>
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
)
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.
52 SolarMutexGuard aGuard
;
53 sPrefix
= SvxResId(pResourceId
);
56 // Forward the call with the resulting string.
60 void DescriptionGenerator::Initialize(const OUString
& sPrefix
)
62 msDescription
= sPrefix
;
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('=');
81 uno::Any aValue
= mxSet
->getPropertyValue("Style");
82 uno::Reference
<container::XNamed
> xStyle(aValue
, uno::UNO_QUERY
);
84 msDescription
.append(xStyle
->getName());
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
);
105 || xState
->getPropertyState(sPropertyName
) == beans::PropertyState_DEFAULT_VALUE
)
111 // Append a separator from previous Properties.
112 if (!mbIsFirstProperty
)
113 msDescription
.append(',');
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.
127 case PropertyType::Color
:
128 AddColor(sPropertyName
);
130 case PropertyType::Integer
:
131 AddInteger(sPropertyName
);
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);
153 uno::Any aValue
= mxSet
->getPropertyValue(sPropertyName
);
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('=');
173 uno::Any aValue
= mxSet
->getPropertyValue(sPropertyName
);
174 tools::Long nValue
= 0;
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: */