update credits
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_import.cxx
blob2d3ae432e7a16f75399367de26cc5e6dc9e31a34
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 "imp_share.hxx"
22 #include <xml_import.hxx>
23 #include <xmlscript/xmlns.h>
25 #include <com/sun/star/awt/CharSet.hpp>
26 #include <com/sun/star/awt/FontFamily.hpp>
27 #include <com/sun/star/awt/FontPitch.hpp>
28 #include <com/sun/star/awt/FontSlant.hpp>
29 #include <com/sun/star/awt/FontStrikeout.hpp>
30 #include <com/sun/star/awt/FontType.hpp>
31 #include <com/sun/star/awt/FontUnderline.hpp>
32 #include <com/sun/star/awt/ImagePosition.hpp>
33 #include <com/sun/star/awt/ImageScaleMode.hpp>
34 #include <com/sun/star/awt/LineEndFormat.hpp>
35 #include <com/sun/star/awt/PushButtonType.hpp>
36 #include <com/sun/star/awt/VisualEffect.hpp>
37 #include <com/sun/star/frame/XModel.hpp>
38 #include <com/sun/star/style/VerticalAlignment.hpp>
39 #include <com/sun/star/util/Date.hpp>
40 #include <com/sun/star/util/Time.hpp>
41 #include <sal/log.hxx>
42 #include <tools/date.hxx>
43 #include <tools/diagnose_ex.h>
44 #include <tools/time.hxx>
45 #include <osl/diagnose.h>
47 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
48 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
50 #include <com/sun/star/view/SelectionType.hpp>
51 #include <com/sun/star/form/binding/XBindableValue.hpp>
52 #include <com/sun/star/form/binding/XValueBinding.hpp>
53 #include <com/sun/star/form/binding/XListEntrySink.hpp>
54 #include <com/sun/star/beans/NamedValue.hpp>
55 #include <com/sun/star/table/CellAddress.hpp>
56 #include <com/sun/star/table/CellRangeAddress.hpp>
57 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
58 #include <com/sun/star/document/XStorageBasedDocument.hpp>
59 #include <com/sun/star/graphic/XGraphic.hpp>
60 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::uno;
64 using namespace ::com::sun::star::frame;
66 namespace xmlscript
69 void EventElement::endElement()
71 static_cast< ControlElement * >( m_xParent.get() )->_events.emplace_back(this );
74 ControlElement::ControlElement(
75 OUString const & rLocalName,
76 Reference< xml::input::XAttributes > const & xAttributes,
77 ElementBase * pParent, DialogImport * pImport )
78 : ElementBase(
79 pImport->XMLNS_DIALOGS_UID, rLocalName, xAttributes, pParent, pImport )
81 if (m_xParent.is())
83 // inherit position
84 _nBasePosX = static_cast< ControlElement * >( m_xParent.get() )->_nBasePosX;
85 _nBasePosY = static_cast< ControlElement * >( m_xParent.get() )->_nBasePosY;
87 else
89 _nBasePosX = 0;
90 _nBasePosY = 0;
94 Reference< xml::input::XElement > ControlElement::getStyle(
95 Reference< xml::input::XAttributes > const & xAttributes )
97 OUString aStyleId( xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID,"style-id" ) );
98 if (!aStyleId.isEmpty())
100 return m_xImport->getStyle( aStyleId );
102 return Reference< xml::input::XElement >();
105 OUString ControlElement::getControlId(
106 Reference< xml::input::XAttributes > const & xAttributes )
108 OUString aId( xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID, "id" ) );
109 if (aId.isEmpty())
111 throw xml::sax::SAXException( "missing id attribute!", Reference< XInterface >(), Any() );
113 return aId;
116 OUString ControlElement::getControlModelName(
117 OUString const& rDefaultModel,
118 Reference< xml::input::XAttributes > const & xAttributes )
120 OUString aModel = xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID, "control-implementation");
121 if (aModel.isEmpty())
122 aModel = rDefaultModel;
123 return aModel;
126 void StyleElement::importTextColorStyle(
127 Reference< beans::XPropertySet > const & xProps )
129 if ((_inited & 0x2) != 0)
131 if ((_hasValue & 0x2) != 0)
133 xProps->setPropertyValue("TextColor", makeAny( _textColor ) );
135 return;
137 _inited |= 0x2;
139 if (getLongAttr( &_textColor, "text-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
141 _hasValue |= 0x2;
142 xProps->setPropertyValue( "TextColor", makeAny( _textColor ) );
143 return;
147 void StyleElement::importTextLineColorStyle(
148 Reference< beans::XPropertySet > const & xProps )
150 if ((_inited & 0x20) != 0)
152 if ((_hasValue & 0x20) != 0)
154 xProps->setPropertyValue( "TextLineColor", makeAny( _textLineColor ) );
156 return;
158 _inited |= 0x20;
160 if (getLongAttr( &_textLineColor, "textline-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
162 _hasValue |= 0x20;
163 xProps->setPropertyValue( "TextLineColor", makeAny( _textLineColor ) );
167 void StyleElement::importFillColorStyle(
168 Reference< beans::XPropertySet > const & xProps )
170 if ((_inited & 0x10) != 0)
172 if ((_hasValue & 0x10) != 0)
174 xProps->setPropertyValue( "FillColor", makeAny( _fillColor ) );
176 return;
178 _inited |= 0x10;
180 if (getLongAttr( &_fillColor, "fill-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
182 _hasValue |= 0x10;
183 xProps->setPropertyValue( "FillColor", makeAny( _fillColor ) );
187 void StyleElement::importBackgroundColorStyle(
188 Reference< beans::XPropertySet > const & xProps )
190 if ((_inited & 0x1) != 0)
192 if ((_hasValue & 0x1) != 0)
194 xProps->setPropertyValue( "BackgroundColor", makeAny( _backgroundColor ) );
196 return;
198 _inited |= 0x1;
200 if (getLongAttr( &_backgroundColor, "background-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
202 _hasValue |= 0x1;
203 xProps->setPropertyValue( "BackgroundColor", makeAny( _backgroundColor ) );
207 void StyleElement::importBorderStyle(
208 Reference< beans::XPropertySet > const & xProps )
210 if ((_inited & 0x4) != 0)
212 if ((_hasValue & 0x4) != 0)
214 xProps->setPropertyValue( "Border", makeAny( _border == BORDER_SIMPLE_COLOR ? BORDER_SIMPLE : _border ) );
215 if (_border == BORDER_SIMPLE_COLOR)
216 xProps->setPropertyValue( "BorderColor", makeAny(_borderColor) );
218 return;
220 _inited |= 0x4;
222 OUString aValue;
223 if (!getStringAttr(&aValue, "border", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
224 return;
226 if ( aValue == "none" )
227 _border = BORDER_NONE;
228 else if ( aValue == "3d" )
229 _border = BORDER_3D;
230 else if ( aValue == "simple" )
231 _border = BORDER_SIMPLE;
232 else {
233 _border = BORDER_SIMPLE_COLOR;
234 _borderColor = toInt32(aValue);
237 _hasValue |= 0x4;
238 importBorderStyle(xProps); // write values
241 void StyleElement::importVisualEffectStyle(
242 Reference<beans::XPropertySet> const & xProps )
244 if ((_inited & 0x40) != 0)
246 if ((_hasValue & 0x40) != 0)
248 xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) );
250 return;
252 _inited |= 0x40;
254 OUString aValue;
255 if (!getStringAttr( &aValue, "look", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
256 return;
258 if ( aValue == "none" )
260 _visualEffect = awt::VisualEffect::NONE;
262 else if ( aValue == "3d" )
264 _visualEffect = awt::VisualEffect::LOOK3D;
266 else if ( aValue == "simple" )
268 _visualEffect = awt::VisualEffect::FLAT;
270 else
271 OSL_ASSERT( false );
273 _hasValue |= 0x40;
274 xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) );
277 void StyleElement::setFontProperties(
278 Reference< beans::XPropertySet > const & xProps ) const
280 xProps->setPropertyValue("FontDescriptor", makeAny( _descr ) );
281 xProps->setPropertyValue("FontEmphasisMark", makeAny( _fontEmphasisMark ) );
282 xProps->setPropertyValue("FontRelief", makeAny( _fontRelief ) );
285 void StyleElement::importFontStyle(
286 Reference< beans::XPropertySet > const & xProps )
288 if ((_inited & 0x8) != 0)
290 if ((_hasValue & 0x8) != 0)
292 setFontProperties( xProps );
294 return;
296 _inited |= 0x8;
298 OUString aValue;
299 bool bFontImport;
301 // dialog:font-name CDATA #IMPLIED
302 bFontImport = getStringAttr( &_descr.Name, "font-name", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
304 // dialog:font-height %numeric; #IMPLIED
305 if (getStringAttr( &aValue, "font-height", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
307 _descr.Height = static_cast<sal_Int16>(toInt32( aValue ));
308 bFontImport = true;
310 // dialog:font-width %numeric; #IMPLIED
311 if (getStringAttr(&aValue, "font-width", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
313 _descr.Width = static_cast<sal_Int16>(toInt32( aValue ));
314 bFontImport = true;
316 // dialog:font-stylename CDATA #IMPLIED
317 bFontImport |= getStringAttr( &_descr.StyleName, "font-stylename", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
319 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
320 if (getStringAttr(&aValue, "font-family", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
322 if ( aValue == "decorative" )
324 _descr.Family = awt::FontFamily::DECORATIVE;
326 else if ( aValue == "modern" )
328 _descr.Family = awt::FontFamily::MODERN;
330 else if ( aValue == "roman" )
332 _descr.Family = awt::FontFamily::ROMAN;
334 else if ( aValue == "script" )
336 _descr.Family = awt::FontFamily::SCRIPT;
338 else if ( aValue == "swiss" )
340 _descr.Family = awt::FontFamily::SWISS;
342 else if ( aValue == "system" )
344 _descr.Family = awt::FontFamily::SYSTEM;
346 else
348 throw xml::sax::SAXException("invalid font-family style!", Reference< XInterface >(), Any() );
350 bFontImport = true;
353 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
354 if (getStringAttr(&aValue, "font-charset", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
356 if ( aValue == "ansi" )
358 _descr.CharSet = awt::CharSet::ANSI;
360 else if ( aValue == "mac" )
362 _descr.CharSet = awt::CharSet::MAC;
364 else if ( aValue == "ibmpc_437" )
366 _descr.CharSet = awt::CharSet::IBMPC_437;
368 else if ( aValue == "ibmpc_850" )
370 _descr.CharSet = awt::CharSet::IBMPC_850;
372 else if ( aValue == "ibmpc_860" )
374 _descr.CharSet = awt::CharSet::IBMPC_860;
376 else if ( aValue == "ibmpc_861" )
378 _descr.CharSet = awt::CharSet::IBMPC_861;
380 else if ( aValue == "ibmpc_863" )
382 _descr.CharSet = awt::CharSet::IBMPC_863;
384 else if ( aValue == "ibmpc_865" )
386 _descr.CharSet = awt::CharSet::IBMPC_865;
388 else if ( aValue == "system" )
390 _descr.CharSet = awt::CharSet::SYSTEM;
392 else if ( aValue == "symbol" )
394 _descr.CharSet = awt::CharSet::SYMBOL;
396 else
398 throw xml::sax::SAXException("invalid font-charset style!", Reference< XInterface >(), Any() );
400 bFontImport = true;
403 // dialog:font-pitch "(fixed|variable)" #IMPLIED
404 if (getStringAttr( &aValue, "font-pitch", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
406 if ( aValue == "fixed" )
408 _descr.Pitch = awt::FontPitch::FIXED;
410 else if ( aValue == "variable" )
412 _descr.Pitch = awt::FontPitch::VARIABLE;
414 else
416 throw xml::sax::SAXException("invalid font-pitch style!", Reference< XInterface >(), Any() );
418 bFontImport = true;
421 // dialog:font-charwidth CDATA #IMPLIED
422 if (getStringAttr( &aValue, "font-charwidth", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
424 _descr.CharacterWidth = aValue.toFloat();
425 bFontImport = true;
427 // dialog:font-weight CDATA #IMPLIED
428 if (getStringAttr( &aValue, "font-weight", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
430 _descr.Weight = aValue.toFloat();
431 bFontImport = true;
434 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
435 if (getStringAttr( &aValue, "font-slant", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
437 if ( aValue == "oblique" )
439 _descr.Slant = awt::FontSlant_OBLIQUE;
441 else if ( aValue == "italic" )
443 _descr.Slant = awt::FontSlant_ITALIC;
445 else if ( aValue == "reverse_oblique" )
447 _descr.Slant = awt::FontSlant_REVERSE_OBLIQUE;
449 else if ( aValue == "reverse_italic" )
451 _descr.Slant = awt::FontSlant_REVERSE_ITALIC;
453 else
455 throw xml::sax::SAXException("invalid font-slant style!", Reference< XInterface >(), Any() );
457 bFontImport = true;
460 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
461 if (getStringAttr( &aValue, "font-underline", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
463 if ( aValue == "single" )
465 _descr.Underline = awt::FontUnderline::SINGLE;
467 else if ( aValue == "double" )
469 _descr.Underline = awt::FontUnderline::DOUBLE;
471 else if ( aValue == "dotted" )
473 _descr.Underline = awt::FontUnderline::DOTTED;
475 else if ( aValue == "dash" )
477 _descr.Underline = awt::FontUnderline::DASH;
479 else if ( aValue == "longdash" )
481 _descr.Underline = awt::FontUnderline::LONGDASH;
483 else if ( aValue == "dashdot" )
485 _descr.Underline = awt::FontUnderline::DASHDOT;
487 else if ( aValue == "dashdotdot" )
489 _descr.Underline = awt::FontUnderline::DASHDOTDOT;
491 else if ( aValue == "smallwave" )
493 _descr.Underline = awt::FontUnderline::SMALLWAVE;
495 else if ( aValue == "wave" )
497 _descr.Underline = awt::FontUnderline::WAVE;
499 else if ( aValue == "doublewave" )
501 _descr.Underline = awt::FontUnderline::DOUBLEWAVE;
503 else if ( aValue == "bold" )
505 _descr.Underline = awt::FontUnderline::BOLD;
507 else if ( aValue == "bolddotted" )
509 _descr.Underline = awt::FontUnderline::BOLDDOTTED;
511 else if ( aValue == "bolddash" )
513 _descr.Underline = awt::FontUnderline::BOLDDASH;
515 else if ( aValue == "boldlongdash" )
517 _descr.Underline = awt::FontUnderline::BOLDLONGDASH;
519 else if ( aValue == "bolddashdot" )
521 _descr.Underline = awt::FontUnderline::BOLDDASHDOT;
523 else if ( aValue == "bolddashdotdot" )
525 _descr.Underline = awt::FontUnderline::BOLDDASHDOTDOT;
527 else if ( aValue == "boldwave" )
529 _descr.Underline = awt::FontUnderline::BOLDWAVE;
531 else
533 throw xml::sax::SAXException("invalid font-underline style!", Reference< XInterface >(), Any() );
535 bFontImport = true;
538 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
539 if (getStringAttr( &aValue, "font-strikeout", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
541 if ( aValue == "single" )
543 _descr.Strikeout = awt::FontStrikeout::SINGLE;
545 else if ( aValue == "double" )
547 _descr.Strikeout = awt::FontStrikeout::DOUBLE;
549 else if ( aValue == "bold" )
551 _descr.Strikeout = awt::FontStrikeout::BOLD;
553 else if ( aValue == "slash" )
555 _descr.Strikeout = awt::FontStrikeout::SLASH;
557 else if ( aValue == "x" )
559 _descr.Strikeout = awt::FontStrikeout::X;
561 else
563 throw xml::sax::SAXException( "invalid font-strikeout style!" , Reference< XInterface >(), Any() );
565 bFontImport = true;
568 // dialog:font-orientation CDATA #IMPLIED
569 if (getStringAttr( &aValue, "font-orientation", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
571 _descr.Orientation = aValue.toFloat();
572 bFontImport = true;
574 // dialog:font-kerning %boolean; #IMPLIED
575 bFontImport |= getBoolAttr( &_descr.Kerning, "font-kerning", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
576 // dialog:font-wordlinemode %boolean; #IMPLIED
577 bFontImport |= getBoolAttr( &_descr.WordLineMode,"font-wordlinemode", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
579 // dialog:font-type "(raster|device|scalable)" #IMPLIED
580 if (getStringAttr( &aValue, "font-type", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
582 if ( aValue == "raster" )
584 _descr.Type = awt::FontType::RASTER;
586 else if ( aValue == "device" )
588 _descr.Type = awt::FontType::DEVICE;
590 else if ( aValue == "scalable" )
592 _descr.Type = awt::FontType::SCALABLE;
594 else
596 throw xml::sax::SAXException( "invalid font-type style!", Reference< XInterface >(), Any() );
598 bFontImport = true;
601 // additional properties which are not part of the FontDescriptor struct
602 // dialog:font-relief (none|embossed|engraved) #IMPLIED
603 if (getStringAttr( &aValue, "font-relief", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
605 if ( aValue == "none" )
607 _fontRelief = awt::FontRelief::NONE;
609 else if ( aValue == "embossed" )
611 _fontRelief = awt::FontRelief::EMBOSSED;
613 else if ( aValue == "engraved" )
615 _fontRelief = awt::FontRelief::ENGRAVED;
617 else
619 throw xml::sax::SAXException("invalid font-relief style!", Reference< XInterface >(), Any() );
621 bFontImport = true;
623 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
624 if (getStringAttr(&aValue, "font-emphasismark", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
626 if ( aValue == "none" )
628 _fontEmphasisMark = awt::FontEmphasisMark::NONE;
630 else if ( aValue == "dot" )
632 _fontEmphasisMark = awt::FontEmphasisMark::DOT;
634 else if ( aValue == "circle" )
636 _fontEmphasisMark = awt::FontEmphasisMark::CIRCLE;
638 else if ( aValue == "disc" )
640 _fontEmphasisMark = awt::FontEmphasisMark::DISC;
642 else if ( aValue == "accent" )
644 _fontEmphasisMark = awt::FontEmphasisMark::ACCENT;
646 else if ( aValue == "above" )
648 _fontEmphasisMark = awt::FontEmphasisMark::ABOVE;
650 else if ( aValue == "below" )
652 _fontEmphasisMark = awt::FontEmphasisMark::BELOW;
654 else
656 throw xml::sax::SAXException( "invalid font-emphasismark style!", Reference< XInterface >(), Any() );
658 bFontImport = true;
661 if (bFontImport)
663 _hasValue |= 0x8;
664 setFontProperties( xProps );
668 bool ImportContext::importStringProperty(
669 OUString const & rPropName, OUString const & rAttrName,
670 Reference< xml::input::XAttributes > const & xAttributes )
672 OUString aValue(
673 xAttributes->getValueByUidName(
674 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
675 if (!aValue.isEmpty())
677 _xControlModel->setPropertyValue( rPropName, makeAny( aValue ) );
678 return true;
680 return false;
683 bool ImportContext::importDoubleProperty(
684 OUString const & rPropName, OUString const & rAttrName,
685 Reference< xml::input::XAttributes > const & xAttributes )
687 OUString aValue(
688 xAttributes->getValueByUidName(
689 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
690 if (!aValue.isEmpty())
692 _xControlModel->setPropertyValue( rPropName, makeAny( aValue.toDouble() ) );
693 return true;
695 return false;
698 bool ImportContext::importBooleanProperty(
699 OUString const & rPropName, OUString const & rAttrName,
700 Reference< xml::input::XAttributes > const & xAttributes )
702 sal_Bool bBool;
703 if (getBoolAttr(
704 &bBool, rAttrName, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
706 _xControlModel->setPropertyValue( rPropName, makeAny( bBool ) );
707 return true;
709 return false;
712 bool ImportContext::importLongProperty(
713 OUString const & rPropName, OUString const & rAttrName,
714 Reference< xml::input::XAttributes > const & xAttributes )
716 OUString aValue(
717 xAttributes->getValueByUidName(
718 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
719 if (!aValue.isEmpty())
721 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
722 return true;
724 return false;
727 bool ImportContext::importLongProperty(
728 sal_Int32 nOffset,
729 OUString const & rPropName, OUString const & rAttrName,
730 Reference< xml::input::XAttributes > const & xAttributes )
732 OUString aValue(
733 xAttributes->getValueByUidName(
734 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
735 if (!aValue.isEmpty())
737 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) + nOffset ) );
738 return true;
740 return false;
743 bool ImportContext::importHexLongProperty(
744 OUString const & rPropName, OUString const & rAttrName,
745 Reference< xml::input::XAttributes > const & xAttributes )
747 OUString aValue(
748 xAttributes->getValueByUidName(
749 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
750 if (!aValue.isEmpty())
752 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
753 return true;
755 return false;
758 bool ImportContext::importShortProperty(
759 OUString const & rPropName, OUString const & rAttrName,
760 Reference< xml::input::XAttributes > const & xAttributes )
762 OUString aValue(
763 xAttributes->getValueByUidName(
764 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
765 if (!aValue.isEmpty())
767 _xControlModel->setPropertyValue( rPropName, makeAny( static_cast<sal_Int16>(toInt32( aValue )) ) );
768 return true;
770 return false;
773 bool ImportContext::importAlignProperty(
774 OUString const & rPropName, OUString const & rAttrName,
775 Reference< xml::input::XAttributes > const & xAttributes )
777 OUString aAlign(
778 xAttributes->getValueByUidName(
779 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
780 if (!aAlign.isEmpty())
782 sal_Int16 nAlign;
783 if ( aAlign == "left" )
785 nAlign = 0;
787 else if ( aAlign == "center" )
789 nAlign = 1;
791 else if ( aAlign == "right" )
793 nAlign = 2;
795 else if ( aAlign == "none" )
797 nAlign = 0; // default
799 else
801 throw xml::sax::SAXException("invalid align value!", Reference< XInterface >(), Any() );
804 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
805 return true;
807 return false;
810 bool ImportContext::importVerticalAlignProperty(
811 OUString const & rPropName, OUString const & rAttrName,
812 Reference< xml::input::XAttributes > const & xAttributes )
814 OUString aAlign(
815 xAttributes->getValueByUidName(
816 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
817 if (!aAlign.isEmpty())
819 style::VerticalAlignment eAlign;
821 if ( aAlign == "top" )
823 eAlign = style::VerticalAlignment_TOP;
825 else if ( aAlign == "center" )
827 eAlign = style::VerticalAlignment_MIDDLE;
829 else if ( aAlign == "bottom" )
831 eAlign = style::VerticalAlignment_BOTTOM;
833 else
835 throw xml::sax::SAXException( "invalid vertical align value!", Reference< XInterface >(), Any() );
838 _xControlModel->setPropertyValue( rPropName, makeAny( eAlign ) );
839 return true;
841 return false;
844 bool ImportContext::importGraphicOrImageProperty(
845 OUString const & rAttrName,
846 Reference< xml::input::XAttributes > const & xAttributes )
848 OUString sURL = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rAttrName );
849 if ( !sURL.isEmpty() )
851 Reference< document::XStorageBasedDocument > xDocStorage( _pImport->getDocOwner(), UNO_QUERY );
853 uno::Reference<graphic::XGraphic> xGraphic;
855 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
856 if ( xDocStorage.is() )
858 uno::Sequence< Any > aArgs( 1 );
859 aArgs[ 0 ] <<= xDocStorage->getDocumentStorage();
860 xGraphicStorageHandler.set(
861 _pImport->getComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext( "com.sun.star.comp.Svx.GraphicImportHelper" , aArgs, _pImport->getComponentContext() ),
862 UNO_QUERY );
863 if (xGraphicStorageHandler.is())
867 xGraphic = xGraphicStorageHandler->loadGraphic(sURL);
869 catch( const uno::Exception& )
871 return false;
875 if (xGraphic.is())
877 Reference<beans::XPropertySet> xProps = getControlModel();
878 if (xProps.is())
880 xProps->setPropertyValue("Graphic", makeAny(xGraphic));
881 return true;
884 else if (!sURL.isEmpty())
886 // tdf#130793 Above fails if the dialog is not part of a document.
887 // In this case we need to set the ImageURL.
888 Reference<beans::XPropertySet> xProps = getControlModel();
889 if (xProps.is())
891 xProps->setPropertyValue("ImageURL", makeAny(sURL));
892 return true;
896 return false;
899 bool ImportContext::importDataAwareProperty(
900 OUString const & rPropName,
901 Reference<xml::input::XAttributes> const & xAttributes )
903 OUString sLinkedCell;
904 OUString sCellRange;
905 if ( rPropName == "linked-cell" )
906 sLinkedCell = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rPropName );
907 if ( rPropName == "source-cell-range" )
908 sCellRange = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rPropName );
909 bool bRes = false;
910 Reference< lang::XMultiServiceFactory > xFac( _pImport->getDocOwner(), UNO_QUERY );
911 if ( xFac.is() && ( !sLinkedCell.isEmpty() || !sCellRange.isEmpty() ) )
913 // Set up cell link
914 if ( !sLinkedCell.isEmpty() )
916 Reference< form::binding::XBindableValue > xBindable( getControlModel(), uno::UNO_QUERY );
917 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
918 if ( xBindable.is() && xConvertor.is() )
920 table::CellAddress aAddress;
921 xConvertor->setPropertyValue( "PersistentRepresentation" , uno::makeAny( sLinkedCell ) );
922 xConvertor->getPropertyValue( "Address" ) >>= aAddress;
923 beans::NamedValue aArg1;
924 aArg1.Name = "BoundCell";
925 aArg1.Value <<= aAddress;
927 uno::Sequence< uno::Any > aArgs(1);
928 aArgs[ 0 ] <<= aArg1;
930 uno::Reference< form::binding::XValueBinding > xBinding( xFac->createInstanceWithArguments( "com.sun.star.table.CellValueBinding" , aArgs ), uno::UNO_QUERY );
931 xBindable->setValueBinding( xBinding );
932 bRes = true;
935 // Set up CellRange
936 if ( !sCellRange.isEmpty() )
938 Reference< form::binding::XListEntrySink > xListEntrySink( getControlModel(), uno::UNO_QUERY );
939 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
940 if ( xListEntrySink.is() && xConvertor.is() )
942 table::CellRangeAddress aAddress;
943 xConvertor->setPropertyValue( "PersistentRepresentation" , uno::makeAny( sCellRange ) );
944 xConvertor->getPropertyValue( "Address" ) >>= aAddress;
945 beans::NamedValue aArg1;
946 aArg1.Name = "CellRange";
947 aArg1.Value <<= aAddress;
949 uno::Sequence< uno::Any > aArgs(1);
950 aArgs[ 0 ] <<= aArg1;
952 uno::Reference< form::binding::XListEntrySource > xSource( xFac->createInstanceWithArguments( "com.sun.star.table.CellRangeListSource" , aArgs ), uno::UNO_QUERY );
953 xListEntrySink->setListEntrySource( xSource );
954 bRes = true;
958 return bRes;
961 bool ImportContext::importImageAlignProperty(
962 OUString const & rPropName, OUString const & rAttrName,
963 Reference< xml::input::XAttributes > const & xAttributes )
965 OUString aAlign(
966 xAttributes->getValueByUidName(
967 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
968 if (!aAlign.isEmpty())
970 sal_Int16 nAlign;
971 if ( aAlign == "left" )
973 nAlign = 0;
975 else if ( aAlign == "top" )
977 nAlign = 1;
979 else if ( aAlign == "right" )
981 nAlign = 2;
983 else if ( aAlign == "bottom" )
985 nAlign = 3;
987 else
989 throw xml::sax::SAXException( "invalid image align value!", Reference< XInterface >(), Any() );
992 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
993 return true;
995 return false;
998 bool ImportContext::importImagePositionProperty(
999 OUString const & rPropName, OUString const & rAttrName,
1000 Reference< xml::input::XAttributes > const & xAttributes )
1002 OUString aPosition(
1003 xAttributes->getValueByUidName(
1004 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1005 if (!aPosition.isEmpty())
1007 sal_Int16 nPosition;
1008 if ( aPosition == "left-top" )
1010 nPosition = awt::ImagePosition::LeftTop;
1012 else if ( aPosition == "left-center" )
1014 nPosition = awt::ImagePosition::LeftCenter;
1016 else if ( aPosition == "left-bottom" )
1018 nPosition = awt::ImagePosition::LeftBottom;
1020 else if ( aPosition == "right-top" )
1022 nPosition = awt::ImagePosition::RightTop;
1024 else if ( aPosition == "right-center" )
1026 nPosition = awt::ImagePosition::RightCenter;
1028 else if ( aPosition == "right-bottom" )
1030 nPosition = awt::ImagePosition::RightBottom;
1032 else if ( aPosition == "top-left" )
1034 nPosition = awt::ImagePosition::AboveLeft;
1036 else if ( aPosition == "top-center" )
1038 nPosition = awt::ImagePosition::AboveCenter;
1040 else if ( aPosition == "top-right" )
1042 nPosition = awt::ImagePosition::AboveRight;
1044 else if ( aPosition == "bottom-left" )
1046 nPosition = awt::ImagePosition::BelowLeft;
1048 else if ( aPosition == "bottom-center" )
1050 nPosition = awt::ImagePosition::BelowCenter;
1052 else if ( aPosition == "bottom-right" )
1054 nPosition = awt::ImagePosition::BelowRight;
1056 else if ( aPosition == "center" )
1058 nPosition = awt::ImagePosition::Centered;
1060 else
1062 throw xml::sax::SAXException( "invalid image position value!", Reference< XInterface >(), Any() );
1065 _xControlModel->setPropertyValue( rPropName, makeAny( nPosition ) );
1066 return true;
1068 return false;
1071 bool ImportContext::importButtonTypeProperty(
1072 OUString const & rPropName, OUString const & rAttrName,
1073 Reference< xml::input::XAttributes > const & xAttributes )
1075 OUString buttonType(
1076 xAttributes->getValueByUidName(
1077 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1078 if (!buttonType.isEmpty())
1080 awt::PushButtonType nButtonType;
1081 if ( buttonType == "standard" )
1083 nButtonType = awt::PushButtonType_STANDARD;
1085 else if ( buttonType == "ok" )
1087 nButtonType = awt::PushButtonType_OK;
1089 else if ( buttonType == "cancel" )
1091 nButtonType = awt::PushButtonType_CANCEL;
1093 else if ( buttonType == "help" )
1095 nButtonType = awt::PushButtonType_HELP;
1097 else
1099 throw xml::sax::SAXException( "invalid button-type value!", Reference< XInterface >(), Any() );
1102 _xControlModel->setPropertyValue( rPropName, makeAny( static_cast<sal_Int16>(nButtonType) ) );
1103 return true;
1105 return false;
1108 bool ImportContext::importDateFormatProperty(
1109 OUString const & rPropName, OUString const & rAttrName,
1110 Reference< xml::input::XAttributes > const & xAttributes )
1112 OUString aFormat(
1113 xAttributes->getValueByUidName(
1114 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1115 if (!aFormat.isEmpty())
1117 sal_Int16 nFormat;
1118 if ( aFormat == "system_short" )
1120 nFormat = 0;
1122 else if ( aFormat == "system_short_YY" )
1124 nFormat = 1;
1126 else if ( aFormat == "system_short_YYYY" )
1128 nFormat = 2;
1130 else if ( aFormat == "system_long" )
1132 nFormat = 3;
1134 else if ( aFormat == "short_DDMMYY" )
1136 nFormat = 4;
1138 else if ( aFormat == "short_MMDDYY" )
1140 nFormat = 5;
1142 else if ( aFormat == "short_YYMMDD" )
1144 nFormat = 6;
1146 else if ( aFormat == "short_DDMMYYYY" )
1148 nFormat = 7;
1150 else if ( aFormat == "short_MMDDYYYY" )
1152 nFormat = 8;
1154 else if ( aFormat == "short_YYYYMMDD" )
1156 nFormat = 9;
1158 else if ( aFormat == "short_YYMMDD_DIN5008" )
1160 nFormat = 10;
1162 else if ( aFormat == "short_YYYYMMDD_DIN5008" )
1164 nFormat = 11;
1166 else
1168 throw xml::sax::SAXException( "invalid date-format value!", Reference< XInterface >(), Any() );
1171 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1172 return true;
1174 return false;
1177 bool ImportContext::importTimeProperty(
1178 OUString const & rPropName, OUString const & rAttrName,
1179 Reference< xml::input::XAttributes > const & xAttributes )
1181 OUString aValue(
1182 xAttributes->getValueByUidName(
1183 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1184 if (!aValue.isEmpty())
1186 ::tools::Time aTTime(toInt32( aValue ) * ::tools::Time::nanoPerCenti);
1187 util::Time aUTime(aTTime.GetUNOTime());
1188 _xControlModel->setPropertyValue( rPropName, makeAny( aUTime ) );
1189 return true;
1191 return false;
1194 bool ImportContext::importDateProperty(
1195 OUString const & rPropName, OUString const & rAttrName,
1196 Reference< xml::input::XAttributes > const & xAttributes )
1198 OUString aValue(
1199 xAttributes->getValueByUidName(
1200 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1201 if (!aValue.isEmpty())
1203 ::Date aTDate(toInt32( aValue ));
1204 util::Date aUDate(aTDate.GetUNODate());
1205 _xControlModel->setPropertyValue( rPropName, makeAny( aUDate ) );
1206 return true;
1208 return false;
1211 bool ImportContext::importTimeFormatProperty(
1212 OUString const & rPropName, OUString const & rAttrName,
1213 Reference< xml::input::XAttributes > const & xAttributes )
1215 OUString aFormat(
1216 xAttributes->getValueByUidName(
1217 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1218 if (!aFormat.isEmpty())
1220 sal_Int16 nFormat;
1221 if ( aFormat == "24h_short" )
1223 nFormat = 0;
1225 else if ( aFormat == "24h_long" )
1227 nFormat = 1;
1229 else if ( aFormat == "12h_short" )
1231 nFormat = 2;
1233 else if ( aFormat == "12h_long" )
1235 nFormat = 3;
1237 else if ( aFormat == "Duration_short" )
1239 nFormat = 4;
1241 else if ( aFormat == "Duration_long" )
1243 nFormat = 5;
1245 else
1247 throw xml::sax::SAXException( "invalid time-format value!", Reference< XInterface >(), Any() );
1250 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1251 return true;
1253 return false;
1256 bool ImportContext::importOrientationProperty(
1257 OUString const & rPropName, OUString const & rAttrName,
1258 Reference< xml::input::XAttributes > const & xAttributes )
1260 OUString aOrient(
1261 xAttributes->getValueByUidName(
1262 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1263 if (!aOrient.isEmpty())
1265 sal_Int32 nOrient;
1266 if ( aOrient == "horizontal" )
1268 nOrient = 0;
1270 else if ( aOrient == "vertical" )
1272 nOrient = 1;
1274 else
1276 throw xml::sax::SAXException( "invalid orientation value!", Reference< XInterface >(), Any() );
1279 _xControlModel->setPropertyValue( rPropName, makeAny( nOrient ) );
1280 return true;
1282 return false;
1285 bool ImportContext::importLineEndFormatProperty(
1286 OUString const & rPropName, OUString const & rAttrName,
1287 Reference< xml::input::XAttributes > const & xAttributes )
1289 OUString aFormat(
1290 xAttributes->getValueByUidName(
1291 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1292 if (!aFormat.isEmpty())
1294 sal_Int16 nFormat;
1295 if ( aFormat == "carriage-return" )
1297 nFormat = awt::LineEndFormat::CARRIAGE_RETURN;
1299 else if ( aFormat == "line-feed" )
1301 nFormat = awt::LineEndFormat::LINE_FEED;
1303 else if ( aFormat == "carriage-return-line-feed" )
1305 nFormat = awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED;
1307 else
1309 throw xml::sax::SAXException( "invalid line end format value!", Reference< XInterface >(), Any() );
1312 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1313 return true;
1315 return false;
1318 bool ImportContext::importSelectionTypeProperty(
1319 OUString const & rPropName, OUString const & rAttrName,
1320 Reference< xml::input::XAttributes > const & xAttributes )
1322 OUString aSelectionType(
1323 xAttributes->getValueByUidName(
1324 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1325 if (!aSelectionType.isEmpty())
1327 view::SelectionType eSelectionType;
1329 if ( aSelectionType == "none" )
1331 eSelectionType = view::SelectionType_NONE;
1333 else if ( aSelectionType == "single" )
1335 eSelectionType = view::SelectionType_SINGLE;
1337 else if ( aSelectionType == "multi" )
1339 eSelectionType = view::SelectionType_MULTI;
1341 else if ( aSelectionType == "range" )
1343 eSelectionType = view::SelectionType_RANGE;
1345 else
1347 throw xml::sax::SAXException( "invalid selection type value!", Reference< XInterface >(), Any() );
1350 _xControlModel->setPropertyValue( rPropName, makeAny( eSelectionType ) );
1351 return true;
1353 return false;
1356 bool ImportContext::importImageScaleModeProperty(
1357 OUString const & rPropName, OUString const & rAttrName,
1358 Reference< xml::input::XAttributes > const & xAttributes )
1360 OUString aImageScaleMode(
1361 xAttributes->getValueByUidName(
1362 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1363 if (!aImageScaleMode.isEmpty())
1365 sal_Int16 nImageScaleMode;
1367 if (aImageScaleMode == "none")
1369 nImageScaleMode = awt::ImageScaleMode::NONE;
1371 else if (aImageScaleMode == "isotropic")
1373 nImageScaleMode = awt::ImageScaleMode::ISOTROPIC;
1375 else if (aImageScaleMode == "anisotropic")
1377 nImageScaleMode = awt::ImageScaleMode::ANISOTROPIC;
1379 else
1381 throw xml::sax::SAXException( "invalid scale image mode value!",
1382 Reference< XInterface >(), Any() );
1385 _xControlModel->setPropertyValue( rPropName, makeAny( nImageScaleMode ) );
1386 return true;
1388 return false;
1391 StringTriple const s_aEventTranslations[] =
1393 // from xmloff/source/forms/formevents.cxx
1394 // 28.09.2001 tbe added on-adjustmentvaluechange
1395 { "com.sun.star.form.XApproveActionListener", "approveAction", "on-approveaction" },
1396 { "com.sun.star.awt.XActionListener", "actionPerformed", "on-performaction" },
1397 { "com.sun.star.form.XChangeListener", "changed", "on-change" },
1398 { "com.sun.star.awt.XTextListener", "textChanged", "on-textchange" },
1399 { "com.sun.star.awt.XItemListener", "itemStateChanged", "on-itemstatechange" },
1400 { "com.sun.star.awt.XFocusListener", "focusGained", "on-focus" },
1401 { "com.sun.star.awt.XFocusListener", "focusLost", "on-blur" },
1402 { "com.sun.star.awt.XKeyListener", "keyPressed", "on-keydown" },
1403 { "com.sun.star.awt.XKeyListener", "keyReleased", "on-keyup" },
1404 { "com.sun.star.awt.XMouseListener", "mouseEntered", "on-mouseover" },
1405 { "com.sun.star.awt.XMouseMotionListener", "mouseDragged", "on-mousedrag" },
1406 { "com.sun.star.awt.XMouseMotionListener", "mouseMoved", "on-mousemove" },
1407 { "com.sun.star.awt.XMouseListener", "mousePressed", "on-mousedown" },
1408 { "com.sun.star.awt.XMouseListener", "mouseReleased", "on-mouseup" },
1409 { "com.sun.star.awt.XMouseListener", "mouseExited", "on-mouseout" },
1410 { "com.sun.star.form.XResetListener", "approveReset", "on-approvereset" },
1411 { "com.sun.star.form.XResetListener", "resetted", "on-reset" },
1412 { "com.sun.star.form.XSubmitListener", "approveSubmit", "on-submit" },
1413 { "com.sun.star.form.XUpdateListener", "approveUpdate", "on-approveupdate" },
1414 { "com.sun.star.form.XUpdateListener", "updated", "on-update" },
1415 { "com.sun.star.form.XLoadListener", "loaded", "on-load" },
1416 { "com.sun.star.form.XLoadListener", "reloading", "on-startreload" },
1417 { "com.sun.star.form.XLoadListener", "reloaded", "on-reload" },
1418 { "com.sun.star.form.XLoadListener", "unloading", "on-startunload" },
1419 { "com.sun.star.form.XLoadListener", "unloaded", "on-unload" },
1420 { "com.sun.star.form.XConfirmDeleteListener", "confirmDelete", "on-confirmdelete" },
1421 { "com.sun.star.sdb.XRowSetApproveListener", "approveRowChange", "on-approverowchange" },
1422 { "com.sun.star.sdbc.XRowSetListener", "rowChanged", "on-rowchange" },
1423 { "com.sun.star.sdb.XRowSetApproveListener", "approveCursorMove", "on-approvecursormove" },
1424 { "com.sun.star.sdbc.XRowSetListener", "cursorMoved", "on-cursormove" },
1425 { "com.sun.star.form.XDatabaseParameterListener", "approveParameter", "on-supplyparameter" },
1426 { "com.sun.star.sdb.XSQLErrorListener", "errorOccured", "on-error" },
1427 { "com.sun.star.awt.XAdjustmentListener", "adjustmentValueChanged", "on-adjustmentvaluechange" },
1428 { nullptr, nullptr, nullptr }
1431 StringTriple const * const g_pEventTranslations = s_aEventTranslations;
1433 void ImportContext::importEvents(
1434 std::vector< Reference< xml::input::XElement > > const & rEvents )
1436 Reference< script::XScriptEventsSupplier > xSupplier(
1437 _xControlModel, UNO_QUERY );
1438 if (!xSupplier.is())
1439 return;
1441 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1442 if (!xEvents.is())
1443 return;
1445 for (const auto & rEvent : rEvents)
1447 script::ScriptEventDescriptor descr;
1449 EventElement * pEventElement = static_cast< EventElement * >( rEvent.get() );
1450 sal_Int32 nUid = pEventElement->getUid();
1451 OUString aLocalName( pEventElement->getLocalName() );
1452 Reference< xml::input::XAttributes > xAttributes( pEventElement->getAttributes() );
1454 // nowadays script events
1455 if (_pImport->XMLNS_SCRIPT_UID == nUid)
1457 if (!getStringAttr( &descr.ScriptType, "language" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1458 !getStringAttr( &descr.ScriptCode, "macro-name", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1460 throw xml::sax::SAXException( "missing language or macro-name attribute(s) of event!", Reference< XInterface >(), Any() );
1462 if ( descr.ScriptType == "StarBasic" )
1464 OUString aLocation;
1465 if (getStringAttr( &aLocation, "location", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1467 // prepend location
1468 descr.ScriptCode = aLocation + ":" + descr.ScriptCode;
1471 else if ( descr.ScriptType == "Script" )
1473 // Check if there is a protocol, if not assume
1474 // this is an early scripting framework url ( without
1475 // the protocol ) and fix it up!!
1476 if ( descr.ScriptCode.indexOf( ':' ) == -1 )
1478 descr.ScriptCode = "vnd.sun.start.script:" + descr.ScriptCode;
1482 // script:event element
1483 if ( aLocalName == "event" )
1485 OUString aEventName;
1486 if (! getStringAttr( &aEventName, "event-name", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1488 throw xml::sax::SAXException( "missing event-name attribute!", Reference< XInterface >(), Any() );
1491 // lookup in table
1492 OString str( OUStringToOString( aEventName, RTL_TEXTENCODING_ASCII_US ) );
1493 StringTriple const * p = g_pEventTranslations;
1494 while (p->first)
1496 if (0 == ::rtl_str_compare( p->third, str.getStr() ))
1498 descr.ListenerType = OUString(
1499 p->first, ::rtl_str_getLength( p->first ),
1500 RTL_TEXTENCODING_ASCII_US );
1501 descr.EventMethod = OUString(
1502 p->second, ::rtl_str_getLength( p->second ),
1503 RTL_TEXTENCODING_ASCII_US );
1504 break;
1506 ++p;
1509 if (! p->first)
1511 throw xml::sax::SAXException( "no matching event-name found!", Reference< XInterface >(), Any() );
1514 else // script:listener-event element
1516 SAL_WARN_IF( aLocalName != "listener-event", "xmlscript.xmldlg", "aLocalName != listener-event" );
1518 if (!getStringAttr( &descr.ListenerType, "listener-type" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1519 !getStringAttr( &descr.EventMethod , "listener-method", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1521 throw xml::sax::SAXException("missing listener-type or listener-method attribute(s)!", Reference< XInterface >(), Any() );
1523 // optional listener param
1524 getStringAttr( &descr.AddListenerParam, "listener-param", xAttributes, _pImport->XMLNS_SCRIPT_UID );
1527 else // deprecated dlg:event element
1529 SAL_WARN_IF( _pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != "event", "xmlscript.xmldlg", "_pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != \"event\"" );
1531 if (!getStringAttr( &descr.ListenerType, "listener-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ) ||
1532 !getStringAttr( &descr.EventMethod, "event-method", xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1534 throw xml::sax::SAXException("missing listener-type or event-method attribute(s)!", Reference< XInterface >(), Any() );
1537 getStringAttr( &descr.ScriptType, "script-type", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1538 getStringAttr( &descr.ScriptCode, "script-code", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1539 getStringAttr( &descr.AddListenerParam, "param", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1542 xEvents->insertByName( descr.ListenerType + "::" + descr.EventMethod, makeAny( descr ) );
1545 void ImportContext::importScollableSettings(
1546 Reference< xml::input::XAttributes > const & _xAttributes )
1548 importLongProperty( "ScrollHeight",
1549 "scrollheight",
1550 _xAttributes );
1551 importLongProperty( "ScrollWidth",
1552 "scrollwidth",
1553 _xAttributes );
1554 importLongProperty( "ScrollTop",
1555 "scrolltop",
1556 _xAttributes );
1557 importLongProperty( "ScrollLeft",
1558 "scrollleft",
1559 _xAttributes );
1560 importBooleanProperty( "HScroll",
1561 "hscroll",
1562 _xAttributes );
1563 importBooleanProperty( "VScroll",
1564 "vscroll",
1565 _xAttributes );
1568 void ImportContext::importDefaults(
1569 sal_Int32 nBaseX, sal_Int32 nBaseY,
1570 Reference< xml::input::XAttributes > const & xAttributes,
1571 bool supportPrintable )
1573 _xControlModel->setPropertyValue( "Name", makeAny( _aId ) );
1575 importShortProperty( "TabIndex", "tab-index", xAttributes );
1577 sal_Bool bDisable = false;
1578 if (getBoolAttr( &bDisable,"disabled", xAttributes, _pImport->XMLNS_DIALOGS_UID ) && bDisable)
1580 _xControlModel->setPropertyValue( "Enabled", makeAny( false ) );
1583 sal_Bool bVisible = true;
1584 if (getBoolAttr( &bVisible, "visible", xAttributes, _pImport->XMLNS_DIALOGS_UID ) && !bVisible)
1588 _xControlModel->setPropertyValue( "EnableVisible", makeAny( false ) );
1590 catch( Exception& )
1592 DBG_UNHANDLED_EXCEPTION("xmlscript.xmldlg");
1596 if (!importLongProperty( nBaseX, "PositionX", "left", xAttributes ) ||
1597 !importLongProperty( nBaseY, "PositionY", "top", xAttributes ) ||
1598 !importLongProperty( "Width", "width", xAttributes ) ||
1599 !importLongProperty( "Height", "height", xAttributes ))
1601 throw xml::sax::SAXException( "missing pos size attribute(s)!", Reference< XInterface >(), Any() );
1604 if (supportPrintable)
1606 importBooleanProperty("Printable", "printable", xAttributes );
1609 sal_Int32 nLong;
1610 if (! getLongAttr( &nLong, "page", xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1612 nLong = 0;
1614 _xControlModel->setPropertyValue( "Step", makeAny( nLong ) );
1616 importStringProperty("Tag", "tag", xAttributes );
1617 importStringProperty( "HelpText", "help-text", xAttributes );
1618 importStringProperty( "HelpURL", "help-url", xAttributes );
1621 Reference< xml::input::XElement > ElementBase::getParent()
1623 return static_cast< xml::input::XElement * >( m_xParent.get() );
1626 OUString ElementBase::getLocalName()
1628 return _aLocalName;
1631 sal_Int32 ElementBase::getUid()
1633 return _nUid;
1636 Reference< xml::input::XAttributes > ElementBase::getAttributes()
1638 return _xAttributes;
1641 void ElementBase::ignorableWhitespace(
1642 OUString const & /*rWhitespaces*/ )
1644 // not used
1647 void ElementBase::characters( OUString const & /*rChars*/ )
1649 // not used, all characters ignored
1652 void ElementBase::endElement()
1656 void ElementBase::processingInstruction(
1657 OUString const & /*Target*/, OUString const & /*Data*/ )
1661 Reference< xml::input::XElement > ElementBase::startChildElement(
1662 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
1663 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
1665 throw xml::sax::SAXException( "unexpected element!", Reference< XInterface >(), Any() );
1668 ElementBase::ElementBase(
1669 sal_Int32 nUid, OUString const & rLocalName,
1670 Reference< xml::input::XAttributes > const & xAttributes,
1671 ElementBase * pParent, DialogImport * pImport )
1672 : m_xImport( pImport )
1673 , m_xParent( pParent )
1674 , _nUid( nUid )
1675 , _aLocalName( rLocalName )
1676 , _xAttributes( xAttributes )
1680 ElementBase::~ElementBase()
1682 SAL_INFO("xmlscript.xmldlg", "ElementBase::~ElementBase(): " << _aLocalName );
1685 // XRoot
1687 void DialogImport::startDocument(
1688 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
1690 XMLNS_DIALOGS_UID = xNamespaceMapping->getUidByUri( XMLNS_DIALOGS_URI );
1691 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
1694 void DialogImport::endDocument()
1696 // ignored
1699 void DialogImport::processingInstruction(
1700 OUString const & /*rTarget*/, OUString const & /*rData*/ )
1702 // ignored for now: xxx todo
1705 void DialogImport::setDocumentLocator(
1706 Reference< xml::sax::XLocator > const & /*xLocator*/ )
1708 // ignored for now: xxx todo
1711 Reference< xml::input::XElement > DialogImport::startRootElement(
1712 sal_Int32 nUid, OUString const & rLocalName,
1713 Reference< xml::input::XAttributes > const & xAttributes )
1715 if (XMLNS_DIALOGS_UID != nUid)
1717 throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
1719 // window
1720 else if ( rLocalName == "window" )
1722 return new WindowElement( rLocalName, xAttributes, this );
1724 else
1726 throw xml::sax::SAXException( "illegal root element (expected window) given: " + rLocalName, Reference< XInterface >(), Any() );
1730 DialogImport::~DialogImport()
1732 SAL_INFO("xmlscript.xmldlg", "DialogImport::~DialogImport()." );
1735 Reference< util::XNumberFormatsSupplier > const & DialogImport::getNumberFormatsSupplier()
1737 if (! _xSupplier.is())
1739 Reference< util::XNumberFormatsSupplier > xSupplier = util::NumberFormatsSupplier::createWithDefaultLocale( getComponentContext() );
1741 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1742 if (! _xSupplier.is())
1744 _xSupplier = xSupplier;
1747 return _xSupplier;
1750 void DialogImport::addStyle(
1751 OUString const & rStyleId,
1752 Reference< xml::input::XElement > const & xStyle )
1754 (*_pStyleNames).push_back( rStyleId );
1755 (*_pStyles).push_back( xStyle );
1758 Reference< xml::input::XElement > DialogImport::getStyle(
1759 std::u16string_view rStyleId ) const
1761 for ( size_t nPos = 0; nPos < (*_pStyleNames).size(); ++nPos )
1763 if ( (*_pStyleNames)[ nPos ] == rStyleId)
1765 return (*_pStyles)[ nPos ];
1768 return nullptr;
1771 Reference< xml::sax::XDocumentHandler > importDialogModel(
1772 Reference< container::XNameContainer > const & xDialogModel,
1773 Reference< XComponentContext > const & xContext,
1774 Reference< XModel > const & xDocument )
1776 // single set of styles and stylenames apply to all containers
1777 auto pStyleNames = std::make_shared<std::vector< OUString >>();
1778 auto pStyles = std::make_shared<std::vector< css::uno::Reference< css::xml::input::XElement > >>();
1779 return ::xmlscript::createDocumentHandler(
1780 new DialogImport(xContext, xDialogModel, pStyleNames, pStyles, xDocument));
1784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */