vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_export.cxx
blob413facd876524ac16ee0ed7689afb5bcde040c29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "common.hxx"
21 #include "exp_share.hxx"
22 #include <xmlscript/xmlns.h>
24 #include <o3tl/any.hxx>
25 #include <sal/log.hxx>
26 #include <tools/diagnose_ex.h>
28 #include <com/sun/star/awt/CharSet.hpp>
29 #include <com/sun/star/awt/FontFamily.hpp>
30 #include <com/sun/star/awt/FontPitch.hpp>
31 #include <com/sun/star/awt/FontSlant.hpp>
32 #include <com/sun/star/awt/FontStrikeout.hpp>
33 #include <com/sun/star/awt/FontType.hpp>
34 #include <com/sun/star/awt/FontUnderline.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>
45 #include <com/sun/star/io/XPersistObject.hpp>
47 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
48 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
50 #include <com/sun/star/style/VerticalAlignment.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include <com/sun/star/lang/Locale.hpp>
56 #include <com/sun/star/view/SelectionType.hpp>
58 #include <com/sun/star/form/binding/XListEntrySink.hpp>
59 #include <com/sun/star/form/binding/XBindableValue.hpp>
60 #include <com/sun/star/table/CellAddress.hpp>
61 #include <com/sun/star/table/CellRangeAddress.hpp>
62 #include <com/sun/star/document/XStorageBasedDocument.hpp>
63 #include <com/sun/star/document/GraphicStorageHandler.hpp>
64 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
65 #include <com/sun/star/graphic/XGraphic.hpp>
66 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
68 #include <comphelper/processfactory.hxx>
69 #include <i18nlangtag/languagetag.hxx>
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
74 namespace xmlscript
77 Reference< xml::sax::XAttributeList > Style::createElement()
79 ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" );
81 // style-id
82 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id );
84 // background-color
85 if (_set & 0x1)
87 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":background-color", "0x" + OUString::number(_backgroundColor,16));
90 // text-color
91 if (_set & 0x2)
93 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":text-color", "0x" + OUString::number(_textColor,16));
96 // textline-color
97 if (_set & 0x20)
99 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":textline-color", "0x" + OUString::number(_textLineColor,16));
102 // fill-color
103 if (_set & 0x10)
105 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":fill-color", "0x" + OUString::number(_fillColor,16));
108 // border
109 if (_set & 0x4)
111 switch (_border)
113 case BORDER_NONE:
114 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "none" );
115 break;
116 case BORDER_3D:
117 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "3d" );
118 break;
119 case BORDER_SIMPLE:
120 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "simple" );
121 break;
122 case BORDER_SIMPLE_COLOR: {
123 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "0x" + OUString::number(_borderColor,16));
124 break;
126 default:
127 SAL_WARN( "xmlscript.xmldlg", "### unexpected border value!" );
128 break;
132 // visual effect (look)
133 if (_set & 0x40)
135 switch (_visualEffect)
137 case awt::VisualEffect::NONE:
138 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "none" );
139 break;
140 case awt::VisualEffect::LOOK3D:
141 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "3d" );
142 break;
143 case awt::VisualEffect::FLAT:
144 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "simple" );
145 break;
146 default:
147 SAL_WARN( "xmlscript.xmldlg", "### unexpected visual effect value!" );
148 break;
152 // font-
153 if (_set & 0x8)
155 awt::FontDescriptor def_descr;
157 // dialog:font-name CDATA #IMPLIED
158 if (def_descr.Name != _descr.Name)
160 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-name", _descr.Name );
162 // dialog:font-height %numeric; #IMPLIED
163 if (def_descr.Height != _descr.Height)
165 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-height", OUString::number( _descr.Height ) );
167 // dialog:font-width %numeric; #IMPLIED
168 if (def_descr.Width != _descr.Width)
170 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-width", OUString::number( _descr.Width ) );
172 // dialog:font-stylename CDATA #IMPLIED
173 if (def_descr.StyleName != _descr.StyleName)
175 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-stylename", _descr.StyleName );
177 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
178 if (def_descr.Family != _descr.Family)
180 switch (_descr.Family)
182 case awt::FontFamily::DECORATIVE:
183 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "decorative" );
184 break;
185 case awt::FontFamily::MODERN:
186 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "modern" );
187 break;
188 case awt::FontFamily::ROMAN:
189 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "roman" );
190 break;
191 case awt::FontFamily::SCRIPT:
192 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "script" );
193 break;
194 case awt::FontFamily::SWISS:
195 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "swiss" );
196 break;
197 case awt::FontFamily::SYSTEM:
198 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "system" );
199 break;
200 default:
201 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-family!" );
202 break;
205 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
206 if (def_descr.CharSet != _descr.CharSet)
208 switch (_descr.CharSet)
210 case awt::CharSet::ANSI:
211 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ansi" );
212 break;
213 case awt::CharSet::MAC:
214 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "mac" );
215 break;
216 case awt::CharSet::IBMPC_437:
217 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_437" );
218 break;
219 case awt::CharSet::IBMPC_850:
220 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_850" );
221 break;
222 case awt::CharSet::IBMPC_860:
223 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_860" );
224 break;
225 case awt::CharSet::IBMPC_861:
226 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_861" );
227 break;
228 case awt::CharSet::IBMPC_863:
229 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_863" );
230 break;
231 case awt::CharSet::IBMPC_865:
232 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_865" );
233 break;
234 case awt::CharSet::SYSTEM:
235 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "system" );
236 break;
237 case awt::CharSet::SYMBOL:
238 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "symbol" );
239 break;
240 default:
241 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-charset!" );
242 break;
245 // dialog:font-pitch "(fixed|variable)" #IMPLIED
246 if (def_descr.Pitch != _descr.Pitch)
248 switch (_descr.Pitch)
250 case awt::FontPitch::FIXED:
251 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "fixed" );
252 break;
253 case awt::FontPitch::VARIABLE:
254 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "variable" );
255 break;
256 default:
257 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-pitch!" );
258 break;
261 // dialog:font-charwidth CDATA #IMPLIED
262 if (def_descr.CharacterWidth != _descr.CharacterWidth)
264 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charwidth", OUString::number( _descr.CharacterWidth ) );
266 // dialog:font-weight CDATA #IMPLIED
267 if (def_descr.Weight != _descr.Weight)
269 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-weight", OUString::number( _descr.Weight ) );
271 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
272 if (def_descr.Slant != _descr.Slant)
274 switch (_descr.Slant)
276 case awt::FontSlant_OBLIQUE:
277 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "oblique" );
278 break;
279 case awt::FontSlant_ITALIC:
280 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "italic" );
281 break;
282 case awt::FontSlant_REVERSE_OBLIQUE:
283 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_oblique" );
284 break;
285 case awt::FontSlant_REVERSE_ITALIC:
286 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_italic" );
287 break;
288 default:
289 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-slant!" );
290 break;
293 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
294 if (def_descr.Underline != _descr.Underline)
296 switch (_descr.Underline)
298 case awt::FontUnderline::SINGLE:
299 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "single" );
300 break;
301 case awt::FontUnderline::DOUBLE:
302 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "double" );
303 break;
304 case awt::FontUnderline::DOTTED:
305 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dotted" );
306 break;
307 case awt::FontUnderline::DASH:
308 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dash" );
309 break;
310 case awt::FontUnderline::LONGDASH:
311 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "longdash" );
312 break;
313 case awt::FontUnderline::DASHDOT:
314 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdot" );
315 break;
316 case awt::FontUnderline::DASHDOTDOT:
317 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdotdot" );
318 break;
319 case awt::FontUnderline::SMALLWAVE:
320 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "smallwave" );
321 break;
322 case awt::FontUnderline::WAVE:
323 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "wave" );
324 break;
325 case awt::FontUnderline::DOUBLEWAVE:
326 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "doublewave" );
327 break;
328 case awt::FontUnderline::BOLD:
329 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bold" );
330 break;
331 case awt::FontUnderline::BOLDDOTTED:
332 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddotted" );
333 break;
334 case awt::FontUnderline::BOLDDASH:
335 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddash" );
336 break;
337 case awt::FontUnderline::BOLDLONGDASH:
338 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldlongdash" );
339 break;
340 case awt::FontUnderline::BOLDDASHDOT:
341 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdot" );
342 break;
343 case awt::FontUnderline::BOLDDASHDOTDOT:
344 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdotdot" );
345 break;
346 case awt::FontUnderline::BOLDWAVE:
347 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldwave" );
348 break;
349 default:
350 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-underline!" );
351 break;
354 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
355 if (def_descr.Strikeout != _descr.Strikeout)
357 switch (_descr.Strikeout)
359 case awt::FontStrikeout::SINGLE:
360 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "single" );
361 break;
362 case awt::FontStrikeout::DOUBLE:
363 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "double" );
364 break;
365 case awt::FontStrikeout::BOLD:
366 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "bold" );
367 break;
368 case awt::FontStrikeout::SLASH:
369 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "slash" );
370 break;
371 case awt::FontStrikeout::X:
372 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "x" );
373 break;
374 default:
375 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-strikeout!" );
376 break;
379 // dialog:font-orientation CDATA #IMPLIED
380 if (def_descr.Orientation != _descr.Orientation)
382 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::number( _descr.Orientation ) );
384 // dialog:font-kerning %boolean; #IMPLIED
385 if (bool(def_descr.Kerning) != bool(_descr.Kerning))
387 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
389 // dialog:font-wordlinemode %boolean; #IMPLIED
390 if (bool(def_descr.WordLineMode) != bool(_descr.WordLineMode))
392 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
394 // dialog:font-type "(raster|device|scalable)" #IMPLIED
395 if (def_descr.Type != _descr.Type)
397 switch (_descr.Type)
399 case awt::FontType::RASTER:
400 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "raster" );
401 break;
402 case awt::FontType::DEVICE:
403 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "device" );
404 break;
405 case awt::FontType::SCALABLE:
406 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "scalable" );
407 break;
408 default:
409 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-type!" );
410 break;
414 // additional attributes not in FontDescriptor struct
415 // dialog:font-relief (none|embossed|engraved) #IMPLIED
416 switch (_fontRelief)
418 case awt::FontRelief::NONE: // don't export default
419 break;
420 case awt::FontRelief::EMBOSSED:
421 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "embossed" );
422 break;
423 case awt::FontRelief::ENGRAVED:
424 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "engraved" );
425 break;
426 default:
427 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-relief!" );
428 break;
430 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
431 switch (_fontEmphasisMark)
433 case awt::FontEmphasisMark::NONE: // don't export default
434 break;
435 case awt::FontEmphasisMark::DOT:
436 pStyle->addAttribute(XMLNS_DIALOGS_PREFIX ":font-emphasismark", "dot" );
437 break;
438 case awt::FontEmphasisMark::CIRCLE:
439 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "circle" );
440 break;
441 case awt::FontEmphasisMark::DISC:
442 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "disc" );
443 break;
444 case awt::FontEmphasisMark::ACCENT:
445 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "accent" );
446 break;
447 case awt::FontEmphasisMark::ABOVE:
448 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "above" );
449 break;
450 case awt::FontEmphasisMark::BELOW:
451 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "below" );
452 break;
453 default:
454 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-emphasismark!" );
455 break;
459 return pStyle;
462 void ElementDescriptor::addNumberFormatAttr(
463 Reference< beans::XPropertySet > const & xFormatProperties )
465 OUString sFormat;
466 lang::Locale locale;
467 OSL_VERIFY( xFormatProperties->getPropertyValue( "FormatString" ) >>= sFormat );
468 OSL_VERIFY( xFormatProperties->getPropertyValue( "Locale" ) >>= locale );
470 addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
472 // format-locale
473 LanguageTag aLanguageTag( locale);
474 OUString aStr;
475 if (aLanguageTag.isIsoLocale())
477 // Old style "lll;CC" for compatibility, I really don't know what may
478 // consume this.
479 if (aLanguageTag.getCountry().isEmpty())
480 aStr = aLanguageTag.getLanguage();
481 else
482 aStr = aLanguageTag.getLanguage() + ";" + aLanguageTag.getCountry();
484 else
486 aStr = aLanguageTag.getBcp47( false);
488 addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", aStr );
491 Any ElementDescriptor::readProp( OUString const & rPropName )
493 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
495 return _xProps->getPropertyValue( rPropName );
497 return Any();
500 void ElementDescriptor::readStringAttr(
501 OUString const & rPropName, OUString const & rAttrName )
503 if (beans::PropertyState_DEFAULT_VALUE !=
504 _xPropState->getPropertyState( rPropName ))
506 Any a( _xProps->getPropertyValue( rPropName ) );
507 OUString v;
508 if (a >>= v)
509 addAttribute( rAttrName, v );
510 else
511 SAL_WARN( "xmlscript.xmldlg", "### unexpected property type!" );
515 void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
517 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
519 Any a( _xProps->getPropertyValue( rPropName ) );
520 if (auto n = o3tl::tryAccess<sal_uInt32>(a))
522 addAttribute( rAttrName, "0x" + OUString::number(*n, 16) );
527 void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
529 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
531 Any a( _xProps->getPropertyValue( rPropName ) );
532 if (auto n = o3tl::tryAccess<sal_Int16>(a))
534 switch (*n)
536 case 0:
537 addAttribute( rAttrName, "system_short" );
538 break;
539 case 1:
540 addAttribute( rAttrName, "system_short_YY" );
541 break;
542 case 2:
543 addAttribute( rAttrName, "system_short_YYYY" );
544 break;
545 case 3:
546 addAttribute( rAttrName, "system_long" );
547 break;
548 case 4:
549 addAttribute( rAttrName, "short_DDMMYY" );
550 break;
551 case 5:
552 addAttribute( rAttrName, "short_MMDDYY" );
553 break;
554 case 6:
555 addAttribute( rAttrName, "short_YYMMDD" );
556 break;
557 case 7:
558 addAttribute( rAttrName, "short_DDMMYYYY" );
559 break;
560 case 8:
561 addAttribute( rAttrName, "short_MMDDYYYY" );
562 break;
563 case 9:
564 addAttribute( rAttrName, "short_YYYYMMDD" );
565 break;
566 case 10:
567 addAttribute( rAttrName, "short_YYMMDD_DIN5008" );
568 break;
569 case 11:
570 addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" );
571 break;
572 default:
573 SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" );
574 break;
577 else
578 OSL_FAIL( "### unexpected property type!" );
582 void ElementDescriptor::readDateAttr( OUString const & rPropName, OUString const & rAttrName )
584 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
586 Any a( _xProps->getPropertyValue( rPropName ) );
587 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get())
589 util::Date aUDate;
590 if (a >>= aUDate)
592 ::Date aTDate(aUDate);
593 addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) );
595 else
596 OSL_FAIL( "### internal error" );
598 else
599 OSL_FAIL( "### unexpected property type!" );
603 void ElementDescriptor::readTimeAttr( OUString const & rPropName, OUString const & rAttrName )
605 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
607 Any a( _xProps->getPropertyValue( rPropName ) );
608 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get())
610 util::Time aUTime;
611 if (a >>= aUTime)
613 ::tools::Time aTTime(aUTime);
614 addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) );
616 else
617 OSL_FAIL( "### internal error" );
619 else
620 OSL_FAIL( "### unexpected property type!" );
624 void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
626 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
628 Any a( _xProps->getPropertyValue( rPropName ) );
629 if (auto n = o3tl::tryAccess<sal_Int16>(a))
631 switch (*n)
633 case 0:
634 addAttribute( rAttrName, "24h_short" );
635 break;
636 case 1:
637 addAttribute( rAttrName, "24h_long" );
638 break;
639 case 2:
640 addAttribute( rAttrName, "12h_short" );
641 break;
642 case 3:
643 addAttribute( rAttrName, "12h_long" );
644 break;
645 case 4:
646 addAttribute( rAttrName, "Duration_short" );
647 break;
648 case 5:
649 addAttribute( rAttrName, "Duration_long" );
650 break;
651 default:
652 SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" );
653 break;
656 else
657 OSL_FAIL( "### unexpected property type!" );
661 void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
663 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
665 Any a( _xProps->getPropertyValue( rPropName ) );
666 if (auto n = o3tl::tryAccess<sal_Int16>(a))
668 switch (*n)
670 case 0:
671 addAttribute( rAttrName, "left" );
672 break;
673 case 1:
674 addAttribute( rAttrName, "center" );
675 break;
676 case 2:
677 addAttribute( rAttrName, "right" );
678 break;
679 default:
680 SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" );
681 break;
684 else
685 OSL_FAIL( "### unexpected property type!" );
689 void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
691 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
693 Any a( _xProps->getPropertyValue( rPropName ) );
694 if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get())
696 style::VerticalAlignment eAlign;
697 a >>= eAlign;
698 switch (eAlign)
700 case style::VerticalAlignment_TOP:
701 addAttribute( rAttrName, "top" );
702 break;
703 case style::VerticalAlignment_MIDDLE:
704 addAttribute( rAttrName, "center" );
705 break;
706 case style::VerticalAlignment_BOTTOM:
707 addAttribute( rAttrName, "bottom" );
708 break;
709 default:
710 SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" );
711 break;
714 else
715 OSL_FAIL( "### unexpected property type!" );
719 void ElementDescriptor::readImageOrGraphicAttr(OUString const & rAttrName)
721 OUString sURL;
722 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("Graphic"))
724 uno::Reference<graphic::XGraphic> xGraphic;
725 _xProps->getPropertyValue("Graphic") >>= xGraphic;
726 if (xGraphic.is())
728 Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
729 if ( xDocStorage.is() )
731 Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
732 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
733 xGraphicStorageHandler.set(document::GraphicStorageHandler::createWithStorage(xContext, xDocStorage->getDocumentStorage()));
734 if (xGraphicStorageHandler.is())
736 sURL = xGraphicStorageHandler->saveGraphic(xGraphic);
741 // tdf#130793 Above fails if the dialog is not part of a document. Export the ImageURL then.
742 if (sURL.isEmpty()
743 && beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("ImageURL"))
745 _xProps->getPropertyValue("ImageURL") >>= sURL;
747 if (!sURL.isEmpty())
748 addAttribute(rAttrName, sURL);
751 void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
753 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
755 Any a( _xProps->getPropertyValue( rPropName ) );
756 if (auto n = o3tl::tryAccess<sal_Int16>(a))
758 switch (*n)
760 case 0:
761 addAttribute( rAttrName, "left" );
762 break;
763 case 1:
764 addAttribute( rAttrName, "top" );
765 break;
766 case 2:
767 addAttribute( rAttrName, "right" );
768 break;
769 case 3:
770 addAttribute( rAttrName, "bottom" );
771 break;
772 default:
773 SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" );
774 break;
777 else
778 OSL_FAIL( "### unexpected property type!" );
782 void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
784 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
786 Any a( _xProps->getPropertyValue( rPropName ) );
787 if (auto n = o3tl::tryAccess<sal_Int16>(a))
789 switch (*n)
791 case awt::ImagePosition::LeftTop:
792 addAttribute( rAttrName, "left-top" );
793 break;
794 case awt::ImagePosition::LeftCenter:
795 addAttribute( rAttrName, "left-center" );
796 break;
797 case awt::ImagePosition::LeftBottom:
798 addAttribute( rAttrName, "left-bottom" );
799 break;
800 case awt::ImagePosition::RightTop:
801 addAttribute( rAttrName, "right-top" );
802 break;
803 case awt::ImagePosition::RightCenter:
804 addAttribute( rAttrName, "right-center" );
805 break;
806 case awt::ImagePosition::RightBottom:
807 addAttribute( rAttrName, "right-bottom" );
808 break;
809 case awt::ImagePosition::AboveLeft:
810 addAttribute( rAttrName, "top-left" );
811 break;
812 case awt::ImagePosition::AboveCenter:
813 addAttribute( rAttrName, "top-center" );
814 break;
815 case awt::ImagePosition::AboveRight:
816 addAttribute( rAttrName, "top-right" );
817 break;
818 case awt::ImagePosition::BelowLeft:
819 addAttribute( rAttrName, "bottom-left" );
820 break;
821 case awt::ImagePosition::BelowCenter:
822 addAttribute( rAttrName, "bottom-center" );
823 break;
824 case awt::ImagePosition::BelowRight:
825 addAttribute( rAttrName, "bottom-right" );
826 break;
827 case awt::ImagePosition::Centered:
828 addAttribute( rAttrName, "center" );
829 break;
830 default:
831 SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" );
832 break;
838 void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
840 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
842 Any a( _xProps->getPropertyValue( rPropName ) );
843 if (auto n = o3tl::tryAccess<sal_Int16>(a))
845 switch (static_cast<awt::PushButtonType>(*n))
847 case awt::PushButtonType_STANDARD:
848 addAttribute( rAttrName, "standard" );
849 break;
850 case awt::PushButtonType_OK:
851 addAttribute( rAttrName, "ok" );
852 break;
853 case awt::PushButtonType_CANCEL:
854 addAttribute( rAttrName, "cancel" );
855 break;
856 case awt::PushButtonType_HELP:
857 addAttribute( rAttrName, "help" );
858 break;
859 default:
860 SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" );
861 break;
867 void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
869 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
871 Any a( _xProps->getPropertyValue( rPropName ) );
872 if (auto n = o3tl::tryAccess<sal_Int32>(a))
874 switch (*n)
876 case 0:
877 addAttribute( rAttrName, "horizontal" );
878 break;
879 case 1:
880 addAttribute( rAttrName, "vertical" );
881 break;
882 default:
883 SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" );
884 break;
890 void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
892 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
894 Any a( _xProps->getPropertyValue( rPropName ) );
895 if (auto n = o3tl::tryAccess<sal_Int16>(a))
897 switch (*n)
899 case awt::LineEndFormat::CARRIAGE_RETURN:
900 addAttribute( rAttrName, "carriage-return" );
901 break;
902 case awt::LineEndFormat::LINE_FEED:
903 addAttribute( rAttrName, "line-feed" );
904 break;
905 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
906 addAttribute( rAttrName, "carriage-return-line-feed" );
907 break;
908 default:
909 SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" );
910 break;
916 void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
918 Reference< lang::XMultiServiceFactory > xFac;
919 if ( _xDocument.is() )
920 xFac.set( _xDocument, uno::UNO_QUERY );
922 Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
924 if ( xFac.is() && xBinding.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":linked-cell" )
928 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
929 Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
930 if ( xBindable.is() )
932 table::CellAddress aAddress;
933 xBindable->getPropertyValue( "BoundCell" ) >>= aAddress;
934 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
935 OUString sAddress;
936 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
937 if ( !sAddress.isEmpty() )
938 addAttribute( rAttrName, sAddress );
940 SAL_INFO("xmlscript.xmldlg", "*** Bindable value " << sAddress );
944 catch( uno::Exception& )
948 Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
949 if ( xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range" )
951 Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
952 if ( xListSource.is() )
956 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
958 table::CellRangeAddress aAddress;
959 xListSource->getPropertyValue( "CellRange" ) >>= aAddress;
961 OUString sAddress;
962 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
963 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
964 SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress );
965 if ( !sAddress.isEmpty() )
966 addAttribute( rAttrName, sAddress );
968 catch( uno::Exception& )
975 void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
977 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
979 Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
981 if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get())
983 ::view::SelectionType eSelectionType;
984 aSelectionType >>= eSelectionType;
986 switch (eSelectionType)
988 case ::view::SelectionType_NONE:
989 addAttribute( rAttrName, "none" );
990 break;
991 case ::view::SelectionType_SINGLE:
992 addAttribute( rAttrName, "single" );
993 break;
994 case ::view::SelectionType_MULTI:
995 addAttribute( rAttrName, "multi" );
996 break;
997 case ::view::SelectionType_RANGE:
998 addAttribute( rAttrName, "range" );
999 break;
1000 default:
1001 SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" );
1002 break;
1008 void ElementDescriptor::readScrollableSettings()
1010 readLongAttr( "ScrollHeight",
1011 XMLNS_DIALOGS_PREFIX ":scrollheight" );
1012 readLongAttr( "ScrollWidth",
1013 XMLNS_DIALOGS_PREFIX ":scrollwidth" );
1014 readLongAttr( "ScrollTop",
1015 XMLNS_DIALOGS_PREFIX ":scrolltop" );
1016 readLongAttr( "ScrollLeft",
1017 XMLNS_DIALOGS_PREFIX ":scrollleft" );
1018 readBoolAttr( "HScroll",
1019 XMLNS_DIALOGS_PREFIX ":hscroll" );
1020 readBoolAttr( "VScroll",
1021 XMLNS_DIALOGS_PREFIX ":vscroll" );
1024 void ElementDescriptor::readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName )
1026 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
1028 Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) );
1030 if (aImageScaleMode.getValueTypeClass() == TypeClass_SHORT)
1032 sal_Int16 nImageScaleMode = 0;
1033 aImageScaleMode >>= nImageScaleMode;
1035 switch(nImageScaleMode)
1037 case ::awt::ImageScaleMode::NONE:
1038 addAttribute( rAttrName, "none" );
1039 break;
1040 case ::awt::ImageScaleMode::ISOTROPIC:
1041 addAttribute( rAttrName, "isotropic" );
1042 break;
1043 case ::awt::ImageScaleMode::ANISOTROPIC:
1044 addAttribute( rAttrName, "anisotropic" );
1045 break;
1046 default:
1047 OSL_ENSURE( false, "### illegal image scale mode value.");
1048 break;
1054 void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
1056 Any a( _xProps->getPropertyValue( "Name" ) );
1058 // The following is a hack to allow 'form' controls to override the default
1059 // control supported by dialogs. This should work well for both VBA support and
1060 // normal LibreOffice (when normal 'Dialogs' decide to support form control models)
1061 // In the future VBA support might require custom models ( and not the just the form
1062 // variant of a control that we currently use ) In this case the door is still open,
1063 // we just need to define a new way for the 'ServiceName' to be extracted from the
1064 // incoming model. E.g. the use of supporting service
1065 // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1066 // is only an implementation detail here, in the future some other
1067 // method (perhaps a custom prop) could be used instead.
1068 Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1069 if ( xSrvInfo.is() && xSrvInfo->supportsService( "com.sun.star.form.FormComponent" ) )
1071 Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1072 if ( xPersist.is() )
1074 OUString sCtrlName = xPersist->getServiceName();
1075 if ( !sCtrlName.isEmpty() )
1076 addAttribute( XMLNS_DIALOGS_PREFIX ":control-implementation", sCtrlName );
1079 addAttribute( XMLNS_DIALOGS_PREFIX ":id", *o3tl::doAccess<OUString>(a) );
1080 readShortAttr( "TabIndex", XMLNS_DIALOGS_PREFIX ":tab-index" );
1082 bool bEnabled = false;
1083 if (_xProps->getPropertyValue( "Enabled" ) >>= bEnabled)
1085 if (! bEnabled)
1087 addAttribute( XMLNS_DIALOGS_PREFIX ":disabled", "true" );
1090 else
1092 SAL_WARN( "xmlscript.xmldlg", "unexpected property type for \"Enabled\": not bool!" );
1095 if (supportVisible) try
1097 bool bVisible = true;
1098 if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible)
1101 // only write out the non default case
1102 if (! bVisible)
1104 addAttribute( XMLNS_DIALOGS_PREFIX ":visible", "false" );
1108 catch( Exception& )
1110 DBG_UNHANDLED_EXCEPTION("xmlscript.xmldlg");
1112 // force writing of pos/size
1113 a = _xProps->getPropertyValue( "PositionX" );
1114 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1116 addAttribute( XMLNS_DIALOGS_PREFIX ":left", OUString::number(*n) );
1118 a = _xProps->getPropertyValue( "PositionY" );
1119 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1121 addAttribute( XMLNS_DIALOGS_PREFIX ":top", OUString::number(*n) );
1123 a = _xProps->getPropertyValue( "Width" );
1124 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1126 addAttribute( XMLNS_DIALOGS_PREFIX ":width", OUString::number(*n) );
1128 a = _xProps->getPropertyValue( "Height" );
1129 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1131 addAttribute( XMLNS_DIALOGS_PREFIX ":height", OUString::number(*n) );
1134 if (supportPrintable)
1136 readBoolAttr( "Printable", XMLNS_DIALOGS_PREFIX ":printable" );
1138 readLongAttr( "Step", XMLNS_DIALOGS_PREFIX ":page" );
1139 readStringAttr( "Tag", XMLNS_DIALOGS_PREFIX ":tag" );
1140 readStringAttr( "HelpText", XMLNS_DIALOGS_PREFIX ":help-text" );
1141 readStringAttr( "HelpURL", XMLNS_DIALOGS_PREFIX ":help-url" );
1144 void ElementDescriptor::readEvents()
1146 Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1147 if (xSupplier.is())
1149 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1150 if (xEvents.is())
1152 const Sequence< OUString > aNames( xEvents->getElementNames() );
1153 for ( const auto& rName : aNames )
1155 script::ScriptEventDescriptor descr;
1156 if (xEvents->getByName( rName ) >>= descr)
1158 SAL_WARN_IF( descr.ListenerType.isEmpty() ||
1159 descr.EventMethod.isEmpty() ||
1160 descr.ScriptCode.isEmpty() ||
1161 descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" );
1163 OUString aEventName;
1165 if (descr.AddListenerParam.isEmpty())
1167 // detection of event-name
1168 OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) );
1169 OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) );
1170 StringTriple const * p = g_pEventTranslations;
1171 while (p->first)
1173 if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1174 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1176 aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1177 break;
1179 ++p;
1183 ElementDescriptor * pElem;
1184 Reference< xml::sax::XAttributeList > xElem;
1186 if (!aEventName.isEmpty()) // script:event
1188 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" );
1189 xElem = pElem;
1191 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName );
1193 else // script:listener-event
1195 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" );
1196 xElem = pElem;
1198 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType );
1199 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod );
1201 if (!descr.AddListenerParam.isEmpty())
1203 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam );
1206 if ( descr.ScriptType == "StarBasic" )
1208 // separate optional location
1209 sal_Int32 nIndex = descr.ScriptCode.indexOf( ':' );
1210 if (nIndex >= 0)
1212 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) );
1213 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) );
1215 else
1217 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1220 else
1222 pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1225 // language
1226 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType );
1228 addSubElement( xElem );
1230 else
1232 SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" );
1239 static bool equalFont( Style const & style1, Style const & style2 )
1241 awt::FontDescriptor const & f1 = style1._descr;
1242 awt::FontDescriptor const & f2 = style2._descr;
1243 return (
1244 f1.Name == f2.Name &&
1245 f1.Height == f2.Height &&
1246 f1.Width == f2.Width &&
1247 f1.StyleName == f2.StyleName &&
1248 f1.Family == f2.Family &&
1249 f1.CharSet == f2.CharSet &&
1250 f1.Pitch == f2.Pitch &&
1251 f1.CharacterWidth == f2.CharacterWidth &&
1252 f1.Weight == f2.Weight &&
1253 f1.Slant == f2.Slant &&
1254 f1.Underline == f2.Underline &&
1255 f1.Strikeout == f2.Strikeout &&
1256 f1.Orientation == f2.Orientation &&
1257 bool(f1.Kerning) == bool(f2.Kerning) &&
1258 bool(f1.WordLineMode) == bool(f2.WordLineMode) &&
1259 f1.Type == f2.Type &&
1260 style1._fontRelief == style2._fontRelief &&
1261 style1._fontEmphasisMark == style2._fontEmphasisMark
1265 OUString StyleBag::getStyleId( Style const & rStyle )
1267 if (! rStyle._set) // nothing set
1269 return OUString(); // everything default: no need to export a specific style
1272 // lookup existing style
1273 for (auto const & pStyle : _styles)
1275 short demanded_defaults = ~rStyle._set & rStyle._all;
1276 // test, if defaults are not set
1277 if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1278 (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1280 short bset = rStyle._set & pStyle->_set;
1281 if ((bset & 0x1) &&
1282 rStyle._backgroundColor != pStyle->_backgroundColor)
1283 continue;
1284 if ((bset & 0x2) &&
1285 rStyle._textColor != pStyle->_textColor)
1286 continue;
1287 if ((bset & 0x20) &&
1288 rStyle._textLineColor != pStyle->_textLineColor)
1289 continue;
1290 if ((bset & 0x10) &&
1291 rStyle._fillColor != pStyle->_fillColor)
1292 continue;
1293 if ((bset & 0x4) &&
1294 (rStyle._border != pStyle->_border ||
1295 (rStyle._border == BORDER_SIMPLE_COLOR &&
1296 rStyle._borderColor != pStyle->_borderColor)))
1297 continue;
1298 if ((bset & 0x8) &&
1299 !equalFont( rStyle, *pStyle ))
1300 continue;
1301 if ((bset & 0x40) &&
1302 rStyle._visualEffect != pStyle->_visualEffect)
1303 continue;
1305 // merge in
1306 short bnset = rStyle._set & ~pStyle->_set;
1307 if (bnset & 0x1)
1308 pStyle->_backgroundColor = rStyle._backgroundColor;
1309 if (bnset & 0x2)
1310 pStyle->_textColor = rStyle._textColor;
1311 if (bnset & 0x20)
1312 pStyle->_textLineColor = rStyle._textLineColor;
1313 if (bnset & 0x10)
1314 pStyle->_fillColor = rStyle._fillColor;
1315 if (bnset & 0x4) {
1316 pStyle->_border = rStyle._border;
1317 pStyle->_borderColor = rStyle._borderColor;
1319 if (bnset & 0x8) {
1320 pStyle->_descr = rStyle._descr;
1321 pStyle->_fontRelief = rStyle._fontRelief;
1322 pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1324 if (bnset & 0x40)
1325 pStyle->_visualEffect = rStyle._visualEffect;
1327 pStyle->_all |= rStyle._all;
1328 pStyle->_set |= rStyle._set;
1330 return pStyle->_id;
1334 // no appr style found, append new
1335 std::unique_ptr<Style> pStyle(new Style( rStyle ));
1336 pStyle->_id = OUString::number( _styles.size() );
1337 _styles.push_back( std::move(pStyle) );
1338 return _styles.back()->_id;
1341 StyleBag::~StyleBag()
1345 void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1347 if (! _styles.empty())
1349 OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" );
1350 xOut->ignorableWhitespace( OUString() );
1351 xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1352 // export styles
1353 for (auto const & _style : _styles)
1355 Reference< xml::sax::XAttributeList > xAttr( _style->createElement() );
1356 static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1358 xOut->ignorableWhitespace( OUString() );
1359 xOut->endElement( aStylesName );
1363 void exportDialogModel(
1364 Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1365 Reference< container::XNameContainer > const & xDialogModel,
1366 Reference< frame::XModel > const & xDocument )
1368 StyleBag all_styles;
1369 // window
1370 Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1371 OSL_ASSERT( xProps.is() );
1372 Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1373 OSL_ASSERT( xPropState.is() );
1375 ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument );
1376 Reference< xml::sax::XAttributeList > xElem( pElem );
1377 pElem->readBullitinBoard( &all_styles );
1379 xOut->startDocument();
1381 xOut->unknown(
1382 "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1383 " \"dialog.dtd\">" );
1384 xOut->ignorableWhitespace( OUString() );
1386 OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" );
1387 ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1388 Reference< xml::sax::XAttributeList > xWindow( pWindow );
1389 pWindow->readDialogModel( &all_styles );
1390 xOut->ignorableWhitespace( OUString() );
1391 xOut->startElement( aWindowName, xWindow );
1392 // dump out events
1393 pWindow->dumpSubElements( xOut.get() );
1394 // dump out stylebag
1395 all_styles.dump( xOut );
1397 if ( xDialogModel->getElementNames().hasElements() )
1399 // open up bulletinboard
1400 OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" );
1401 xOut->ignorableWhitespace( OUString() );
1402 xOut->startElement( aBBoardName, xElem );
1404 pElem->dumpSubElements( xOut.get() );
1405 // end bulletinboard
1406 xOut->ignorableWhitespace( OUString() );
1407 xOut->endElement( aBBoardName );
1410 // end window
1411 xOut->ignorableWhitespace( OUString() );
1412 xOut->endElement( aWindowName );
1414 xOut->endDocument();
1419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */