vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_import.cxx
blobe3cf908f0186d32681b57955fdde793dac3c23b3
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/style/VerticalAlignment.hpp>
38 #include <com/sun/star/util/Date.hpp>
39 #include <com/sun/star/util/Time.hpp>
40 #include <sal/log.hxx>
41 #include <tools/date.hxx>
42 #include <tools/diagnose_ex.h>
43 #include <tools/time.hxx>
44 #include <osl/diagnose.h>
46 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
47 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
49 #include <com/sun/star/view/SelectionType.hpp>
50 #include <com/sun/star/form/binding/XBindableValue.hpp>
51 #include <com/sun/star/form/binding/XValueBinding.hpp>
52 #include <com/sun/star/form/binding/XListEntrySink.hpp>
53 #include <com/sun/star/beans/NamedValue.hpp>
54 #include <com/sun/star/table/CellAddress.hpp>
55 #include <com/sun/star/table/CellRangeAddress.hpp>
56 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
57 #include <com/sun/star/document/XStorageBasedDocument.hpp>
58 #include <com/sun/star/graphic/XGraphic.hpp>
59 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::frame;
65 namespace xmlscript
68 void EventElement::endElement()
70 static_cast< ControlElement * >( m_xParent.get() )->_events.emplace_back(this );
73 ControlElement::ControlElement(
74 OUString const & rLocalName,
75 Reference< xml::input::XAttributes > const & xAttributes,
76 ElementBase * pParent, DialogImport * pImport )
77 : ElementBase(
78 pImport->XMLNS_DIALOGS_UID, rLocalName, xAttributes, pParent, pImport )
80 if (m_xParent.is())
82 // inherit position
83 _nBasePosX = static_cast< ControlElement * >( m_xParent.get() )->_nBasePosX;
84 _nBasePosY = static_cast< ControlElement * >( m_xParent.get() )->_nBasePosY;
86 else
88 _nBasePosX = 0;
89 _nBasePosY = 0;
93 Reference< xml::input::XElement > ControlElement::getStyle(
94 Reference< xml::input::XAttributes > const & xAttributes )
96 OUString aStyleId( xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID,"style-id" ) );
97 if (!aStyleId.isEmpty())
99 return m_xImport->getStyle( aStyleId );
101 return Reference< xml::input::XElement >();
104 OUString ControlElement::getControlId(
105 Reference< xml::input::XAttributes > const & xAttributes )
107 OUString aId( xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID, "id" ) );
108 if (aId.isEmpty())
110 throw xml::sax::SAXException( "missing id attribute!", Reference< XInterface >(), Any() );
112 return aId;
115 OUString ControlElement::getControlModelName(
116 OUString const& rDefaultModel,
117 Reference< xml::input::XAttributes > const & xAttributes )
119 OUString aModel = xAttributes->getValueByUidName( m_xImport->XMLNS_DIALOGS_UID, "control-implementation");
120 if (aModel.isEmpty())
121 aModel = rDefaultModel;
122 return aModel;
125 void StyleElement::importTextColorStyle(
126 Reference< beans::XPropertySet > const & xProps )
128 if ((_inited & 0x2) != 0)
130 if ((_hasValue & 0x2) != 0)
132 xProps->setPropertyValue("TextColor", makeAny( _textColor ) );
134 return;
136 _inited |= 0x2;
138 if (getLongAttr( &_textColor, "text-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
140 _hasValue |= 0x2;
141 xProps->setPropertyValue( "TextColor", makeAny( _textColor ) );
142 return;
146 void StyleElement::importTextLineColorStyle(
147 Reference< beans::XPropertySet > const & xProps )
149 if ((_inited & 0x20) != 0)
151 if ((_hasValue & 0x20) != 0)
153 xProps->setPropertyValue( "TextLineColor", makeAny( _textLineColor ) );
155 return;
157 _inited |= 0x20;
159 if (getLongAttr( &_textLineColor, "textline-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
161 _hasValue |= 0x20;
162 xProps->setPropertyValue( "TextLineColor", makeAny( _textLineColor ) );
166 void StyleElement::importFillColorStyle(
167 Reference< beans::XPropertySet > const & xProps )
169 if ((_inited & 0x10) != 0)
171 if ((_hasValue & 0x10) != 0)
173 xProps->setPropertyValue( "FillColor", makeAny( _fillColor ) );
175 return;
177 _inited |= 0x10;
179 if (getLongAttr( &_fillColor, "fill-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
181 _hasValue |= 0x10;
182 xProps->setPropertyValue( "FillColor", makeAny( _fillColor ) );
186 void StyleElement::importBackgroundColorStyle(
187 Reference< beans::XPropertySet > const & xProps )
189 if ((_inited & 0x1) != 0)
191 if ((_hasValue & 0x1) != 0)
193 xProps->setPropertyValue( "BackgroundColor", makeAny( _backgroundColor ) );
195 return;
197 _inited |= 0x1;
199 if (getLongAttr( &_backgroundColor, "background-color", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
201 _hasValue |= 0x1;
202 xProps->setPropertyValue( "BackgroundColor", makeAny( _backgroundColor ) );
206 void StyleElement::importBorderStyle(
207 Reference< beans::XPropertySet > const & xProps )
209 if ((_inited & 0x4) != 0)
211 if ((_hasValue & 0x4) != 0)
213 xProps->setPropertyValue( "Border", makeAny( _border == BORDER_SIMPLE_COLOR ? BORDER_SIMPLE : _border ) );
214 if (_border == BORDER_SIMPLE_COLOR)
215 xProps->setPropertyValue( "BorderColor", makeAny(_borderColor) );
217 return;
219 _inited |= 0x4;
221 OUString aValue;
222 if (getStringAttr(&aValue, "border", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
224 if ( aValue == "none" )
225 _border = BORDER_NONE;
226 else if ( aValue == "3d" )
227 _border = BORDER_3D;
228 else if ( aValue == "simple" )
229 _border = BORDER_SIMPLE;
230 else {
231 _border = BORDER_SIMPLE_COLOR;
232 _borderColor = toInt32(aValue);
235 _hasValue |= 0x4;
236 importBorderStyle(xProps); // write values
240 void StyleElement::importVisualEffectStyle(
241 Reference<beans::XPropertySet> const & xProps )
243 if ((_inited & 0x40) != 0)
245 if ((_hasValue & 0x40) != 0)
247 xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) );
249 return;
251 _inited |= 0x40;
253 OUString aValue;
254 if (getStringAttr( &aValue, "look", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
256 if ( aValue == "none" )
258 _visualEffect = awt::VisualEffect::NONE;
260 else if ( aValue == "3d" )
262 _visualEffect = awt::VisualEffect::LOOK3D;
264 else if ( aValue == "simple" )
266 _visualEffect = awt::VisualEffect::FLAT;
268 else
269 OSL_ASSERT( false );
271 _hasValue |= 0x40;
272 xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) );
276 void StyleElement::setFontProperties(
277 Reference< beans::XPropertySet > const & xProps ) const
279 xProps->setPropertyValue("FontDescriptor", makeAny( _descr ) );
280 xProps->setPropertyValue("FontEmphasisMark", makeAny( _fontEmphasisMark ) );
281 xProps->setPropertyValue("FontRelief", makeAny( _fontRelief ) );
284 void StyleElement::importFontStyle(
285 Reference< beans::XPropertySet > const & xProps )
287 if ((_inited & 0x8) != 0)
289 if ((_hasValue & 0x8) != 0)
291 setFontProperties( xProps );
293 return;
295 _inited |= 0x8;
297 OUString aValue;
298 bool bFontImport;
300 // dialog:font-name CDATA #IMPLIED
301 bFontImport = getStringAttr( &_descr.Name, "font-name", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
303 // dialog:font-height %numeric; #IMPLIED
304 if (getStringAttr( &aValue, "font-height", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
306 _descr.Height = static_cast<sal_Int16>(toInt32( aValue ));
307 bFontImport = true;
309 // dialog:font-width %numeric; #IMPLIED
310 if (getStringAttr(&aValue, "font-width", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
312 _descr.Width = static_cast<sal_Int16>(toInt32( aValue ));
313 bFontImport = true;
315 // dialog:font-stylename CDATA #IMPLIED
316 bFontImport |= getStringAttr( &_descr.StyleName, "font-stylename", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
318 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
319 if (getStringAttr(&aValue, "font-family", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
321 if ( aValue == "decorative" )
323 _descr.Family = awt::FontFamily::DECORATIVE;
325 else if ( aValue == "modern" )
327 _descr.Family = awt::FontFamily::MODERN;
329 else if ( aValue == "roman" )
331 _descr.Family = awt::FontFamily::ROMAN;
333 else if ( aValue == "script" )
335 _descr.Family = awt::FontFamily::SCRIPT;
337 else if ( aValue == "swiss" )
339 _descr.Family = awt::FontFamily::SWISS;
341 else if ( aValue == "system" )
343 _descr.Family = awt::FontFamily::SYSTEM;
345 else
347 throw xml::sax::SAXException("invalid font-family style!", Reference< XInterface >(), Any() );
349 bFontImport = true;
352 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
353 if (getStringAttr(&aValue, "font-charset", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
355 if ( aValue == "ansi" )
357 _descr.CharSet = awt::CharSet::ANSI;
359 else if ( aValue == "mac" )
361 _descr.CharSet = awt::CharSet::MAC;
363 else if ( aValue == "ibmpc_437" )
365 _descr.CharSet = awt::CharSet::IBMPC_437;
367 else if ( aValue == "ibmpc_850" )
369 _descr.CharSet = awt::CharSet::IBMPC_850;
371 else if ( aValue == "ibmpc_860" )
373 _descr.CharSet = awt::CharSet::IBMPC_860;
375 else if ( aValue == "ibmpc_861" )
377 _descr.CharSet = awt::CharSet::IBMPC_861;
379 else if ( aValue == "ibmpc_863" )
381 _descr.CharSet = awt::CharSet::IBMPC_863;
383 else if ( aValue == "ibmpc_865" )
385 _descr.CharSet = awt::CharSet::IBMPC_865;
387 else if ( aValue == "system" )
389 _descr.CharSet = awt::CharSet::SYSTEM;
391 else if ( aValue == "symbol" )
393 _descr.CharSet = awt::CharSet::SYMBOL;
395 else
397 throw xml::sax::SAXException("invalid font-charset style!", Reference< XInterface >(), Any() );
399 bFontImport = true;
402 // dialog:font-pitch "(fixed|variable)" #IMPLIED
403 if (getStringAttr( &aValue, "font-pitch", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
405 if ( aValue == "fixed" )
407 _descr.Pitch = awt::FontPitch::FIXED;
409 else if ( aValue == "variable" )
411 _descr.Pitch = awt::FontPitch::VARIABLE;
413 else
415 throw xml::sax::SAXException("invalid font-pitch style!", Reference< XInterface >(), Any() );
417 bFontImport = true;
420 // dialog:font-charwidth CDATA #IMPLIED
421 if (getStringAttr( &aValue, "font-charwidth", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
423 _descr.CharacterWidth = aValue.toFloat();
424 bFontImport = true;
426 // dialog:font-weight CDATA #IMPLIED
427 if (getStringAttr( &aValue, "font-weight", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
429 _descr.Weight = aValue.toFloat();
430 bFontImport = true;
433 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
434 if (getStringAttr( &aValue, "font-slant", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
436 if ( aValue == "oblique" )
438 _descr.Slant = awt::FontSlant_OBLIQUE;
440 else if ( aValue == "italic" )
442 _descr.Slant = awt::FontSlant_ITALIC;
444 else if ( aValue == "reverse_oblique" )
446 _descr.Slant = awt::FontSlant_REVERSE_OBLIQUE;
448 else if ( aValue == "reverse_italic" )
450 _descr.Slant = awt::FontSlant_REVERSE_ITALIC;
452 else
454 throw xml::sax::SAXException("invalid font-slant style!", Reference< XInterface >(), Any() );
456 bFontImport = true;
459 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
460 if (getStringAttr( &aValue, "font-underline", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
462 if ( aValue == "single" )
464 _descr.Underline = awt::FontUnderline::SINGLE;
466 else if ( aValue == "double" )
468 _descr.Underline = awt::FontUnderline::DOUBLE;
470 else if ( aValue == "dotted" )
472 _descr.Underline = awt::FontUnderline::DOTTED;
474 else if ( aValue == "dash" )
476 _descr.Underline = awt::FontUnderline::DASH;
478 else if ( aValue == "longdash" )
480 _descr.Underline = awt::FontUnderline::LONGDASH;
482 else if ( aValue == "dashdot" )
484 _descr.Underline = awt::FontUnderline::DASHDOT;
486 else if ( aValue == "dashdotdot" )
488 _descr.Underline = awt::FontUnderline::DASHDOTDOT;
490 else if ( aValue == "smallwave" )
492 _descr.Underline = awt::FontUnderline::SMALLWAVE;
494 else if ( aValue == "wave" )
496 _descr.Underline = awt::FontUnderline::WAVE;
498 else if ( aValue == "doublewave" )
500 _descr.Underline = awt::FontUnderline::DOUBLEWAVE;
502 else if ( aValue == "bold" )
504 _descr.Underline = awt::FontUnderline::BOLD;
506 else if ( aValue == "bolddotted" )
508 _descr.Underline = awt::FontUnderline::BOLDDOTTED;
510 else if ( aValue == "bolddash" )
512 _descr.Underline = awt::FontUnderline::BOLDDASH;
514 else if ( aValue == "boldlongdash" )
516 _descr.Underline = awt::FontUnderline::BOLDLONGDASH;
518 else if ( aValue == "bolddashdot" )
520 _descr.Underline = awt::FontUnderline::BOLDDASHDOT;
522 else if ( aValue == "bolddashdotdot" )
524 _descr.Underline = awt::FontUnderline::BOLDDASHDOTDOT;
526 else if ( aValue == "boldwave" )
528 _descr.Underline = awt::FontUnderline::BOLDWAVE;
530 else
532 throw xml::sax::SAXException("invalid font-underline style!", Reference< XInterface >(), Any() );
534 bFontImport = true;
537 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
538 if (getStringAttr( &aValue, "font-strikeout", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
540 if ( aValue == "single" )
542 _descr.Strikeout = awt::FontStrikeout::SINGLE;
544 else if ( aValue == "double" )
546 _descr.Strikeout = awt::FontStrikeout::DOUBLE;
548 else if ( aValue == "bold" )
550 _descr.Strikeout = awt::FontStrikeout::BOLD;
552 else if ( aValue == "slash" )
554 _descr.Strikeout = awt::FontStrikeout::SLASH;
556 else if ( aValue == "x" )
558 _descr.Strikeout = awt::FontStrikeout::X;
560 else
562 throw xml::sax::SAXException( "invalid font-strikeout style!" , Reference< XInterface >(), Any() );
564 bFontImport = true;
567 // dialog:font-orientation CDATA #IMPLIED
568 if (getStringAttr( &aValue, "font-orientation", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
570 _descr.Orientation = aValue.toFloat();
571 bFontImport = true;
573 // dialog:font-kerning %boolean; #IMPLIED
574 bFontImport |= getBoolAttr( &_descr.Kerning, "font-kerning", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
575 // dialog:font-wordlinemode %boolean; #IMPLIED
576 bFontImport |= getBoolAttr( &_descr.WordLineMode,"font-wordlinemode", _xAttributes, m_xImport->XMLNS_DIALOGS_UID );
578 // dialog:font-type "(raster|device|scalable)" #IMPLIED
579 if (getStringAttr( &aValue, "font-type", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
581 if ( aValue == "raster" )
583 _descr.Type = awt::FontType::RASTER;
585 else if ( aValue == "device" )
587 _descr.Type = awt::FontType::DEVICE;
589 else if ( aValue == "scalable" )
591 _descr.Type = awt::FontType::SCALABLE;
593 else
595 throw xml::sax::SAXException( "invalid font-type style!", Reference< XInterface >(), Any() );
597 bFontImport = true;
600 // additional properties which are not part of the FontDescriptor struct
601 // dialog:font-relief (none|embossed|engraved) #IMPLIED
602 if (getStringAttr( &aValue, "font-relief", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
604 if ( aValue == "none" )
606 _fontRelief = awt::FontRelief::NONE;
608 else if ( aValue == "embossed" )
610 _fontRelief = awt::FontRelief::EMBOSSED;
612 else if ( aValue == "engraved" )
614 _fontRelief = awt::FontRelief::ENGRAVED;
616 else
618 throw xml::sax::SAXException("invalid font-relief style!", Reference< XInterface >(), Any() );
620 bFontImport = true;
622 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
623 if (getStringAttr(&aValue, "font-emphasismark", _xAttributes, m_xImport->XMLNS_DIALOGS_UID ))
625 if ( aValue == "none" )
627 _fontEmphasisMark = awt::FontEmphasisMark::NONE;
629 else if ( aValue == "dot" )
631 _fontEmphasisMark = awt::FontEmphasisMark::DOT;
633 else if ( aValue == "circle" )
635 _fontEmphasisMark = awt::FontEmphasisMark::CIRCLE;
637 else if ( aValue == "disc" )
639 _fontEmphasisMark = awt::FontEmphasisMark::DISC;
641 else if ( aValue == "accent" )
643 _fontEmphasisMark = awt::FontEmphasisMark::ACCENT;
645 else if ( aValue == "above" )
647 _fontEmphasisMark = awt::FontEmphasisMark::ABOVE;
649 else if ( aValue == "below" )
651 _fontEmphasisMark = awt::FontEmphasisMark::BELOW;
653 else
655 throw xml::sax::SAXException( "invalid font-emphasismark style!", Reference< XInterface >(), Any() );
657 bFontImport = true;
660 if (bFontImport)
662 _hasValue |= 0x8;
663 setFontProperties( xProps );
667 bool ImportContext::importStringProperty(
668 OUString const & rPropName, OUString const & rAttrName,
669 Reference< xml::input::XAttributes > const & xAttributes )
671 OUString aValue(
672 xAttributes->getValueByUidName(
673 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
674 if (!aValue.isEmpty())
676 _xControlModel->setPropertyValue( rPropName, makeAny( aValue ) );
677 return true;
679 return false;
682 bool ImportContext::importDoubleProperty(
683 OUString const & rPropName, OUString const & rAttrName,
684 Reference< xml::input::XAttributes > const & xAttributes )
686 OUString aValue(
687 xAttributes->getValueByUidName(
688 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
689 if (!aValue.isEmpty())
691 _xControlModel->setPropertyValue( rPropName, makeAny( aValue.toDouble() ) );
692 return true;
694 return false;
697 bool ImportContext::importBooleanProperty(
698 OUString const & rPropName, OUString const & rAttrName,
699 Reference< xml::input::XAttributes > const & xAttributes )
701 sal_Bool bBool;
702 if (getBoolAttr(
703 &bBool, rAttrName, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
705 _xControlModel->setPropertyValue( rPropName, makeAny( bBool ) );
706 return true;
708 return false;
711 bool ImportContext::importLongProperty(
712 OUString const & rPropName, OUString const & rAttrName,
713 Reference< xml::input::XAttributes > const & xAttributes )
715 OUString aValue(
716 xAttributes->getValueByUidName(
717 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
718 if (!aValue.isEmpty())
720 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
721 return true;
723 return false;
726 bool ImportContext::importLongProperty(
727 sal_Int32 nOffset,
728 OUString const & rPropName, OUString const & rAttrName,
729 Reference< xml::input::XAttributes > const & xAttributes )
731 OUString aValue(
732 xAttributes->getValueByUidName(
733 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
734 if (!aValue.isEmpty())
736 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) + nOffset ) );
737 return true;
739 return false;
742 bool ImportContext::importHexLongProperty(
743 OUString const & rPropName, OUString const & rAttrName,
744 Reference< xml::input::XAttributes > const & xAttributes )
746 OUString aValue(
747 xAttributes->getValueByUidName(
748 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
749 if (!aValue.isEmpty())
751 _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
752 return true;
754 return false;
757 bool ImportContext::importShortProperty(
758 OUString const & rPropName, OUString const & rAttrName,
759 Reference< xml::input::XAttributes > const & xAttributes )
761 OUString aValue(
762 xAttributes->getValueByUidName(
763 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
764 if (!aValue.isEmpty())
766 _xControlModel->setPropertyValue( rPropName, makeAny( static_cast<sal_Int16>(toInt32( aValue )) ) );
767 return true;
769 return false;
772 bool ImportContext::importAlignProperty(
773 OUString const & rPropName, OUString const & rAttrName,
774 Reference< xml::input::XAttributes > const & xAttributes )
776 OUString aAlign(
777 xAttributes->getValueByUidName(
778 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
779 if (!aAlign.isEmpty())
781 sal_Int16 nAlign;
782 if ( aAlign == "left" )
784 nAlign = 0;
786 else if ( aAlign == "center" )
788 nAlign = 1;
790 else if ( aAlign == "right" )
792 nAlign = 2;
794 else if ( aAlign == "none" )
796 nAlign = 0; // default
798 else
800 throw xml::sax::SAXException("invalid align value!", Reference< XInterface >(), Any() );
803 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
804 return true;
806 return false;
809 bool ImportContext::importVerticalAlignProperty(
810 OUString const & rPropName, OUString const & rAttrName,
811 Reference< xml::input::XAttributes > const & xAttributes )
813 OUString aAlign(
814 xAttributes->getValueByUidName(
815 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
816 if (!aAlign.isEmpty())
818 style::VerticalAlignment eAlign;
820 if ( aAlign == "top" )
822 eAlign = style::VerticalAlignment_TOP;
824 else if ( aAlign == "center" )
826 eAlign = style::VerticalAlignment_MIDDLE;
828 else if ( aAlign == "bottom" )
830 eAlign = style::VerticalAlignment_BOTTOM;
832 else
834 throw xml::sax::SAXException( "invalid vertical align value!", Reference< XInterface >(), Any() );
837 _xControlModel->setPropertyValue( rPropName, makeAny( eAlign ) );
838 return true;
840 return false;
843 bool ImportContext::importGraphicOrImageProperty(
844 OUString const & rAttrName,
845 Reference< xml::input::XAttributes > const & xAttributes )
847 OUString sURL = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rAttrName );
848 if ( !sURL.isEmpty() )
850 Reference< document::XStorageBasedDocument > xDocStorage( _pImport->getDocOwner(), UNO_QUERY );
852 uno::Reference<graphic::XGraphic> xGraphic;
854 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
855 if ( xDocStorage.is() )
857 uno::Sequence< Any > aArgs( 1 );
858 aArgs[ 0 ] <<= xDocStorage->getDocumentStorage();
859 xGraphicStorageHandler.set(
860 _pImport->getComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext( "com.sun.star.comp.Svx.GraphicImportHelper" , aArgs, _pImport->getComponentContext() ),
861 UNO_QUERY );
862 if (xGraphicStorageHandler.is())
866 xGraphic = xGraphicStorageHandler->loadGraphic(sURL);
868 catch( const uno::Exception& )
870 return false;
874 if (xGraphic.is())
876 Reference<beans::XPropertySet> xProps = getControlModel();
877 if (xProps.is())
879 xProps->setPropertyValue("Graphic", makeAny(xGraphic));
880 return true;
883 else if (!sURL.isEmpty())
885 // tdf#130793 Above fails if the dialog is not part of a document.
886 // In this case we need to set the ImageURL.
887 Reference<beans::XPropertySet> xProps = getControlModel();
888 if (xProps.is())
890 xProps->setPropertyValue("ImageURL", makeAny(sURL));
891 return true;
895 return false;
898 bool ImportContext::importDataAwareProperty(
899 OUString const & rPropName,
900 Reference<xml::input::XAttributes> const & xAttributes )
902 OUString sLinkedCell;
903 OUString sCellRange;
904 if ( rPropName == "linked-cell" )
905 sLinkedCell = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rPropName );
906 if ( rPropName == "source-cell-range" )
907 sCellRange = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rPropName );
908 bool bRes = false;
909 Reference< lang::XMultiServiceFactory > xFac( _pImport->getDocOwner(), UNO_QUERY );
910 if ( xFac.is() && ( !sLinkedCell.isEmpty() || !sCellRange.isEmpty() ) )
912 // Set up cell link
913 if ( !sLinkedCell.isEmpty() )
915 Reference< form::binding::XBindableValue > xBindable( getControlModel(), uno::UNO_QUERY );
916 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
917 if ( xBindable.is() && xConvertor.is() )
919 table::CellAddress aAddress;
920 xConvertor->setPropertyValue( "PersistentRepresentation" , uno::makeAny( sLinkedCell ) );
921 xConvertor->getPropertyValue( "Address" ) >>= aAddress;
922 beans::NamedValue aArg1;
923 aArg1.Name = "BoundCell";
924 aArg1.Value <<= aAddress;
926 uno::Sequence< uno::Any > aArgs(1);
927 aArgs[ 0 ] <<= aArg1;
929 uno::Reference< form::binding::XValueBinding > xBinding( xFac->createInstanceWithArguments( "com.sun.star.table.CellValueBinding" , aArgs ), uno::UNO_QUERY );
930 xBindable->setValueBinding( xBinding );
931 bRes = true;
934 // Set up CellRange
935 if ( !sCellRange.isEmpty() )
937 Reference< form::binding::XListEntrySink > xListEntrySink( getControlModel(), uno::UNO_QUERY );
938 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
939 if ( xListEntrySink.is() && xConvertor.is() )
941 table::CellRangeAddress aAddress;
942 xConvertor->setPropertyValue( "PersistentRepresentation" , uno::makeAny( sCellRange ) );
943 xConvertor->getPropertyValue( "Address" ) >>= aAddress;
944 beans::NamedValue aArg1;
945 aArg1.Name = "CellRange";
946 aArg1.Value <<= aAddress;
948 uno::Sequence< uno::Any > aArgs(1);
949 aArgs[ 0 ] <<= aArg1;
951 uno::Reference< form::binding::XListEntrySource > xSource( xFac->createInstanceWithArguments( "com.sun.star.table.CellRangeListSource" , aArgs ), uno::UNO_QUERY );
952 xListEntrySink->setListEntrySource( xSource );
953 bRes = true;
957 return bRes;
960 bool ImportContext::importImageAlignProperty(
961 OUString const & rPropName, OUString const & rAttrName,
962 Reference< xml::input::XAttributes > const & xAttributes )
964 OUString aAlign(
965 xAttributes->getValueByUidName(
966 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
967 if (!aAlign.isEmpty())
969 sal_Int16 nAlign;
970 if ( aAlign == "left" )
972 nAlign = 0;
974 else if ( aAlign == "top" )
976 nAlign = 1;
978 else if ( aAlign == "right" )
980 nAlign = 2;
982 else if ( aAlign == "bottom" )
984 nAlign = 3;
986 else
988 throw xml::sax::SAXException( "invalid image align value!", Reference< XInterface >(), Any() );
991 _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
992 return true;
994 return false;
997 bool ImportContext::importImagePositionProperty(
998 OUString const & rPropName, OUString const & rAttrName,
999 Reference< xml::input::XAttributes > const & xAttributes )
1001 OUString aPosition(
1002 xAttributes->getValueByUidName(
1003 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1004 if (!aPosition.isEmpty())
1006 sal_Int16 nPosition;
1007 if ( aPosition == "left-top" )
1009 nPosition = awt::ImagePosition::LeftTop;
1011 else if ( aPosition == "left-center" )
1013 nPosition = awt::ImagePosition::LeftCenter;
1015 else if ( aPosition == "left-bottom" )
1017 nPosition = awt::ImagePosition::LeftBottom;
1019 else if ( aPosition == "right-top" )
1021 nPosition = awt::ImagePosition::RightTop;
1023 else if ( aPosition == "right-center" )
1025 nPosition = awt::ImagePosition::RightCenter;
1027 else if ( aPosition == "right-bottom" )
1029 nPosition = awt::ImagePosition::RightBottom;
1031 else if ( aPosition == "top-left" )
1033 nPosition = awt::ImagePosition::AboveLeft;
1035 else if ( aPosition == "top-center" )
1037 nPosition = awt::ImagePosition::AboveCenter;
1039 else if ( aPosition == "top-right" )
1041 nPosition = awt::ImagePosition::AboveRight;
1043 else if ( aPosition == "bottom-left" )
1045 nPosition = awt::ImagePosition::BelowLeft;
1047 else if ( aPosition == "bottom-center" )
1049 nPosition = awt::ImagePosition::BelowCenter;
1051 else if ( aPosition == "bottom-right" )
1053 nPosition = awt::ImagePosition::BelowRight;
1055 else if ( aPosition == "center" )
1057 nPosition = awt::ImagePosition::Centered;
1059 else
1061 throw xml::sax::SAXException( "invalid image position value!", Reference< XInterface >(), Any() );
1064 _xControlModel->setPropertyValue( rPropName, makeAny( nPosition ) );
1065 return true;
1067 return false;
1070 bool ImportContext::importButtonTypeProperty(
1071 OUString const & rPropName, OUString const & rAttrName,
1072 Reference< xml::input::XAttributes > const & xAttributes )
1074 OUString buttonType(
1075 xAttributes->getValueByUidName(
1076 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1077 if (!buttonType.isEmpty())
1079 awt::PushButtonType nButtonType;
1080 if ( buttonType == "standard" )
1082 nButtonType = awt::PushButtonType_STANDARD;
1084 else if ( buttonType == "ok" )
1086 nButtonType = awt::PushButtonType_OK;
1088 else if ( buttonType == "cancel" )
1090 nButtonType = awt::PushButtonType_CANCEL;
1092 else if ( buttonType == "help" )
1094 nButtonType = awt::PushButtonType_HELP;
1096 else
1098 throw xml::sax::SAXException( "invalid button-type value!", Reference< XInterface >(), Any() );
1101 _xControlModel->setPropertyValue( rPropName, makeAny( static_cast<sal_Int16>(nButtonType) ) );
1102 return true;
1104 return false;
1107 bool ImportContext::importDateFormatProperty(
1108 OUString const & rPropName, OUString const & rAttrName,
1109 Reference< xml::input::XAttributes > const & xAttributes )
1111 OUString aFormat(
1112 xAttributes->getValueByUidName(
1113 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1114 if (!aFormat.isEmpty())
1116 sal_Int16 nFormat;
1117 if ( aFormat == "system_short" )
1119 nFormat = 0;
1121 else if ( aFormat == "system_short_YY" )
1123 nFormat = 1;
1125 else if ( aFormat == "system_short_YYYY" )
1127 nFormat = 2;
1129 else if ( aFormat == "system_long" )
1131 nFormat = 3;
1133 else if ( aFormat == "short_DDMMYY" )
1135 nFormat = 4;
1137 else if ( aFormat == "short_MMDDYY" )
1139 nFormat = 5;
1141 else if ( aFormat == "short_YYMMDD" )
1143 nFormat = 6;
1145 else if ( aFormat == "short_DDMMYYYY" )
1147 nFormat = 7;
1149 else if ( aFormat == "short_MMDDYYYY" )
1151 nFormat = 8;
1153 else if ( aFormat == "short_YYYYMMDD" )
1155 nFormat = 9;
1157 else if ( aFormat == "short_YYMMDD_DIN5008" )
1159 nFormat = 10;
1161 else if ( aFormat == "short_YYYYMMDD_DIN5008" )
1163 nFormat = 11;
1165 else
1167 throw xml::sax::SAXException( "invalid date-format value!", Reference< XInterface >(), Any() );
1170 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1171 return true;
1173 return false;
1176 bool ImportContext::importTimeProperty(
1177 OUString const & rPropName, OUString const & rAttrName,
1178 Reference< xml::input::XAttributes > const & xAttributes )
1180 OUString aValue(
1181 xAttributes->getValueByUidName(
1182 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1183 if (!aValue.isEmpty())
1185 ::tools::Time aTTime(toInt32( aValue ) * ::tools::Time::nanoPerCenti);
1186 util::Time aUTime(aTTime.GetUNOTime());
1187 _xControlModel->setPropertyValue( rPropName, makeAny( aUTime ) );
1188 return true;
1190 return false;
1193 bool ImportContext::importDateProperty(
1194 OUString const & rPropName, OUString const & rAttrName,
1195 Reference< xml::input::XAttributes > const & xAttributes )
1197 OUString aValue(
1198 xAttributes->getValueByUidName(
1199 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1200 if (!aValue.isEmpty())
1202 ::Date aTDate(toInt32( aValue ));
1203 util::Date aUDate(aTDate.GetUNODate());
1204 _xControlModel->setPropertyValue( rPropName, makeAny( aUDate ) );
1205 return true;
1207 return false;
1210 bool ImportContext::importTimeFormatProperty(
1211 OUString const & rPropName, OUString const & rAttrName,
1212 Reference< xml::input::XAttributes > const & xAttributes )
1214 OUString aFormat(
1215 xAttributes->getValueByUidName(
1216 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1217 if (!aFormat.isEmpty())
1219 sal_Int16 nFormat;
1220 if ( aFormat == "24h_short" )
1222 nFormat = 0;
1224 else if ( aFormat == "24h_long" )
1226 nFormat = 1;
1228 else if ( aFormat == "12h_short" )
1230 nFormat = 2;
1232 else if ( aFormat == "12h_long" )
1234 nFormat = 3;
1236 else if ( aFormat == "Duration_short" )
1238 nFormat = 4;
1240 else if ( aFormat == "Duration_long" )
1242 nFormat = 5;
1244 else
1246 throw xml::sax::SAXException( "invalid time-format value!", Reference< XInterface >(), Any() );
1249 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1250 return true;
1252 return false;
1255 bool ImportContext::importOrientationProperty(
1256 OUString const & rPropName, OUString const & rAttrName,
1257 Reference< xml::input::XAttributes > const & xAttributes )
1259 OUString aOrient(
1260 xAttributes->getValueByUidName(
1261 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1262 if (!aOrient.isEmpty())
1264 sal_Int32 nOrient;
1265 if ( aOrient == "horizontal" )
1267 nOrient = 0;
1269 else if ( aOrient == "vertical" )
1271 nOrient = 1;
1273 else
1275 throw xml::sax::SAXException( "invalid orientation value!", Reference< XInterface >(), Any() );
1278 _xControlModel->setPropertyValue( rPropName, makeAny( nOrient ) );
1279 return true;
1281 return false;
1284 bool ImportContext::importLineEndFormatProperty(
1285 OUString const & rPropName, OUString const & rAttrName,
1286 Reference< xml::input::XAttributes > const & xAttributes )
1288 OUString aFormat(
1289 xAttributes->getValueByUidName(
1290 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1291 if (!aFormat.isEmpty())
1293 sal_Int16 nFormat;
1294 if ( aFormat == "carriage-return" )
1296 nFormat = awt::LineEndFormat::CARRIAGE_RETURN;
1298 else if ( aFormat == "line-feed" )
1300 nFormat = awt::LineEndFormat::LINE_FEED;
1302 else if ( aFormat == "carriage-return-line-feed" )
1304 nFormat = awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED;
1306 else
1308 throw xml::sax::SAXException( "invalid line end format value!", Reference< XInterface >(), Any() );
1311 _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1312 return true;
1314 return false;
1317 bool ImportContext::importSelectionTypeProperty(
1318 OUString const & rPropName, OUString const & rAttrName,
1319 Reference< xml::input::XAttributes > const & xAttributes )
1321 OUString aSelectionType(
1322 xAttributes->getValueByUidName(
1323 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1324 if (!aSelectionType.isEmpty())
1326 view::SelectionType eSelectionType;
1328 if ( aSelectionType == "none" )
1330 eSelectionType = view::SelectionType_NONE;
1332 else if ( aSelectionType == "single" )
1334 eSelectionType = view::SelectionType_SINGLE;
1336 else if ( aSelectionType == "multi" )
1338 eSelectionType = view::SelectionType_MULTI;
1340 else if ( aSelectionType == "range" )
1342 eSelectionType = view::SelectionType_RANGE;
1344 else
1346 throw xml::sax::SAXException( "invalid selection type value!", Reference< XInterface >(), Any() );
1349 _xControlModel->setPropertyValue( rPropName, makeAny( eSelectionType ) );
1350 return true;
1352 return false;
1355 bool ImportContext::importImageScaleModeProperty(
1356 OUString const & rPropName, OUString const & rAttrName,
1357 Reference< xml::input::XAttributes > const & xAttributes )
1359 OUString aImageScaleMode(
1360 xAttributes->getValueByUidName(
1361 _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1362 if (!aImageScaleMode.isEmpty())
1364 sal_Int16 nImageScaleMode;
1366 if (aImageScaleMode == "none")
1368 nImageScaleMode = awt::ImageScaleMode::NONE;
1370 else if (aImageScaleMode == "isotropic")
1372 nImageScaleMode = awt::ImageScaleMode::ISOTROPIC;
1374 else if (aImageScaleMode == "anisotropic")
1376 nImageScaleMode = awt::ImageScaleMode::ANISOTROPIC;
1378 else
1380 throw xml::sax::SAXException( "invalid scale image mode value!",
1381 Reference< XInterface >(), Any() );
1384 _xControlModel->setPropertyValue( rPropName, makeAny( nImageScaleMode ) );
1385 return true;
1387 return false;
1390 static StringTriple const s_aEventTranslations[] =
1392 // from xmloff/source/forms/formevents.cxx
1393 // 28.09.2001 tbe added on-adjustmentvaluechange
1394 { "com.sun.star.form.XApproveActionListener", "approveAction", "on-approveaction" },
1395 { "com.sun.star.awt.XActionListener", "actionPerformed", "on-performaction" },
1396 { "com.sun.star.form.XChangeListener", "changed", "on-change" },
1397 { "com.sun.star.awt.XTextListener", "textChanged", "on-textchange" },
1398 { "com.sun.star.awt.XItemListener", "itemStateChanged", "on-itemstatechange" },
1399 { "com.sun.star.awt.XFocusListener", "focusGained", "on-focus" },
1400 { "com.sun.star.awt.XFocusListener", "focusLost", "on-blur" },
1401 { "com.sun.star.awt.XKeyListener", "keyPressed", "on-keydown" },
1402 { "com.sun.star.awt.XKeyListener", "keyReleased", "on-keyup" },
1403 { "com.sun.star.awt.XMouseListener", "mouseEntered", "on-mouseover" },
1404 { "com.sun.star.awt.XMouseMotionListener", "mouseDragged", "on-mousedrag" },
1405 { "com.sun.star.awt.XMouseMotionListener", "mouseMoved", "on-mousemove" },
1406 { "com.sun.star.awt.XMouseListener", "mousePressed", "on-mousedown" },
1407 { "com.sun.star.awt.XMouseListener", "mouseReleased", "on-mouseup" },
1408 { "com.sun.star.awt.XMouseListener", "mouseExited", "on-mouseout" },
1409 { "com.sun.star.form.XResetListener", "approveReset", "on-approvereset" },
1410 { "com.sun.star.form.XResetListener", "resetted", "on-reset" },
1411 { "com.sun.star.form.XSubmitListener", "approveSubmit", "on-submit" },
1412 { "com.sun.star.form.XUpdateListener", "approveUpdate", "on-approveupdate" },
1413 { "com.sun.star.form.XUpdateListener", "updated", "on-update" },
1414 { "com.sun.star.form.XLoadListener", "loaded", "on-load" },
1415 { "com.sun.star.form.XLoadListener", "reloading", "on-startreload" },
1416 { "com.sun.star.form.XLoadListener", "reloaded", "on-reload" },
1417 { "com.sun.star.form.XLoadListener", "unloading", "on-startunload" },
1418 { "com.sun.star.form.XLoadListener", "unloaded", "on-unload" },
1419 { "com.sun.star.form.XConfirmDeleteListener", "confirmDelete", "on-confirmdelete" },
1420 { "com.sun.star.sdb.XRowSetApproveListener", "approveRowChange", "on-approverowchange" },
1421 { "com.sun.star.sdbc.XRowSetListener", "rowChanged", "on-rowchange" },
1422 { "com.sun.star.sdb.XRowSetApproveListener", "approveCursorMove", "on-approvecursormove" },
1423 { "com.sun.star.sdbc.XRowSetListener", "cursorMoved", "on-cursormove" },
1424 { "com.sun.star.form.XDatabaseParameterListener", "approveParameter", "on-supplyparameter" },
1425 { "com.sun.star.sdb.XSQLErrorListener", "errorOccured", "on-error" },
1426 { "com.sun.star.awt.XAdjustmentListener", "adjustmentValueChanged", "on-adjustmentvaluechange" },
1427 { nullptr, nullptr, nullptr }
1430 StringTriple const * const g_pEventTranslations = s_aEventTranslations;
1432 void ImportContext::importEvents(
1433 std::vector< Reference< xml::input::XElement > > const & rEvents )
1435 Reference< script::XScriptEventsSupplier > xSupplier(
1436 _xControlModel, UNO_QUERY );
1437 if (xSupplier.is())
1439 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1440 if (xEvents.is())
1442 for (const auto & rEvent : rEvents)
1444 script::ScriptEventDescriptor descr;
1446 EventElement * pEventElement = static_cast< EventElement * >( rEvent.get() );
1447 sal_Int32 nUid = pEventElement->getUid();
1448 OUString aLocalName( pEventElement->getLocalName() );
1449 Reference< xml::input::XAttributes > xAttributes( pEventElement->getAttributes() );
1451 // nowadays script events
1452 if (_pImport->XMLNS_SCRIPT_UID == nUid)
1454 if (!getStringAttr( &descr.ScriptType, "language" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1455 !getStringAttr( &descr.ScriptCode, "macro-name", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1457 throw xml::sax::SAXException( "missing language or macro-name attribute(s) of event!", Reference< XInterface >(), Any() );
1459 if ( descr.ScriptType == "StarBasic" )
1461 OUString aLocation;
1462 if (getStringAttr( &aLocation, "location", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1464 // prepend location
1465 descr.ScriptCode = aLocation + ":" + descr.ScriptCode;
1468 else if ( descr.ScriptType == "Script" )
1470 // Check if there is a protocol, if not assume
1471 // this is an early scripting framework url ( without
1472 // the protocol ) and fix it up!!
1473 if ( descr.ScriptCode.indexOf( ':' ) == -1 )
1475 descr.ScriptCode = "vnd.sun.start.script:" + descr.ScriptCode;
1479 // script:event element
1480 if ( aLocalName == "event" )
1482 OUString aEventName;
1483 if (! getStringAttr( &aEventName, "event-name", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1485 throw xml::sax::SAXException( "missing event-name attribute!", Reference< XInterface >(), Any() );
1488 // lookup in table
1489 OString str( OUStringToOString( aEventName, RTL_TEXTENCODING_ASCII_US ) );
1490 StringTriple const * p = g_pEventTranslations;
1491 while (p->first)
1493 if (0 == ::rtl_str_compare( p->third, str.getStr() ))
1495 descr.ListenerType = OUString(
1496 p->first, ::rtl_str_getLength( p->first ),
1497 RTL_TEXTENCODING_ASCII_US );
1498 descr.EventMethod = OUString(
1499 p->second, ::rtl_str_getLength( p->second ),
1500 RTL_TEXTENCODING_ASCII_US );
1501 break;
1503 ++p;
1506 if (! p->first)
1508 throw xml::sax::SAXException( "no matching event-name found!", Reference< XInterface >(), Any() );
1511 else // script:listener-event element
1513 SAL_WARN_IF( aLocalName != "listener-event", "xmlscript.xmldlg", "aLocalName != listener-event" );
1515 if (!getStringAttr( &descr.ListenerType, "listener-type" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) ||
1516 !getStringAttr( &descr.EventMethod , "listener-method", xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1518 throw xml::sax::SAXException("missing listener-type or listener-method attribute(s)!", Reference< XInterface >(), Any() );
1520 // optional listener param
1521 getStringAttr( &descr.AddListenerParam, "listener-param", xAttributes, _pImport->XMLNS_SCRIPT_UID );
1524 else // deprecated dlg:event element
1526 SAL_WARN_IF( _pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != "event", "xmlscript.xmldlg", "_pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != \"event\"" );
1528 if (!getStringAttr( &descr.ListenerType, "listener-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ) ||
1529 !getStringAttr( &descr.EventMethod, "event-method", xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1531 throw xml::sax::SAXException("missing listener-type or event-method attribute(s)!", Reference< XInterface >(), Any() );
1534 getStringAttr( &descr.ScriptType, "script-type", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1535 getStringAttr( &descr.ScriptCode, "script-code", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1536 getStringAttr( &descr.AddListenerParam, "param", xAttributes, _pImport->XMLNS_DIALOGS_UID );
1539 xEvents->insertByName( descr.ListenerType + "::" + descr.EventMethod, makeAny( descr ) );
1544 void ImportContext::importScollableSettings(
1545 Reference< xml::input::XAttributes > const & _xAttributes )
1547 importLongProperty( "ScrollHeight",
1548 "scrollheight",
1549 _xAttributes );
1550 importLongProperty( "ScrollWidth",
1551 "scrollwidth",
1552 _xAttributes );
1553 importLongProperty( "ScrollTop",
1554 "scrolltop",
1555 _xAttributes );
1556 importLongProperty( "ScrollLeft",
1557 "scrollleft",
1558 _xAttributes );
1559 importBooleanProperty( "HScroll",
1560 "hscroll",
1561 _xAttributes );
1562 importBooleanProperty( "VScroll",
1563 "vscroll",
1564 _xAttributes );
1567 void ImportContext::importDefaults(
1568 sal_Int32 nBaseX, sal_Int32 nBaseY,
1569 Reference< xml::input::XAttributes > const & xAttributes,
1570 bool supportPrintable )
1572 _xControlModel->setPropertyValue( "Name", makeAny( _aId ) );
1574 importShortProperty( "TabIndex", "tab-index", xAttributes );
1576 sal_Bool bDisable = false;
1577 if (getBoolAttr( &bDisable,"disabled", xAttributes, _pImport->XMLNS_DIALOGS_UID ) && bDisable)
1579 _xControlModel->setPropertyValue( "Enabled", makeAny( false ) );
1582 sal_Bool bVisible = true;
1583 if (getBoolAttr( &bVisible, "visible", xAttributes, _pImport->XMLNS_DIALOGS_UID ) && !bVisible)
1587 _xControlModel->setPropertyValue( "EnableVisible", makeAny( false ) );
1589 catch( Exception& )
1591 DBG_UNHANDLED_EXCEPTION("xmlscript.xmldlg");
1595 if (!importLongProperty( nBaseX, "PositionX", "left", xAttributes ) ||
1596 !importLongProperty( nBaseY, "PositionY", "top", xAttributes ) ||
1597 !importLongProperty( "Width", "width", xAttributes ) ||
1598 !importLongProperty( "Height", "height", xAttributes ))
1600 throw xml::sax::SAXException( "missing pos size attribute(s)!", Reference< XInterface >(), Any() );
1603 if (supportPrintable)
1605 importBooleanProperty("Printable", "printable", xAttributes );
1608 sal_Int32 nLong;
1609 if (! getLongAttr( &nLong, "page", xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1611 nLong = 0;
1613 _xControlModel->setPropertyValue( "Step", makeAny( nLong ) );
1615 importStringProperty("Tag", "tag", xAttributes );
1616 importStringProperty( "HelpText", "help-text", xAttributes );
1617 importStringProperty( "HelpURL", "help-url", xAttributes );
1620 Reference< xml::input::XElement > ElementBase::getParent()
1622 return static_cast< xml::input::XElement * >( m_xParent.get() );
1625 OUString ElementBase::getLocalName()
1627 return _aLocalName;
1630 sal_Int32 ElementBase::getUid()
1632 return _nUid;
1635 Reference< xml::input::XAttributes > ElementBase::getAttributes()
1637 return _xAttributes;
1640 void ElementBase::ignorableWhitespace(
1641 OUString const & /*rWhitespaces*/ )
1643 // not used
1646 void ElementBase::characters( OUString const & /*rChars*/ )
1648 // not used, all characters ignored
1651 void ElementBase::endElement()
1655 void ElementBase::processingInstruction(
1656 OUString const & /*Target*/, OUString const & /*Data*/ )
1660 Reference< xml::input::XElement > ElementBase::startChildElement(
1661 sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
1662 Reference< xml::input::XAttributes > const & /*xAttributes*/ )
1664 throw xml::sax::SAXException( "unexpected element!", Reference< XInterface >(), Any() );
1667 ElementBase::ElementBase(
1668 sal_Int32 nUid, OUString const & rLocalName,
1669 Reference< xml::input::XAttributes > const & xAttributes,
1670 ElementBase * pParent, DialogImport * pImport )
1671 : m_xImport( pImport )
1672 , m_xParent( pParent )
1673 , _nUid( nUid )
1674 , _aLocalName( rLocalName )
1675 , _xAttributes( xAttributes )
1679 ElementBase::~ElementBase()
1681 SAL_INFO("xmlscript.xmldlg", "ElementBase::~ElementBase(): " << _aLocalName );
1684 // XRoot
1686 void DialogImport::startDocument(
1687 Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
1689 XMLNS_DIALOGS_UID = xNamespaceMapping->getUidByUri( XMLNS_DIALOGS_URI );
1690 XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri( XMLNS_SCRIPT_URI );
1693 void DialogImport::endDocument()
1695 // ignored
1698 void DialogImport::processingInstruction(
1699 OUString const & /*rTarget*/, OUString const & /*rData*/ )
1701 // ignored for now: xxx todo
1704 void DialogImport::setDocumentLocator(
1705 Reference< xml::sax::XLocator > const & /*xLocator*/ )
1707 // ignored for now: xxx todo
1710 Reference< xml::input::XElement > DialogImport::startRootElement(
1711 sal_Int32 nUid, OUString const & rLocalName,
1712 Reference< xml::input::XAttributes > const & xAttributes )
1714 if (XMLNS_DIALOGS_UID != nUid)
1716 throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
1718 // window
1719 else if ( rLocalName == "window" )
1721 return new WindowElement( rLocalName, xAttributes, this );
1723 else
1725 throw xml::sax::SAXException( "illegal root element (expected window) given: " + rLocalName, Reference< XInterface >(), Any() );
1729 DialogImport::~DialogImport()
1731 SAL_INFO("xmlscript.xmldlg", "DialogImport::~DialogImport()." );
1734 Reference< util::XNumberFormatsSupplier > const & DialogImport::getNumberFormatsSupplier()
1736 if (! _xSupplier.is())
1738 Reference< util::XNumberFormatsSupplier > xSupplier = util::NumberFormatsSupplier::createWithDefaultLocale( getComponentContext() );
1740 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1741 if (! _xSupplier.is())
1743 _xSupplier = xSupplier;
1746 return _xSupplier;
1749 void DialogImport::addStyle(
1750 OUString const & rStyleId,
1751 Reference< xml::input::XElement > const & xStyle )
1753 (*_pStyleNames).push_back( rStyleId );
1754 (*_pStyles).push_back( xStyle );
1757 Reference< xml::input::XElement > DialogImport::getStyle(
1758 OUString const & rStyleId ) const
1760 for ( size_t nPos = 0; nPos < (*_pStyleNames).size(); ++nPos )
1762 if ( (*_pStyleNames)[ nPos ] == rStyleId)
1764 return (*_pStyles)[ nPos ];
1767 return nullptr;
1770 Reference< xml::sax::XDocumentHandler > importDialogModel(
1771 Reference< container::XNameContainer > const & xDialogModel,
1772 Reference< XComponentContext > const & xContext,
1773 Reference< XModel > const & xDocument )
1775 // single set of styles and stylenames apply to all containers
1776 std::shared_ptr< std::vector< OUString > > pStyleNames( new std::vector< OUString > );
1777 std::shared_ptr< std::vector< css::uno::Reference< css::xml::input::XElement > > > pStyles( new std::vector< css::uno::Reference< css::xml::input::XElement > > );
1778 return ::xmlscript::createDocumentHandler(
1779 new DialogImport(xContext, xDialogModel, pStyleNames, pStyles, xDocument));
1783 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */