Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / accessibility / DescriptionGenerator.cxx
blob4b2aaf43d31105ef32ccb1d566e709d22ebca8b5
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 .
21 #include "svx/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/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 <comphelper/processfactory.hxx>
36 #include <osl/mutex.hxx>
37 #include <vcl/svapp.hxx>
39 #include <com/sun/star/uno/Exception.hpp>
41 // Includes for string resources.
42 #include "accessibility.hrc"
43 #include "svx/svdstr.hrc"
44 #include <svx/dialmgr.hxx>
46 #include <svx/xdef.hxx>
47 #include "svx/unoapi.hxx"
48 #include "lookupcolorname.hxx"
50 using namespace ::rtl;
51 using namespace ::com::sun::star;
54 namespace accessibility {
57 DescriptionGenerator::DescriptionGenerator (
58 const uno::Reference<drawing::XShape>& xShape)
59 : mxShape (xShape),
60 mxSet (mxShape, uno::UNO_QUERY),
61 mbIsFirstProperty (true)
68 DescriptionGenerator::~DescriptionGenerator (void)
75 void DescriptionGenerator::Initialize (sal_Int32 nResourceId)
77 // Get the string from the resource for the specified id.
78 OUString sPrefix;
80 SolarMutexGuard aGuard;
81 sPrefix = OUString (SVX_RESSTR (nResourceId));
84 // Forward the call with the resulting string.
85 Initialize (sPrefix);
91 void DescriptionGenerator::Initialize (const OUString& sPrefix)
93 msDescription = sPrefix;
94 if (mxSet.is())
97 SolarMutexGuard aGuard;
99 msDescription.append(' ');
100 msDescription.append(OUString (SVX_RESSTR(RID_SVXSTR_A11Y_WITH)));
101 msDescription.append(' ');
103 msDescription.append(OUString (SVX_RESSTR (RID_SVXSTR_A11Y_STYLE)));
104 msDescription.append('=');
109 if (mxSet.is())
111 uno::Any aValue = mxSet->getPropertyValue ("Style");
112 uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
113 if (xStyle.is())
114 msDescription.append (xStyle->getName());
116 else
117 msDescription.append ("<no style>");
119 catch (const ::com::sun::star::beans::UnknownPropertyException &)
121 msDescription.append ("<unknown>");
129 OUString DescriptionGenerator::operator() (void)
131 msDescription.append('.');
132 return msDescription.makeStringAndClear();
138 void DescriptionGenerator::AddProperty (
139 const OUString& sPropertyName,
140 PropertyType aType,
141 const sal_Int32 nLocalizedNameId,
142 long nWhichId)
144 OUString sLocalizedName;
146 SolarMutexGuard aGuard;
147 sLocalizedName = SVX_RESSTR (nLocalizedNameId);
149 AddProperty (sPropertyName, aType, sLocalizedName, nWhichId);
155 void DescriptionGenerator::AddProperty (const OUString& sPropertyName,
156 PropertyType aType, const OUString& sLocalizedName, long nWhichId)
158 uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY);
159 if (xState.is()
160 && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
161 if (mxSet.is())
163 // Append a separator from previous Properties.
164 if ( ! mbIsFirstProperty)
165 msDescription.append(',');
166 else
168 SolarMutexGuard aGuard;
170 msDescription.append(' ');
171 msDescription.append(OUString (SVX_RESSTR(RID_SVXSTR_A11Y_AND)));
172 msDescription.append(' ');
173 mbIsFirstProperty = false;
176 // Delegate to type specific property handling.
177 switch (aType)
179 case COLOR:
180 AddColor (sPropertyName, sLocalizedName);
181 break;
182 case INTEGER:
183 AddInteger (sPropertyName, sLocalizedName);
184 break;
185 case STRING:
186 AddString (sPropertyName, sLocalizedName, nWhichId);
187 break;
188 case FILL_STYLE:
189 AddFillStyle (sPropertyName, sLocalizedName);
190 break;
198 void DescriptionGenerator::AppendString (const OUString& sString)
200 msDescription.append (sString);
206 void DescriptionGenerator::AddLineProperties (void)
208 AddProperty ("LineColor", DescriptionGenerator::COLOR, SIP_XA_LINECOLOR);
209 AddProperty ("LineDashName", DescriptionGenerator::STRING,
210 SIP_XA_LINEDASH, XATTR_LINEDASH);
211 AddProperty ("LineWidth", DescriptionGenerator::INTEGER, SIP_XA_LINEWIDTH);
217 /** The fill style is described by the property "FillStyle". Depending on
218 its value a hatch-, gradient-, or bitmap name is appended.
220 void DescriptionGenerator::AddFillProperties (void)
222 AddProperty ("FillStyle", DescriptionGenerator::FILL_STYLE, SIP_XA_FILLSTYLE);
228 void DescriptionGenerator::Add3DProperties (void)
230 AddProperty ("D3DMaterialColor", DescriptionGenerator::COLOR,
231 RID_SVXSTR_A11Y_3D_MATERIAL_COLOR);
232 AddLineProperties ();
233 AddFillProperties ();
239 void DescriptionGenerator::AddTextProperties (void)
241 AddProperty ("CharColor", DescriptionGenerator::COLOR);
242 AddFillProperties ();
248 /** Search for the given color in the global color table. If found append
249 its name to the description. Otherwise append its RGB tuple.
251 void DescriptionGenerator::AddColor (const OUString& sPropertyName,
252 const OUString& sLocalizedName)
254 msDescription.append(sLocalizedName);
255 msDescription.append('=');
260 long nValue(0);
261 if (mxSet.is())
263 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
264 aValue >>= nValue;
267 msDescription.append (lookUpColorName(nValue));
269 catch (const ::com::sun::star::beans::UnknownPropertyException &)
271 msDescription.append ("<unknown>");
278 void DescriptionGenerator::AddInteger (const OUString& sPropertyName,
279 const OUString& sLocalizedName)
281 msDescription.append(sLocalizedName);
282 msDescription.append('=');
286 if (mxSet.is())
288 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
289 long nValue = 0;
290 aValue >>= nValue;
291 msDescription.append (nValue);
294 catch (const ::com::sun::star::beans::UnknownPropertyException &)
296 msDescription.append ("<unknown>");
303 void DescriptionGenerator::AddString (const OUString& sPropertyName,
304 const OUString& sLocalizedName, long nWhichId)
306 msDescription.append(sLocalizedName);
307 msDescription.append('=');
311 if (mxSet.is())
313 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
314 OUString sValue;
315 aValue >>= sValue;
317 if (nWhichId >= 0)
319 SolarMutexGuard aGuard;
320 OUString sLocalizedValue =
321 SvxUnogetInternalNameForItem(sal::static_int_cast<sal_Int16>(nWhichId),
322 sValue);
323 msDescription.append (sLocalizedValue);
325 else
326 msDescription.append (sValue);
329 catch (const ::com::sun::star::beans::UnknownPropertyException &)
331 msDescription.append ("<unknown>");
338 void DescriptionGenerator::AddFillStyle (const OUString& sPropertyName,
339 const OUString& sLocalizedName)
341 msDescription.append(sLocalizedName);
342 msDescription.append('=');
346 if (mxSet.is())
348 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
349 drawing::FillStyle aFillStyle;
350 aValue >>= aFillStyle;
352 // Get the fill style name from the resource.
353 OUString sFillStyleName;
355 SolarMutexGuard aGuard;
356 switch (aFillStyle)
358 case drawing::FillStyle_NONE:
359 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE);
360 break;
361 case drawing::FillStyle_SOLID:
362 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID);
363 break;
364 case drawing::FillStyle_GRADIENT:
365 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT);
366 break;
367 case drawing::FillStyle_HATCH:
368 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH);
369 break;
370 case drawing::FillStyle_BITMAP:
371 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP);
372 break;
373 case drawing::FillStyle_MAKE_FIXED_SIZE:
374 break;
377 msDescription.append (sFillStyleName);
379 // Append the appropriate properties.
380 switch (aFillStyle)
382 case drawing::FillStyle_NONE:
383 break;
384 case drawing::FillStyle_SOLID:
385 AddProperty ("FillColor", COLOR, SIP_XA_FILLCOLOR);
386 break;
387 case drawing::FillStyle_GRADIENT:
388 AddProperty ("FillGradientName", STRING, SIP_XA_FILLGRADIENT,
389 XATTR_FILLGRADIENT);
390 break;
391 case drawing::FillStyle_HATCH:
392 AddProperty ("FillColor", COLOR, SIP_XA_FILLCOLOR);
393 AddProperty ("FillHatchName", STRING, SIP_XA_FILLHATCH,
394 XATTR_FILLHATCH);
395 break;
396 case drawing::FillStyle_BITMAP:
397 AddProperty ("FillBitmapName", STRING, SIP_XA_FILLBITMAP,
398 XATTR_FILLBITMAP);
399 break;
400 case drawing::FillStyle_MAKE_FIXED_SIZE:
401 break;
405 catch (const ::com::sun::star::beans::UnknownPropertyException &)
407 msDescription.append ("<unknown>");
411 } // end of namespace accessibility
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */