update credits
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_export.cxx
blob23dc6c0a90fc6e9e04651a445d8aa7b5aaac8ce7
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/frame/XModel.hpp>
41 #include <com/sun/star/util/Date.hpp>
42 #include <com/sun/star/util/Time.hpp>
43 #include <tools/date.hxx>
44 #include <tools/time.hxx>
46 #include <com/sun/star/io/XPersistObject.hpp>
48 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
49 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
51 #include <com/sun/star/style/VerticalAlignment.hpp>
53 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/lang/Locale.hpp>
57 #include <com/sun/star/view/SelectionType.hpp>
59 #include <com/sun/star/form/binding/XListEntrySink.hpp>
60 #include <com/sun/star/form/binding/XBindableValue.hpp>
61 #include <com/sun/star/table/CellAddress.hpp>
62 #include <com/sun/star/table/CellRangeAddress.hpp>
63 #include <com/sun/star/document/XStorageBasedDocument.hpp>
64 #include <com/sun/star/document/GraphicStorageHandler.hpp>
65 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
66 #include <com/sun/star/graphic/XGraphic.hpp>
67 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
69 #include <comphelper/processfactory.hxx>
70 #include <i18nlangtag/languagetag.hxx>
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
75 namespace xmlscript
78 Reference< xml::sax::XAttributeList > Style::createElement()
80 ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" );
82 // style-id
83 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id );
85 // background-color
86 if (_set & 0x1)
88 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":background-color", "0x" + OUString::number(_backgroundColor,16));
91 // text-color
92 if (_set & 0x2)
94 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":text-color", "0x" + OUString::number(_textColor,16));
97 // textline-color
98 if (_set & 0x20)
100 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":textline-color", "0x" + OUString::number(_textLineColor,16));
103 // fill-color
104 if (_set & 0x10)
106 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":fill-color", "0x" + OUString::number(_fillColor,16));
109 // border
110 if (_set & 0x4)
112 switch (_border)
114 case BORDER_NONE:
115 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "none" );
116 break;
117 case BORDER_3D:
118 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "3d" );
119 break;
120 case BORDER_SIMPLE:
121 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "simple" );
122 break;
123 case BORDER_SIMPLE_COLOR: {
124 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "0x" + OUString::number(_borderColor,16));
125 break;
127 default:
128 SAL_WARN( "xmlscript.xmldlg", "### unexpected border value!" );
129 break;
133 // visual effect (look)
134 if (_set & 0x40)
136 switch (_visualEffect)
138 case awt::VisualEffect::NONE:
139 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "none" );
140 break;
141 case awt::VisualEffect::LOOK3D:
142 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "3d" );
143 break;
144 case awt::VisualEffect::FLAT:
145 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "simple" );
146 break;
147 default:
148 SAL_WARN( "xmlscript.xmldlg", "### unexpected visual effect value!" );
149 break;
153 // font-
154 if (_set & 0x8)
156 awt::FontDescriptor def_descr;
158 // dialog:font-name CDATA #IMPLIED
159 if (def_descr.Name != _descr.Name)
161 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-name", _descr.Name );
163 // dialog:font-height %numeric; #IMPLIED
164 if (def_descr.Height != _descr.Height)
166 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-height", OUString::number( _descr.Height ) );
168 // dialog:font-width %numeric; #IMPLIED
169 if (def_descr.Width != _descr.Width)
171 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-width", OUString::number( _descr.Width ) );
173 // dialog:font-stylename CDATA #IMPLIED
174 if (def_descr.StyleName != _descr.StyleName)
176 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-stylename", _descr.StyleName );
178 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
179 if (def_descr.Family != _descr.Family)
181 switch (_descr.Family)
183 case awt::FontFamily::DECORATIVE:
184 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "decorative" );
185 break;
186 case awt::FontFamily::MODERN:
187 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "modern" );
188 break;
189 case awt::FontFamily::ROMAN:
190 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "roman" );
191 break;
192 case awt::FontFamily::SCRIPT:
193 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "script" );
194 break;
195 case awt::FontFamily::SWISS:
196 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "swiss" );
197 break;
198 case awt::FontFamily::SYSTEM:
199 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "system" );
200 break;
201 default:
202 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-family!" );
203 break;
206 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
207 if (def_descr.CharSet != _descr.CharSet)
209 switch (_descr.CharSet)
211 case awt::CharSet::ANSI:
212 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ansi" );
213 break;
214 case awt::CharSet::MAC:
215 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "mac" );
216 break;
217 case awt::CharSet::IBMPC_437:
218 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_437" );
219 break;
220 case awt::CharSet::IBMPC_850:
221 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_850" );
222 break;
223 case awt::CharSet::IBMPC_860:
224 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_860" );
225 break;
226 case awt::CharSet::IBMPC_861:
227 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_861" );
228 break;
229 case awt::CharSet::IBMPC_863:
230 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_863" );
231 break;
232 case awt::CharSet::IBMPC_865:
233 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_865" );
234 break;
235 case awt::CharSet::SYSTEM:
236 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "system" );
237 break;
238 case awt::CharSet::SYMBOL:
239 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "symbol" );
240 break;
241 default:
242 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-charset!" );
243 break;
246 // dialog:font-pitch "(fixed|variable)" #IMPLIED
247 if (def_descr.Pitch != _descr.Pitch)
249 switch (_descr.Pitch)
251 case awt::FontPitch::FIXED:
252 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "fixed" );
253 break;
254 case awt::FontPitch::VARIABLE:
255 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "variable" );
256 break;
257 default:
258 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-pitch!" );
259 break;
262 // dialog:font-charwidth CDATA #IMPLIED
263 if (def_descr.CharacterWidth != _descr.CharacterWidth)
265 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charwidth", OUString::number( _descr.CharacterWidth ) );
267 // dialog:font-weight CDATA #IMPLIED
268 if (def_descr.Weight != _descr.Weight)
270 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-weight", OUString::number( _descr.Weight ) );
272 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
273 if (def_descr.Slant != _descr.Slant)
275 switch (_descr.Slant)
277 case awt::FontSlant_OBLIQUE:
278 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "oblique" );
279 break;
280 case awt::FontSlant_ITALIC:
281 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "italic" );
282 break;
283 case awt::FontSlant_REVERSE_OBLIQUE:
284 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_oblique" );
285 break;
286 case awt::FontSlant_REVERSE_ITALIC:
287 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_italic" );
288 break;
289 default:
290 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-slant!" );
291 break;
294 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
295 if (def_descr.Underline != _descr.Underline)
297 switch (_descr.Underline)
299 case awt::FontUnderline::SINGLE:
300 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "single" );
301 break;
302 case awt::FontUnderline::DOUBLE:
303 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "double" );
304 break;
305 case awt::FontUnderline::DOTTED:
306 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dotted" );
307 break;
308 case awt::FontUnderline::DASH:
309 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dash" );
310 break;
311 case awt::FontUnderline::LONGDASH:
312 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "longdash" );
313 break;
314 case awt::FontUnderline::DASHDOT:
315 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdot" );
316 break;
317 case awt::FontUnderline::DASHDOTDOT:
318 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdotdot" );
319 break;
320 case awt::FontUnderline::SMALLWAVE:
321 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "smallwave" );
322 break;
323 case awt::FontUnderline::WAVE:
324 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "wave" );
325 break;
326 case awt::FontUnderline::DOUBLEWAVE:
327 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "doublewave" );
328 break;
329 case awt::FontUnderline::BOLD:
330 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bold" );
331 break;
332 case awt::FontUnderline::BOLDDOTTED:
333 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddotted" );
334 break;
335 case awt::FontUnderline::BOLDDASH:
336 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddash" );
337 break;
338 case awt::FontUnderline::BOLDLONGDASH:
339 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldlongdash" );
340 break;
341 case awt::FontUnderline::BOLDDASHDOT:
342 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdot" );
343 break;
344 case awt::FontUnderline::BOLDDASHDOTDOT:
345 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdotdot" );
346 break;
347 case awt::FontUnderline::BOLDWAVE:
348 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldwave" );
349 break;
350 default:
351 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-underline!" );
352 break;
355 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
356 if (def_descr.Strikeout != _descr.Strikeout)
358 switch (_descr.Strikeout)
360 case awt::FontStrikeout::SINGLE:
361 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "single" );
362 break;
363 case awt::FontStrikeout::DOUBLE:
364 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "double" );
365 break;
366 case awt::FontStrikeout::BOLD:
367 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "bold" );
368 break;
369 case awt::FontStrikeout::SLASH:
370 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "slash" );
371 break;
372 case awt::FontStrikeout::X:
373 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "x" );
374 break;
375 default:
376 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-strikeout!" );
377 break;
380 // dialog:font-orientation CDATA #IMPLIED
381 if (def_descr.Orientation != _descr.Orientation)
383 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::number( _descr.Orientation ) );
385 // dialog:font-kerning %boolean; #IMPLIED
386 if (bool(def_descr.Kerning) != bool(_descr.Kerning))
388 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
390 // dialog:font-wordlinemode %boolean; #IMPLIED
391 if (bool(def_descr.WordLineMode) != bool(_descr.WordLineMode))
393 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
395 // dialog:font-type "(raster|device|scalable)" #IMPLIED
396 if (def_descr.Type != _descr.Type)
398 switch (_descr.Type)
400 case awt::FontType::RASTER:
401 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "raster" );
402 break;
403 case awt::FontType::DEVICE:
404 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "device" );
405 break;
406 case awt::FontType::SCALABLE:
407 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "scalable" );
408 break;
409 default:
410 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-type!" );
411 break;
415 // additional attributes not in FontDescriptor struct
416 // dialog:font-relief (none|embossed|engraved) #IMPLIED
417 switch (_fontRelief)
419 case awt::FontRelief::NONE: // don't export default
420 break;
421 case awt::FontRelief::EMBOSSED:
422 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "embossed" );
423 break;
424 case awt::FontRelief::ENGRAVED:
425 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "engraved" );
426 break;
427 default:
428 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-relief!" );
429 break;
431 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
432 switch (_fontEmphasisMark)
434 case awt::FontEmphasisMark::NONE: // don't export default
435 break;
436 case awt::FontEmphasisMark::DOT:
437 pStyle->addAttribute(XMLNS_DIALOGS_PREFIX ":font-emphasismark", "dot" );
438 break;
439 case awt::FontEmphasisMark::CIRCLE:
440 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "circle" );
441 break;
442 case awt::FontEmphasisMark::DISC:
443 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "disc" );
444 break;
445 case awt::FontEmphasisMark::ACCENT:
446 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "accent" );
447 break;
448 case awt::FontEmphasisMark::ABOVE:
449 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "above" );
450 break;
451 case awt::FontEmphasisMark::BELOW:
452 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "below" );
453 break;
454 default:
455 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-emphasismark!" );
456 break;
460 return pStyle;
463 void ElementDescriptor::addNumberFormatAttr(
464 Reference< beans::XPropertySet > const & xFormatProperties )
466 OUString sFormat;
467 lang::Locale locale;
468 OSL_VERIFY( xFormatProperties->getPropertyValue( "FormatString" ) >>= sFormat );
469 OSL_VERIFY( xFormatProperties->getPropertyValue( "Locale" ) >>= locale );
471 addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
473 // format-locale
474 LanguageTag aLanguageTag( locale);
475 OUString aStr;
476 if (aLanguageTag.isIsoLocale())
478 // Old style "lll;CC" for compatibility, I really don't know what may
479 // consume this.
480 if (aLanguageTag.getCountry().isEmpty())
481 aStr = aLanguageTag.getLanguage();
482 else
483 aStr = aLanguageTag.getLanguage() + ";" + aLanguageTag.getCountry();
485 else
487 aStr = aLanguageTag.getBcp47( false);
489 addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", aStr );
492 Any ElementDescriptor::readProp( OUString const & rPropName )
494 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
496 return _xProps->getPropertyValue( rPropName );
498 return Any();
501 void ElementDescriptor::readStringAttr(
502 OUString const & rPropName, OUString const & rAttrName )
504 if (beans::PropertyState_DEFAULT_VALUE !=
505 _xPropState->getPropertyState( rPropName ))
507 Any a( _xProps->getPropertyValue( rPropName ) );
508 OUString v;
509 if (a >>= v)
510 addAttribute( rAttrName, v );
511 else
512 SAL_WARN( "xmlscript.xmldlg", "### unexpected property type!" );
516 void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
518 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
520 Any a( _xProps->getPropertyValue( rPropName ) );
521 if (auto n = o3tl::tryAccess<sal_uInt32>(a))
523 addAttribute( rAttrName, "0x" + OUString::number(*n, 16) );
528 void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
530 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
531 return;
533 Any a( _xProps->getPropertyValue( rPropName ) );
534 if (auto n = o3tl::tryAccess<sal_Int16>(a))
536 switch (*n)
538 case 0:
539 addAttribute( rAttrName, "system_short" );
540 break;
541 case 1:
542 addAttribute( rAttrName, "system_short_YY" );
543 break;
544 case 2:
545 addAttribute( rAttrName, "system_short_YYYY" );
546 break;
547 case 3:
548 addAttribute( rAttrName, "system_long" );
549 break;
550 case 4:
551 addAttribute( rAttrName, "short_DDMMYY" );
552 break;
553 case 5:
554 addAttribute( rAttrName, "short_MMDDYY" );
555 break;
556 case 6:
557 addAttribute( rAttrName, "short_YYMMDD" );
558 break;
559 case 7:
560 addAttribute( rAttrName, "short_DDMMYYYY" );
561 break;
562 case 8:
563 addAttribute( rAttrName, "short_MMDDYYYY" );
564 break;
565 case 9:
566 addAttribute( rAttrName, "short_YYYYMMDD" );
567 break;
568 case 10:
569 addAttribute( rAttrName, "short_YYMMDD_DIN5008" );
570 break;
571 case 11:
572 addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" );
573 break;
574 default:
575 SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" );
576 break;
579 else
580 OSL_FAIL( "### unexpected property type!" );
583 void ElementDescriptor::readDateAttr( OUString const & rPropName, OUString const & rAttrName )
585 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
586 return;
588 Any a( _xProps->getPropertyValue( rPropName ) );
589 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get())
591 util::Date aUDate;
592 if (a >>= aUDate)
594 ::Date aTDate(aUDate);
595 addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) );
597 else
598 OSL_FAIL( "### internal error" );
600 else
601 OSL_FAIL( "### unexpected property type!" );
604 void ElementDescriptor::readTimeAttr( OUString const & rPropName, OUString const & rAttrName )
606 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
607 return;
609 Any a( _xProps->getPropertyValue( rPropName ) );
610 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get())
612 util::Time aUTime;
613 if (a >>= aUTime)
615 ::tools::Time aTTime(aUTime);
616 addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) );
618 else
619 OSL_FAIL( "### internal error" );
621 else
622 OSL_FAIL( "### unexpected property type!" );
625 void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
627 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
628 return;
630 Any a( _xProps->getPropertyValue( rPropName ) );
631 if (auto n = o3tl::tryAccess<sal_Int16>(a))
633 switch (*n)
635 case 0:
636 addAttribute( rAttrName, "24h_short" );
637 break;
638 case 1:
639 addAttribute( rAttrName, "24h_long" );
640 break;
641 case 2:
642 addAttribute( rAttrName, "12h_short" );
643 break;
644 case 3:
645 addAttribute( rAttrName, "12h_long" );
646 break;
647 case 4:
648 addAttribute( rAttrName, "Duration_short" );
649 break;
650 case 5:
651 addAttribute( rAttrName, "Duration_long" );
652 break;
653 default:
654 SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" );
655 break;
658 else
659 OSL_FAIL( "### unexpected property type!" );
662 void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
664 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
665 return;
667 Any a( _xProps->getPropertyValue( rPropName ) );
668 if (auto n = o3tl::tryAccess<sal_Int16>(a))
670 switch (*n)
672 case 0:
673 addAttribute( rAttrName, "left" );
674 break;
675 case 1:
676 addAttribute( rAttrName, "center" );
677 break;
678 case 2:
679 addAttribute( rAttrName, "right" );
680 break;
681 default:
682 SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" );
683 break;
686 else
687 OSL_FAIL( "### unexpected property type!" );
690 void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
692 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
693 return;
695 Any a( _xProps->getPropertyValue( rPropName ) );
696 if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get())
698 style::VerticalAlignment eAlign;
699 a >>= eAlign;
700 switch (eAlign)
702 case style::VerticalAlignment_TOP:
703 addAttribute( rAttrName, "top" );
704 break;
705 case style::VerticalAlignment_MIDDLE:
706 addAttribute( rAttrName, "center" );
707 break;
708 case style::VerticalAlignment_BOTTOM:
709 addAttribute( rAttrName, "bottom" );
710 break;
711 default:
712 SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" );
713 break;
716 else
717 OSL_FAIL( "### unexpected property type!" );
720 void ElementDescriptor::readImageOrGraphicAttr(OUString const & rAttrName)
722 OUString sURL;
723 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("Graphic"))
725 uno::Reference<graphic::XGraphic> xGraphic;
726 _xProps->getPropertyValue("Graphic") >>= xGraphic;
727 if (xGraphic.is())
729 Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
730 if ( xDocStorage.is() )
732 Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
733 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
734 xGraphicStorageHandler.set(document::GraphicStorageHandler::createWithStorage(xContext, xDocStorage->getDocumentStorage()));
735 if (xGraphicStorageHandler.is())
737 sURL = xGraphicStorageHandler->saveGraphic(xGraphic);
742 // tdf#130793 Above fails if the dialog is not part of a document. Export the ImageURL then.
743 if (sURL.isEmpty()
744 && beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("ImageURL"))
746 _xProps->getPropertyValue("ImageURL") >>= sURL;
748 if (!sURL.isEmpty())
749 addAttribute(rAttrName, sURL);
752 void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
754 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
755 return;
757 Any a( _xProps->getPropertyValue( rPropName ) );
758 if (auto n = o3tl::tryAccess<sal_Int16>(a))
760 switch (*n)
762 case 0:
763 addAttribute( rAttrName, "left" );
764 break;
765 case 1:
766 addAttribute( rAttrName, "top" );
767 break;
768 case 2:
769 addAttribute( rAttrName, "right" );
770 break;
771 case 3:
772 addAttribute( rAttrName, "bottom" );
773 break;
774 default:
775 SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" );
776 break;
779 else
780 OSL_FAIL( "### unexpected property type!" );
783 void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
785 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
786 return;
788 Any a( _xProps->getPropertyValue( rPropName ) );
789 auto n = o3tl::tryAccess<sal_Int16>(a);
790 if (!n)
791 return;
793 switch (*n)
795 case awt::ImagePosition::LeftTop:
796 addAttribute( rAttrName, "left-top" );
797 break;
798 case awt::ImagePosition::LeftCenter:
799 addAttribute( rAttrName, "left-center" );
800 break;
801 case awt::ImagePosition::LeftBottom:
802 addAttribute( rAttrName, "left-bottom" );
803 break;
804 case awt::ImagePosition::RightTop:
805 addAttribute( rAttrName, "right-top" );
806 break;
807 case awt::ImagePosition::RightCenter:
808 addAttribute( rAttrName, "right-center" );
809 break;
810 case awt::ImagePosition::RightBottom:
811 addAttribute( rAttrName, "right-bottom" );
812 break;
813 case awt::ImagePosition::AboveLeft:
814 addAttribute( rAttrName, "top-left" );
815 break;
816 case awt::ImagePosition::AboveCenter:
817 addAttribute( rAttrName, "top-center" );
818 break;
819 case awt::ImagePosition::AboveRight:
820 addAttribute( rAttrName, "top-right" );
821 break;
822 case awt::ImagePosition::BelowLeft:
823 addAttribute( rAttrName, "bottom-left" );
824 break;
825 case awt::ImagePosition::BelowCenter:
826 addAttribute( rAttrName, "bottom-center" );
827 break;
828 case awt::ImagePosition::BelowRight:
829 addAttribute( rAttrName, "bottom-right" );
830 break;
831 case awt::ImagePosition::Centered:
832 addAttribute( rAttrName, "center" );
833 break;
834 default:
835 SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" );
836 break;
840 void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
842 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
843 return;
845 Any a( _xProps->getPropertyValue( rPropName ) );
846 auto n = o3tl::tryAccess<sal_Int16>(a);
847 if (!n)
848 return;
850 switch (static_cast<awt::PushButtonType>(*n))
852 case awt::PushButtonType_STANDARD:
853 addAttribute( rAttrName, "standard" );
854 break;
855 case awt::PushButtonType_OK:
856 addAttribute( rAttrName, "ok" );
857 break;
858 case awt::PushButtonType_CANCEL:
859 addAttribute( rAttrName, "cancel" );
860 break;
861 case awt::PushButtonType_HELP:
862 addAttribute( rAttrName, "help" );
863 break;
864 default:
865 SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" );
866 break;
870 void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
872 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
873 return;
875 Any a( _xProps->getPropertyValue( rPropName ) );
876 auto n = o3tl::tryAccess<sal_Int32>(a);
877 if (!n)
878 return;
880 switch (*n)
882 case 0:
883 addAttribute( rAttrName, "horizontal" );
884 break;
885 case 1:
886 addAttribute( rAttrName, "vertical" );
887 break;
888 default:
889 SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" );
890 break;
894 void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
896 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
897 return;
899 Any a( _xProps->getPropertyValue( rPropName ) );
900 auto n = o3tl::tryAccess<sal_Int16>(a);
901 if (!n)
902 return;
904 switch (*n)
906 case awt::LineEndFormat::CARRIAGE_RETURN:
907 addAttribute( rAttrName, "carriage-return" );
908 break;
909 case awt::LineEndFormat::LINE_FEED:
910 addAttribute( rAttrName, "line-feed" );
911 break;
912 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
913 addAttribute( rAttrName, "carriage-return-line-feed" );
914 break;
915 default:
916 SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" );
917 break;
921 void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
923 Reference< lang::XMultiServiceFactory > xFac;
924 if ( _xDocument.is() )
925 xFac.set( _xDocument, uno::UNO_QUERY );
927 Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
929 if ( xFac.is() && xBinding.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":linked-cell" )
933 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
934 Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
935 if ( xBindable.is() )
937 table::CellAddress aAddress;
938 xBindable->getPropertyValue( "BoundCell" ) >>= aAddress;
939 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
940 OUString sAddress;
941 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
942 if ( !sAddress.isEmpty() )
943 addAttribute( rAttrName, sAddress );
945 SAL_INFO("xmlscript.xmldlg", "*** Bindable value " << sAddress );
949 catch( uno::Exception& )
953 Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
954 if ( !(xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range") )
955 return;
957 Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
958 if ( !xListSource.is() )
959 return;
963 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
965 table::CellRangeAddress aAddress;
966 xListSource->getPropertyValue( "CellRange" ) >>= aAddress;
968 OUString sAddress;
969 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
970 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
971 SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress );
972 if ( !sAddress.isEmpty() )
973 addAttribute( rAttrName, sAddress );
975 catch( uno::Exception& )
980 void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
982 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
983 return;
985 Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
987 if (aSelectionType.getValueTypeClass() != TypeClass_ENUM ||
988 aSelectionType.getValueType() != cppu::UnoType<view::SelectionType>::get())
989 return;
991 ::view::SelectionType eSelectionType;
992 aSelectionType >>= eSelectionType;
994 switch (eSelectionType)
996 case ::view::SelectionType_NONE:
997 addAttribute( rAttrName, "none" );
998 break;
999 case ::view::SelectionType_SINGLE:
1000 addAttribute( rAttrName, "single" );
1001 break;
1002 case ::view::SelectionType_MULTI:
1003 addAttribute( rAttrName, "multi" );
1004 break;
1005 case ::view::SelectionType_RANGE:
1006 addAttribute( rAttrName, "range" );
1007 break;
1008 default:
1009 SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" );
1010 break;
1014 void ElementDescriptor::readScrollableSettings()
1016 readLongAttr( "ScrollHeight",
1017 XMLNS_DIALOGS_PREFIX ":scrollheight" );
1018 readLongAttr( "ScrollWidth",
1019 XMLNS_DIALOGS_PREFIX ":scrollwidth" );
1020 readLongAttr( "ScrollTop",
1021 XMLNS_DIALOGS_PREFIX ":scrolltop" );
1022 readLongAttr( "ScrollLeft",
1023 XMLNS_DIALOGS_PREFIX ":scrollleft" );
1024 readBoolAttr( "HScroll",
1025 XMLNS_DIALOGS_PREFIX ":hscroll" );
1026 readBoolAttr( "VScroll",
1027 XMLNS_DIALOGS_PREFIX ":vscroll" );
1030 void ElementDescriptor::readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName )
1032 if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName ))
1033 return;
1035 Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) );
1037 if (aImageScaleMode.getValueTypeClass() != TypeClass_SHORT)
1038 return;
1040 sal_Int16 nImageScaleMode = 0;
1041 aImageScaleMode >>= nImageScaleMode;
1043 switch(nImageScaleMode)
1045 case ::awt::ImageScaleMode::NONE:
1046 addAttribute( rAttrName, "none" );
1047 break;
1048 case ::awt::ImageScaleMode::ISOTROPIC:
1049 addAttribute( rAttrName, "isotropic" );
1050 break;
1051 case ::awt::ImageScaleMode::ANISOTROPIC:
1052 addAttribute( rAttrName, "anisotropic" );
1053 break;
1054 default:
1055 OSL_ENSURE( false, "### illegal image scale mode value.");
1056 break;
1060 void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
1062 Any a( _xProps->getPropertyValue( "Name" ) );
1064 // The following is a hack to allow 'form' controls to override the default
1065 // control supported by dialogs. This should work well for both VBA support and
1066 // normal LibreOffice (when normal 'Dialogs' decide to support form control models)
1067 // In the future VBA support might require custom models ( and not the just the form
1068 // variant of a control that we currently use ) In this case the door is still open,
1069 // we just need to define a new way for the 'ServiceName' to be extracted from the
1070 // incoming model. E.g. the use of supporting service
1071 // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1072 // is only an implementation detail here, in the future some other
1073 // method (perhaps a custom prop) could be used instead.
1074 Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1075 if ( xSrvInfo.is() && xSrvInfo->supportsService( "com.sun.star.form.FormComponent" ) )
1077 Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1078 if ( xPersist.is() )
1080 OUString sCtrlName = xPersist->getServiceName();
1081 if ( !sCtrlName.isEmpty() )
1082 addAttribute( XMLNS_DIALOGS_PREFIX ":control-implementation", sCtrlName );
1085 addAttribute( XMLNS_DIALOGS_PREFIX ":id", *o3tl::doAccess<OUString>(a) );
1086 readShortAttr( "TabIndex", XMLNS_DIALOGS_PREFIX ":tab-index" );
1088 bool bEnabled = false;
1089 if (_xProps->getPropertyValue( "Enabled" ) >>= bEnabled)
1091 if (! bEnabled)
1093 addAttribute( XMLNS_DIALOGS_PREFIX ":disabled", "true" );
1096 else
1098 SAL_WARN( "xmlscript.xmldlg", "unexpected property type for \"Enabled\": not bool!" );
1101 if (supportVisible) try
1103 bool bVisible = true;
1104 if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible)
1107 // only write out the non default case
1108 if (! bVisible)
1110 addAttribute( XMLNS_DIALOGS_PREFIX ":visible", "false" );
1114 catch( Exception& )
1116 DBG_UNHANDLED_EXCEPTION("xmlscript.xmldlg");
1118 // force writing of pos/size
1119 a = _xProps->getPropertyValue( "PositionX" );
1120 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1122 addAttribute( XMLNS_DIALOGS_PREFIX ":left", OUString::number(*n) );
1124 a = _xProps->getPropertyValue( "PositionY" );
1125 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1127 addAttribute( XMLNS_DIALOGS_PREFIX ":top", OUString::number(*n) );
1129 a = _xProps->getPropertyValue( "Width" );
1130 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1132 addAttribute( XMLNS_DIALOGS_PREFIX ":width", OUString::number(*n) );
1134 a = _xProps->getPropertyValue( "Height" );
1135 if (auto n = o3tl::tryAccess<sal_Int32>(a))
1137 addAttribute( XMLNS_DIALOGS_PREFIX ":height", OUString::number(*n) );
1140 if (supportPrintable)
1142 readBoolAttr( "Printable", XMLNS_DIALOGS_PREFIX ":printable" );
1144 readLongAttr( "Step", XMLNS_DIALOGS_PREFIX ":page" );
1145 readStringAttr( "Tag", XMLNS_DIALOGS_PREFIX ":tag" );
1146 readStringAttr( "HelpText", XMLNS_DIALOGS_PREFIX ":help-text" );
1147 readStringAttr( "HelpURL", XMLNS_DIALOGS_PREFIX ":help-url" );
1150 void ElementDescriptor::readEvents()
1152 Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1153 if (!xSupplier.is())
1154 return;
1156 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1157 if (!xEvents.is())
1158 return;
1160 const Sequence< OUString > aNames( xEvents->getElementNames() );
1161 for ( const auto& rName : aNames )
1163 script::ScriptEventDescriptor descr;
1164 if (xEvents->getByName( rName ) >>= descr)
1166 SAL_WARN_IF( descr.ListenerType.isEmpty() ||
1167 descr.EventMethod.isEmpty() ||
1168 descr.ScriptCode.isEmpty() ||
1169 descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" );
1171 OUString aEventName;
1173 if (descr.AddListenerParam.isEmpty())
1175 // detection of event-name
1176 OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) );
1177 OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) );
1178 StringTriple const * p = g_pEventTranslations;
1179 while (p->first)
1181 if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1182 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1184 aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1185 break;
1187 ++p;
1191 ElementDescriptor * pElem;
1192 Reference< xml::sax::XAttributeList > xElem;
1194 if (!aEventName.isEmpty()) // script:event
1196 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" );
1197 xElem = pElem;
1199 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName );
1201 else // script:listener-event
1203 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" );
1204 xElem = pElem;
1206 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType );
1207 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod );
1209 if (!descr.AddListenerParam.isEmpty())
1211 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam );
1214 if ( descr.ScriptType == "StarBasic" )
1216 // separate optional location
1217 sal_Int32 nIndex = descr.ScriptCode.indexOf( ':' );
1218 if (nIndex >= 0)
1220 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) );
1221 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) );
1223 else
1225 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1228 else
1230 pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1233 // language
1234 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType );
1236 addSubElement( xElem );
1238 else
1240 SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" );
1245 static bool equalFont( Style const & style1, Style const & style2 )
1247 awt::FontDescriptor const & f1 = style1._descr;
1248 awt::FontDescriptor const & f2 = style2._descr;
1249 return (
1250 f1.Name == f2.Name &&
1251 f1.Height == f2.Height &&
1252 f1.Width == f2.Width &&
1253 f1.StyleName == f2.StyleName &&
1254 f1.Family == f2.Family &&
1255 f1.CharSet == f2.CharSet &&
1256 f1.Pitch == f2.Pitch &&
1257 f1.CharacterWidth == f2.CharacterWidth &&
1258 f1.Weight == f2.Weight &&
1259 f1.Slant == f2.Slant &&
1260 f1.Underline == f2.Underline &&
1261 f1.Strikeout == f2.Strikeout &&
1262 f1.Orientation == f2.Orientation &&
1263 bool(f1.Kerning) == bool(f2.Kerning) &&
1264 bool(f1.WordLineMode) == bool(f2.WordLineMode) &&
1265 f1.Type == f2.Type &&
1266 style1._fontRelief == style2._fontRelief &&
1267 style1._fontEmphasisMark == style2._fontEmphasisMark
1271 OUString StyleBag::getStyleId( Style const & rStyle )
1273 if (! rStyle._set) // nothing set
1275 return OUString(); // everything default: no need to export a specific style
1278 // lookup existing style
1279 for (auto const & pStyle : _styles)
1281 short demanded_defaults = ~rStyle._set & rStyle._all;
1282 // test, if defaults are not set
1283 if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1284 (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1286 short bset = rStyle._set & pStyle->_set;
1287 if ((bset & 0x1) &&
1288 rStyle._backgroundColor != pStyle->_backgroundColor)
1289 continue;
1290 if ((bset & 0x2) &&
1291 rStyle._textColor != pStyle->_textColor)
1292 continue;
1293 if ((bset & 0x20) &&
1294 rStyle._textLineColor != pStyle->_textLineColor)
1295 continue;
1296 if ((bset & 0x10) &&
1297 rStyle._fillColor != pStyle->_fillColor)
1298 continue;
1299 if ((bset & 0x4) &&
1300 (rStyle._border != pStyle->_border ||
1301 (rStyle._border == BORDER_SIMPLE_COLOR &&
1302 rStyle._borderColor != pStyle->_borderColor)))
1303 continue;
1304 if ((bset & 0x8) &&
1305 !equalFont( rStyle, *pStyle ))
1306 continue;
1307 if ((bset & 0x40) &&
1308 rStyle._visualEffect != pStyle->_visualEffect)
1309 continue;
1311 // merge in
1312 short bnset = rStyle._set & ~pStyle->_set;
1313 if (bnset & 0x1)
1314 pStyle->_backgroundColor = rStyle._backgroundColor;
1315 if (bnset & 0x2)
1316 pStyle->_textColor = rStyle._textColor;
1317 if (bnset & 0x20)
1318 pStyle->_textLineColor = rStyle._textLineColor;
1319 if (bnset & 0x10)
1320 pStyle->_fillColor = rStyle._fillColor;
1321 if (bnset & 0x4) {
1322 pStyle->_border = rStyle._border;
1323 pStyle->_borderColor = rStyle._borderColor;
1325 if (bnset & 0x8) {
1326 pStyle->_descr = rStyle._descr;
1327 pStyle->_fontRelief = rStyle._fontRelief;
1328 pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1330 if (bnset & 0x40)
1331 pStyle->_visualEffect = rStyle._visualEffect;
1333 pStyle->_all |= rStyle._all;
1334 pStyle->_set |= rStyle._set;
1336 return pStyle->_id;
1340 // no appr style found, append new
1341 std::unique_ptr<Style> pStyle(new Style( rStyle ));
1342 pStyle->_id = OUString::number( _styles.size() );
1343 _styles.push_back( std::move(pStyle) );
1344 return _styles.back()->_id;
1347 StyleBag::~StyleBag()
1351 void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1353 if ( _styles.empty())
1354 return;
1356 OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" );
1357 xOut->ignorableWhitespace( OUString() );
1358 xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1359 // export styles
1360 for (auto const & _style : _styles)
1362 Reference< xml::sax::XAttributeList > xAttr( _style->createElement() );
1363 static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1365 xOut->ignorableWhitespace( OUString() );
1366 xOut->endElement( aStylesName );
1369 void exportDialogModel(
1370 Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1371 Reference< container::XNameContainer > const & xDialogModel,
1372 Reference< frame::XModel > const & xDocument )
1374 StyleBag all_styles;
1375 // window
1376 Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1377 OSL_ASSERT( xProps.is() );
1378 Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1379 OSL_ASSERT( xPropState.is() );
1381 ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument );
1382 Reference< xml::sax::XAttributeList > xElem( pElem );
1383 pElem->readBullitinBoard( &all_styles );
1385 xOut->startDocument();
1387 xOut->unknown(
1388 "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1389 " \"dialog.dtd\">" );
1390 xOut->ignorableWhitespace( OUString() );
1392 OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" );
1393 ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1394 Reference< xml::sax::XAttributeList > xWindow( pWindow );
1395 pWindow->readDialogModel( &all_styles );
1396 xOut->ignorableWhitespace( OUString() );
1397 xOut->startElement( aWindowName, xWindow );
1398 // dump out events
1399 pWindow->dumpSubElements( xOut.get() );
1400 // dump out stylebag
1401 all_styles.dump( xOut );
1403 if ( xDialogModel->getElementNames().hasElements() )
1405 // open up bulletinboard
1406 OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" );
1407 xOut->ignorableWhitespace( OUString() );
1408 xOut->startElement( aBBoardName, xElem );
1410 pElem->dumpSubElements( xOut.get() );
1411 // end bulletinboard
1412 xOut->ignorableWhitespace( OUString() );
1413 xOut->endElement( aBBoardName );
1416 // end window
1417 xOut->ignorableWhitespace( OUString() );
1418 xOut->endElement( aWindowName );
1420 xOut->endDocument();
1425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */