tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_import.cxx
blobfec74e7ad123d873e3d2ea9e8d32d0385cfdbed6
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 <utility>
23 #include <xml_import.hxx>
24 #include <xmlscript/xmlns.h>
26 #include <com/sun/star/awt/CharSet.hpp>
27 #include <com/sun/star/awt/FontFamily.hpp>
28 #include <com/sun/star/awt/FontPitch.hpp>
29 #include <com/sun/star/awt/FontSlant.hpp>
30 #include <com/sun/star/awt/FontStrikeout.hpp>
31 #include <com/sun/star/awt/FontType.hpp>
32 #include <com/sun/star/awt/FontUnderline.hpp>
33 #include <com/sun/star/awt/ImagePosition.hpp>
34 #include <com/sun/star/awt/ImageScaleMode.hpp>
35 #include <com/sun/star/awt/LineEndFormat.hpp>
36 #include <com/sun/star/awt/PushButtonType.hpp>
37 #include <com/sun/star/awt/VisualEffect.hpp>
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <com/sun/star/style/VerticalAlignment.hpp>
40 #include <com/sun/star/util/Date.hpp>
41 #include <com/sun/star/util/Time.hpp>
42 #include <sal/log.hxx>
43 #include <tools/date.hxx>
44 #include <comphelper/diagnose_ex.hxx>
45 #include <tools/time.hxx>
46 #include <osl/diagnose.h>
48 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
49 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
51 #include <com/sun/star/view/SelectionType.hpp>
52 #include <com/sun/star/form/binding/XBindableValue.hpp>
53 #include <com/sun/star/form/binding/XValueBinding.hpp>
54 #include <com/sun/star/form/binding/XListEntrySink.hpp>
55 #include <com/sun/star/beans/NamedValue.hpp>
56 #include <com/sun/star/table/CellAddress.hpp>
57 #include <com/sun/star/table/CellRangeAddress.hpp>
58 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
59 #include <com/sun/star/document/XStorageBasedDocument.hpp>
60 #include <com/sun/star/graphic/XGraphic.hpp>
61 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::frame;
67 namespace xmlscript
70 void EventElement::endElement()
72 static_cast< ControlElement * >( m_pParent )->_events.emplace_back(this );
75 ControlElement::ControlElement(
76 OUString const & rLocalName,
77 Reference< xml::input::XAttributes > const & xAttributes,
78 ElementBase * pParent, DialogImport * pImport )
79 : ElementBase(
80 pImport->XMLNS_DIALOGS_UID, rLocalName, xAttributes, pParent, pImport )
82 if (m_pParent)
84 // inherit position
85 _nBasePosX = static_cast< ControlElement * >( m_pParent )->_nBasePosX;
86 _nBasePosY = static_cast< ControlElement * >( m_pParent )->_nBasePosY;
88 else
90 _nBasePosX = 0;
91 _nBasePosY = 0;
95 Reference< xml::input::XElement > ControlElement::getStyle(
96 Reference< xml::input::XAttributes > const & xAttributes )
98 OUString aStyleId( xAttributes->getValueByUidName( m_pImport->XMLNS_DIALOGS_UID,u"style-id"_ustr ) );
99 if (!aStyleId.isEmpty())
101 return m_pImport->getStyle( aStyleId );
103 return Reference< xml::input::XElement >();
106 OUString ControlElement::getControlId(
107 Reference< xml::input::XAttributes > const & xAttributes )
109 OUString aId( xAttributes->getValueByUidName( m_pImport->XMLNS_DIALOGS_UID, u"id"_ustr ) );
110 if (aId.isEmpty())
112 throw xml::sax::SAXException( u"missing id attribute!"_ustr, Reference< XInterface >(), Any() );
114 return aId;
117 OUString ControlElement::getControlModelName(
118 OUString const& rDefaultModel,
119 Reference< xml::input::XAttributes > const & xAttributes )
121 OUString aModel = xAttributes->getValueByUidName( m_pImport->XMLNS_DIALOGS_UID, u"control-implementation"_ustr);
122 if (aModel.isEmpty())
123 aModel = rDefaultModel;
124 return aModel;
127 void StyleElement::importTextColorStyle(
128 Reference< beans::XPropertySet > const & xProps )
130 if ((_inited & 0x2) != 0)
132 if ((_hasValue & 0x2) != 0)
134 xProps->setPropertyValue(u"TextColor"_ustr, Any( _textColor ) );
136 return;
138 _inited |= 0x2;
140 if (getLongAttr( &_textColor, u"text-color"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
142 _hasValue |= 0x2;
143 xProps->setPropertyValue( u"TextColor"_ustr, Any( _textColor ) );
144 return;
148 void StyleElement::importTextLineColorStyle(
149 Reference< beans::XPropertySet > const & xProps )
151 if ((_inited & 0x20) != 0)
153 if ((_hasValue & 0x20) != 0)
155 xProps->setPropertyValue( u"TextLineColor"_ustr, Any( _textLineColor ) );
157 return;
159 _inited |= 0x20;
161 if (getLongAttr( &_textLineColor, u"textline-color"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
163 _hasValue |= 0x20;
164 xProps->setPropertyValue( u"TextLineColor"_ustr, Any( _textLineColor ) );
168 void StyleElement::importFillColorStyle(
169 Reference< beans::XPropertySet > const & xProps )
171 if ((_inited & 0x10) != 0)
173 if ((_hasValue & 0x10) != 0)
175 xProps->setPropertyValue( u"FillColor"_ustr, Any( _fillColor ) );
177 return;
179 _inited |= 0x10;
181 if (getLongAttr( &_fillColor, u"fill-color"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
183 _hasValue |= 0x10;
184 xProps->setPropertyValue( u"FillColor"_ustr, Any( _fillColor ) );
188 void StyleElement::importBackgroundColorStyle(
189 Reference< beans::XPropertySet > const & xProps )
191 if ((_inited & 0x1) != 0)
193 if ((_hasValue & 0x1) != 0)
195 xProps->setPropertyValue( u"BackgroundColor"_ustr, Any( _backgroundColor ) );
197 return;
199 _inited |= 0x1;
201 if (getLongAttr( &_backgroundColor, u"background-color"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
203 _hasValue |= 0x1;
204 xProps->setPropertyValue( u"BackgroundColor"_ustr, Any( _backgroundColor ) );
208 void StyleElement::importBorderStyle(
209 Reference< beans::XPropertySet > const & xProps )
211 if ((_inited & 0x4) != 0)
213 if ((_hasValue & 0x4) != 0)
215 xProps->setPropertyValue( u"Border"_ustr, Any( _border == BORDER_SIMPLE_COLOR ? BORDER_SIMPLE : _border ) );
216 if (_border == BORDER_SIMPLE_COLOR)
217 xProps->setPropertyValue( u"BorderColor"_ustr, Any(_borderColor) );
219 return;
221 _inited |= 0x4;
223 OUString aValue;
224 if (!getStringAttr(&aValue, u"border"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
225 return;
227 if ( aValue == "none" )
228 _border = BORDER_NONE;
229 else if ( aValue == "3d" )
230 _border = BORDER_3D;
231 else if ( aValue == "simple" )
232 _border = BORDER_SIMPLE;
233 else {
234 _border = BORDER_SIMPLE_COLOR;
235 _borderColor = toInt32(aValue);
238 _hasValue |= 0x4;
239 importBorderStyle(xProps); // write values
242 void StyleElement::importVisualEffectStyle(
243 Reference<beans::XPropertySet> const & xProps )
245 if ((_inited & 0x40) != 0)
247 if ((_hasValue & 0x40) != 0)
249 xProps->setPropertyValue( u"VisualEffect"_ustr, Any(_visualEffect) );
251 return;
253 _inited |= 0x40;
255 OUString aValue;
256 if (!getStringAttr( &aValue, u"look"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
257 return;
259 if ( aValue == "none" )
261 _visualEffect = awt::VisualEffect::NONE;
263 else if ( aValue == "3d" )
265 _visualEffect = awt::VisualEffect::LOOK3D;
267 else if ( aValue == "simple" )
269 _visualEffect = awt::VisualEffect::FLAT;
271 else
272 OSL_ASSERT( false );
274 _hasValue |= 0x40;
275 xProps->setPropertyValue( u"VisualEffect"_ustr, Any(_visualEffect) );
278 void StyleElement::setFontProperties(
279 Reference< beans::XPropertySet > const & xProps ) const
281 xProps->setPropertyValue(u"FontDescriptor"_ustr, Any( _descr ) );
282 xProps->setPropertyValue(u"FontEmphasisMark"_ustr, Any( _fontEmphasisMark ) );
283 xProps->setPropertyValue(u"FontRelief"_ustr, Any( _fontRelief ) );
286 void StyleElement::importFontStyle(
287 Reference< beans::XPropertySet > const & xProps )
289 if ((_inited & 0x8) != 0)
291 if ((_hasValue & 0x8) != 0)
293 setFontProperties( xProps );
295 return;
297 _inited |= 0x8;
299 OUString aValue;
300 bool bFontImport;
302 // dialog:font-name CDATA #IMPLIED
303 bFontImport = getStringAttr( &_descr.Name, u"font-name"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID );
305 // dialog:font-height %numeric; #IMPLIED
306 if (getStringAttr( &aValue, u"font-height"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
308 _descr.Height = static_cast<sal_Int16>(toInt32( aValue ));
309 bFontImport = true;
311 // dialog:font-width %numeric; #IMPLIED
312 if (getStringAttr(&aValue, u"font-width"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
314 _descr.Width = static_cast<sal_Int16>(toInt32( aValue ));
315 bFontImport = true;
317 // dialog:font-stylename CDATA #IMPLIED
318 bFontImport |= getStringAttr( &_descr.StyleName, u"font-stylename"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID );
320 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
321 if (getStringAttr(&aValue, u"font-family"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
323 if ( aValue == "decorative" )
325 _descr.Family = awt::FontFamily::DECORATIVE;
327 else if ( aValue == "modern" )
329 _descr.Family = awt::FontFamily::MODERN;
331 else if ( aValue == "roman" )
333 _descr.Family = awt::FontFamily::ROMAN;
335 else if ( aValue == "script" )
337 _descr.Family = awt::FontFamily::SCRIPT;
339 else if ( aValue == "swiss" )
341 _descr.Family = awt::FontFamily::SWISS;
343 else if ( aValue == "system" )
345 _descr.Family = awt::FontFamily::SYSTEM;
347 else
349 throw xml::sax::SAXException(u"invalid font-family style!"_ustr, Reference< XInterface >(), Any() );
351 bFontImport = true;
354 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
355 if (getStringAttr(&aValue, u"font-charset"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
357 if ( aValue == "ansi" )
359 _descr.CharSet = awt::CharSet::ANSI;
361 else if ( aValue == "mac" )
363 _descr.CharSet = awt::CharSet::MAC;
365 else if ( aValue == "ibmpc_437" )
367 _descr.CharSet = awt::CharSet::IBMPC_437;
369 else if ( aValue == "ibmpc_850" )
371 _descr.CharSet = awt::CharSet::IBMPC_850;
373 else if ( aValue == "ibmpc_860" )
375 _descr.CharSet = awt::CharSet::IBMPC_860;
377 else if ( aValue == "ibmpc_861" )
379 _descr.CharSet = awt::CharSet::IBMPC_861;
381 else if ( aValue == "ibmpc_863" )
383 _descr.CharSet = awt::CharSet::IBMPC_863;
385 else if ( aValue == "ibmpc_865" )
387 _descr.CharSet = awt::CharSet::IBMPC_865;
389 else if ( aValue == "system" )
391 _descr.CharSet = awt::CharSet::SYSTEM;
393 else if ( aValue == "symbol" )
395 _descr.CharSet = awt::CharSet::SYMBOL;
397 else
399 throw xml::sax::SAXException(u"invalid font-charset style!"_ustr, Reference< XInterface >(), Any() );
401 bFontImport = true;
404 // dialog:font-pitch "(fixed|variable)" #IMPLIED
405 if (getStringAttr( &aValue, u"font-pitch"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
407 if ( aValue == "fixed" )
409 _descr.Pitch = awt::FontPitch::FIXED;
411 else if ( aValue == "variable" )
413 _descr.Pitch = awt::FontPitch::VARIABLE;
415 else
417 throw xml::sax::SAXException(u"invalid font-pitch style!"_ustr, Reference< XInterface >(), Any() );
419 bFontImport = true;
422 // dialog:font-charwidth CDATA #IMPLIED
423 if (getStringAttr( &aValue, u"font-charwidth"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
425 _descr.CharacterWidth = aValue.toFloat();
426 bFontImport = true;
428 // dialog:font-weight CDATA #IMPLIED
429 if (getStringAttr( &aValue, u"font-weight"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
431 _descr.Weight = aValue.toFloat();
432 bFontImport = true;
435 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
436 if (getStringAttr( &aValue, u"font-slant"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
438 if ( aValue == "oblique" )
440 _descr.Slant = awt::FontSlant_OBLIQUE;
442 else if ( aValue == "italic" )
444 _descr.Slant = awt::FontSlant_ITALIC;
446 else if ( aValue == "reverse_oblique" )
448 _descr.Slant = awt::FontSlant_REVERSE_OBLIQUE;
450 else if ( aValue == "reverse_italic" )
452 _descr.Slant = awt::FontSlant_REVERSE_ITALIC;
454 else
456 throw xml::sax::SAXException(u"invalid font-slant style!"_ustr, Reference< XInterface >(), Any() );
458 bFontImport = true;
461 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
462 if (getStringAttr( &aValue, u"font-underline"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
464 if ( aValue == "single" )
466 _descr.Underline = awt::FontUnderline::SINGLE;
468 else if ( aValue == "double" )
470 _descr.Underline = awt::FontUnderline::DOUBLE;
472 else if ( aValue == "dotted" )
474 _descr.Underline = awt::FontUnderline::DOTTED;
476 else if ( aValue == "dash" )
478 _descr.Underline = awt::FontUnderline::DASH;
480 else if ( aValue == "longdash" )
482 _descr.Underline = awt::FontUnderline::LONGDASH;
484 else if ( aValue == "dashdot" )
486 _descr.Underline = awt::FontUnderline::DASHDOT;
488 else if ( aValue == "dashdotdot" )
490 _descr.Underline = awt::FontUnderline::DASHDOTDOT;
492 else if ( aValue == "smallwave" )
494 _descr.Underline = awt::FontUnderline::SMALLWAVE;
496 else if ( aValue == "wave" )
498 _descr.Underline = awt::FontUnderline::WAVE;
500 else if ( aValue == "doublewave" )
502 _descr.Underline = awt::FontUnderline::DOUBLEWAVE;
504 else if ( aValue == "bold" )
506 _descr.Underline = awt::FontUnderline::BOLD;
508 else if ( aValue == "bolddotted" )
510 _descr.Underline = awt::FontUnderline::BOLDDOTTED;
512 else if ( aValue == "bolddash" )
514 _descr.Underline = awt::FontUnderline::BOLDDASH;
516 else if ( aValue == "boldlongdash" )
518 _descr.Underline = awt::FontUnderline::BOLDLONGDASH;
520 else if ( aValue == "bolddashdot" )
522 _descr.Underline = awt::FontUnderline::BOLDDASHDOT;
524 else if ( aValue == "bolddashdotdot" )
526 _descr.Underline = awt::FontUnderline::BOLDDASHDOTDOT;
528 else if ( aValue == "boldwave" )
530 _descr.Underline = awt::FontUnderline::BOLDWAVE;
532 else
534 throw xml::sax::SAXException(u"invalid font-underline style!"_ustr, Reference< XInterface >(), Any() );
536 bFontImport = true;
539 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
540 if (getStringAttr( &aValue, u"font-strikeout"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
542 if ( aValue == "single" )
544 _descr.Strikeout = awt::FontStrikeout::SINGLE;
546 else if ( aValue == "double" )
548 _descr.Strikeout = awt::FontStrikeout::DOUBLE;
550 else if ( aValue == "bold" )
552 _descr.Strikeout = awt::FontStrikeout::BOLD;
554 else if ( aValue == "slash" )
556 _descr.Strikeout = awt::FontStrikeout::SLASH;
558 else if ( aValue == "x" )
560 _descr.Strikeout = awt::FontStrikeout::X;
562 else
564 throw xml::sax::SAXException( u"invalid font-strikeout style!"_ustr , Reference< XInterface >(), Any() );
566 bFontImport = true;
569 // dialog:font-orientation CDATA #IMPLIED
570 if (getStringAttr( &aValue, u"font-orientation"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
572 _descr.Orientation = aValue.toFloat();
573 bFontImport = true;
575 // dialog:font-kerning %boolean; #IMPLIED
576 bFontImport |= getBoolAttr( &_descr.Kerning, u"font-kerning"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID );
577 // dialog:font-wordlinemode %boolean; #IMPLIED
578 bFontImport |= getBoolAttr( &_descr.WordLineMode,u"font-wordlinemode"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID );
580 // dialog:font-type "(raster|device|scalable)" #IMPLIED
581 if (getStringAttr( &aValue, u"font-type"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
583 if ( aValue == "raster" )
585 _descr.Type = awt::FontType::RASTER;
587 else if ( aValue == "device" )
589 _descr.Type = awt::FontType::DEVICE;
591 else if ( aValue == "scalable" )
593 _descr.Type = awt::FontType::SCALABLE;
595 else
597 throw xml::sax::SAXException( u"invalid font-type style!"_ustr, Reference< XInterface >(), Any() );
599 bFontImport = true;
602 // additional properties which are not part of the FontDescriptor struct
603 // dialog:font-relief (none|embossed|engraved) #IMPLIED
604 if (getStringAttr( &aValue, u"font-relief"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
606 if ( aValue == "none" )
608 _fontRelief = awt::FontRelief::NONE;
610 else if ( aValue == "embossed" )
612 _fontRelief = awt::FontRelief::EMBOSSED;
614 else if ( aValue == "engraved" )
616 _fontRelief = awt::FontRelief::ENGRAVED;
618 else
620 throw xml::sax::SAXException(u"invalid font-relief style!"_ustr, Reference< XInterface >(), Any() );
622 bFontImport = true;
624 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
625 if (getStringAttr(&aValue, u"font-emphasismark"_ustr, _xAttributes, m_pImport->XMLNS_DIALOGS_UID ))
627 if ( aValue == "none" )
629 _fontEmphasisMark = awt::FontEmphasisMark::NONE;
631 else if ( aValue == "dot" )
633 _fontEmphasisMark = awt::FontEmphasisMark::DOT;
635 else if ( aValue == "circle" )
637 _fontEmphasisMark = awt::FontEmphasisMark::CIRCLE;
639 else if ( aValue == "disc" )
641 _fontEmphasisMark = awt::FontEmphasisMark::DISC;
643 else if ( aValue == "accent" )
645 _fontEmphasisMark = awt::FontEmphasisMark::ACCENT;
647 else if ( aValue == "above" )
649 _fontEmphasisMark = awt::FontEmphasisMark::ABOVE;
651 else if ( aValue == "below" )
653 _fontEmphasisMark = awt::FontEmphasisMark::BELOW;
655 else
657 throw xml::sax::SAXException( u"invalid font-emphasismark style!"_ustr, Reference< XInterface >(), Any() );
659 bFontImport = true;
662 if (bFontImport)
664 _hasValue |= 0x8;
665 setFontProperties( xProps );
669 bool ImportContext::importStringProperty(
670 OUString const & rPropName, OUString const & rAttrName,
671 Reference< xml::input::XAttributes > const & xAttributes )
673 OUString aValue(
674 xAttributes->getValueByUidName(
675 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
676 if (!aValue.isEmpty())
678 _xControlModel->setPropertyValue( rPropName, Any( aValue ) );
679 return true;
681 return false;
684 bool ImportContext::importDoubleProperty(
685 OUString const & rPropName, OUString const & rAttrName,
686 Reference< xml::input::XAttributes > const & xAttributes )
688 OUString aValue(
689 xAttributes->getValueByUidName(
690 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
691 if (!aValue.isEmpty())
693 _xControlModel->setPropertyValue( rPropName, Any( aValue.toDouble() ) );
694 return true;
696 return false;
699 bool ImportContext::importBooleanProperty(
700 OUString const & rPropName, OUString const & rAttrName,
701 Reference< xml::input::XAttributes > const & xAttributes )
703 sal_Bool bBool;
704 if (getBoolAttr(
705 &bBool, rAttrName, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
707 _xControlModel->setPropertyValue( rPropName, Any( bBool ) );
708 return true;
710 return false;
713 bool ImportContext::importLongProperty(
714 OUString const & rPropName, OUString const & rAttrName,
715 Reference< xml::input::XAttributes > const & xAttributes )
717 OUString aValue(
718 xAttributes->getValueByUidName(
719 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
720 if (!aValue.isEmpty())
722 _xControlModel->setPropertyValue( rPropName, Any( toInt32( aValue ) ) );
723 return true;
725 return false;
728 bool ImportContext::importLongProperty(
729 sal_Int32 nOffset,
730 OUString const & rPropName, OUString const & rAttrName,
731 Reference< xml::input::XAttributes > const & xAttributes )
733 OUString aValue(
734 xAttributes->getValueByUidName(
735 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
736 if (!aValue.isEmpty())
738 _xControlModel->setPropertyValue( rPropName, Any( toInt32( aValue ) + nOffset ) );
739 return true;
741 return false;
744 bool ImportContext::importHexLongProperty(
745 OUString const & rPropName, OUString const & rAttrName,
746 Reference< xml::input::XAttributes > const & xAttributes )
748 OUString aValue(
749 xAttributes->getValueByUidName(
750 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
751 if (!aValue.isEmpty())
753 _xControlModel->setPropertyValue( rPropName, Any( toInt32( aValue ) ) );
754 return true;
756 return false;
759 bool ImportContext::importShortProperty(
760 OUString const & rPropName, OUString const & rAttrName,
761 Reference< xml::input::XAttributes > const & xAttributes )
763 OUString aValue(
764 xAttributes->getValueByUidName(
765 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
766 if (!aValue.isEmpty())
768 _xControlModel->setPropertyValue( rPropName, Any( static_cast<sal_Int16>(toInt32( aValue )) ) );
769 return true;
771 return false;
774 bool ImportContext::importAlignProperty(
775 OUString const & rPropName, OUString const & rAttrName,
776 Reference< xml::input::XAttributes > const & xAttributes )
778 OUString aAlign(
779 xAttributes->getValueByUidName(
780 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
781 if (!aAlign.isEmpty())
783 sal_Int16 nAlign;
784 if ( aAlign == "left" )
786 nAlign = 0;
788 else if ( aAlign == "center" )
790 nAlign = 1;
792 else if ( aAlign == "right" )
794 nAlign = 2;
796 else if ( aAlign == "none" )
798 nAlign = 0; // default
800 else
802 throw xml::sax::SAXException(u"invalid align value!"_ustr, Reference< XInterface >(), Any() );
805 _xControlModel->setPropertyValue( rPropName, Any( nAlign ) );
806 return true;
808 return false;
811 bool ImportContext::importVerticalAlignProperty(
812 OUString const & rPropName, OUString const & rAttrName,
813 Reference< xml::input::XAttributes > const & xAttributes )
815 OUString aAlign(
816 xAttributes->getValueByUidName(
817 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
818 if (!aAlign.isEmpty())
820 style::VerticalAlignment eAlign;
822 if ( aAlign == "top" )
824 eAlign = style::VerticalAlignment_TOP;
826 else if ( aAlign == "center" )
828 eAlign = style::VerticalAlignment_MIDDLE;
830 else if ( aAlign == "bottom" )
832 eAlign = style::VerticalAlignment_BOTTOM;
834 else
836 throw xml::sax::SAXException( u"invalid vertical align value!"_ustr, Reference< XInterface >(), Any() );
839 _xControlModel->setPropertyValue( rPropName, Any( eAlign ) );
840 return true;
842 return false;
845 bool ImportContext::importGraphicOrImageProperty(
846 OUString const & rAttrName,
847 Reference< xml::input::XAttributes > const & xAttributes )
849 OUString sURL = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rAttrName );
850 if ( !sURL.isEmpty() )
852 Reference< document::XStorageBasedDocument > xDocStorage( _pImport->getDocOwner(), UNO_QUERY );
854 uno::Reference<graphic::XGraphic> xGraphic;
856 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
857 if ( xDocStorage.is() )
859 uno::Sequence< Any > aArgs{ Any(xDocStorage->getDocumentStorage()) };
860 xGraphicStorageHandler.set(
861 _pImport->getComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext( u"com.sun.star.comp.Svx.GraphicImportHelper"_ustr , 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(u"Graphic"_ustr, Any(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(u"ImageURL"_ustr, Any(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( u"com.sun.star.table.CellAddressConversion"_ustr ), uno::UNO_QUERY );
918 if ( xBindable.is() && xConvertor.is() )
920 table::CellAddress aAddress;
921 xConvertor->setPropertyValue( u"PersistentRepresentation"_ustr , uno::Any( sLinkedCell ) );
922 xConvertor->getPropertyValue( u"Address"_ustr ) >>= aAddress;
923 beans::NamedValue aArg1;
924 aArg1.Name = "BoundCell";
925 aArg1.Value <<= aAddress;
927 uno::Reference< form::binding::XValueBinding > xBinding( xFac->createInstanceWithArguments( u"com.sun.star.table.CellValueBinding"_ustr , { uno::Any(aArg1) }), uno::UNO_QUERY );
928 xBindable->setValueBinding( xBinding );
929 bRes = true;
932 // Set up CellRange
933 if ( !sCellRange.isEmpty() )
935 Reference< form::binding::XListEntrySink > xListEntrySink( getControlModel(), uno::UNO_QUERY );
936 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( u"com.sun.star.table.CellRangeAddressConversion"_ustr ), uno::UNO_QUERY );
937 if ( xListEntrySink.is() && xConvertor.is() )
939 table::CellRangeAddress aAddress;
940 xConvertor->setPropertyValue( u"PersistentRepresentation"_ustr , uno::Any( sCellRange ) );
941 xConvertor->getPropertyValue( u"Address"_ustr ) >>= aAddress;
942 beans::NamedValue aArg1;
943 aArg1.Name = "CellRange";
944 aArg1.Value <<= aAddress;
946 uno::Reference< form::binding::XListEntrySource > xSource( xFac->createInstanceWithArguments( u"com.sun.star.table.CellRangeListSource"_ustr , { uno::Any(aArg1) } ), uno::UNO_QUERY );
947 xListEntrySink->setListEntrySource( xSource );
948 bRes = true;
952 return bRes;
955 bool ImportContext::importImageAlignProperty(
956 OUString const & rPropName, OUString const & rAttrName,
957 Reference< xml::input::XAttributes > const & xAttributes )
959 OUString aAlign(
960 xAttributes->getValueByUidName(
961 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
962 if (!aAlign.isEmpty())
964 sal_Int16 nAlign;
965 if ( aAlign == "left" )
967 nAlign = 0;
969 else if ( aAlign == "top" )
971 nAlign = 1;
973 else if ( aAlign == "right" )
975 nAlign = 2;
977 else if ( aAlign == "bottom" )
979 nAlign = 3;
981 else
983 throw xml::sax::SAXException( u"invalid image align value!"_ustr, Reference< XInterface >(), Any() );
986 _xControlModel->setPropertyValue( rPropName, Any( nAlign ) );
987 return true;
989 return false;
992 bool ImportContext::importImagePositionProperty(
993 OUString const & rPropName, OUString const & rAttrName,
994 Reference< xml::input::XAttributes > const & xAttributes )
996 OUString aPosition(
997 xAttributes->getValueByUidName(
998 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
999 if (!aPosition.isEmpty())
1001 sal_Int16 nPosition;
1002 if ( aPosition == "left-top" )
1004 nPosition = awt::ImagePosition::LeftTop;
1006 else if ( aPosition == "left-center" )
1008 nPosition = awt::ImagePosition::LeftCenter;
1010 else if ( aPosition == "left-bottom" )
1012 nPosition = awt::ImagePosition::LeftBottom;
1014 else if ( aPosition == "right-top" )
1016 nPosition = awt::ImagePosition::RightTop;
1018 else if ( aPosition == "right-center" )
1020 nPosition = awt::ImagePosition::RightCenter;
1022 else if ( aPosition == "right-bottom" )
1024 nPosition = awt::ImagePosition::RightBottom;
1026 else if ( aPosition == "top-left" )
1028 nPosition = awt::ImagePosition::AboveLeft;
1030 else if ( aPosition == "top-center" )
1032 nPosition = awt::ImagePosition::AboveCenter;
1034 else if ( aPosition == "top-right" )
1036 nPosition = awt::ImagePosition::AboveRight;
1038 else if ( aPosition == "bottom-left" )
1040 nPosition = awt::ImagePosition::BelowLeft;
1042 else if ( aPosition == "bottom-center" )
1044 nPosition = awt::ImagePosition::BelowCenter;
1046 else if ( aPosition == "bottom-right" )
1048 nPosition = awt::ImagePosition::BelowRight;
1050 else if ( aPosition == "center" )
1052 nPosition = awt::ImagePosition::Centered;
1054 else
1056 throw xml::sax::SAXException( u"invalid image position value!"_ustr, Reference< XInterface >(), Any() );
1059 _xControlModel->setPropertyValue( rPropName, Any( nPosition ) );
1060 return true;
1062 return false;
1065 bool ImportContext::importButtonTypeProperty(
1066 OUString const & rPropName, OUString const & rAttrName,
1067 Reference< xml::input::XAttributes > const & xAttributes )
1069 OUString buttonType(
1070 xAttributes->getValueByUidName(
1071 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1072 if (!buttonType.isEmpty())
1074 awt::PushButtonType nButtonType;
1075 if ( buttonType == "standard" )
1077 nButtonType = awt::PushButtonType_STANDARD;
1079 else if ( buttonType == "ok" )
1081 nButtonType = awt::PushButtonType_OK;
1083 else if ( buttonType == "cancel" )
1085 nButtonType = awt::PushButtonType_CANCEL;
1087 else if ( buttonType == "help" )
1089 nButtonType = awt::PushButtonType_HELP;
1091 else
1093 throw xml::sax::SAXException( u"invalid button-type value!"_ustr, Reference< XInterface >(), Any() );
1096 _xControlModel->setPropertyValue( rPropName, Any( static_cast<sal_Int16>(nButtonType) ) );
1097 return true;
1099 return false;
1102 bool ImportContext::importDateFormatProperty(
1103 OUString const & rPropName, OUString const & rAttrName,
1104 Reference< xml::input::XAttributes > const & xAttributes )
1106 OUString aFormat(
1107 xAttributes->getValueByUidName(
1108 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1109 if (!aFormat.isEmpty())
1111 sal_Int16 nFormat;
1112 if ( aFormat == "system_short" )
1114 nFormat = 0;
1116 else if ( aFormat == "system_short_YY" )
1118 nFormat = 1;
1120 else if ( aFormat == "system_short_YYYY" )
1122 nFormat = 2;
1124 else if ( aFormat == "system_long" )
1126 nFormat = 3;
1128 else if ( aFormat == "short_DDMMYY" )
1130 nFormat = 4;
1132 else if ( aFormat == "short_MMDDYY" )
1134 nFormat = 5;
1136 else if ( aFormat == "short_YYMMDD" )
1138 nFormat = 6;
1140 else if ( aFormat == "short_DDMMYYYY" )
1142 nFormat = 7;
1144 else if ( aFormat == "short_MMDDYYYY" )
1146 nFormat = 8;
1148 else if ( aFormat == "short_YYYYMMDD" )
1150 nFormat = 9;
1152 else if ( aFormat == "short_YYMMDD_DIN5008" )
1154 nFormat = 10;
1156 else if ( aFormat == "short_YYYYMMDD_DIN5008" )
1158 nFormat = 11;
1160 else
1162 throw xml::sax::SAXException( u"invalid date-format value!"_ustr, Reference< XInterface >(), Any() );
1165 _xControlModel->setPropertyValue( rPropName, Any( nFormat ) );
1166 return true;
1168 return false;
1171 bool ImportContext::importTimeProperty(
1172 OUString const & rPropName, OUString const & rAttrName,
1173 Reference< xml::input::XAttributes > const & xAttributes )
1175 OUString aValue(
1176 xAttributes->getValueByUidName(
1177 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1178 if (!aValue.isEmpty())
1180 // Is it really the legacy "encoded value in centiseconds"?
1181 tools::Time aTTime(tools::Time::fromEncodedTime(toInt32(aValue) * tools::Time::nanoPerCenti));
1182 util::Time aUTime(aTTime.GetUNOTime());
1183 _xControlModel->setPropertyValue( rPropName, Any( aUTime ) );
1184 return true;
1186 return false;
1189 bool ImportContext::importDateProperty(
1190 OUString const & rPropName, OUString const & rAttrName,
1191 Reference< xml::input::XAttributes > const & xAttributes )
1193 OUString aValue(
1194 xAttributes->getValueByUidName(
1195 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1196 if (!aValue.isEmpty())
1198 ::Date aTDate(toInt32( aValue ));
1199 util::Date aUDate(aTDate.GetUNODate());
1200 _xControlModel->setPropertyValue( rPropName, Any( aUDate ) );
1201 return true;
1203 return false;
1206 bool ImportContext::importTimeFormatProperty(
1207 OUString const & rPropName, OUString const & rAttrName,
1208 Reference< xml::input::XAttributes > const & xAttributes )
1210 OUString aFormat(
1211 xAttributes->getValueByUidName(
1212 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1213 if (!aFormat.isEmpty())
1215 sal_Int16 nFormat;
1216 if ( aFormat == "24h_short" )
1218 nFormat = 0;
1220 else if ( aFormat == "24h_long" )
1222 nFormat = 1;
1224 else if ( aFormat == "12h_short" )
1226 nFormat = 2;
1228 else if ( aFormat == "12h_long" )
1230 nFormat = 3;
1232 else if ( aFormat == "Duration_short" )
1234 nFormat = 4;
1236 else if ( aFormat == "Duration_long" )
1238 nFormat = 5;
1240 else
1242 throw xml::sax::SAXException( u"invalid time-format value!"_ustr, Reference< XInterface >(), Any() );
1245 _xControlModel->setPropertyValue( rPropName, Any( nFormat ) );
1246 return true;
1248 return false;
1251 bool ImportContext::importOrientationProperty(
1252 OUString const & rPropName, OUString const & rAttrName,
1253 Reference< xml::input::XAttributes > const & xAttributes )
1255 OUString aOrient(
1256 xAttributes->getValueByUidName(
1257 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1258 if (!aOrient.isEmpty())
1260 sal_Int32 nOrient;
1261 if ( aOrient == "horizontal" )
1263 nOrient = 0;
1265 else if ( aOrient == "vertical" )
1267 nOrient = 1;
1269 else
1271 throw xml::sax::SAXException( u"invalid orientation value!"_ustr, Reference< XInterface >(), Any() );
1274 _xControlModel->setPropertyValue( rPropName, Any( nOrient ) );
1275 return true;
1277 return false;
1280 bool ImportContext::importLineEndFormatProperty(
1281 OUString const & rPropName, OUString const & rAttrName,
1282 Reference< xml::input::XAttributes > const & xAttributes )
1284 OUString aFormat(
1285 xAttributes->getValueByUidName(
1286 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1287 if (!aFormat.isEmpty())
1289 sal_Int16 nFormat;
1290 if ( aFormat == "carriage-return" )
1292 nFormat = awt::LineEndFormat::CARRIAGE_RETURN;
1294 else if ( aFormat == "line-feed" )
1296 nFormat = awt::LineEndFormat::LINE_FEED;
1298 else if ( aFormat == "carriage-return-line-feed" )
1300 nFormat = awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED;
1302 else
1304 throw xml::sax::SAXException( u"invalid line end format value!"_ustr, Reference< XInterface >(), Any() );
1307 _xControlModel->setPropertyValue( rPropName, Any( nFormat ) );
1308 return true;
1310 return false;
1313 bool ImportContext::importSelectionTypeProperty(
1314 OUString const & rPropName, OUString const & rAttrName,
1315 Reference< xml::input::XAttributes > const & xAttributes )
1317 OUString aSelectionType(
1318 xAttributes->getValueByUidName(
1319 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1320 if (!aSelectionType.isEmpty())
1322 view::SelectionType eSelectionType;
1324 if ( aSelectionType == "none" )
1326 eSelectionType = view::SelectionType_NONE;
1328 else if ( aSelectionType == "single" )
1330 eSelectionType = view::SelectionType_SINGLE;
1332 else if ( aSelectionType == "multi" )
1334 eSelectionType = view::SelectionType_MULTI;
1336 else if ( aSelectionType == "range" )
1338 eSelectionType = view::SelectionType_RANGE;
1340 else
1342 throw xml::sax::SAXException( u"invalid selection type value!"_ustr, Reference< XInterface >(), Any() );
1345 _xControlModel->setPropertyValue( rPropName, Any( eSelectionType ) );
1346 return true;
1348 return false;
1351 bool ImportContext::importImageScaleModeProperty(
1352 OUString const & rPropName, OUString const & rAttrName,
1353 Reference< xml::input::XAttributes > const & xAttributes )
1355 OUString aImageScaleMode(
1356 xAttributes->getValueByUidName(
1357 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1358 if (!aImageScaleMode.isEmpty())
1360 sal_Int16 nImageScaleMode;
1362 if (aImageScaleMode == "none")
1364 nImageScaleMode = awt::ImageScaleMode::NONE;
1366 else if (aImageScaleMode == "isotropic")
1368 nImageScaleMode = awt::ImageScaleMode::ISOTROPIC;
1370 else if (aImageScaleMode == "anisotropic")
1372 nImageScaleMode = awt::ImageScaleMode::ANISOTROPIC;
1374 else
1376 throw xml::sax::SAXException( u"invalid scale image mode value!"_ustr,
1377 Reference< XInterface >(), Any() );
1380 _xControlModel->setPropertyValue( rPropName, Any( nImageScaleMode ) );
1381 return true;
1383 return false;
1386 StringTriple const s_aEventTranslations[] =
1388 // from xmloff/source/forms/formevents.cxx
1389 // 28.09.2001 tbe added on-adjustmentvaluechange
1390 { "com.sun.star.form.XApproveActionListener", "approveAction", "on-approveaction" },
1391 { "com.sun.star.awt.XActionListener", "actionPerformed", "on-performaction" },
1392 { "com.sun.star.form.XChangeListener", "changed", "on-change" },
1393 { "com.sun.star.awt.XTextListener", "textChanged", "on-textchange" },
1394 { "com.sun.star.awt.XItemListener", "itemStateChanged", "on-itemstatechange" },
1395 { "com.sun.star.awt.XFocusListener", "focusGained", "on-focus" },
1396 { "com.sun.star.awt.XFocusListener", "focusLost", "on-blur" },
1397 { "com.sun.star.awt.XKeyListener", "keyPressed", "on-keydown" },
1398 { "com.sun.star.awt.XKeyListener", "keyReleased", "on-keyup" },
1399 { "com.sun.star.awt.XMouseListener", "mouseEntered", "on-mouseover" },
1400 { "com.sun.star.awt.XMouseMotionListener", "mouseDragged", "on-mousedrag" },
1401 { "com.sun.star.awt.XMouseMotionListener", "mouseMoved", "on-mousemove" },
1402 { "com.sun.star.awt.XMouseListener", "mousePressed", "on-mousedown" },
1403 { "com.sun.star.awt.XMouseListener", "mouseReleased", "on-mouseup" },
1404 { "com.sun.star.awt.XMouseListener", "mouseExited", "on-mouseout" },
1405 { "com.sun.star.form.XResetListener", "approveReset", "on-approvereset" },
1406 { "com.sun.star.form.XResetListener", "resetted", "on-reset" },
1407 { "com.sun.star.form.XSubmitListener", "approveSubmit", "on-submit" },
1408 { "com.sun.star.form.XUpdateListener", "approveUpdate", "on-approveupdate" },
1409 { "com.sun.star.form.XUpdateListener", "updated", "on-update" },
1410 { "com.sun.star.form.XLoadListener", "loaded", "on-load" },
1411 { "com.sun.star.form.XLoadListener", "reloading", "on-startreload" },
1412 { "com.sun.star.form.XLoadListener", "reloaded", "on-reload" },
1413 { "com.sun.star.form.XLoadListener", "unloading", "on-startunload" },
1414 { "com.sun.star.form.XLoadListener", "unloaded", "on-unload" },
1415 { "com.sun.star.form.XConfirmDeleteListener", "confirmDelete", "on-confirmdelete" },
1416 { "com.sun.star.sdb.XRowSetApproveListener", "approveRowChange", "on-approverowchange" },
1417 { "com.sun.star.sdbc.XRowSetListener", "rowChanged", "on-rowchange" },
1418 { "com.sun.star.sdb.XRowSetApproveListener", "approveCursorMove", "on-approvecursormove" },
1419 { "com.sun.star.sdbc.XRowSetListener", "cursorMoved", "on-cursormove" },
1420 { "com.sun.star.form.XDatabaseParameterListener", "approveParameter", "on-supplyparameter" },
1421 { "com.sun.star.sdb.XSQLErrorListener", "errorOccured", "on-error" },
1422 { "com.sun.star.awt.XAdjustmentListener", "adjustmentValueChanged", "on-adjustmentvaluechange" },
1423 { nullptr, nullptr, nullptr }
1426 StringTriple const * const g_pEventTranslations = s_aEventTranslations;
1428 void ImportContext::importEvents(
1429 std::vector< Reference< xml::input::XElement > > const & rEvents )
1431 Reference< script::XScriptEventsSupplier > xSupplier(
1432 _xControlModel, UNO_QUERY );
1433 if (!xSupplier.is())
1434 return;
1436 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1437 if (!xEvents.is())
1438 return;
1440 for (const auto & rEvent : rEvents)
1442 script::ScriptEventDescriptor descr;
1444 EventElement * pEventElement = static_cast< EventElement * >( rEvent.get() );
1445 sal_Int32 nUid = pEventElement->getUid();
1446 OUString aLocalName( pEventElement->getLocalName() );
1447 Reference< xml::input::XAttributes > xAttributes( pEventElement->getAttributes() );
1449 // nowadays script events
1450 if (_pImport->XMLNS_SCRIPT_UID == nUid)
1452 if (!getStringAttr( &descr.ScriptType, u"language"_ustr , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1453 !getStringAttr( &descr.ScriptCode, u"macro-name"_ustr, xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1455 throw xml::sax::SAXException( u"missing language or macro-name attribute(s) of event!"_ustr, Reference< XInterface >(), Any() );
1457 if ( descr.ScriptType == "StarBasic" )
1459 OUString aLocation;
1460 if (getStringAttr( &aLocation, u"location"_ustr, xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1462 // prepend location
1463 descr.ScriptCode = aLocation + ":" + descr.ScriptCode;
1466 else if ( descr.ScriptType == "Script" )
1468 // Check if there is a protocol, if not assume
1469 // this is an early scripting framework url ( without
1470 // the protocol ) and fix it up!!
1471 if ( descr.ScriptCode.indexOf( ':' ) == -1 )
1473 descr.ScriptCode = "vnd.sun.start.script:" + descr.ScriptCode;
1477 // script:event element
1478 if ( aLocalName == "event" )
1480 OUString aEventName;
1481 if (! getStringAttr( &aEventName, u"event-name"_ustr, xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1483 throw xml::sax::SAXException( u"missing event-name attribute!"_ustr, Reference< XInterface >(), Any() );
1486 // lookup in table
1487 OString str( OUStringToOString( aEventName, RTL_TEXTENCODING_ASCII_US ) );
1488 StringTriple const * p = g_pEventTranslations;
1489 while (p->first)
1491 if (0 == ::rtl_str_compare( p->third, str.getStr() ))
1493 descr.ListenerType = OUString(
1494 p->first, ::rtl_str_getLength( p->first ),
1495 RTL_TEXTENCODING_ASCII_US );
1496 descr.EventMethod = OUString(
1497 p->second, ::rtl_str_getLength( p->second ),
1498 RTL_TEXTENCODING_ASCII_US );
1499 break;
1501 ++p;
1504 if (! p->first)
1506 throw xml::sax::SAXException( u"no matching event-name found!"_ustr, Reference< XInterface >(), Any() );
1509 else // script:listener-event element
1511 SAL_WARN_IF( aLocalName != "listener-event", "xmlscript.xmldlg", "aLocalName != listener-event" );
1513 if (!getStringAttr( &descr.ListenerType, u"listener-type"_ustr , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1514 !getStringAttr( &descr.EventMethod , u"listener-method"_ustr, xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1516 throw xml::sax::SAXException(u"missing listener-type or listener-method attribute(s)!"_ustr, Reference< XInterface >(), Any() );
1518 // optional listener param
1519 getStringAttr( &descr.AddListenerParam, u"listener-param"_ustr, xAttributes, _pImport->XMLNS_SCRIPT_UID );
1522 else // deprecated dlg:event element
1524 SAL_WARN_IF( _pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != "event", "xmlscript.xmldlg", "_pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != \"event\"" );
1526 if (!getStringAttr( &descr.ListenerType, u"listener-type"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID ) ||
1527 !getStringAttr( &descr.EventMethod, u"event-method"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1529 throw xml::sax::SAXException(u"missing listener-type or event-method attribute(s)!"_ustr, Reference< XInterface >(), Any() );
1532 getStringAttr( &descr.ScriptType, u"script-type"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID );
1533 getStringAttr( &descr.ScriptCode, u"script-code"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID );
1534 getStringAttr( &descr.AddListenerParam, u"param"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID );
1537 xEvents->insertByName( descr.ListenerType + "::" + descr.EventMethod, Any( descr ) );
1540 void ImportContext::importScollableSettings(
1541 Reference< xml::input::XAttributes > const & _xAttributes )
1543 importLongProperty( u"ScrollHeight"_ustr,
1544 u"scrollheight"_ustr,
1545 _xAttributes );
1546 importLongProperty( u"ScrollWidth"_ustr,
1547 u"scrollwidth"_ustr,
1548 _xAttributes );
1549 importLongProperty( u"ScrollTop"_ustr,
1550 u"scrolltop"_ustr,
1551 _xAttributes );
1552 importLongProperty( u"ScrollLeft"_ustr,
1553 u"scrollleft"_ustr,
1554 _xAttributes );
1555 importBooleanProperty( u"HScroll"_ustr,
1556 u"hscroll"_ustr,
1557 _xAttributes );
1558 importBooleanProperty( u"VScroll"_ustr,
1559 u"vscroll"_ustr,
1560 _xAttributes );
1563 void ImportContext::importDefaults(
1564 sal_Int32 nBaseX, sal_Int32 nBaseY,
1565 Reference< xml::input::XAttributes > const & xAttributes,
1566 bool supportPrintable )
1568 _xControlModel->setPropertyValue( u"Name"_ustr, Any( _aId ) );
1570 importShortProperty( u"TabIndex"_ustr, u"tab-index"_ustr, xAttributes );
1572 sal_Bool bDisable = false;
1573 if (getBoolAttr( &bDisable,u"disabled"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID ) && bDisable)
1575 _xControlModel->setPropertyValue( u"Enabled"_ustr, Any( false ) );
1578 sal_Bool bVisible = true;
1579 if (getBoolAttr( &bVisible, u"visible"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID ) && !bVisible)
1583 _xControlModel->setPropertyValue( u"EnableVisible"_ustr, Any( false ) );
1585 catch( Exception& )
1587 DBG_UNHANDLED_EXCEPTION("xmlscript.xmldlg");
1591 if (!importLongProperty( nBaseX, u"PositionX"_ustr, u"left"_ustr, xAttributes ) ||
1592 !importLongProperty( nBaseY, u"PositionY"_ustr, u"top"_ustr, xAttributes ) ||
1593 !importLongProperty( u"Width"_ustr, u"width"_ustr, xAttributes ) ||
1594 !importLongProperty( u"Height"_ustr, u"height"_ustr, xAttributes ))
1596 throw xml::sax::SAXException( u"missing pos size attribute(s)!"_ustr, Reference< XInterface >(), Any() );
1599 if (supportPrintable)
1601 importBooleanProperty(u"Printable"_ustr, u"printable"_ustr, xAttributes );
1604 sal_Int32 nLong;
1605 if (! getLongAttr( &nLong, u"page"_ustr, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1607 nLong = 0;
1609 _xControlModel->setPropertyValue( u"Step"_ustr, Any( nLong ) );
1611 importStringProperty(u"Tag"_ustr, u"tag"_ustr, xAttributes );
1612 importStringProperty( u"HelpText"_ustr, u"help-text"_ustr, xAttributes );
1613 importStringProperty( u"HelpURL"_ustr, u"help-url"_ustr, xAttributes );
1616 Reference< xml::input::XElement > ElementBase::getParent()
1618 return static_cast< xml::input::XElement * >( m_pParent );
1621 OUString ElementBase::getLocalName()
1623 return _aLocalName;
1626 sal_Int32 ElementBase::getUid()
1628 return _nUid;
1631 Reference< xml::input::XAttributes > ElementBase::getAttributes()
1633 return _xAttributes;
1636 void ElementBase::ignorableWhitespace(
1637 OUString const & /*rWhitespaces*/ )
1639 // not used
1642 void ElementBase::characters( OUString const & /*rChars*/ )
1644 // not used, all characters ignored
1647 void ElementBase::endElement()
1651 void ElementBase::processingInstruction(
1652 OUString const & /*Target*/, OUString const & /*Data*/ )
1656 Reference< xml::input::XElement > ElementBase::startChildElement(
1657 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
1658 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
1660 throw xml::sax::SAXException( u"unexpected element!"_ustr, Reference< XInterface >(), Any() );
1663 ElementBase::ElementBase(
1664 sal_Int32 nUid, OUString aLocalName,
1665 Reference< xml::input::XAttributes > const & xAttributes,
1666 ElementBase * pParent, DialogImport * pImport )
1667 : m_pImport( pImport )
1668 , m_pParent( pParent )
1669 , _nUid( nUid )
1670 , _aLocalName(std::move(aLocalName ))
1671 , _xAttributes( xAttributes )
1675 ElementBase::~ElementBase()
1677 SAL_INFO("xmlscript.xmldlg", "ElementBase::~ElementBase(): " << _aLocalName );
1680 // XRoot
1682 void DialogImport::startDocument(
1683 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
1685 XMLNS_DIALOGS_UID = xNamespaceMapping->getUidByUri( XMLNS_DIALOGS_URI );
1686 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
1689 void DialogImport::endDocument()
1691 // ignored
1694 void DialogImport::processingInstruction(
1695 OUString const & /*rTarget*/, OUString const & /*rData*/ )
1697 // ignored for now: xxx todo
1700 void DialogImport::setDocumentLocator(
1701 Reference< xml::sax::XLocator > const & /*xLocator*/ )
1703 // ignored for now: xxx todo
1706 Reference< xml::input::XElement > DialogImport::startRootElement(
1707 sal_Int32 nUid, OUString const & rLocalName,
1708 Reference< xml::input::XAttributes > const & xAttributes )
1710 if (XMLNS_DIALOGS_UID != nUid)
1712 throw xml::sax::SAXException( u"illegal namespace!"_ustr, Reference< XInterface >(), Any() );
1714 // window
1715 else if ( rLocalName == "window" )
1717 return new WindowElement( rLocalName, xAttributes, this );
1719 else
1721 throw xml::sax::SAXException( "illegal root element (expected window) given: " + rLocalName, Reference< XInterface >(), Any() );
1725 DialogImport::~DialogImport()
1727 SAL_INFO("xmlscript.xmldlg", "DialogImport::~DialogImport()." );
1730 Reference< util::XNumberFormatsSupplier > const & DialogImport::getNumberFormatsSupplier()
1732 if (! _xSupplier.is())
1734 Reference< util::XNumberFormatsSupplier > xSupplier = util::NumberFormatsSupplier::createWithDefaultLocale( getComponentContext() );
1736 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1737 if (! _xSupplier.is())
1739 _xSupplier = std::move(xSupplier);
1742 return _xSupplier;
1745 void DialogImport::addStyle(
1746 OUString const & rStyleId,
1747 Reference< xml::input::XElement > const & xStyle )
1749 (*_pStyleNames).push_back( rStyleId );
1750 (*_pStyles).push_back( xStyle );
1753 Reference< xml::input::XElement > DialogImport::getStyle(
1754 std::u16string_view rStyleId ) const
1756 for ( size_t nPos = 0; nPos < (*_pStyleNames).size(); ++nPos )
1758 if ( (*_pStyleNames)[ nPos ] == rStyleId)
1760 return (*_pStyles)[ nPos ];
1763 return nullptr;
1766 Reference< xml::sax::XDocumentHandler > importDialogModel(
1767 Reference< container::XNameContainer > const & xDialogModel,
1768 Reference< XComponentContext > const & xContext,
1769 Reference< XModel > const & xDocument )
1771 // single set of styles and stylenames apply to all containers
1772 auto xStyleNames = std::make_shared<std::vector< OUString >>();
1773 auto xStyles = std::make_shared<std::vector< css::uno::Reference< css::xml::input::XElement > >>();
1774 return ::xmlscript::createDocumentHandler(
1775 new DialogImport(xContext, xDialogModel, std::move(xStyleNames), std::move(xStyles), xDocument));
1779 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */