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 ::rtl
;
51 using namespace ::com::sun::star
;
54 namespace accessibility
{
57 DescriptionGenerator::DescriptionGenerator (
58 const uno::Reference
<drawing::XShape
>& 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.
80 SolarMutexGuard aGuard
;
81 sPrefix
= OUString (SVX_RESSTR (nResourceId
));
84 // Forward the call with the resulting string.
91 void DescriptionGenerator::Initialize (const OUString
& sPrefix
)
93 msDescription
= sPrefix
;
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('=');
111 uno::Any aValue
= mxSet
->getPropertyValue ("Style");
112 uno::Reference
<container::XNamed
> xStyle (aValue
, uno::UNO_QUERY
);
114 msDescription
.append (xStyle
->getName());
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
,
141 const sal_Int32 nLocalizedNameId
,
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
);
160 && xState
->getPropertyState(sPropertyName
)!=beans::PropertyState_DEFAULT_VALUE
)
163 // Append a separator from previous Properties.
164 if ( ! mbIsFirstProperty
)
165 msDescription
.append(',');
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.
180 AddColor (sPropertyName
, sLocalizedName
);
183 AddInteger (sPropertyName
, sLocalizedName
);
186 AddString (sPropertyName
, sLocalizedName
, nWhichId
);
189 AddFillStyle (sPropertyName
, sLocalizedName
);
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('=');
263 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
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('=');
288 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
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('=');
313 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
319 SolarMutexGuard aGuard
;
320 OUString sLocalizedValue
=
321 SvxUnogetInternalNameForItem(sal::static_int_cast
<sal_Int16
>(nWhichId
),
323 msDescription
.append (sLocalizedValue
);
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('=');
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
;
358 case drawing::FillStyle_NONE
:
359 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE
);
361 case drawing::FillStyle_SOLID
:
362 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID
);
364 case drawing::FillStyle_GRADIENT
:
365 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT
);
367 case drawing::FillStyle_HATCH
:
368 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH
);
370 case drawing::FillStyle_BITMAP
:
371 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP
);
373 case drawing::FillStyle_MAKE_FIXED_SIZE
:
377 msDescription
.append (sFillStyleName
);
379 // Append the appropriate properties.
382 case drawing::FillStyle_NONE
:
384 case drawing::FillStyle_SOLID
:
385 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
387 case drawing::FillStyle_GRADIENT
:
388 AddProperty ("FillGradientName", STRING
, SIP_XA_FILLGRADIENT
,
391 case drawing::FillStyle_HATCH
:
392 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
393 AddProperty ("FillHatchName", STRING
, SIP_XA_FILLHATCH
,
396 case drawing::FillStyle_BITMAP
:
397 AddProperty ("FillBitmapName", STRING
, SIP_XA_FILLBITMAP
,
400 case drawing::FillStyle_MAKE_FIXED_SIZE
:
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: */