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 
20 
22 #include <com/sun/star/beans/PropertyState.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/XPropertyState.hpp>
25 #include <com/sun/star/container/XChild.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XNamed.hpp>
29 #include <com/sun/star/drawing/FillStyle.hpp>
30 #include <com/sun/star/drawing/XShapes.hpp>
31 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
32 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <vcl/svapp.hxx>
36 
37 #include <com/sun/star/uno/Exception.hpp>
38 
39 // Includes for string resources.
40 #include <svx/strings.hrc>
41 #include <svx/dialmgr.hxx>
42 
43 #include <svx/xdef.hxx>
44 #include <svx/unoapi.hxx>
45 #include "lookupcolorname.hxx"
46 
47 using namespace ::com::sun::star;
48 
49 
50 namespace accessibility {
51 
52 
54  const uno::Reference<drawing::XShape>& xShape)
55  : mxShape (xShape),
56  mxSet (mxShape, uno::UNO_QUERY),
57  mbIsFirstProperty (true)
58 {
59 }
60 
61 
63 {
64 }
65 
66 
67 void DescriptionGenerator::Initialize(const char* pResourceId)
68 {
69  // Get the string from the resource for the specified id.
70  OUString sPrefix;
71  {
72  SolarMutexGuard aGuard;
73  sPrefix = SvxResId(pResourceId);
74  }
75 
76  // Forward the call with the resulting string.
77  Initialize (sPrefix);
78 }
79 
80 
82 {
84  if (mxSet.is())
85  {
86  {
87  SolarMutexGuard aGuard;
88 
89  msDescription.append(' ');
90  msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH));
91  msDescription.append(' ');
92 
93  msDescription.append(SvxResId (RID_SVXSTR_A11Y_STYLE));
94  msDescription.append('=');
95  }
96 
97  try
98  {
99  if (mxSet.is())
100  {
101  uno::Any aValue = mxSet->getPropertyValue ("Style");
102  uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
103  if (xStyle.is())
104  msDescription.append (xStyle->getName());
105  }
106  else
107  msDescription.append ("<no style>");
108  }
109  catch (const css::beans::UnknownPropertyException &)
110  {
111  msDescription.append ("<unknown>");
112  }
113  }
114 }
115 
116 
118 {
119  msDescription.append('.');
120  return msDescription.makeStringAndClear();
121 }
122 
123 
124 void DescriptionGenerator::AddProperty (const OUString& sPropertyName,
125  PropertyType aType)
126 {
127  uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY);
128  if (xState.is()
129  && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
130  if (mxSet.is())
131  {
132  // Append a separator from previous Properties.
133  if ( ! mbIsFirstProperty)
134  msDescription.append(',');
135  else
136  {
137  SolarMutexGuard aGuard;
138 
139  msDescription.append(' ');
140  msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND));
141  msDescription.append(' ');
142  mbIsFirstProperty = false;
143  }
144 
145  // Delegate to type specific property handling.
146  switch (aType)
147  {
148  case PropertyType::Color:
149  AddColor (sPropertyName, "");
150  break;
152  AddInteger (sPropertyName, "");
153  break;
154  }
155  }
156 }
157 
158 
159 void DescriptionGenerator::AppendString (const OUString& sString)
160 {
161  msDescription.append (sString);
162 }
163 
164 
168 void DescriptionGenerator::AddColor (const OUString& sPropertyName,
169  const OUString& sLocalizedName)
170 {
171  msDescription.append(sLocalizedName);
172  msDescription.append('=');
173 
174  try
175  {
176 
177  long nValue(0);
178  if (mxSet.is())
179  {
180  uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
181  aValue >>= nValue;
182  }
183 
184  msDescription.append (lookUpColorName(nValue));
185  }
186  catch (const css::beans::UnknownPropertyException &)
187  {
188  msDescription.append ("<unknown>");
189  }
190 }
191 
192 
193 void DescriptionGenerator::AddInteger (const OUString& sPropertyName,
194  const OUString& sLocalizedName)
195 {
196  msDescription.append(sLocalizedName);
197  msDescription.append('=');
198 
199  try
200  {
201  if (mxSet.is())
202  {
203  uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
204  long nValue = 0;
205  aValue >>= nValue;
206  msDescription.append (nValue);
207  }
208  }
209  catch (const css::beans::UnknownPropertyException &)
210  {
211  msDescription.append ("<unknown>");
212  }
213 }
214 
215 } // end of namespace accessibility
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUStringBuffer msDescription
The description string that is build.
uno::Reference< drawing::XShape > const mxShape
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
void AddColor(const OUString &sPropertyName, const OUString &sLocalizedName)
Add a property value formatted as color to the description string.
OUString sPrefix
css::uno::Reference< css::beans::XPropertySet > mxSet
Reference to the shape's property set.
OUString operator()(void)
Returns the description string and then resets it.
void Initialize(const OUString &sPrefix)
Initialize the description with the given prefix followed by the shape style in parentheses and a col...
bool mbIsFirstProperty
This flag is used to determine whether to insert a separator e.g.
css::uno::Reference< css::drawing::XShape > mxShape
Reference to the shape from which the properties are extracted.
OUString lookUpColorName(long color)
This is a color name lookup targeted to be used by the accessibility DescriptionGenerator
DescriptionGenerator(const css::uno::Reference< css::drawing::XShape > &xShape)
Creates a new description generator with an empty description string.
void AppendString(const OUString &sString)
Append the given string as is to the current description.
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, const OUString &sLocalizedName)
Add a property value formatted as integer to the description string.