Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "svx/DescriptionGenerator.hxx"
31 : : #include <com/sun/star/beans/PropertyState.hpp>
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/beans/XPropertyState.hpp>
34 : : #include <com/sun/star/container/XChild.hpp>
35 : : #include <com/sun/star/container/XNameContainer.hpp>
36 : : #include <com/sun/star/container/XNameAccess.hpp>
37 : : #include <com/sun/star/container/XNamed.hpp>
38 : : #include <com/sun/star/drawing/FillStyle.hpp>
39 : : #include <com/sun/star/drawing/XShapes.hpp>
40 : : #include <com/sun/star/drawing/XShapeDescriptor.hpp>
41 : : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
42 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 : : #include <com/sun/star/style/XStyle.hpp>
44 : : #include <comphelper/processfactory.hxx>
45 : : #include <osl/mutex.hxx>
46 : : #include <vcl/svapp.hxx>
47 : :
48 : : #include <com/sun/star/uno/Exception.hpp>
49 : :
50 : : // Includes for string resources.
51 : : #include "accessibility.hrc"
52 : : #include "svx/svdstr.hrc"
53 : : #include <svx/dialmgr.hxx>
54 : : #include <tools/string.hxx>
55 : :
56 : : #include <svx/xdef.hxx>
57 : : #include "svx/unoapi.hxx"
58 : : #include "lookupcolorname.hxx"
59 : :
60 : : using namespace ::rtl;
61 : : using namespace ::com::sun::star;
62 : :
63 : :
64 : : void SvxUnogetInternalNameForItem( const sal_Int16 nWhich, const rtl::OUString& rApiName, String& rInternalName ) throw();
65 : :
66 : : namespace accessibility {
67 : :
68 : :
69 : 0 : DescriptionGenerator::DescriptionGenerator (
70 : : const uno::Reference<drawing::XShape>& xShape)
71 : : : mxShape (xShape),
72 : : mxSet (mxShape, uno::UNO_QUERY),
73 [ # # ]: 0 : mbIsFirstProperty (true)
74 : : {
75 : 0 : }
76 : :
77 : :
78 : :
79 : :
80 : 0 : DescriptionGenerator::~DescriptionGenerator (void)
81 : : {
82 : 0 : }
83 : :
84 : :
85 : :
86 : :
87 : 0 : void DescriptionGenerator::Initialize (sal_Int32 nResourceId)
88 : : {
89 : : // Get the string from the resource for the specified id.
90 : 0 : OUString sPrefix;
91 : : {
92 [ # # ]: 0 : SolarMutexGuard aGuard;
93 [ # # ][ # # ]: 0 : sPrefix = OUString (SVX_RESSTR (nResourceId));
[ # # ]
94 : : }
95 : :
96 : : // Forward the call with the resulting string.
97 [ # # ]: 0 : Initialize (sPrefix);
98 : 0 : }
99 : :
100 : :
101 : :
102 : :
103 : 0 : void DescriptionGenerator::Initialize (::rtl::OUString sPrefix)
104 : : {
105 [ # # ][ # # ]: 0 : msDescription = sPrefix;
106 [ # # ]: 0 : if (mxSet.is())
107 : : {
108 : : {
109 [ # # ]: 0 : SolarMutexGuard aGuard;
110 : :
111 [ # # ]: 0 : msDescription.append (sal_Unicode (' '));
112 [ # # ][ # # ]: 0 : msDescription.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_WITH)));
[ # # ]
113 [ # # ]: 0 : msDescription.append (sal_Unicode (' '));
114 : :
115 [ # # ][ # # ]: 0 : msDescription.append (OUString (SVX_RESSTR (RID_SVXSTR_A11Y_STYLE)));
[ # # ]
116 [ # # ][ # # ]: 0 : msDescription.append (sal_Unicode ('='));
117 : : }
118 : :
119 : : try
120 : : {
121 [ # # ]: 0 : if (mxSet.is())
122 : : {
123 [ # # ][ # # ]: 0 : uno::Any aValue = mxSet->getPropertyValue (OUString(RTL_CONSTASCII_USTRINGPARAM("Style")) );
[ # # ]
124 [ # # ]: 0 : uno::Reference<container::XNamed> xStyle (aValue, uno::UNO_QUERY);
125 [ # # ]: 0 : if (xStyle.is())
126 [ # # ][ # # ]: 0 : msDescription.append (xStyle->getName());
[ # # ]
127 : : }
128 : : else
129 : : msDescription.append (
130 [ # # ][ # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<no style>")) );
131 : : }
132 [ # # ]: 0 : catch (const ::com::sun::star::beans::UnknownPropertyException &)
133 : : {
134 : : msDescription.append (
135 [ # # # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<unknown>")) );
136 : : }
137 : : }
138 : 0 : }
139 : :
140 : :
141 : :
142 : :
143 : 0 : ::rtl::OUString DescriptionGenerator::operator() (void)
144 : : {
145 : 0 : msDescription.append (sal_Unicode ('.'));
146 : 0 : return msDescription.makeStringAndClear();
147 : : }
148 : :
149 : :
150 : :
151 : :
152 : 0 : void DescriptionGenerator::AddProperty (
153 : : const OUString& sPropertyName,
154 : : PropertyType aType,
155 : : const sal_Int32 nLocalizedNameId,
156 : : long nWhichId)
157 : : {
158 : 0 : OUString sLocalizedName;
159 : : {
160 [ # # ]: 0 : SolarMutexGuard aGuard;
161 [ # # ][ # # ]: 0 : sLocalizedName = SVX_RESSTR (nLocalizedNameId);
[ # # ]
162 : : }
163 [ # # ]: 0 : AddProperty (sPropertyName, aType, sLocalizedName, nWhichId);
164 : 0 : }
165 : :
166 : :
167 : :
168 : :
169 : 0 : void DescriptionGenerator::AddProperty (const OUString& sPropertyName,
170 : : PropertyType aType, const OUString& sLocalizedName, long nWhichId)
171 : : {
172 [ # # ]: 0 : uno::Reference<beans::XPropertyState> xState (mxShape, uno::UNO_QUERY);
173 [ # # ][ # # ]: 0 : if (xState.is()
[ # # ]
174 [ # # ][ # # ]: 0 : && xState->getPropertyState(sPropertyName)!=beans::PropertyState_DEFAULT_VALUE)
175 [ # # ]: 0 : if (mxSet.is())
176 : : {
177 : : // Append a seperator from previous Properties.
178 [ # # ]: 0 : if ( ! mbIsFirstProperty)
179 [ # # ]: 0 : msDescription.append (sal_Unicode (','));
180 : : else
181 : : {
182 [ # # ]: 0 : SolarMutexGuard aGuard;
183 : :
184 [ # # ]: 0 : msDescription.append (sal_Unicode (' '));
185 [ # # ][ # # ]: 0 : msDescription.append (OUString (SVX_RESSTR(RID_SVXSTR_A11Y_AND)));
[ # # ]
186 [ # # ]: 0 : msDescription.append (sal_Unicode (' '));
187 [ # # ]: 0 : mbIsFirstProperty = false;
188 : : }
189 : :
190 : : // Delegate to type specific property handling.
191 [ # # # # : 0 : switch (aType)
# ]
192 : : {
193 : : case COLOR:
194 [ # # ]: 0 : AddColor (sPropertyName, sLocalizedName);
195 : 0 : break;
196 : : case INTEGER:
197 [ # # ]: 0 : AddInteger (sPropertyName, sLocalizedName);
198 : 0 : break;
199 : : case STRING:
200 [ # # ]: 0 : AddString (sPropertyName, sLocalizedName, nWhichId);
201 : 0 : break;
202 : : case FILL_STYLE:
203 [ # # ]: 0 : AddFillStyle (sPropertyName, sLocalizedName);
204 : 0 : break;
205 : : }
206 : 0 : }
207 : 0 : }
208 : :
209 : :
210 : :
211 : :
212 : 0 : void DescriptionGenerator::AppendString (const ::rtl::OUString& sString)
213 : : {
214 : 0 : msDescription.append (sString);
215 : 0 : }
216 : :
217 : :
218 : :
219 : :
220 : 0 : void DescriptionGenerator::AddLineProperties (void)
221 : : {
222 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("LineColor")),
223 : : DescriptionGenerator::COLOR,
224 [ # # ]: 0 : SIP_XA_LINECOLOR);
225 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("LineDashName")),
226 : : DescriptionGenerator::STRING,
227 : : SIP_XA_LINEDASH,
228 [ # # ]: 0 : XATTR_LINEDASH);
229 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("LineWidth")),
230 : : DescriptionGenerator::INTEGER,
231 [ # # ]: 0 : SIP_XA_LINEWIDTH);
232 : 0 : }
233 : :
234 : :
235 : :
236 : :
237 : : /** The fill style is described by the property "FillStyle". Depending on
238 : : its value a hatch-, gradient-, or bitmap name is appended.
239 : : */
240 : 0 : void DescriptionGenerator::AddFillProperties (void)
241 : : {
242 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle")),
243 : : DescriptionGenerator::FILL_STYLE,
244 [ # # ]: 0 : SIP_XA_FILLSTYLE);
245 : 0 : }
246 : :
247 : :
248 : :
249 : :
250 : 0 : void DescriptionGenerator::Add3DProperties (void)
251 : : {
252 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("D3DMaterialColor")),
253 : : DescriptionGenerator::COLOR,
254 [ # # ]: 0 : RID_SVXSTR_A11Y_3D_MATERIAL_COLOR);
255 : 0 : AddLineProperties ();
256 : 0 : AddFillProperties ();
257 : 0 : }
258 : :
259 : :
260 : :
261 : :
262 : 0 : void DescriptionGenerator::AddTextProperties (void)
263 : : {
264 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("CharColor")),
265 [ # # ][ # # ]: 0 : DescriptionGenerator::COLOR);
266 : 0 : AddFillProperties ();
267 : 0 : }
268 : :
269 : :
270 : :
271 : :
272 : : /** Search for the given color in the global color table. If found append
273 : : its name to the description. Otherwise append its RGB tuple.
274 : : */
275 : 0 : void DescriptionGenerator::AddColor (const OUString& sPropertyName,
276 : : const OUString& sLocalizedName)
277 : : {
278 : 0 : msDescription.append (sLocalizedName);
279 : 0 : msDescription.append (sal_Unicode('='));
280 : :
281 : : try
282 : : {
283 : :
284 : 0 : long nValue(0);
285 [ # # ]: 0 : if (mxSet.is())
286 : : {
287 [ # # ][ # # ]: 0 : uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
288 : 0 : aValue >>= nValue;
289 : : }
290 : :
291 [ # # ][ # # ]: 0 : msDescription.append (lookUpColorName(nValue));
292 : : }
293 [ # # ]: 0 : catch (const ::com::sun::star::beans::UnknownPropertyException &)
294 : : {
295 : : msDescription.append (
296 [ # # # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<unknown>")) );
297 : : }
298 : 0 : }
299 : :
300 : :
301 : :
302 : :
303 : 0 : void DescriptionGenerator::AddInteger (const OUString& sPropertyName,
304 : : const OUString& sLocalizedName)
305 : : {
306 : 0 : msDescription.append (sLocalizedName);
307 : 0 : msDescription.append (sal_Unicode('='));
308 : :
309 : : try
310 : : {
311 [ # # ]: 0 : if (mxSet.is())
312 : : {
313 [ # # ][ # # ]: 0 : uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
314 : 0 : long nValue = 0;
315 : 0 : aValue >>= nValue;
316 [ # # ]: 0 : msDescription.append (nValue);
317 : : }
318 : : }
319 [ # # ]: 0 : catch (const ::com::sun::star::beans::UnknownPropertyException &)
320 : : {
321 : : msDescription.append (
322 [ # # # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<unknown>")) );
323 : : }
324 : 0 : }
325 : :
326 : :
327 : :
328 : :
329 : 0 : void DescriptionGenerator::AddString (const OUString& sPropertyName,
330 : : const OUString& sLocalizedName, long nWhichId)
331 : : {
332 : 0 : msDescription.append (sLocalizedName);
333 : 0 : msDescription.append (sal_Unicode('='));
334 : :
335 : : try
336 : : {
337 [ # # ]: 0 : if (mxSet.is())
338 : : {
339 [ # # ][ # # ]: 0 : uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
340 : 0 : OUString sValue;
341 : 0 : aValue >>= sValue;
342 : :
343 [ # # ]: 0 : if (nWhichId >= 0)
344 : : {
345 [ # # ]: 0 : SolarMutexGuard aGuard;
346 [ # # ]: 0 : String sLocalizedValue;
347 : 0 : SvxUnogetInternalNameForItem (sal::static_int_cast<sal_Int16>(nWhichId),
348 : 0 : sValue, sLocalizedValue);
349 [ # # ][ # # ]: 0 : msDescription.append (sLocalizedValue);
[ # # ][ # # ]
350 : : }
351 : : else
352 [ # # ]: 0 : msDescription.append (sValue);
353 : : }
354 : : }
355 [ # # ]: 0 : catch (const ::com::sun::star::beans::UnknownPropertyException &)
356 : : {
357 : : msDescription.append (
358 [ # # # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<unknown>")) );
359 : : }
360 : 0 : }
361 : :
362 : :
363 : :
364 : :
365 : 0 : void DescriptionGenerator::AddFillStyle (const OUString& sPropertyName,
366 : : const OUString& sLocalizedName)
367 : : {
368 : 0 : msDescription.append (sLocalizedName);
369 : 0 : msDescription.append (sal_Unicode('='));
370 : :
371 : : try
372 : : {
373 [ # # ]: 0 : if (mxSet.is())
374 : : {
375 [ # # ][ # # ]: 0 : uno::Any aValue = mxSet->getPropertyValue (sPropertyName);
376 : : drawing::FillStyle aFillStyle;
377 [ # # ]: 0 : aValue >>= aFillStyle;
378 : :
379 : : // Get the fill style name from the resource.
380 : 0 : OUString sFillStyleName;
381 : : {
382 [ # # ]: 0 : SolarMutexGuard aGuard;
383 [ # # # # : 0 : switch (aFillStyle)
# # # ]
384 : : {
385 : : case drawing::FillStyle_NONE:
386 [ # # ][ # # ]: 0 : sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_NONE);
387 : 0 : break;
388 : : case drawing::FillStyle_SOLID:
389 [ # # ][ # # ]: 0 : sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_SOLID);
390 : 0 : break;
391 : : case drawing::FillStyle_GRADIENT:
392 [ # # ][ # # ]: 0 : sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_GRADIENT);
393 : 0 : break;
394 : : case drawing::FillStyle_HATCH:
395 [ # # ][ # # ]: 0 : sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_HATCH);
396 : 0 : break;
397 : : case drawing::FillStyle_BITMAP:
398 [ # # ][ # # ]: 0 : sFillStyleName = SVX_RESSTR(RID_SVXSTR_A11Y_FILLSTYLE_BITMAP);
399 : 0 : break;
400 : : case drawing::FillStyle_MAKE_FIXED_SIZE:
401 : 0 : break;
402 [ # # ]: 0 : }
403 : : }
404 [ # # ]: 0 : msDescription.append (sFillStyleName);
405 : :
406 : : // Append the appropriate properties.
407 [ # # # # : 0 : switch (aFillStyle)
# # # ]
408 : : {
409 : : case drawing::FillStyle_NONE:
410 : 0 : break;
411 : : case drawing::FillStyle_SOLID:
412 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")),
413 : : COLOR,
414 [ # # ][ # # ]: 0 : SIP_XA_FILLCOLOR);
415 : 0 : break;
416 : : case drawing::FillStyle_GRADIENT:
417 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillGradientName")),
418 : : STRING,
419 : : SIP_XA_FILLGRADIENT,
420 [ # # ][ # # ]: 0 : XATTR_FILLGRADIENT);
421 : 0 : break;
422 : : case drawing::FillStyle_HATCH:
423 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")),
424 : : COLOR,
425 [ # # ][ # # ]: 0 : SIP_XA_FILLCOLOR);
426 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillHatchName")),
427 : : STRING,
428 : : SIP_XA_FILLHATCH,
429 [ # # ][ # # ]: 0 : XATTR_FILLHATCH);
430 : 0 : break;
431 : : case drawing::FillStyle_BITMAP:
432 : : AddProperty (OUString(RTL_CONSTASCII_USTRINGPARAM("FillBitmapName")),
433 : : STRING,
434 : : SIP_XA_FILLBITMAP,
435 [ # # ][ # # ]: 0 : XATTR_FILLBITMAP);
436 : 0 : break;
437 : : case drawing::FillStyle_MAKE_FIXED_SIZE:
438 : 0 : break;
439 : 0 : }
440 : : }
441 : : }
442 [ # # ]: 0 : catch (const ::com::sun::star::beans::UnknownPropertyException &)
443 : : {
444 : : msDescription.append (
445 [ # # # # ]: 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("<unknown>")) );
446 : : }
447 : 0 : }
448 : :
449 : : } // end of namespace accessibility
450 : :
451 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|