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 
21 #include <DescriptionGenerator.hxx>
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/XNamed.hpp>
26 #include <vcl/svapp.hxx>
27 
28 // Includes for string resources.
29 #include <svx/strings.hrc>
30 #include <svx/dialmgr.hxx>
31 
32 #include "lookupcolorname.hxx"
33 
34 using namespace ::com::sun::star;
35 
36 
37 namespace accessibility {
38 
39 
41  const uno::Reference<drawing::XShape>& xShape)
42  : mxShape (xShape),
43  mxSet (mxShape, uno::UNO_QUERY),
44  mbIsFirstProperty (true)
45 {
46 }
47 
48 
50 {
51 }
52 
53 
54 void DescriptionGenerator::Initialize(const char* pResourceId)
55 {
56  // Get the string from the resource for the specified id.
57  OUString sPrefix;
58  {
59  SolarMutexGuard aGuard;
60  sPrefix = SvxResId(pResourceId);
61  }
62 
63  // Forward the call with the resulting string.
64  Initialize (sPrefix);
65 }
66 
67 
69 {
71  if (mxSet.is())
72  {
73  {
74  SolarMutexGuard aGuard;
75 
76  msDescription.append(' ');
77  msDescription.append(SvxResId(RID_SVXSTR_A11Y_WITH));
78  msDescription.append(' ');
79 
80  msDescription.append(SvxResId (RID_SVXSTR_A11Y_STYLE));
81  msDescription.append('=');
82  }
83 
84  try
85  {
86  if (mxSet.is())
87  {
88  uno::Any aValue = mxSet->getPropertyValue ("Style");
89  uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
90  if (xStyle.is())
91  msDescription.append (xStyle->getName());
92  }
93  else
94  msDescription.append ("<no style>");
95  }
96  catch (const css::beans::UnknownPropertyException &)
97  {
98  msDescription.append ("<unknown>");
99  }
100  }
101 }
102 
103 
105 {
106  msDescription.append('.');
107  return msDescription.makeStringAndClear();
108 }
109 
110 
111 void DescriptionGenerator::AddProperty (const OUString& sPropertyName,
112  PropertyType aType)
113 {
114  uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY);
115  if (xState.is()
116  && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
117  if (mxSet.is())
118  {
119  // Append a separator from previous Properties.
120  if ( ! mbIsFirstProperty)
121  msDescription.append(',');
122  else
123  {
124  SolarMutexGuard aGuard;
125 
126  msDescription.append(' ');
127  msDescription.append(SvxResId(RID_SVXSTR_A11Y_AND));
128  msDescription.append(' ');
129  mbIsFirstProperty = false;
130  }
131 
132  // Delegate to type specific property handling.
133  switch (aType)
134  {
135  case PropertyType::Color:
136  AddColor (sPropertyName);
137  break;
139  AddInteger (sPropertyName);
140  break;
141  }
142  }
143 }
144 
145 
146 void DescriptionGenerator::AppendString (const OUString& sString)
147 {
148  msDescription.append (sString);
149 }
150 
151 
155 void DescriptionGenerator::AddColor (const OUString& sPropertyName)
156 {
157  msDescription.append('=');
158 
159  try
160  {
161 
162  long nValue(0);
163  if (mxSet.is())
164  {
165  uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
166  aValue >>= nValue;
167  }
168 
169  msDescription.append (lookUpColorName(nValue));
170  }
171  catch (const css::beans::UnknownPropertyException &)
172  {
173  msDescription.append ("<unknown>");
174  }
175 }
176 
177 
178 void DescriptionGenerator::AddInteger (const OUString& sPropertyName)
179 {
180  msDescription.append('=');
181 
182  try
183  {
184  if (mxSet.is())
185  {
186  uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
187  long nValue = 0;
188  aValue >>= nValue;
189  msDescription.append (nValue);
190  }
191  }
192  catch (const css::beans::UnknownPropertyException &)
193  {
194  msDescription.append ("<unknown>");
195  }
196 }
197 
198 } // end of namespace accessibility
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddInteger(const OUString &sPropertyName)
Add a property value formatted as integer to the description string.
OUStringBuffer msDescription
The description string that is build.
uno::Reference< drawing::XShape > const mxShape
void AddColor(const OUString &sPropertyName)
Add a property value formatted as color to the description string.
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
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.