fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / accessibility / DescriptionGenerator.cxx
blob441aef6d42fa4c4b239eb1ec165a1b9fc21b4acb
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>
45 #include <tools/string.hxx>
47 #include <svx/xdef.hxx>
48 #include "svx/unoapi.hxx"
49 #include "lookupcolorname.hxx"
51 using namespace ::rtl;
52 using namespace ::com::sun::star;
55 namespace accessibility {
58 DescriptionGenerator::DescriptionGenerator (
59 const uno::Reference<drawing::XShape>& xShape)
60 : mxShape (xShape),
61 mxSet (mxShape, uno::UNO_QUERY),
62 mbIsFirstProperty (true)
69 DescriptionGenerator::~DescriptionGenerator (void)
76 void DescriptionGenerator::Initialize (sal_Int32 nResourceId)
78 // Get the string from the resource for the specified id.
79 OUString sPrefix;
81 SolarMutexGuard aGuard;
82 sPrefix = OUString (SVX_RESSTR (nResourceId));
85 // Forward the call with the resulting string.
86 Initialize (sPrefix);
92 void DescriptionGenerator::Initialize (OUString sPrefix)
94 msDescription = sPrefix;
95 if (mxSet.is())
98 SolarMutexGuard aGuard;
100 msDescription.append (sal_Unicode (' '));
101 msDescription.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_WITH)));
102 msDescription.append (sal_Unicode (' '));
104 msDescription.append (OUString (SVX_RESSTR (RID_SVXSTR_A11Y_STYLE)));
105 msDescription.append (sal_Unicode ('='));
110 if (mxSet.is())
112 uno::Any aValue = mxSet->getPropertyValue ("Style");
113 uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
114 if (xStyle.is())
115 msDescription.append (xStyle->getName());
117 else
118 msDescription.append ("<no style>");
120 catch (const ::com::sun::star::beans::UnknownPropertyException &)
122 msDescription.append ("<unknown>");
130 OUString DescriptionGenerator::operator() (void)
132 msDescription.append (sal_Unicode ('.'));
133 return msDescription.makeStringAndClear();
139 void DescriptionGenerator::AddProperty (
140 const OUString& sPropertyName,
141 PropertyType aType,
142 const sal_Int32 nLocalizedNameId,
143 long nWhichId)
145 OUString sLocalizedName;
147 SolarMutexGuard aGuard;
148 sLocalizedName = SVX_RESSTR (nLocalizedNameId);
150 AddProperty (sPropertyName, aType, sLocalizedName, nWhichId);
156 void DescriptionGenerator::AddProperty (const OUString& sPropertyName,
157 PropertyType aType, const OUString& sLocalizedName, long nWhichId)
159 uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY);
160 if (xState.is()
161 && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
162 if (mxSet.is())
164 // Append a separator from previous Properties.
165 if ( ! mbIsFirstProperty)
166 msDescription.append (sal_Unicode (','));
167 else
169 SolarMutexGuard aGuard;
171 msDescription.append (sal_Unicode (' '));
172 msDescription.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_AND)));
173 msDescription.append (sal_Unicode (' '));
174 mbIsFirstProperty = false;
177 // Delegate to type specific property handling.
178 switch (aType)
180 case COLOR:
181 AddColor (sPropertyName, sLocalizedName);
182 break;
183 case INTEGER:
184 AddInteger (sPropertyName, sLocalizedName);
185 break;
186 case STRING:
187 AddString (sPropertyName, sLocalizedName, nWhichId);
188 break;
189 case FILL_STYLE:
190 AddFillStyle (sPropertyName, sLocalizedName);
191 break;
199 void DescriptionGenerator::AppendString (const OUString& sString)
201 msDescription.append (sString);
207 void DescriptionGenerator::AddLineProperties (void)
209 AddProperty ("LineColor", DescriptionGenerator::COLOR, SIP_XA_LINECOLOR);
210 AddProperty ("LineDashName", DescriptionGenerator::STRING,
211 SIP_XA_LINEDASH, XATTR_LINEDASH);
212 AddProperty ("LineWidth", DescriptionGenerator::INTEGER, SIP_XA_LINEWIDTH);
218 /** The fill style is described by the property "FillStyle". Depending on
219 its value a hatch-, gradient-, or bitmap name is appended.
221 void DescriptionGenerator::AddFillProperties (void)
223 AddProperty ("FillStyle", DescriptionGenerator::FILL_STYLE, SIP_XA_FILLSTYLE);
229 void DescriptionGenerator::Add3DProperties (void)
231 AddProperty ("D3DMaterialColor", DescriptionGenerator::COLOR,
232 RID_SVXSTR_A11Y_3D_MATERIAL_COLOR);
233 AddLineProperties ();
234 AddFillProperties ();
240 void DescriptionGenerator::AddTextProperties (void)
242 AddProperty ("CharColor", DescriptionGenerator::COLOR);
243 AddFillProperties ();
249 /** Search for the given color in the global color table. If found append
250 its name to the description. Otherwise append its RGB tuple.
252 void DescriptionGenerator::AddColor (const OUString& sPropertyName,
253 const OUString& sLocalizedName)
255 msDescription.append (sLocalizedName);
256 msDescription.append (sal_Unicode('='));
261 long nValue(0);
262 if (mxSet.is())
264 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
265 aValue >>= nValue;
268 msDescription.append (lookUpColorName(nValue));
270 catch (const ::com::sun::star::beans::UnknownPropertyException &)
272 msDescription.append ("<unknown>");
279 void DescriptionGenerator::AddInteger (const OUString& sPropertyName,
280 const OUString& sLocalizedName)
282 msDescription.append (sLocalizedName);
283 msDescription.append (sal_Unicode('='));
287 if (mxSet.is())
289 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
290 long nValue = 0;
291 aValue >>= nValue;
292 msDescription.append (nValue);
295 catch (const ::com::sun::star::beans::UnknownPropertyException &)
297 msDescription.append ("<unknown>");
304 void DescriptionGenerator::AddString (const OUString& sPropertyName,
305 const OUString& sLocalizedName, long nWhichId)
307 msDescription.append (sLocalizedName);
308 msDescription.append (sal_Unicode('='));
312 if (mxSet.is())
314 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
315 OUString sValue;
316 aValue >>= sValue;
318 if (nWhichId >= 0)
320 SolarMutexGuard aGuard;
321 OUString sLocalizedValue =
322 SvxUnogetInternalNameForItem(sal::static_int_cast<sal_Int16>(nWhichId),
323 sValue);
324 msDescription.append (sLocalizedValue);
326 else
327 msDescription.append (sValue);
330 catch (const ::com::sun::star::beans::UnknownPropertyException &)
332 msDescription.append ("<unknown>");
339 void DescriptionGenerator::AddFillStyle (const OUString& sPropertyName,
340 const OUString& sLocalizedName)
342 msDescription.append (sLocalizedName);
343 msDescription.append (sal_Unicode('='));
347 if (mxSet.is())
349 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
350 drawing::FillStyle aFillStyle;
351 aValue >>= aFillStyle;
353 // Get the fill style name from the resource.
354 OUString sFillStyleName;
356 SolarMutexGuard aGuard;
357 switch (aFillStyle)
359 case drawing::FillStyle_NONE:
360 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE);
361 break;
362 case drawing::FillStyle_SOLID:
363 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID);
364 break;
365 case drawing::FillStyle_GRADIENT:
366 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT);
367 break;
368 case drawing::FillStyle_HATCH:
369 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH);
370 break;
371 case drawing::FillStyle_BITMAP:
372 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP);
373 break;
374 case drawing::FillStyle_MAKE_FIXED_SIZE:
375 break;
378 msDescription.append (sFillStyleName);
380 // Append the appropriate properties.
381 switch (aFillStyle)
383 case drawing::FillStyle_NONE:
384 break;
385 case drawing::FillStyle_SOLID:
386 AddProperty ("FillColor", COLOR, SIP_XA_FILLCOLOR);
387 break;
388 case drawing::FillStyle_GRADIENT:
389 AddProperty ("FillGradientName", STRING, SIP_XA_FILLGRADIENT,
390 XATTR_FILLGRADIENT);
391 break;
392 case drawing::FillStyle_HATCH:
393 AddProperty ("FillColor", COLOR, SIP_XA_FILLCOLOR);
394 AddProperty ("FillHatchName", STRING, SIP_XA_FILLHATCH,
395 XATTR_FILLHATCH);
396 break;
397 case drawing::FillStyle_BITMAP:
398 AddProperty ("FillBitmapName", STRING, SIP_XA_FILLBITMAP,
399 XATTR_FILLBITMAP);
400 break;
401 case drawing::FillStyle_MAKE_FIXED_SIZE:
402 break;
406 catch (const ::com::sun::star::beans::UnknownPropertyException &)
408 msDescription.append ("<unknown>");
412 } // end of namespace accessibility
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */