1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 ::com::sun::star
;
53 namespace accessibility
{
56 DescriptionGenerator::DescriptionGenerator (
57 const uno::Reference
<drawing::XShape
>& xShape
)
59 mxSet (mxShape
, uno::UNO_QUERY
),
60 mbIsFirstProperty (true)
67 DescriptionGenerator::~DescriptionGenerator()
74 void DescriptionGenerator::Initialize (sal_Int32 nResourceId
)
76 // Get the string from the resource for the specified id.
79 SolarMutexGuard aGuard
;
80 sPrefix
= OUString (SVX_RESSTR (nResourceId
));
83 // Forward the call with the resulting string.
90 void DescriptionGenerator::Initialize (const OUString
& sPrefix
)
92 msDescription
= sPrefix
;
96 SolarMutexGuard aGuard
;
98 msDescription
.append(' ');
99 msDescription
.append(OUString (SVX_RESSTR(RID_SVXSTR_A11Y_WITH
)));
100 msDescription
.append(' ');
102 msDescription
.append(OUString (SVX_RESSTR (RID_SVXSTR_A11Y_STYLE
)));
103 msDescription
.append('=');
110 uno::Any aValue
= mxSet
->getPropertyValue ("Style");
111 uno::Reference
<container::XNamed
> xStyle (aValue
, uno::UNO_QUERY
);
113 msDescription
.append (xStyle
->getName());
116 msDescription
.append ("<no style>");
118 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
120 msDescription
.append ("<unknown>");
128 OUString
DescriptionGenerator::operator() (void)
130 msDescription
.append('.');
131 return msDescription
.makeStringAndClear();
137 void DescriptionGenerator::AddProperty (
138 const OUString
& sPropertyName
,
140 const sal_Int32 nLocalizedNameId
,
143 OUString sLocalizedName
;
145 SolarMutexGuard aGuard
;
146 sLocalizedName
= SVX_RESSTR (nLocalizedNameId
);
148 AddProperty (sPropertyName
, aType
, sLocalizedName
, nWhichId
);
154 void DescriptionGenerator::AddProperty (const OUString
& sPropertyName
,
155 PropertyType aType
, const OUString
& sLocalizedName
, long nWhichId
)
157 uno::Reference
<beans::XPropertyState
> xState (mxShape
, uno::UNO_QUERY
);
159 && xState
->getPropertyState(sPropertyName
)!=beans::PropertyState_DEFAULT_VALUE
)
162 // Append a separator from previous Properties.
163 if ( ! mbIsFirstProperty
)
164 msDescription
.append(',');
167 SolarMutexGuard aGuard
;
169 msDescription
.append(' ');
170 msDescription
.append(OUString (SVX_RESSTR(RID_SVXSTR_A11Y_AND
)));
171 msDescription
.append(' ');
172 mbIsFirstProperty
= false;
175 // Delegate to type specific property handling.
179 AddColor (sPropertyName
, sLocalizedName
);
182 AddInteger (sPropertyName
, sLocalizedName
);
185 AddString (sPropertyName
, sLocalizedName
, nWhichId
);
188 AddFillStyle (sPropertyName
, sLocalizedName
);
197 void DescriptionGenerator::AppendString (const OUString
& sString
)
199 msDescription
.append (sString
);
205 void DescriptionGenerator::AddLineProperties()
207 AddProperty ("LineColor", DescriptionGenerator::COLOR
, SIP_XA_LINECOLOR
);
208 AddProperty ("LineDashName", DescriptionGenerator::STRING
,
209 SIP_XA_LINEDASH
, XATTR_LINEDASH
);
210 AddProperty ("LineWidth", DescriptionGenerator::INTEGER
, SIP_XA_LINEWIDTH
);
216 /** The fill style is described by the property "FillStyle". Depending on
217 its value a hatch-, gradient-, or bitmap name is appended.
219 void DescriptionGenerator::AddFillProperties()
221 AddProperty ("FillStyle", DescriptionGenerator::FILL_STYLE
, SIP_XA_FILLSTYLE
);
227 void DescriptionGenerator::Add3DProperties()
229 AddProperty ("D3DMaterialColor", DescriptionGenerator::COLOR
,
230 RID_SVXSTR_A11Y_3D_MATERIAL_COLOR
);
231 AddLineProperties ();
232 AddFillProperties ();
238 void DescriptionGenerator::AddTextProperties()
240 AddProperty ("CharColor", DescriptionGenerator::COLOR
);
241 AddFillProperties ();
247 /** Search for the given color in the global color table. If found append
248 its name to the description. Otherwise append its RGB tuple.
250 void DescriptionGenerator::AddColor (const OUString
& sPropertyName
,
251 const OUString
& sLocalizedName
)
253 msDescription
.append(sLocalizedName
);
254 msDescription
.append('=');
262 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
266 msDescription
.append (lookUpColorName(nValue
));
268 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
270 msDescription
.append ("<unknown>");
277 void DescriptionGenerator::AddInteger (const OUString
& sPropertyName
,
278 const OUString
& sLocalizedName
)
280 msDescription
.append(sLocalizedName
);
281 msDescription
.append('=');
287 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
290 msDescription
.append (nValue
);
293 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
295 msDescription
.append ("<unknown>");
302 void DescriptionGenerator::AddString (const OUString
& sPropertyName
,
303 const OUString
& sLocalizedName
, long nWhichId
)
305 msDescription
.append(sLocalizedName
);
306 msDescription
.append('=');
312 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
318 SolarMutexGuard aGuard
;
319 OUString sLocalizedValue
=
320 SvxUnogetInternalNameForItem(sal::static_int_cast
<sal_Int16
>(nWhichId
),
322 msDescription
.append (sLocalizedValue
);
325 msDescription
.append (sValue
);
328 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
330 msDescription
.append ("<unknown>");
337 void DescriptionGenerator::AddFillStyle (const OUString
& sPropertyName
,
338 const OUString
& sLocalizedName
)
340 msDescription
.append(sLocalizedName
);
341 msDescription
.append('=');
347 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
348 drawing::FillStyle aFillStyle
;
349 aValue
>>= aFillStyle
;
351 // Get the fill style name from the resource.
352 OUString sFillStyleName
;
354 SolarMutexGuard aGuard
;
357 case drawing::FillStyle_NONE
:
358 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE
);
360 case drawing::FillStyle_SOLID
:
361 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID
);
363 case drawing::FillStyle_GRADIENT
:
364 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT
);
366 case drawing::FillStyle_HATCH
:
367 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH
);
369 case drawing::FillStyle_BITMAP
:
370 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP
);
372 case drawing::FillStyle_MAKE_FIXED_SIZE
:
376 msDescription
.append (sFillStyleName
);
378 // Append the appropriate properties.
381 case drawing::FillStyle_NONE
:
383 case drawing::FillStyle_SOLID
:
384 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
386 case drawing::FillStyle_GRADIENT
:
387 AddProperty ("FillGradientName", STRING
, SIP_XA_FILLGRADIENT
,
390 case drawing::FillStyle_HATCH
:
391 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
392 AddProperty ("FillHatchName", STRING
, SIP_XA_FILLHATCH
,
395 case drawing::FillStyle_BITMAP
:
396 AddProperty ("FillBitmapName", STRING
, SIP_XA_FILLBITMAP
,
399 case drawing::FillStyle_MAKE_FIXED_SIZE
:
404 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
406 msDescription
.append ("<unknown>");
410 } // end of namespace accessibility
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */