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