Update ooo320-m1
[ooovba.git] / svx / source / accessibility / DescriptionGenerator.cxx
blobd21faf1fc2b4044482f39bedbc66135317ffc623
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DescriptionGenerator.cxx,v $
10 * $Revision: 1.13 $
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"
57 #endif
58 #include "svdstr.hrc"
59 #include <svx/dialmgr.hxx>
60 #include <tools/string.hxx>
62 #include <svx/xdef.hxx>
63 #include "unoapi.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)
78 : mxShape (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.
97 OUString sPrefix;
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;
113 if (mxSet.is())
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 ('='));
128 if (mxSet.is())
130 uno::Any aValue = mxSet->getPropertyValue (OUString::createFromAscii ("Style"));
131 uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
132 if (xStyle.is())
133 msDescription.append (xStyle->getName());
135 else
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,
161 PropertyType aType,
162 const sal_Int32 nLocalizedNameId,
163 long nWhichId)
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);
180 if (xState.is()
181 && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
182 if (mxSet.is())
184 // Append a seperator from previous Properties.
185 if ( ! mbIsFirstProperty)
186 msDescription.append (sal_Unicode (','));
187 else
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.
198 switch (aType)
200 case COLOR:
201 AddColor (sPropertyName, sLocalizedName);
202 break;
203 case INTEGER:
204 AddInteger (sPropertyName, sLocalizedName);
205 break;
206 case STRING:
207 AddString (sPropertyName, sLocalizedName, nWhichId);
208 break;
209 case FILL_STYLE:
210 AddFillStyle (sPropertyName, sLocalizedName);
211 break;
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,
231 SIP_XA_LINECOLOR);
232 AddProperty (OUString::createFromAscii ("LineDashName"),
233 DescriptionGenerator::STRING,
234 SIP_XA_LINEDASH,
235 XATTR_LINEDASH);
236 AddProperty (OUString::createFromAscii ("LineWidth"),
237 DescriptionGenerator::INTEGER,
238 SIP_XA_LINEWIDTH);
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,
251 SIP_XA_FILLSTYLE);
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('='));
291 long nValue(0);
292 if (mxSet.is())
294 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
295 aValue >>= nValue;
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('='));
328 if (mxSet.is())
330 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
331 long nValue = 0;
332 aValue >>= nValue;
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('='));
354 if (mxSet.is())
356 uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
357 OUString sValue;
358 aValue >>= sValue;
360 if (nWhichId >= 0)
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);
368 else
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('='));
390 if (mxSet.is())
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());
400 switch (aFillStyle)
402 case drawing::FillStyle_NONE:
403 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE);
404 break;
405 case drawing::FillStyle_SOLID:
406 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID);
407 break;
408 case drawing::FillStyle_GRADIENT:
409 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT);
410 break;
411 case drawing::FillStyle_HATCH:
412 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH);
413 break;
414 case drawing::FillStyle_BITMAP:
415 sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP);
416 break;
417 case drawing::FillStyle_MAKE_FIXED_SIZE:
418 break;
421 msDescription.append (sFillStyleName);
423 // Append the appropriate properties.
424 switch (aFillStyle)
426 case drawing::FillStyle_NONE:
427 break;
428 case drawing::FillStyle_SOLID:
429 AddProperty (OUString::createFromAscii ("FillColor"),
430 COLOR,
431 SIP_XA_FILLCOLOR);
432 break;
433 case drawing::FillStyle_GRADIENT:
434 AddProperty (OUString::createFromAscii ("FillGradientName"),
435 STRING,
436 SIP_XA_FILLGRADIENT,
437 XATTR_FILLGRADIENT);
438 break;
439 case drawing::FillStyle_HATCH:
440 AddProperty (OUString::createFromAscii ("FillColor"),
441 COLOR,
442 SIP_XA_FILLCOLOR);
443 AddProperty (OUString::createFromAscii ("FillHatchName"),
444 STRING,
445 SIP_XA_FILLHATCH,
446 XATTR_FILLHATCH);
447 break;
448 case drawing::FillStyle_BITMAP:
449 AddProperty (OUString::createFromAscii ("FillBitmapName"),
450 STRING,
451 SIP_XA_FILLBITMAP,
452 XATTR_FILLBITMAP);
453 break;
454 case drawing::FillStyle_MAKE_FIXED_SIZE:
455 break;
459 catch (::com::sun::star::beans::UnknownPropertyException)
461 msDescription.append (
462 OUString::createFromAscii("<unknown>"));
469 void DescriptionGenerator::AddPropertyNames (void)
471 if (mxSet.is())
473 uno::Reference<beans::XPropertySetInfo> xInfo (mxSet->getPropertySetInfo());
474 if (xInfo.is())
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