1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DescriptionGenerator.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "DescriptionGenerator.hxx"
35 #include <com/sun/star/beans/PropertyState.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/beans/XPropertyState.hpp>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/drawing/FillStyle.hpp>
43 #include <com/sun/star/drawing/XShapes.hpp>
44 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
45 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/style/XStyle.hpp>
48 #include <comphelper/processfactory.hxx>
49 #include <vos/mutex.hxx>
50 #include <vcl/svapp.hxx>
52 #include <com/sun/star/uno/Exception.hpp>
54 // Includes for string resources.
55 #ifndef _SVX_ACCESSIBILITY_HRC
56 #include "accessibility.hrc"
59 #include <svx/dialmgr.hxx>
60 #include <tools/string.hxx>
62 #include <svx/xdef.hxx>
64 #include "accessibility.hrc"
65 #include "DGColorNameLookUp.hxx"
67 using namespace ::rtl
;
68 using namespace ::com::sun::star
;
71 void SvxUnogetInternalNameForItem( const sal_Int16 nWhich
, const rtl::OUString
& rApiName
, String
& rInternalName
) throw();
73 namespace accessibility
{
76 DescriptionGenerator::DescriptionGenerator (
77 const uno::Reference
<drawing::XShape
>& xShape
)
79 mxSet (mxShape
, uno::UNO_QUERY
),
80 mbIsFirstProperty (true)
87 DescriptionGenerator::~DescriptionGenerator (void)
94 void DescriptionGenerator::Initialize (sal_Int32 nResourceId
)
96 // Get the string from the resource for the specified id.
99 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
100 sPrefix
= OUString (SVX_RESSTR (nResourceId
));
103 // Forward the call with the resulting string.
104 Initialize (sPrefix
);
110 void DescriptionGenerator::Initialize (::rtl::OUString sPrefix
)
112 msDescription
= sPrefix
;
116 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
118 msDescription
.append (sal_Unicode (' '));
119 msDescription
.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_WITH
)));
120 msDescription
.append (sal_Unicode (' '));
122 msDescription
.append (OUString (SVX_RESSTR (RID_SVXSTR_A11Y_STYLE
)));
123 msDescription
.append (sal_Unicode ('='));
130 uno::Any aValue
= mxSet
->getPropertyValue (OUString::createFromAscii ("Style"));
131 uno::Reference
<container::XNamed
> xStyle (aValue
, uno::UNO_QUERY
);
133 msDescription
.append (xStyle
->getName());
136 msDescription
.append (
137 OUString::createFromAscii("<no style>"));
139 catch (::com::sun::star::beans::UnknownPropertyException
)
141 msDescription
.append (
142 OUString::createFromAscii("<unknown>"));
150 ::rtl::OUString
DescriptionGenerator::operator() (void)
152 msDescription
.append (sal_Unicode ('.'));
153 return msDescription
.makeStringAndClear();
159 void DescriptionGenerator::AddProperty (
160 const OUString
& sPropertyName
,
162 const sal_Int32 nLocalizedNameId
,
165 OUString sLocalizedName
;
167 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
168 sLocalizedName
= SVX_RESSTR (nLocalizedNameId
);
170 AddProperty (sPropertyName
, aType
, sLocalizedName
, nWhichId
);
176 void DescriptionGenerator::AddProperty (const OUString
& sPropertyName
,
177 PropertyType aType
, const OUString
& sLocalizedName
, long nWhichId
)
179 uno::Reference
<beans::XPropertyState
> xState (mxShape
, uno::UNO_QUERY
);
181 && xState
->getPropertyState(sPropertyName
)!=beans::PropertyState_DEFAULT_VALUE
)
184 // Append a seperator from previous Properties.
185 if ( ! mbIsFirstProperty
)
186 msDescription
.append (sal_Unicode (','));
189 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
191 msDescription
.append (sal_Unicode (' '));
192 msDescription
.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_AND
)));
193 msDescription
.append (sal_Unicode (' '));
194 mbIsFirstProperty
= false;
197 // Delegate to type specific property handling.
201 AddColor (sPropertyName
, sLocalizedName
);
204 AddInteger (sPropertyName
, sLocalizedName
);
207 AddString (sPropertyName
, sLocalizedName
, nWhichId
);
210 AddFillStyle (sPropertyName
, sLocalizedName
);
219 void DescriptionGenerator::AppendString (const ::rtl::OUString
& sString
)
221 msDescription
.append (sString
);
227 void DescriptionGenerator::AddLineProperties (void)
229 AddProperty (OUString::createFromAscii ("LineColor"),
230 DescriptionGenerator::COLOR
,
232 AddProperty (OUString::createFromAscii ("LineDashName"),
233 DescriptionGenerator::STRING
,
236 AddProperty (OUString::createFromAscii ("LineWidth"),
237 DescriptionGenerator::INTEGER
,
244 /** The fill style is described by the property "FillStyle". Depending on
245 its value a hatch-, gradient-, or bitmap name is appended.
247 void DescriptionGenerator::AddFillProperties (void)
249 AddProperty (OUString::createFromAscii ("FillStyle"),
250 DescriptionGenerator::FILL_STYLE
,
257 void DescriptionGenerator::Add3DProperties (void)
259 AddProperty (OUString::createFromAscii ("D3DMaterialColor"),
260 DescriptionGenerator::COLOR
,
261 RID_SVXSTR_A11Y_3D_MATERIAL_COLOR
);
262 AddLineProperties ();
263 AddFillProperties ();
269 void DescriptionGenerator::AddTextProperties (void)
271 AddProperty (OUString::createFromAscii ("CharColor"),
272 DescriptionGenerator::COLOR
);
273 AddFillProperties ();
279 /** Search for the given color in the global color table. If found append
280 its name to the description. Otherwise append its RGB tuple.
282 void DescriptionGenerator::AddColor (const OUString
& sPropertyName
,
283 const OUString
& sLocalizedName
)
285 msDescription
.append (sLocalizedName
);
286 msDescription
.append (sal_Unicode('='));
294 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
298 msDescription
.append (DGColorNameLookUp::Instance().LookUpColor (nValue
));
300 catch (::com::sun::star::beans::UnknownPropertyException
)
302 msDescription
.append (
303 OUString::createFromAscii("<unknown>"));
310 void DescriptionGenerator::AddUnknown (const OUString
& /*sPropertyName*/,
311 const OUString
& sLocalizedName
)
313 // uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
314 msDescription
.append (sLocalizedName
);
320 void DescriptionGenerator::AddInteger (const OUString
& sPropertyName
,
321 const OUString
& sLocalizedName
)
323 msDescription
.append (sLocalizedName
);
324 msDescription
.append (sal_Unicode('='));
330 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
333 msDescription
.append (nValue
);
336 catch (::com::sun::star::beans::UnknownPropertyException
)
338 msDescription
.append (
339 OUString::createFromAscii("<unknown>"));
346 void DescriptionGenerator::AddString (const OUString
& sPropertyName
,
347 const OUString
& sLocalizedName
, long nWhichId
)
349 msDescription
.append (sLocalizedName
);
350 msDescription
.append (sal_Unicode('='));
356 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
362 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
363 String sLocalizedValue
;
364 SvxUnogetInternalNameForItem (sal::static_int_cast
<sal_Int16
>(nWhichId
),
365 sValue
, sLocalizedValue
);
366 msDescription
.append (sLocalizedValue
);
369 msDescription
.append (sValue
);
372 catch (::com::sun::star::beans::UnknownPropertyException
)
374 msDescription
.append (
375 OUString::createFromAscii("<unknown>"));
382 void DescriptionGenerator::AddFillStyle (const OUString
& sPropertyName
,
383 const OUString
& sLocalizedName
)
385 msDescription
.append (sLocalizedName
);
386 msDescription
.append (sal_Unicode('='));
392 uno::Any aValue
= mxSet
->getPropertyValue (sPropertyName
);
393 drawing::FillStyle aFillStyle
;
394 aValue
>>= aFillStyle
;
396 // Get the fill style name from the resource.
397 OUString sFillStyleName
;
399 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
402 case drawing::FillStyle_NONE
:
403 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE
);
405 case drawing::FillStyle_SOLID
:
406 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID
);
408 case drawing::FillStyle_GRADIENT
:
409 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT
);
411 case drawing::FillStyle_HATCH
:
412 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH
);
414 case drawing::FillStyle_BITMAP
:
415 sFillStyleName
= SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP
);
417 case drawing::FillStyle_MAKE_FIXED_SIZE
:
421 msDescription
.append (sFillStyleName
);
423 // Append the appropriate properties.
426 case drawing::FillStyle_NONE
:
428 case drawing::FillStyle_SOLID
:
429 AddProperty (OUString::createFromAscii ("FillColor"),
433 case drawing::FillStyle_GRADIENT
:
434 AddProperty (OUString::createFromAscii ("FillGradientName"),
439 case drawing::FillStyle_HATCH
:
440 AddProperty (OUString::createFromAscii ("FillColor"),
443 AddProperty (OUString::createFromAscii ("FillHatchName"),
448 case drawing::FillStyle_BITMAP
:
449 AddProperty (OUString::createFromAscii ("FillBitmapName"),
454 case drawing::FillStyle_MAKE_FIXED_SIZE
:
459 catch (::com::sun::star::beans::UnknownPropertyException
)
461 msDescription
.append (
462 OUString::createFromAscii("<unknown>"));
469 void DescriptionGenerator::AddPropertyNames (void)
473 uno::Reference
<beans::XPropertySetInfo
> xInfo (mxSet
->getPropertySetInfo());
476 uno::Sequence
<beans::Property
> aPropertyList (xInfo
->getProperties ());
477 for (int i
=0; i
<aPropertyList
.getLength(); i
++)
479 msDescription
.append (aPropertyList
[i
].Name
);
480 msDescription
.append (sal_Unicode(','));
487 } // end of namespace accessibility