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>
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
)
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.
81 SolarMutexGuard aGuard
;
82 sPrefix
= OUString (SVX_RESSTR (nResourceId
));
85 // Forward the call with the resulting string.
92 void DescriptionGenerator::Initialize (OUString sPrefix
)
94 msDescription
= sPrefix
;
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 ('='));
112 uno::Any aValue
= mxSet
->getPropertyValue ("Style");
113 uno::Reference
<container::XNamed
> xStyle (aValue
, uno::UNO_QUERY
);
115 msDescription
.append (xStyle
->getName());
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
,
142 const sal_Int32 nLocalizedNameId
,
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
);
161 && xState
->getPropertyState(sPropertyName
)!=beans::PropertyState_DEFAULT_VALUE
)
164 // Append a separator from previous Properties.
165 if ( ! mbIsFirstProperty
)
166 msDescription
.append (sal_Unicode (','));
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.
181 AddColor (sPropertyName
, sLocalizedName
);
184 AddInteger (sPropertyName
, sLocalizedName
);
187 AddString (sPropertyName
, sLocalizedName
, nWhichId
);
190 AddFillStyle (sPropertyName
, sLocalizedName
);
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('='));
264 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
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('='));
289 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
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('='));
314 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
320 SolarMutexGuard aGuard
;
321 OUString sLocalizedValue
=
322 SvxUnogetInternalNameForItem(sal::static_int_cast
<sal_Int16
>(nWhichId
),
324 msDescription
.append (sLocalizedValue
);
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('='));
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
;
359 case drawing::FillStyle_NONE
:
360 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE
);
362 case drawing::FillStyle_SOLID
:
363 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID
);
365 case drawing::FillStyle_GRADIENT
:
366 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT
);
368 case drawing::FillStyle_HATCH
:
369 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH
);
371 case drawing::FillStyle_BITMAP
:
372 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP
);
374 case drawing::FillStyle_MAKE_FIXED_SIZE
:
378 msDescription
.append (sFillStyleName
);
380 // Append the appropriate properties.
383 case drawing::FillStyle_NONE
:
385 case drawing::FillStyle_SOLID
:
386 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
388 case drawing::FillStyle_GRADIENT
:
389 AddProperty ("FillGradientName", STRING
, SIP_XA_FILLGRADIENT
,
392 case drawing::FillStyle_HATCH
:
393 AddProperty ("FillColor", COLOR
, SIP_XA_FILLCOLOR
);
394 AddProperty ("FillHatchName", STRING
, SIP_XA_FILLHATCH
,
397 case drawing::FillStyle_BITMAP
:
398 AddProperty ("FillBitmapName", STRING
, SIP_XA_FILLBITMAP
,
401 case drawing::FillStyle_MAKE_FIXED_SIZE
:
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: */