Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "exp_share.hxx"
21 :
22 : #include <rtl/ustrbuf.hxx>
23 : #include <sal/log.hxx>
24 : #include <tools/diagnose_ex.h>
25 :
26 : #include <com/sun/star/awt/CharSet.hpp>
27 : #include <com/sun/star/awt/FontFamily.hpp>
28 : #include <com/sun/star/awt/FontPitch.hpp>
29 : #include <com/sun/star/awt/FontSlant.hpp>
30 : #include <com/sun/star/awt/FontStrikeout.hpp>
31 : #include <com/sun/star/awt/FontType.hpp>
32 : #include <com/sun/star/awt/FontUnderline.hpp>
33 : #include <com/sun/star/awt/FontWeight.hpp>
34 : #include <com/sun/star/awt/FontWidth.hpp>
35 : #include <com/sun/star/awt/ImagePosition.hpp>
36 : #include <com/sun/star/awt/ImageScaleMode.hpp>
37 : #include <com/sun/star/awt/LineEndFormat.hpp>
38 : #include <com/sun/star/awt/PushButtonType.hpp>
39 : #include <com/sun/star/awt/VisualEffect.hpp>
40 : #include <com/sun/star/util/Date.hpp>
41 : #include <com/sun/star/util/Time.hpp>
42 : #include <tools/date.hxx>
43 : #include <tools/time.hxx>
44 :
45 : #include <com/sun/star/io/XPersistObject.hpp>
46 :
47 : #include <com/sun/star/script/XScriptEventsSupplier.hpp>
48 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
49 :
50 : #include <com/sun/star/style/VerticalAlignment.hpp>
51 :
52 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 : #include <com/sun/star/lang/XServiceInfo.hpp>
54 : #include <com/sun/star/lang/Locale.hpp>
55 : #include <com/sun/star/util/NumberFormat.hpp>
56 :
57 : #include <com/sun/star/view/SelectionType.hpp>
58 :
59 : #include <com/sun/star/form/binding/XListEntrySink.hpp>
60 : #include <com/sun/star/form/binding/XBindableValue.hpp>
61 : #include <com/sun/star/form/binding/XValueBinding.hpp>
62 : #include <com/sun/star/table/CellAddress.hpp>
63 : #include <com/sun/star/table/CellRangeAddress.hpp>
64 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
65 : #include <com/sun/star/document/GraphicObjectResolver.hpp>
66 :
67 : #include <comphelper/processfactory.hxx>
68 : #include <i18nlangtag/languagetag.hxx>
69 :
70 : using namespace ::com::sun::star;
71 : using namespace ::com::sun::star::uno;
72 :
73 : namespace xmlscript
74 : {
75 :
76 8 : Reference< xml::sax::XAttributeList > Style::createElement()
77 : {
78 8 : ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" );
79 :
80 : // style-id
81 8 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id );
82 :
83 : // background-color
84 8 : if (_set & 0x1)
85 : {
86 8 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":background-color", "0x" + OUString::number(_backgroundColor,16));
87 : }
88 :
89 : // text-color
90 8 : if (_set & 0x2)
91 : {
92 6 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":text-color", "0x" + OUString::number(_textColor,16));
93 : }
94 :
95 : // textline-color
96 8 : if (_set & 0x20)
97 : {
98 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":textline-color", "0x" + OUString::number(_textLineColor,16));
99 : }
100 :
101 : // fill-color
102 8 : if (_set & 0x10)
103 : {
104 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":fill-color", "0x" + OUString::number(_fillColor,16));
105 : }
106 :
107 : // border
108 8 : if (_set & 0x4)
109 : {
110 0 : switch (_border)
111 : {
112 : case BORDER_NONE:
113 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "none" );
114 0 : break;
115 : case BORDER_3D:
116 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "3d" );
117 0 : break;
118 : case BORDER_SIMPLE:
119 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "simple" );
120 0 : break;
121 : case BORDER_SIMPLE_COLOR: {
122 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "0x" + OUString::number(_borderColor,16));
123 0 : break;
124 : }
125 : default:
126 : SAL_WARN( "xmlscript.xmldlg", "### unexpected border value!" );
127 0 : break;
128 : }
129 : }
130 :
131 : // visual effect (look)
132 8 : if (_set & 0x40)
133 : {
134 0 : switch (_visualEffect)
135 : {
136 : case awt::VisualEffect::NONE:
137 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "none" );
138 0 : break;
139 : case awt::VisualEffect::LOOK3D:
140 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "3d" );
141 0 : break;
142 : case awt::VisualEffect::FLAT:
143 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "simple" );
144 0 : break;
145 : default:
146 : SAL_WARN( "xmlscript.xmldlg", "### unexpected visual effect value!" );
147 0 : break;
148 : }
149 : }
150 :
151 : // font-
152 8 : if (_set & 0x8)
153 : {
154 6 : awt::FontDescriptor def_descr;
155 :
156 : // dialog:font-name CDATA #IMPLIED
157 6 : if (def_descr.Name != _descr.Name)
158 : {
159 6 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-name", _descr.Name );
160 : }
161 : // dialog:font-height %numeric; #IMPLIED
162 6 : if (def_descr.Height != _descr.Height)
163 : {
164 6 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-height", OUString::number( _descr.Height ) );
165 : }
166 : // dialog:font-width %numeric; #IMPLIED
167 6 : if (def_descr.Width != _descr.Width)
168 : {
169 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-width", OUString::number( _descr.Width ) );
170 : }
171 : // dialog:font-stylename CDATA #IMPLIED
172 6 : if (def_descr.StyleName != _descr.StyleName)
173 : {
174 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-stylename", _descr.StyleName );
175 : }
176 : // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
177 6 : if (def_descr.Family != _descr.Family)
178 : {
179 0 : switch (_descr.Family)
180 : {
181 : case awt::FontFamily::DECORATIVE:
182 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "decorative" );
183 0 : break;
184 : case awt::FontFamily::MODERN:
185 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "modern" );
186 0 : break;
187 : case awt::FontFamily::ROMAN:
188 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "roman" );
189 0 : break;
190 : case awt::FontFamily::SCRIPT:
191 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "script" );
192 0 : break;
193 : case awt::FontFamily::SWISS:
194 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "swiss" );
195 0 : break;
196 : case awt::FontFamily::SYSTEM:
197 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "system" );
198 0 : break;
199 : default:
200 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-family!" );
201 0 : break;
202 : }
203 : }
204 : // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
205 6 : if (def_descr.CharSet != _descr.CharSet)
206 : {
207 6 : switch (_descr.CharSet)
208 : {
209 : case awt::CharSet::ANSI:
210 6 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ansi" );
211 6 : break;
212 : case awt::CharSet::MAC:
213 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "mac" );
214 0 : break;
215 : case awt::CharSet::IBMPC_437:
216 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_437" );
217 0 : break;
218 : case awt::CharSet::IBMPC_850:
219 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_850" );
220 0 : break;
221 : case awt::CharSet::IBMPC_860:
222 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_860" );
223 0 : break;
224 : case awt::CharSet::IBMPC_861:
225 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_861" );
226 0 : break;
227 : case awt::CharSet::IBMPC_863:
228 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_863" );
229 0 : break;
230 : case awt::CharSet::IBMPC_865:
231 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_865" );
232 0 : break;
233 : case awt::CharSet::SYSTEM:
234 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "system" );
235 0 : break;
236 : case awt::CharSet::SYMBOL:
237 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "symbol" );
238 0 : break;
239 : default:
240 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-charset!" );
241 0 : break;
242 : }
243 : }
244 : // dialog:font-pitch "(fixed|variable)" #IMPLIED
245 6 : if (def_descr.Pitch != _descr.Pitch)
246 : {
247 0 : switch (_descr.Pitch)
248 : {
249 : case awt::FontPitch::FIXED:
250 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "fixed" );
251 0 : break;
252 : case awt::FontPitch::VARIABLE:
253 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "variable" );
254 0 : break;
255 : default:
256 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-pitch!" );
257 0 : break;
258 : }
259 : }
260 : // dialog:font-charwidth CDATA #IMPLIED
261 6 : if (def_descr.CharacterWidth != _descr.CharacterWidth)
262 : {
263 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charwidth", OUString::number( (float)_descr.CharacterWidth ) );
264 : }
265 : // dialog:font-weight CDATA #IMPLIED
266 6 : if (def_descr.Weight != _descr.Weight)
267 : {
268 6 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-weight", OUString::number( (float)_descr.Weight ) );
269 : }
270 : // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
271 6 : if (def_descr.Slant != _descr.Slant)
272 : {
273 0 : switch (_descr.Slant)
274 : {
275 : case awt::FontSlant_OBLIQUE:
276 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "oblique" );
277 0 : break;
278 : case awt::FontSlant_ITALIC:
279 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "italic" );
280 0 : break;
281 : case awt::FontSlant_REVERSE_OBLIQUE:
282 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_oblique" );
283 0 : break;
284 : case awt::FontSlant_REVERSE_ITALIC:
285 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_italic" );
286 0 : break;
287 : default:
288 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-slant!" );
289 0 : break;
290 : }
291 : }
292 : // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
293 6 : if (def_descr.Underline != _descr.Underline)
294 : {
295 0 : switch (_descr.Underline)
296 : {
297 : case awt::FontUnderline::SINGLE:
298 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "single" );
299 0 : break;
300 : case awt::FontUnderline::DOUBLE:
301 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "double" );
302 0 : break;
303 : case awt::FontUnderline::DOTTED:
304 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dotted" );
305 0 : break;
306 : case awt::FontUnderline::DASH:
307 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dash" );
308 0 : break;
309 : case awt::FontUnderline::LONGDASH:
310 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "longdash" );
311 0 : break;
312 : case awt::FontUnderline::DASHDOT:
313 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdot" );
314 0 : break;
315 : case awt::FontUnderline::DASHDOTDOT:
316 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdotdot" );
317 0 : break;
318 : case awt::FontUnderline::SMALLWAVE:
319 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "smallwave" );
320 0 : break;
321 : case awt::FontUnderline::WAVE:
322 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "wave" );
323 0 : break;
324 : case awt::FontUnderline::DOUBLEWAVE:
325 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "doublewave" );
326 0 : break;
327 : case awt::FontUnderline::BOLD:
328 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bold" );
329 0 : break;
330 : case awt::FontUnderline::BOLDDOTTED:
331 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddotted" );
332 0 : break;
333 : case awt::FontUnderline::BOLDDASH:
334 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddash" );
335 0 : break;
336 : case awt::FontUnderline::BOLDLONGDASH:
337 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldlongdash" );
338 0 : break;
339 : case awt::FontUnderline::BOLDDASHDOT:
340 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdot" );
341 0 : break;
342 : case awt::FontUnderline::BOLDDASHDOTDOT:
343 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdotdot" );
344 0 : break;
345 : case awt::FontUnderline::BOLDWAVE:
346 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldwave" );
347 0 : break;
348 : default:
349 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-underline!" );
350 0 : break;
351 : }
352 : }
353 : // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
354 6 : if (def_descr.Strikeout != _descr.Strikeout)
355 : {
356 0 : switch (_descr.Strikeout)
357 : {
358 : case awt::FontStrikeout::SINGLE:
359 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "single" );
360 0 : break;
361 : case awt::FontStrikeout::DOUBLE:
362 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "double" );
363 0 : break;
364 : case awt::FontStrikeout::BOLD:
365 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "bold" );
366 0 : break;
367 : case awt::FontStrikeout::SLASH:
368 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "slash" );
369 0 : break;
370 : case awt::FontStrikeout::X:
371 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "x" );
372 0 : break;
373 : default:
374 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-strikeout!" );
375 0 : break;
376 : }
377 : }
378 : // dialog:font-orientation CDATA #IMPLIED
379 6 : if (def_descr.Orientation != _descr.Orientation)
380 : {
381 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::number( (float)_descr.Orientation ) );
382 : }
383 : // dialog:font-kerning %boolean; #IMPLIED
384 6 : if ((def_descr.Kerning != sal_False) != (_descr.Kerning != sal_False))
385 : {
386 0 : pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
387 : }
388 : // dialog:font-wordlinemode %boolean; #IMPLIED
389 6 : if ((def_descr.WordLineMode != sal_False) != (_descr.WordLineMode != sal_False))
390 : {
391 0 : pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
392 : }
393 : // dialog:font-type "(raster|device|scalable)" #IMPLIED
394 6 : if (def_descr.Type != _descr.Type)
395 : {
396 0 : switch (_descr.Type)
397 : {
398 : case awt::FontType::RASTER:
399 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "raster" );
400 0 : break;
401 : case awt::FontType::DEVICE:
402 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "device" );
403 0 : break;
404 : case awt::FontType::SCALABLE:
405 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "scalable" );
406 0 : break;
407 : default:
408 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-type!" );
409 0 : break;
410 : }
411 : }
412 :
413 : // additional attributes not in FontDescriptor struct
414 : // dialog:font-relief (none|embossed|engraved) #IMPLIED
415 6 : switch (_fontRelief)
416 : {
417 : case awt::FontRelief::NONE: // dont export default
418 6 : break;
419 : case awt::FontRelief::EMBOSSED:
420 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "embossed" );
421 0 : break;
422 : case awt::FontRelief::ENGRAVED:
423 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "engraved" );
424 0 : break;
425 : default:
426 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-relief!" );
427 0 : break;
428 : }
429 : // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
430 6 : switch (_fontEmphasisMark)
431 : {
432 : case awt::FontEmphasisMark::NONE: // dont export default
433 6 : break;
434 : case awt::FontEmphasisMark::DOT:
435 0 : pStyle->addAttribute(XMLNS_DIALOGS_PREFIX ":font-emphasismark", "dot" );
436 0 : break;
437 : case awt::FontEmphasisMark::CIRCLE:
438 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "circle" );
439 0 : break;
440 : case awt::FontEmphasisMark::DISC:
441 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "disc" );
442 0 : break;
443 : case awt::FontEmphasisMark::ACCENT:
444 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "accent" );
445 0 : break;
446 : case awt::FontEmphasisMark::ABOVE:
447 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "above" );
448 0 : break;
449 : case awt::FontEmphasisMark::BELOW:
450 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "below" );
451 0 : break;
452 : default:
453 : SAL_WARN( "xmlscript.xmldlg", "### unexpected font-emphasismark!" );
454 0 : break;
455 6 : }
456 : }
457 :
458 8 : return pStyle;
459 : }
460 :
461 0 : void ElementDescriptor::addNumberFormatAttr(
462 : Reference< beans::XPropertySet > const & xFormatProperties )
463 : {
464 0 : Reference< beans::XPropertyState > xState( xFormatProperties, UNO_QUERY );
465 0 : OUString sFormat;
466 0 : lang::Locale locale;
467 0 : OSL_VERIFY( xFormatProperties->getPropertyValue( "FormatString" ) >>= sFormat );
468 0 : OSL_VERIFY( xFormatProperties->getPropertyValue( "Locale" ) >>= locale );
469 :
470 0 : addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
471 :
472 : // format-locale
473 0 : LanguageTag aLanguageTag( locale);
474 0 : OUString aStr;
475 0 : if (aLanguageTag.isIsoLocale())
476 : {
477 : // Old style "lll;CC" for compatibility, I really don't know what may
478 : // consume this.
479 0 : if (aLanguageTag.getCountry().isEmpty())
480 0 : aStr = aLanguageTag.getLanguage();
481 : else
482 0 : aStr = aLanguageTag.getLanguage() + ";" + aLanguageTag.getCountry();
483 : }
484 : else
485 : {
486 0 : aStr = aLanguageTag.getBcp47( false);
487 : }
488 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", aStr );
489 0 : }
490 :
491 53 : Any ElementDescriptor::readProp( OUString const & rPropName )
492 : {
493 53 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
494 : {
495 16 : return _xProps->getPropertyValue( rPropName );
496 : }
497 37 : return Any();
498 : }
499 :
500 56 : void ElementDescriptor::readStringAttr(
501 : OUString const & rPropName, OUString const & rAttrName )
502 : {
503 56 : if (beans::PropertyState_DEFAULT_VALUE !=
504 56 : _xPropState->getPropertyState( rPropName ))
505 : {
506 5 : Any a( _xProps->getPropertyValue( rPropName ) );
507 10 : OUString v;
508 5 : if (a >>= v)
509 5 : addAttribute( rAttrName, v );
510 : else
511 5 : SAL_WARN( "xmlscript.xmldlg", "### unexpected property type!" );
512 : }
513 56 : }
514 :
515 0 : void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
516 : {
517 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
518 : {
519 0 : Any a( _xProps->getPropertyValue( rPropName ) );
520 0 : if (a.getValueTypeClass() == TypeClass_LONG)
521 : {
522 0 : addAttribute( rAttrName, "0x" + OUString::number((sal_Int64)(sal_uInt64)*static_cast<sal_uInt32 const *>(a.getValue()),16) );
523 0 : }
524 : }
525 0 : }
526 :
527 0 : void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
528 : {
529 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
530 : {
531 0 : Any a( _xProps->getPropertyValue( rPropName ) );
532 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
533 : {
534 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
535 : {
536 : case 0:
537 0 : addAttribute( rAttrName, "system_short" );
538 0 : break;
539 : case 1:
540 0 : addAttribute( rAttrName, "system_short_YY" );
541 0 : break;
542 : case 2:
543 0 : addAttribute( rAttrName, "system_short_YYYY" );
544 0 : break;
545 : case 3:
546 0 : addAttribute( rAttrName, "system_long" );
547 0 : break;
548 : case 4:
549 0 : addAttribute( rAttrName, "short_DDMMYY" );
550 0 : break;
551 : case 5:
552 0 : addAttribute( rAttrName, "short_MMDDYY" );
553 0 : break;
554 : case 6:
555 0 : addAttribute( rAttrName, "short_YYMMDD" );
556 0 : break;
557 : case 7:
558 0 : addAttribute( rAttrName, "short_DDMMYYYY" );
559 0 : break;
560 : case 8:
561 0 : addAttribute( rAttrName, "short_MMDDYYYY" );
562 0 : break;
563 : case 9:
564 0 : addAttribute( rAttrName, "short_YYYYMMDD" );
565 0 : break;
566 : case 10:
567 0 : addAttribute( rAttrName, "short_YYMMDD_DIN5008" );
568 0 : break;
569 : case 11:
570 0 : addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" );
571 0 : break;
572 : default:
573 : SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" );
574 0 : break;
575 : }
576 : }
577 : else
578 0 : OSL_FAIL( "### unexpected property type!" );
579 : }
580 0 : }
581 :
582 0 : void ElementDescriptor::readDateAttr( OUString const & rPropName, OUString const & rAttrName )
583 : {
584 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
585 : {
586 0 : Any a( _xProps->getPropertyValue( rPropName ) );
587 0 : if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get())
588 : {
589 0 : util::Date aUDate;
590 0 : if (a >>= aUDate)
591 : {
592 0 : ::Date aTDate(aUDate);
593 0 : addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) );
594 : }
595 : else
596 : OSL_FAIL( "### internal error" );
597 : }
598 : else
599 0 : OSL_FAIL( "### unexpected property type!" );
600 : }
601 0 : }
602 :
603 0 : void ElementDescriptor::readTimeAttr( OUString const & rPropName, OUString const & rAttrName )
604 : {
605 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
606 : {
607 0 : Any a( _xProps->getPropertyValue( rPropName ) );
608 0 : if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get())
609 : {
610 0 : util::Time aUTime;
611 0 : if (a >>= aUTime)
612 : {
613 0 : ::tools::Time aTTime(aUTime);
614 0 : addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) );
615 : }
616 : else
617 : OSL_FAIL( "### internal error" );
618 : }
619 : else
620 0 : OSL_FAIL( "### unexpected property type!" );
621 : }
622 0 : }
623 :
624 0 : void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
625 : {
626 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
627 : {
628 0 : Any a( _xProps->getPropertyValue( rPropName ) );
629 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
630 : {
631 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
632 : {
633 : case 0:
634 0 : addAttribute( rAttrName, "24h_short" );
635 0 : break;
636 : case 1:
637 0 : addAttribute( rAttrName, "24h_long" );
638 0 : break;
639 : case 2:
640 0 : addAttribute( rAttrName, "12h_short" );
641 0 : break;
642 : case 3:
643 0 : addAttribute( rAttrName, "12h_long" );
644 0 : break;
645 : case 4:
646 0 : addAttribute( rAttrName, "Duration_short" );
647 0 : break;
648 : case 5:
649 0 : addAttribute( rAttrName, "Duration_long" );
650 0 : break;
651 : default:
652 : SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" );
653 0 : break;
654 : }
655 : }
656 : else
657 0 : OSL_FAIL( "### unexpected property type!" );
658 : }
659 0 : }
660 :
661 9 : void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
662 : {
663 9 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
664 : {
665 0 : Any a( _xProps->getPropertyValue( rPropName ) );
666 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
667 : {
668 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
669 : {
670 : case 0:
671 0 : addAttribute( rAttrName, "left" );
672 0 : break;
673 : case 1:
674 0 : addAttribute( rAttrName, "center" );
675 0 : break;
676 : case 2:
677 0 : addAttribute( rAttrName, "right" );
678 0 : break;
679 : default:
680 : SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" );
681 0 : break;
682 : }
683 : }
684 : else
685 0 : OSL_FAIL( "### unexpected property type!" );
686 : }
687 9 : }
688 :
689 3 : void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
690 : {
691 3 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
692 : {
693 3 : Any a( _xProps->getPropertyValue( rPropName ) );
694 3 : if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get())
695 : {
696 : style::VerticalAlignment eAlign;
697 3 : a >>= eAlign;
698 3 : switch (eAlign)
699 : {
700 : case style::VerticalAlignment_TOP:
701 0 : addAttribute( rAttrName, "top" );
702 0 : break;
703 : case style::VerticalAlignment_MIDDLE:
704 3 : addAttribute( rAttrName, "center" );
705 3 : break;
706 : case style::VerticalAlignment_BOTTOM:
707 0 : addAttribute( rAttrName, "bottom" );
708 0 : break;
709 : default:
710 : SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" );
711 0 : break;
712 : }
713 : }
714 : else
715 3 : OSL_FAIL( "### unexpected property type!" );
716 : }
717 3 : }
718 :
719 8 : void ElementDescriptor::readImageURLAttr( OUString const & rPropName, OUString const & rAttrName )
720 : {
721 8 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
722 : {
723 0 : OUString sURL;
724 0 : _xProps->getPropertyValue( rPropName ) >>= sURL;
725 :
726 0 : if ( sURL.startsWith( XMLSCRIPT_GRAPHOBJ_URLPREFIX ) )
727 : {
728 0 : Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
729 0 : if ( xDocStorage.is() )
730 : {
731 0 : Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
732 : uno::Reference< document::XGraphicObjectResolver > xGraphicResolver =
733 0 : document::GraphicObjectResolver::createWithStorage( xContext, xDocStorage->getDocumentStorage() );
734 0 : sURL = xGraphicResolver->resolveGraphicObjectURL( sURL );
735 0 : }
736 : }
737 0 : if ( !sURL.isEmpty() )
738 0 : addAttribute( rAttrName, sURL );
739 : }
740 8 : }
741 :
742 1 : void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
743 : {
744 1 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
745 : {
746 0 : Any a( _xProps->getPropertyValue( rPropName ) );
747 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
748 : {
749 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
750 : {
751 : case 0:
752 0 : addAttribute( rAttrName, "left" );
753 0 : break;
754 : case 1:
755 0 : addAttribute( rAttrName, "top" );
756 0 : break;
757 : case 2:
758 0 : addAttribute( rAttrName, "right" );
759 0 : break;
760 : case 3:
761 0 : addAttribute( rAttrName, "bottom" );
762 0 : break;
763 : default:
764 : SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" );
765 0 : break;
766 : }
767 : }
768 : else
769 0 : OSL_FAIL( "### unexpected property type!" );
770 : }
771 1 : }
772 :
773 3 : void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
774 : {
775 3 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
776 : {
777 3 : Any a( _xProps->getPropertyValue( rPropName ) );
778 3 : if (a.getValueTypeClass() == TypeClass_SHORT)
779 : {
780 3 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
781 : {
782 : case awt::ImagePosition::LeftTop:
783 0 : addAttribute( rAttrName, "left-top" );
784 0 : break;
785 : case awt::ImagePosition::LeftCenter:
786 0 : addAttribute( rAttrName, "left-center" );
787 0 : break;
788 : case awt::ImagePosition::LeftBottom:
789 0 : addAttribute( rAttrName, "left-bottom" );
790 0 : break;
791 : case awt::ImagePosition::RightTop:
792 0 : addAttribute( rAttrName, "right-top" );
793 0 : break;
794 : case awt::ImagePosition::RightCenter:
795 0 : addAttribute( rAttrName, "right-center" );
796 0 : break;
797 : case awt::ImagePosition::RightBottom:
798 0 : addAttribute( rAttrName, "right-bottom" );
799 0 : break;
800 : case awt::ImagePosition::AboveLeft:
801 0 : addAttribute( rAttrName, "top-left" );
802 0 : break;
803 : case awt::ImagePosition::AboveCenter:
804 3 : addAttribute( rAttrName, "top-center" );
805 3 : break;
806 : case awt::ImagePosition::AboveRight:
807 0 : addAttribute( rAttrName, "top-right" );
808 0 : break;
809 : case awt::ImagePosition::BelowLeft:
810 0 : addAttribute( rAttrName, "bottom-left" );
811 0 : break;
812 : case awt::ImagePosition::BelowCenter:
813 0 : addAttribute( rAttrName, "bottom-center" );
814 0 : break;
815 : case awt::ImagePosition::BelowRight:
816 0 : addAttribute( rAttrName, "bottom-right" );
817 0 : break;
818 : case awt::ImagePosition::Centered:
819 0 : addAttribute( rAttrName, "center" );
820 0 : break;
821 : default:
822 : SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" );
823 0 : break;
824 : }
825 3 : }
826 : }
827 3 : }
828 :
829 1 : void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
830 : {
831 1 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
832 : {
833 0 : Any a( _xProps->getPropertyValue( rPropName ) );
834 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
835 : {
836 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
837 : {
838 : case awt::PushButtonType_STANDARD:
839 0 : addAttribute( rAttrName, "standard" );
840 0 : break;
841 : case awt::PushButtonType_OK:
842 0 : addAttribute( rAttrName, "ok" );
843 0 : break;
844 : case awt::PushButtonType_CANCEL:
845 0 : addAttribute( rAttrName, "cancel" );
846 0 : break;
847 : case awt::PushButtonType_HELP:
848 0 : addAttribute( rAttrName, "help" );
849 0 : break;
850 : default:
851 : SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" );
852 0 : break;
853 : }
854 0 : }
855 : }
856 1 : }
857 :
858 0 : void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
859 : {
860 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
861 : {
862 0 : Any a( _xProps->getPropertyValue( rPropName ) );
863 0 : if (a.getValueTypeClass() == TypeClass_LONG)
864 : {
865 0 : switch (*static_cast<sal_Int32 const *>(a.getValue()))
866 : {
867 : case 0:
868 0 : addAttribute( rAttrName, "horizontal" );
869 0 : break;
870 : case 1:
871 0 : addAttribute( rAttrName, "vertical" );
872 0 : break;
873 : default:
874 : SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" );
875 0 : break;
876 : }
877 0 : }
878 : }
879 0 : }
880 :
881 4 : void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
882 : {
883 4 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
884 : {
885 0 : Any a( _xProps->getPropertyValue( rPropName ) );
886 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
887 : {
888 0 : switch (*static_cast<sal_Int16 const *>(a.getValue()))
889 : {
890 : case awt::LineEndFormat::CARRIAGE_RETURN:
891 0 : addAttribute( rAttrName, "carriage-return" );
892 0 : break;
893 : case awt::LineEndFormat::LINE_FEED:
894 0 : addAttribute( rAttrName, "line-feed" );
895 0 : break;
896 : case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
897 0 : addAttribute( rAttrName, "carriage-return-line-feed" );
898 0 : break;
899 : default:
900 : SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" );
901 0 : break;
902 : }
903 0 : }
904 : }
905 4 : }
906 :
907 9 : void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
908 : {
909 9 : Reference< lang::XMultiServiceFactory > xFac;
910 9 : if ( _xDocument.is() )
911 9 : xFac.set( _xDocument, uno::UNO_QUERY );
912 :
913 18 : Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
914 :
915 9 : if ( xFac.is() && xBinding.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":linked-cell" )
916 : {
917 : try
918 : {
919 3 : Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
920 6 : Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
921 3 : if ( xBindable.is() )
922 : {
923 0 : table::CellAddress aAddress;
924 0 : xBindable->getPropertyValue( "BoundCell" ) >>= aAddress;
925 0 : xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
926 0 : OUString sAddress;
927 0 : xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
928 0 : if ( !sAddress.isEmpty() )
929 0 : addAttribute( rAttrName, sAddress );
930 :
931 0 : SAL_INFO("xmlscript.xmldlg", "*** Bindable value " << sAddress );
932 :
933 3 : }
934 : }
935 0 : catch( uno::Exception& )
936 : {
937 : }
938 : }
939 18 : Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
940 9 : if ( xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range" )
941 : {
942 2 : Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
943 2 : if ( xListSource.is() )
944 : {
945 : try
946 : {
947 1 : Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
948 :
949 1 : table::CellRangeAddress aAddress;
950 1 : xListSource->getPropertyValue( "CellRange" ) >>= aAddress;
951 :
952 2 : OUString sAddress;
953 1 : xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
954 1 : xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
955 : SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress );
956 1 : if ( !sAddress.isEmpty() )
957 2 : addAttribute( rAttrName, sAddress );
958 : }
959 0 : catch( uno::Exception& )
960 : {
961 : }
962 2 : }
963 9 : }
964 9 : }
965 :
966 0 : void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
967 : {
968 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
969 : {
970 0 : Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
971 :
972 0 : if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get())
973 : {
974 : ::view::SelectionType eSelectionType;
975 0 : aSelectionType >>= eSelectionType;
976 :
977 0 : switch (eSelectionType)
978 : {
979 : case ::view::SelectionType_NONE:
980 0 : addAttribute( rAttrName, "none" );
981 0 : break;
982 : case ::view::SelectionType_SINGLE:
983 0 : addAttribute( rAttrName, "single" );
984 0 : break;
985 : case ::view::SelectionType_MULTI:
986 0 : addAttribute( rAttrName, "multi" );
987 0 : break;
988 : case ::view::SelectionType_RANGE:
989 0 : addAttribute( rAttrName, "range" );
990 0 : break;
991 : default:
992 : SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" );
993 0 : break;
994 : }
995 0 : }
996 : }
997 0 : }
998 :
999 5 : void ElementDescriptor::readScrollableSettings()
1000 : {
1001 : readLongAttr( "ScrollHeight",
1002 5 : XMLNS_DIALOGS_PREFIX ":scrollheight" );
1003 : readLongAttr( "ScrollWidth",
1004 5 : XMLNS_DIALOGS_PREFIX ":scrollwidth" );
1005 : readLongAttr( "ScrollTop",
1006 5 : XMLNS_DIALOGS_PREFIX ":scrolltop" );
1007 : readLongAttr( "ScrollLeft",
1008 5 : XMLNS_DIALOGS_PREFIX ":scrollleft" );
1009 : readBoolAttr( "HScroll",
1010 5 : XMLNS_DIALOGS_PREFIX ":hscroll" );
1011 : readBoolAttr( "VScroll",
1012 5 : XMLNS_DIALOGS_PREFIX ":vscroll" );
1013 5 : }
1014 :
1015 0 : void ElementDescriptor::readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName )
1016 : {
1017 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
1018 : {
1019 0 : Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) );
1020 :
1021 0 : if (aImageScaleMode.getValueTypeClass() == TypeClass_SHORT)
1022 : {
1023 : sal_Int16 nImageScaleMode;
1024 0 : aImageScaleMode >>= nImageScaleMode;
1025 :
1026 0 : switch(nImageScaleMode)
1027 : {
1028 : case ::awt::ImageScaleMode::NONE:
1029 0 : addAttribute( rAttrName, OUString( "none") );
1030 0 : break;
1031 : case ::awt::ImageScaleMode::ISOTROPIC:
1032 0 : addAttribute( rAttrName, OUString( "isotropic") );
1033 0 : break;
1034 : case ::awt::ImageScaleMode::ANISOTROPIC:
1035 0 : addAttribute( rAttrName, OUString( "anisotropic" ) );
1036 0 : break;
1037 : default:
1038 : OSL_ENSURE( false, "### illegal image scale mode value.");
1039 0 : break;
1040 : }
1041 0 : }
1042 : }
1043 0 : }
1044 :
1045 14 : void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
1046 : {
1047 14 : Any a( _xProps->getPropertyValue( "Name" ) );
1048 :
1049 : // The following is a hack to allow 'form' controls to override the default
1050 : // control supported by dialogs. This should work well for both vba support and
1051 : // normal openoffice ( when normal 'Dialogs' decide to support form control models )
1052 : // In the future VBA support might require custom models ( and not the just the form
1053 : // variant of a control that we currently use ) In this case the door is still open,
1054 : // we just need to define a new way for the 'ServiceName' to be extracted from the
1055 : // incoming model. E.g. the use of supporting service
1056 : // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1057 : // is only an implementation detail here, in the future some other
1058 : // method ( perhaps a custom prop ) could be used instead.
1059 28 : Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1060 14 : if ( xSrvInfo.is() && xSrvInfo->supportsService( "com.sun.star.form.FormComponent" ) )
1061 : {
1062 3 : Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1063 3 : if ( xPersist.is() )
1064 : {
1065 3 : OUString sCtrlName = xPersist->getServiceName();
1066 3 : if ( !sCtrlName.isEmpty() )
1067 3 : addAttribute( XMLNS_DIALOGS_PREFIX ":control-implementation", sCtrlName );
1068 3 : }
1069 : }
1070 14 : addAttribute( XMLNS_DIALOGS_PREFIX ":id", * static_cast< const OUString * >( a.getValue() ) );
1071 14 : readShortAttr( "TabIndex", XMLNS_DIALOGS_PREFIX ":tab-index" );
1072 :
1073 14 : bool bEnabled = false;
1074 14 : if (_xProps->getPropertyValue( "Enabled" ) >>= bEnabled)
1075 : {
1076 14 : if (! bEnabled)
1077 : {
1078 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":disabled", "true" );
1079 : }
1080 : }
1081 : else
1082 : {
1083 : SAL_WARN( "xmlscript.xmldlg", "unexpected property type for \"Enabled\": not bool!" );
1084 : }
1085 :
1086 14 : if (supportVisible) try
1087 : {
1088 9 : bool bVisible = true;
1089 9 : if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible)
1090 : {
1091 :
1092 : // only write out the non default case
1093 9 : if (! bVisible)
1094 : {
1095 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":visible", "false" );
1096 : }
1097 : }
1098 : }
1099 0 : catch( Exception& )
1100 : {
1101 : DBG_UNHANDLED_EXCEPTION();
1102 : }
1103 : // force writing of pos/size
1104 14 : a = _xProps->getPropertyValue( "PositionX" );
1105 14 : if (a.getValueTypeClass() == TypeClass_LONG)
1106 : {
1107 14 : addAttribute( XMLNS_DIALOGS_PREFIX ":left", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1108 : }
1109 14 : a = _xProps->getPropertyValue( "PositionY" );
1110 14 : if (a.getValueTypeClass() == TypeClass_LONG)
1111 : {
1112 14 : addAttribute( XMLNS_DIALOGS_PREFIX ":top", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1113 : }
1114 14 : a = _xProps->getPropertyValue( "Width" );
1115 14 : if (a.getValueTypeClass() == TypeClass_LONG)
1116 : {
1117 14 : addAttribute( XMLNS_DIALOGS_PREFIX ":width", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1118 : }
1119 14 : a = _xProps->getPropertyValue( "Height" );
1120 14 : if (a.getValueTypeClass() == TypeClass_LONG)
1121 : {
1122 14 : addAttribute( XMLNS_DIALOGS_PREFIX ":height", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1123 : }
1124 :
1125 14 : if (supportPrintable)
1126 : {
1127 9 : readBoolAttr( "Printable", XMLNS_DIALOGS_PREFIX ":printable" );
1128 : }
1129 14 : readLongAttr( "Step", XMLNS_DIALOGS_PREFIX ":page" );
1130 14 : readStringAttr( "Tag", XMLNS_DIALOGS_PREFIX ":tag" );
1131 14 : readStringAttr( "HelpText", XMLNS_DIALOGS_PREFIX ":help-text" );
1132 28 : readStringAttr( "HelpURL", XMLNS_DIALOGS_PREFIX ":help-url" );
1133 14 : }
1134 :
1135 : struct StringTriple
1136 : {
1137 : char const * first;
1138 : char const * second;
1139 : char const * third;
1140 : };
1141 : extern StringTriple const * const g_pEventTranslations;
1142 :
1143 14 : void ElementDescriptor::readEvents()
1144 : {
1145 14 : Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1146 14 : if (xSupplier.is())
1147 : {
1148 14 : Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1149 14 : if (xEvents.is())
1150 : {
1151 14 : Sequence< OUString > aNames( xEvents->getElementNames() );
1152 14 : OUString const * pNames = aNames.getConstArray();
1153 14 : for ( sal_Int32 nPos = 0; nPos < aNames.getLength(); ++nPos )
1154 : {
1155 0 : script::ScriptEventDescriptor descr;
1156 0 : if (xEvents->getByName( pNames[ nPos ] ) >>= descr)
1157 : {
1158 : SAL_WARN_IF( descr.ListenerType.isEmpty() ||
1159 : descr.EventMethod.isEmpty() ||
1160 : descr.ScriptCode.isEmpty() ||
1161 : descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" );
1162 :
1163 0 : OUString aEventName;
1164 :
1165 0 : if (descr.AddListenerParam.isEmpty())
1166 : {
1167 : // detection of event-name
1168 0 : OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) );
1169 0 : OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) );
1170 0 : StringTriple const * p = g_pEventTranslations;
1171 0 : while (p->first)
1172 : {
1173 0 : if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1174 0 : 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1175 : {
1176 0 : aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1177 0 : break;
1178 : }
1179 0 : ++p;
1180 0 : }
1181 : }
1182 :
1183 : ElementDescriptor * pElem;
1184 0 : Reference< xml::sax::XAttributeList > xElem;
1185 :
1186 0 : if (!aEventName.isEmpty()) // script:event
1187 : {
1188 0 : pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" );
1189 0 : xElem = pElem;
1190 :
1191 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName );
1192 : }
1193 : else // script:listener-event
1194 : {
1195 0 : pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" );
1196 0 : xElem = pElem;
1197 :
1198 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType );
1199 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod );
1200 :
1201 0 : if (!descr.AddListenerParam.isEmpty())
1202 : {
1203 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam );
1204 : }
1205 : }
1206 0 : if ( descr.ScriptType == "StarBasic" )
1207 : {
1208 : // separate optional location
1209 0 : sal_Int32 nIndex = descr.ScriptCode.indexOf( (sal_Unicode)':' );
1210 0 : if (nIndex >= 0)
1211 : {
1212 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) );
1213 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) );
1214 : }
1215 : else
1216 : {
1217 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1218 : }
1219 : }
1220 : else
1221 : {
1222 0 : pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1223 : }
1224 :
1225 : // language
1226 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType );
1227 :
1228 0 : addSubElement( xElem );
1229 : }
1230 : else
1231 : {
1232 : SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" );
1233 : }
1234 14 : }
1235 14 : }
1236 14 : }
1237 14 : }
1238 :
1239 6 : inline bool equalFont( Style const & style1, Style const & style2 )
1240 : {
1241 6 : awt::FontDescriptor const & f1 = style1._descr;
1242 6 : awt::FontDescriptor const & f2 = style2._descr;
1243 : return (
1244 12 : f1.Name == f2.Name &&
1245 12 : f1.Height == f2.Height &&
1246 12 : f1.Width == f2.Width &&
1247 12 : f1.StyleName == f2.StyleName &&
1248 12 : f1.Family == f2.Family &&
1249 12 : f1.CharSet == f2.CharSet &&
1250 6 : f1.Pitch == f2.CharSet &&
1251 0 : f1.CharacterWidth == f2.CharacterWidth &&
1252 0 : f1.Weight == f2.Weight &&
1253 0 : f1.Slant == f2.Slant &&
1254 0 : f1.Underline == f2.Underline &&
1255 0 : f1.Strikeout == f2.Strikeout &&
1256 0 : f1.Orientation == f2.Orientation &&
1257 0 : (f1.Kerning != sal_False) == (f2.Kerning != sal_False) &&
1258 0 : (f1.WordLineMode != sal_False) == (f2.WordLineMode != sal_False) &&
1259 0 : f1.Type == f2.Type &&
1260 6 : style1._fontRelief == style2._fontRelief &&
1261 0 : style1._fontEmphasisMark == style2._fontEmphasisMark
1262 6 : );
1263 : }
1264 :
1265 8 : OUString StyleBag::getStyleId( Style const & rStyle )
1266 : {
1267 8 : if (! rStyle._set) // nothin set
1268 : {
1269 0 : return OUString(); // everything default: no need to export a specific style
1270 : }
1271 :
1272 : // lookup existing style
1273 20 : for ( size_t nStylesPos = 0; nStylesPos < _styles.size(); ++nStylesPos )
1274 : {
1275 12 : Style * pStyle = _styles[ nStylesPos ];
1276 :
1277 12 : short demanded_defaults = ~rStyle._set & rStyle._all;
1278 : // test, if defaults are not set
1279 18 : if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1280 6 : (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1281 : {
1282 6 : short bset = rStyle._set & pStyle->_set;
1283 12 : if ((bset & 0x1) &&
1284 6 : rStyle._backgroundColor != pStyle->_backgroundColor)
1285 0 : continue;
1286 12 : if ((bset & 0x2) &&
1287 6 : rStyle._textColor != pStyle->_textColor)
1288 0 : continue;
1289 6 : if ((bset & 0x20) &&
1290 0 : rStyle._textLineColor != pStyle->_textLineColor)
1291 0 : continue;
1292 6 : if ((bset & 0x10) &&
1293 0 : rStyle._fillColor != pStyle->_fillColor)
1294 0 : continue;
1295 6 : if ((bset & 0x4) &&
1296 0 : (rStyle._border != pStyle->_border ||
1297 0 : (rStyle._border == BORDER_SIMPLE_COLOR &&
1298 0 : rStyle._borderColor != pStyle->_borderColor)))
1299 0 : continue;
1300 12 : if ((bset & 0x8) &&
1301 6 : !equalFont( rStyle, *pStyle ))
1302 6 : continue;
1303 0 : if ((bset & 0x40) &&
1304 0 : rStyle._visualEffect != pStyle->_visualEffect)
1305 0 : continue;
1306 :
1307 : // merge in
1308 0 : short bnset = rStyle._set & ~pStyle->_set;
1309 0 : if (bnset & 0x1)
1310 0 : pStyle->_backgroundColor = rStyle._backgroundColor;
1311 0 : if (bnset & 0x2)
1312 0 : pStyle->_textColor = rStyle._textColor;
1313 0 : if (bnset & 0x20)
1314 0 : pStyle->_textLineColor = rStyle._textLineColor;
1315 0 : if (bnset & 0x10)
1316 0 : pStyle->_fillColor = rStyle._fillColor;
1317 0 : if (bnset & 0x4) {
1318 0 : pStyle->_border = rStyle._border;
1319 0 : pStyle->_borderColor = rStyle._borderColor;
1320 : }
1321 0 : if (bnset & 0x8) {
1322 0 : pStyle->_descr = rStyle._descr;
1323 0 : pStyle->_fontRelief = rStyle._fontRelief;
1324 0 : pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1325 : }
1326 0 : if (bnset & 0x40)
1327 0 : pStyle->_visualEffect = rStyle._visualEffect;
1328 :
1329 0 : pStyle->_all |= rStyle._all;
1330 0 : pStyle->_set |= rStyle._set;
1331 :
1332 0 : return pStyle->_id;
1333 : }
1334 : }
1335 :
1336 : // no appr style found, append new
1337 8 : Style * pStyle = new Style( rStyle );
1338 8 : pStyle->_id = OUString::number( _styles.size() );
1339 8 : _styles.push_back( pStyle );
1340 8 : return pStyle->_id;
1341 : }
1342 :
1343 10 : StyleBag::~StyleBag()
1344 : {
1345 13 : for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1346 : {
1347 8 : delete _styles[ nPos ];
1348 : }
1349 5 : }
1350 :
1351 5 : void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1352 : {
1353 5 : if (! _styles.empty())
1354 : {
1355 2 : OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" );
1356 2 : xOut->ignorableWhitespace( OUString() );
1357 2 : xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1358 : // export styles
1359 10 : for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1360 : {
1361 8 : Reference< xml::sax::XAttributeList > xAttr( _styles[ nPos ]->createElement() );
1362 8 : static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1363 8 : }
1364 2 : xOut->ignorableWhitespace( OUString() );
1365 2 : xOut->endElement( aStylesName );
1366 : }
1367 5 : }
1368 :
1369 5 : void SAL_CALL exportDialogModel(
1370 : Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1371 : Reference< container::XNameContainer > const & xDialogModel,
1372 : Reference< frame::XModel > const & xDocument )
1373 : {
1374 5 : StyleBag all_styles;
1375 : // window
1376 10 : Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1377 : OSL_ASSERT( xProps.is() );
1378 10 : Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1379 : OSL_ASSERT( xPropState.is() );
1380 :
1381 5 : ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument );
1382 10 : Reference< xml::sax::XAttributeList > xElem( pElem );
1383 5 : pElem->readBullitinBoard( &all_styles );
1384 :
1385 5 : xOut->startDocument();
1386 :
1387 : OUString aDocTypeStr(
1388 : "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1389 10 : " \"dialog.dtd\">" );
1390 5 : xOut->unknown( aDocTypeStr );
1391 5 : xOut->ignorableWhitespace( OUString() );
1392 :
1393 10 : OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" );
1394 5 : ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1395 10 : Reference< xml::sax::XAttributeList > xWindow( pWindow );
1396 5 : pWindow->readDialogModel( &all_styles );
1397 5 : xOut->ignorableWhitespace( OUString() );
1398 5 : xOut->startElement( aWindowName, xWindow );
1399 : // dump out events
1400 5 : pWindow->dumpSubElements( xOut.get() );
1401 : // dump out stylebag
1402 5 : all_styles.dump( xOut );
1403 :
1404 5 : if ( xDialogModel->getElementNames().getLength() )
1405 : {
1406 : // open up bulletinboard
1407 5 : OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" );
1408 5 : xOut->ignorableWhitespace( OUString() );
1409 5 : xOut->startElement( aBBoardName, xElem );
1410 :
1411 5 : pElem->dumpSubElements( xOut.get() );
1412 : // end bulletinboard
1413 5 : xOut->ignorableWhitespace( OUString() );
1414 5 : xOut->endElement( aBBoardName );
1415 : }
1416 :
1417 : // end window
1418 5 : xOut->ignorableWhitespace( OUString() );
1419 5 : xOut->endElement( aWindowName );
1420 :
1421 10 : xOut->endDocument();
1422 5 : }
1423 :
1424 : }
1425 :
1426 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|