xref: /trunk/main/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmlscript.hxx"
26 #include "imp_share.hxx"
27 
28 #include <osl/diagnose.h>
29 #include <tools/diagnose_ex.h>
30 #include <osl/mutex.hxx>
31 
32 #include <rtl/ustrbuf.hxx>
33 
34 #include <xml_import.hxx>
35 #include <comphelper/processfactory.hxx>
36 
37 #include <com/sun/star/awt/CharSet.hpp>
38 #include <com/sun/star/awt/FontFamily.hpp>
39 #include <com/sun/star/awt/FontPitch.hpp>
40 #include <com/sun/star/awt/FontSlant.hpp>
41 #include <com/sun/star/awt/FontStrikeout.hpp>
42 #include <com/sun/star/awt/FontType.hpp>
43 #include <com/sun/star/awt/FontUnderline.hpp>
44 #include <com/sun/star/awt/FontWeight.hpp>
45 #include <com/sun/star/awt/FontWidth.hpp>
46 #include <com/sun/star/awt/ImagePosition.hpp>
47 #include <com/sun/star/awt/ImageScaleMode.hpp>
48 #include <com/sun/star/awt/LineEndFormat.hpp>
49 #include <com/sun/star/awt/PushButtonType.hpp>
50 #include <com/sun/star/awt/VisualEffect.hpp>
51 #include <com/sun/star/style/VerticalAlignment.hpp>
52 
53 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
54 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
55 
56 #include <com/sun/star/view/SelectionType.hpp>
57 
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using ::rtl::OUString;
61 
62 namespace xmlscript
63 {
64 
65 //__________________________________________________________________________________________________
endElement()66 void EventElement::endElement()
67 {
68     static_cast< ControlElement * >( _pParent )->_events.push_back( this );
69 }
70 //__________________________________________________________________________________________________
ControlElement(OUString const & rLocalName,Reference<xml::input::XAttributes> const & xAttributes,ElementBase * pParent,DialogImport * pImport)71 ControlElement::ControlElement(
72     OUString const & rLocalName,
73     Reference< xml::input::XAttributes > const & xAttributes,
74     ElementBase * pParent, DialogImport * pImport )
75     SAL_THROW( () )
76     : ElementBase(
77         pImport->XMLNS_DIALOGS_UID, rLocalName, xAttributes, pParent, pImport )
78 {
79     if (_pParent)
80     {
81         // inherit position
82         _nBasePosX = static_cast< ControlElement * >( _pParent )->_nBasePosX;
83         _nBasePosY = static_cast< ControlElement * >( _pParent )->_nBasePosY;
84     }
85     else
86     {
87         _nBasePosX = 0;
88         _nBasePosY = 0;
89     }
90 }
91 
92 //__________________________________________________________________________________________________
getStyle(Reference<xml::input::XAttributes> const & xAttributes)93 Reference< xml::input::XElement > ControlElement::getStyle(
94     Reference< xml::input::XAttributes > const & xAttributes )
95 {
96     OUString aStyleId(
97         xAttributes->getValueByUidName(
98             _pImport->XMLNS_DIALOGS_UID,
99             OUString( RTL_CONSTASCII_USTRINGPARAM("style-id") ) ) );
100     if (aStyleId.getLength())
101     {
102         return _pImport->getStyle( aStyleId );
103     }
104     return Reference< xml::input::XElement >();
105 }
106 //__________________________________________________________________________________________________
getControlId(Reference<xml::input::XAttributes> const & xAttributes)107 OUString ControlElement::getControlId(
108     Reference< xml::input::XAttributes > const & xAttributes )
109 {
110     OUString aId(
111         xAttributes->getValueByUidName(
112             _pImport->XMLNS_DIALOGS_UID,
113             OUString( RTL_CONSTASCII_USTRINGPARAM("id") ) ) );
114     if (! aId.getLength())
115     {
116         throw xml::sax::SAXException(
117             OUString( RTL_CONSTASCII_USTRINGPARAM("missing id attribute!") ),
118             Reference< XInterface >(), Any() );
119     }
120     return aId;
121 }
122 
123 //##################################################################################################
124 
125 //__________________________________________________________________________________________________
importTextColorStyle(Reference<beans::XPropertySet> const & xProps)126 bool StyleElement::importTextColorStyle(
127     Reference< beans::XPropertySet > const & xProps )
128 {
129     if ((_inited & 0x2) != 0)
130     {
131         if ((_hasValue & 0x2) != 0)
132         {
133             xProps->setPropertyValue(
134                 OUString( RTL_CONSTASCII_USTRINGPARAM("TextColor") ),
135                 makeAny( _textColor ) );
136             return true;
137         }
138         return false;
139     }
140     _inited |= 0x2;
141 
142     if (getLongAttr( &_textColor,
143                      OUString( RTL_CONSTASCII_USTRINGPARAM("text-color") ),
144                      _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
145     {
146         _hasValue |= 0x2;
147         xProps->setPropertyValue(
148             OUString( RTL_CONSTASCII_USTRINGPARAM("TextColor") ),
149             makeAny( _textColor ) );
150         return true;
151     }
152     return false;
153 }
154 //__________________________________________________________________________________________________
importTextLineColorStyle(Reference<beans::XPropertySet> const & xProps)155 bool StyleElement::importTextLineColorStyle(
156     Reference< beans::XPropertySet > const & xProps )
157 {
158     if ((_inited & 0x20) != 0)
159     {
160         if ((_hasValue & 0x20) != 0)
161         {
162             xProps->setPropertyValue(
163                 OUString( RTL_CONSTASCII_USTRINGPARAM("TextLineColor") ),
164                 makeAny( _textLineColor ) );
165             return true;
166         }
167         return false;
168     }
169     _inited |= 0x20;
170 
171     if (getLongAttr( &_textLineColor,
172                      OUString( RTL_CONSTASCII_USTRINGPARAM("textline-color") ),
173                      _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
174     {
175         _hasValue |= 0x20;
176         xProps->setPropertyValue(
177             OUString( RTL_CONSTASCII_USTRINGPARAM("TextLineColor") ),
178             makeAny( _textLineColor ) );
179         return true;
180     }
181     return false;
182 }
183 //__________________________________________________________________________________________________
importFillColorStyle(Reference<beans::XPropertySet> const & xProps)184 bool StyleElement::importFillColorStyle(
185     Reference< beans::XPropertySet > const & xProps )
186 {
187     if ((_inited & 0x10) != 0)
188     {
189         if ((_hasValue & 0x10) != 0)
190         {
191             xProps->setPropertyValue(
192                 OUString( RTL_CONSTASCII_USTRINGPARAM("FillColor") ), makeAny( _fillColor ) );
193             return true;
194         }
195         return false;
196     }
197     _inited |= 0x10;
198 
199     if (getLongAttr(
200             &_fillColor,
201             OUString( RTL_CONSTASCII_USTRINGPARAM("fill-color") ),
202             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
203     {
204         _hasValue |= 0x10;
205         xProps->setPropertyValue(
206             OUString( RTL_CONSTASCII_USTRINGPARAM("FillColor") ),
207             makeAny( _fillColor ) );
208         return true;
209     }
210     return false;
211 }
212 //__________________________________________________________________________________________________
importBackgroundColorStyle(Reference<beans::XPropertySet> const & xProps)213 bool StyleElement::importBackgroundColorStyle(
214     Reference< beans::XPropertySet > const & xProps )
215 {
216     if ((_inited & 0x1) != 0)
217     {
218         if ((_hasValue & 0x1) != 0)
219         {
220             xProps->setPropertyValue(
221                 OUString( RTL_CONSTASCII_USTRINGPARAM("BackgroundColor") ), makeAny( _backgroundColor ) );
222             return true;
223         }
224         return false;
225     }
226     _inited |= 0x1;
227 
228     if (getLongAttr(
229             &_backgroundColor,
230             OUString( RTL_CONSTASCII_USTRINGPARAM("background-color") ),
231             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
232     {
233         _hasValue |= 0x1;
234         xProps->setPropertyValue(
235             OUString( RTL_CONSTASCII_USTRINGPARAM("BackgroundColor") ), makeAny( _backgroundColor ) );
236         return true;
237     }
238     return false;
239 }
240 
241 //__________________________________________________________________________________________________
importBorderStyle(Reference<beans::XPropertySet> const & xProps)242 bool StyleElement::importBorderStyle(
243     Reference< beans::XPropertySet > const & xProps )
244 {
245     if ((_inited & 0x4) != 0)
246     {
247         if ((_hasValue & 0x4) != 0)
248         {
249             xProps->setPropertyValue(
250                 OUSTR("Border"), makeAny( _border == BORDER_SIMPLE_COLOR
251                                           ? BORDER_SIMPLE : _border ) );
252             if (_border == BORDER_SIMPLE_COLOR)
253                 xProps->setPropertyValue( OUSTR("BorderColor"),
254                                           makeAny(_borderColor) );
255             return true;
256         }
257         return false;
258     }
259     _inited |= 0x4;
260 
261     OUString aValue;
262     if (getStringAttr(
263             &aValue, OUSTR("border"),
264             _xAttributes, _pImport->XMLNS_DIALOGS_UID )) {
265         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
266             _border = BORDER_NONE;
267         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("3d") ))
268             _border = BORDER_3D;
269         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("simple") ))
270             _border = BORDER_SIMPLE;
271         else {
272             _border = BORDER_SIMPLE_COLOR;
273             _borderColor = toInt32(aValue);
274         }
275 
276         _hasValue |= 0x4;
277         importBorderStyle(xProps); // write values
278     }
279     return false;
280 }
281 
282 //______________________________________________________________________________
importVisualEffectStyle(Reference<beans::XPropertySet> const & xProps)283 bool StyleElement::importVisualEffectStyle(
284     Reference<beans::XPropertySet> const & xProps )
285 {
286     if ((_inited & 0x40) != 0)
287     {
288         if ((_hasValue & 0x40) != 0)
289         {
290             xProps->setPropertyValue( OUSTR("VisualEffect"),
291                                       makeAny(_visualEffect) );
292             return true;
293         }
294         return false;
295     }
296     _inited |= 0x40;
297 
298     OUString aValue;
299     if (getStringAttr( &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("look") ),
300                        _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
301     {
302         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
303         {
304             _visualEffect = awt::VisualEffect::NONE;
305         }
306         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("3d") ))
307         {
308             _visualEffect = awt::VisualEffect::LOOK3D;
309         }
310         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("simple") ))
311         {
312             _visualEffect = awt::VisualEffect::FLAT;
313         }
314         else
315             OSL_ASSERT( 0 );
316 
317         _hasValue |= 0x40;
318         xProps->setPropertyValue( OUSTR("VisualEffect"),
319                                   makeAny(_visualEffect) );
320     }
321     return false;
322 }
323 
324 //__________________________________________________________________________________________________
setFontProperties(Reference<beans::XPropertySet> const & xProps)325 void StyleElement::setFontProperties(
326     Reference< beans::XPropertySet > const & xProps )
327 {
328     xProps->setPropertyValue(
329         OUString( RTL_CONSTASCII_USTRINGPARAM("FontDescriptor") ), makeAny( _descr ) );
330     xProps->setPropertyValue(
331         OUString( RTL_CONSTASCII_USTRINGPARAM("FontEmphasisMark") ), makeAny( _fontEmphasisMark ) );
332     xProps->setPropertyValue(
333         OUString( RTL_CONSTASCII_USTRINGPARAM("FontRelief") ), makeAny( _fontRelief ) );
334 }
335 //__________________________________________________________________________________________________
importFontStyle(Reference<beans::XPropertySet> const & xProps)336 bool StyleElement::importFontStyle(
337     Reference< beans::XPropertySet > const & xProps )
338 {
339     if ((_inited & 0x8) != 0)
340     {
341         if ((_hasValue & 0x8) != 0)
342         {
343             setFontProperties( xProps );
344             return true;
345         }
346         return false;
347     }
348     _inited |= 0x8;
349 
350     OUString aValue;
351     bool bFontImport;
352 
353     // dialog:font-name CDATA #IMPLIED
354     bFontImport = getStringAttr(
355         &_descr.Name, OUString( RTL_CONSTASCII_USTRINGPARAM("font-name") ),
356         _xAttributes, _pImport->XMLNS_DIALOGS_UID );
357 
358     // dialog:font-height %numeric; #IMPLIED
359     if (getStringAttr(
360             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-height") ),
361             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
362     {
363         _descr.Height = (sal_Int16)toInt32( aValue );
364         bFontImport = true;
365     }
366     // dialog:font-width %numeric; #IMPLIED
367     if (getStringAttr(
368             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-width") ),
369             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
370     {
371         _descr.Width = (sal_Int16)toInt32( aValue );
372         bFontImport = true;
373     }
374     // dialog:font-stylename CDATA #IMPLIED
375     bFontImport |= getStringAttr(
376         &_descr.StyleName,
377         OUString( RTL_CONSTASCII_USTRINGPARAM("font-stylename") ),
378         _xAttributes, _pImport->XMLNS_DIALOGS_UID );
379 
380     // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
381     if (getStringAttr(
382             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-family") ),
383             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
384     {
385         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("decorative") ))
386         {
387             _descr.Family = awt::FontFamily::DECORATIVE;
388         }
389         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("modern") ))
390         {
391             _descr.Family = awt::FontFamily::MODERN;
392         }
393         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("roman") ))
394         {
395             _descr.Family = awt::FontFamily::ROMAN;
396         }
397         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("script") ))
398         {
399             _descr.Family = awt::FontFamily::SCRIPT;
400         }
401         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("swiss") ))
402         {
403             _descr.Family = awt::FontFamily::SWISS;
404         }
405         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system") ))
406         {
407             _descr.Family = awt::FontFamily::SYSTEM;
408         }
409         else
410         {
411             throw xml::sax::SAXException(
412                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-family style!") ),
413                 Reference< XInterface >(), Any() );
414         }
415         bFontImport = true;
416     }
417 
418     // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
419     if (getStringAttr(
420             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-charset") ),
421             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
422     {
423         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ansi") ))
424         {
425             _descr.CharSet = awt::CharSet::ANSI;
426         }
427         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("mac") ))
428         {
429             _descr.CharSet = awt::CharSet::MAC;
430         }
431         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_437") ))
432         {
433             _descr.CharSet = awt::CharSet::IBMPC_437;
434         }
435         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_850") ))
436         {
437             _descr.CharSet = awt::CharSet::IBMPC_850;
438         }
439         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_860") ))
440         {
441             _descr.CharSet = awt::CharSet::IBMPC_860;
442         }
443         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_861") ))
444         {
445             _descr.CharSet = awt::CharSet::IBMPC_861;
446         }
447         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_863") ))
448         {
449             _descr.CharSet = awt::CharSet::IBMPC_863;
450         }
451         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ibmpc_865") ))
452         {
453             _descr.CharSet = awt::CharSet::IBMPC_865;
454         }
455         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system") ))
456         {
457             _descr.CharSet = awt::CharSet::SYSTEM;
458         }
459         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("symbol") ))
460         {
461             _descr.CharSet = awt::CharSet::SYMBOL;
462         }
463         else
464         {
465             throw xml::sax::SAXException(
466                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-charset style!") ),
467                 Reference< XInterface >(), Any() );
468         }
469         bFontImport = true;
470     }
471 
472     // dialog:font-pitch "(fixed|variable)" #IMPLIED
473     if (getStringAttr(
474             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-pitch") ),
475             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
476     {
477         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("fixed") ))
478         {
479             _descr.Pitch = awt::FontPitch::FIXED;
480         }
481         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("variable") ))
482         {
483             _descr.Pitch = awt::FontPitch::VARIABLE;
484         }
485         else
486         {
487             throw xml::sax::SAXException(
488                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-pitch style!") ),
489                 Reference< XInterface >(), Any() );
490         }
491         bFontImport = true;
492     }
493 
494     // dialog:font-charwidth CDATA #IMPLIED
495     if (getStringAttr(
496             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-charwidth") ),
497             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
498     {
499         _descr.CharacterWidth = aValue.toFloat();
500         bFontImport = true;
501     }
502     // dialog:font-weight CDATA #IMPLIED
503     if (getStringAttr(
504             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-weight") ),
505             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
506     {
507         _descr.Weight = aValue.toFloat();
508         bFontImport = true;
509     }
510 
511     // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
512     if (getStringAttr(
513             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-slant") ),
514             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
515     {
516         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("oblique") ))
517         {
518             _descr.Slant = awt::FontSlant_OBLIQUE;
519         }
520         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("italic") ))
521         {
522             _descr.Slant = awt::FontSlant_ITALIC;
523         }
524         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("reverse_oblique") ))
525         {
526             _descr.Slant = awt::FontSlant_REVERSE_OBLIQUE;
527         }
528         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("reverse_italic") ))
529         {
530             _descr.Slant = awt::FontSlant_REVERSE_ITALIC;
531         }
532         else
533         {
534             throw xml::sax::SAXException(
535                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-slant style!") ),
536                 Reference< XInterface >(), Any() );
537         }
538         bFontImport = true;
539     }
540 
541     // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
542     if (getStringAttr(
543             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-underline") ),
544             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
545     {
546         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") ))
547         {
548             _descr.Underline = awt::FontUnderline::SINGLE;
549         }
550         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("double") ))
551         {
552             _descr.Underline = awt::FontUnderline::DOUBLE;
553         }
554         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dotted") ))
555         {
556             _descr.Underline = awt::FontUnderline::DOTTED;
557         }
558         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dash") ))
559         {
560             _descr.Underline = awt::FontUnderline::DASH;
561         }
562         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("longdash") ))
563         {
564             _descr.Underline = awt::FontUnderline::LONGDASH;
565         }
566         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dashdot") ))
567         {
568             _descr.Underline = awt::FontUnderline::DASHDOT;
569         }
570         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dashdotdot") ))
571         {
572             _descr.Underline = awt::FontUnderline::DASHDOTDOT;
573         }
574         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("smallwave") ))
575         {
576             _descr.Underline = awt::FontUnderline::SMALLWAVE;
577         }
578         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("wave") ))
579         {
580             _descr.Underline = awt::FontUnderline::WAVE;
581         }
582         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("doublewave") ))
583         {
584             _descr.Underline = awt::FontUnderline::DOUBLEWAVE;
585         }
586         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bold") ))
587         {
588             _descr.Underline = awt::FontUnderline::BOLD;
589         }
590         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddotted") ))
591         {
592             _descr.Underline = awt::FontUnderline::BOLDDOTTED;
593         }
594         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddash") ))
595         {
596             _descr.Underline = awt::FontUnderline::BOLDDASH;
597         }
598         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("boldlongdash") ))
599         {
600             _descr.Underline = awt::FontUnderline::BOLDLONGDASH;
601         }
602         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddashdot") ))
603         {
604             _descr.Underline = awt::FontUnderline::BOLDDASHDOT;
605         }
606         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bolddashdotdot") ))
607         {
608             _descr.Underline = awt::FontUnderline::BOLDDASHDOTDOT;
609         }
610         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("boldwave") ))
611         {
612             _descr.Underline = awt::FontUnderline::BOLDWAVE;
613         }
614         else
615         {
616             throw xml::sax::SAXException(
617                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-underline style!") ),
618                 Reference< XInterface >(), Any() );
619         }
620         bFontImport = true;
621     }
622 
623     // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
624     if (getStringAttr(
625             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-strikeout") ),
626             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
627     {
628         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") ))
629         {
630             _descr.Strikeout = awt::FontStrikeout::SINGLE;
631         }
632         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("double") ))
633         {
634             _descr.Strikeout = awt::FontStrikeout::DOUBLE;
635         }
636         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bold") ))
637         {
638             _descr.Strikeout = awt::FontStrikeout::BOLD;
639         }
640         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("slash") ))
641         {
642             _descr.Strikeout = awt::FontStrikeout::SLASH;
643         }
644         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("x") ))
645         {
646             _descr.Strikeout = awt::FontStrikeout::X;
647         }
648         else
649         {
650             throw xml::sax::SAXException(
651                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-strikeout style!") ),
652                 Reference< XInterface >(), Any() );
653         }
654         bFontImport = true;
655     }
656 
657     // dialog:font-orientation CDATA #IMPLIED
658     if (getStringAttr(
659             &aValue,
660             OUString( RTL_CONSTASCII_USTRINGPARAM("font-orientation") ),
661             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
662     {
663         _descr.Orientation = aValue.toFloat();
664         bFontImport = true;
665     }
666     // dialog:font-kerning %boolean; #IMPLIED
667     bFontImport |= getBoolAttr(
668         &_descr.Kerning,
669         OUString( RTL_CONSTASCII_USTRINGPARAM("font-kerning") ),
670         _xAttributes, _pImport->XMLNS_DIALOGS_UID );
671     // dialog:font-wordlinemode %boolean; #IMPLIED
672     bFontImport |= getBoolAttr(
673         &_descr.WordLineMode,
674         OUString( RTL_CONSTASCII_USTRINGPARAM("font-wordlinemode") ),
675         _xAttributes, _pImport->XMLNS_DIALOGS_UID );
676 
677     // dialog:font-type "(raster|device|scalable)" #IMPLIED
678     if (getStringAttr(
679             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-type") ),
680             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
681     {
682         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("raster") ))
683         {
684             _descr.Type = awt::FontType::RASTER;
685         }
686         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("device") ))
687         {
688             _descr.Type = awt::FontType::DEVICE;
689         }
690         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("scalable") ))
691         {
692             _descr.Type = awt::FontType::SCALABLE;
693         }
694         else
695         {
696             throw xml::sax::SAXException(
697                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-type style!") ),
698                 Reference< XInterface >(), Any() );
699         }
700         bFontImport = true;
701     }
702 
703     // additional properties which are not part of the FontDescriptor struct
704     // dialog:font-relief (none|embossed|engraved) #IMPLIED
705     if (getStringAttr(
706             &aValue, OUString( RTL_CONSTASCII_USTRINGPARAM("font-relief") ),
707             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
708     {
709         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
710         {
711             _fontRelief = awt::FontRelief::NONE;
712         }
713         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("embossed") ))
714         {
715             _fontRelief = awt::FontRelief::EMBOSSED;
716         }
717         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("engraved") ))
718         {
719             _fontRelief = awt::FontRelief::ENGRAVED;
720         }
721         else
722         {
723             throw xml::sax::SAXException(
724                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-relief style!") ),
725                 Reference< XInterface >(), Any() );
726         }
727         bFontImport = true;
728     }
729     // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
730     if (getStringAttr(
731             &aValue,
732             OUString( RTL_CONSTASCII_USTRINGPARAM("font-emphasismark") ),
733             _xAttributes, _pImport->XMLNS_DIALOGS_UID ))
734     {
735         if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
736         {
737             _fontEmphasisMark = awt::FontEmphasisMark::NONE;
738         }
739         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("dot") ))
740         {
741             _fontEmphasisMark = awt::FontEmphasisMark::DOT;
742         }
743         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("circle") ))
744         {
745             _fontEmphasisMark = awt::FontEmphasisMark::CIRCLE;
746         }
747         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("disc") ))
748         {
749             _fontEmphasisMark = awt::FontEmphasisMark::DISC;
750         }
751         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("accent") ))
752         {
753             _fontEmphasisMark = awt::FontEmphasisMark::ACCENT;
754         }
755         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("above") ))
756         {
757             _fontEmphasisMark = awt::FontEmphasisMark::ABOVE;
758         }
759         else if (aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("below") ))
760         {
761             _fontEmphasisMark = awt::FontEmphasisMark::BELOW;
762         }
763         else
764         {
765             throw xml::sax::SAXException(
766                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid font-emphasismark style!") ),
767                 Reference< XInterface >(), Any() );
768         }
769         bFontImport = true;
770     }
771 
772     // ==================================================
773     if (bFontImport)
774     {
775         _hasValue |= 0x8;
776         setFontProperties( xProps );
777     }
778 
779     return bFontImport;
780 }
781 
782 //##################################################################################################
783 
784 //__________________________________________________________________________________________________
importStringProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)785 bool ImportContext::importStringProperty(
786     OUString const & rPropName, OUString const & rAttrName,
787     Reference< xml::input::XAttributes > const & xAttributes )
788 {
789     OUString aValue(
790         xAttributes->getValueByUidName(
791             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
792     if (aValue.getLength())
793     {
794         _xControlModel->setPropertyValue( rPropName, makeAny( aValue ) );
795         return true;
796     }
797     return false;
798 }
799 //__________________________________________________________________________________________________
importDoubleProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)800 bool ImportContext::importDoubleProperty(
801     OUString const & rPropName, OUString const & rAttrName,
802     Reference< xml::input::XAttributes > const & xAttributes )
803 {
804     OUString aValue(
805         xAttributes->getValueByUidName(
806             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
807     if (aValue.getLength())
808     {
809         _xControlModel->setPropertyValue( rPropName, makeAny( aValue.toDouble() ) );
810         return true;
811     }
812     return false;
813 }
814 //__________________________________________________________________________________________________
importBooleanProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)815 bool ImportContext::importBooleanProperty(
816     OUString const & rPropName, OUString const & rAttrName,
817     Reference< xml::input::XAttributes > const & xAttributes )
818 {
819     sal_Bool bBool;
820     if (getBoolAttr(
821             &bBool, rAttrName, xAttributes, _pImport->XMLNS_DIALOGS_UID ))
822     {
823         _xControlModel->setPropertyValue( rPropName, makeAny( bBool ) );
824         return true;
825     }
826     return false;
827 }
828 //__________________________________________________________________________________________________
importLongProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)829 bool ImportContext::importLongProperty(
830     OUString const & rPropName, OUString const & rAttrName,
831     Reference< xml::input::XAttributes > const & xAttributes )
832 {
833     OUString aValue(
834         xAttributes->getValueByUidName(
835             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
836     if (aValue.getLength())
837     {
838         _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
839         return true;
840     }
841     return false;
842 }
843 //__________________________________________________________________________________________________
importLongProperty(sal_Int32 nOffset,OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)844 bool ImportContext::importLongProperty(
845     sal_Int32 nOffset,
846     OUString const & rPropName, OUString const & rAttrName,
847     Reference< xml::input::XAttributes > const & xAttributes )
848 {
849     OUString aValue(
850         xAttributes->getValueByUidName(
851             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
852     if (aValue.getLength())
853     {
854         _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) + nOffset ) );
855         return true;
856     }
857     return false;
858 }
859 //__________________________________________________________________________________________________
importHexLongProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)860 bool ImportContext::importHexLongProperty(
861     OUString const & rPropName, OUString const & rAttrName,
862     Reference< xml::input::XAttributes > const & xAttributes )
863 {
864     OUString aValue(
865         xAttributes->getValueByUidName(
866             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
867     if (aValue.getLength())
868     {
869         _xControlModel->setPropertyValue( rPropName, makeAny( toInt32( aValue ) ) );
870         return true;
871     }
872     return false;
873 }
874 //__________________________________________________________________________________________________
importShortProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)875 bool ImportContext::importShortProperty(
876     OUString const & rPropName, OUString const & rAttrName,
877     Reference< xml::input::XAttributes > const & xAttributes )
878 {
879     OUString aValue(
880         xAttributes->getValueByUidName(
881             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
882     if (aValue.getLength())
883     {
884         _xControlModel->setPropertyValue( rPropName, makeAny( (sal_Int16)toInt32( aValue ) ) );
885         return true;
886     }
887     return false;
888 }
889 //__________________________________________________________________________________________________
importAlignProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)890 bool ImportContext::importAlignProperty(
891     OUString const & rPropName, OUString const & rAttrName,
892     Reference< xml::input::XAttributes > const & xAttributes )
893 {
894     OUString aAlign(
895         xAttributes->getValueByUidName(
896             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
897     if (aAlign.getLength())
898     {
899         sal_Int16 nAlign;
900         if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left") ))
901         {
902             nAlign = 0;
903         }
904         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") ))
905         {
906             nAlign = 1;
907         }
908         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right") ))
909         {
910             nAlign = 2;
911         }
912         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
913         {
914             nAlign = 0; // default
915         }
916         else
917         {
918             throw xml::sax::SAXException(
919                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid align value!") ),
920                 Reference< XInterface >(), Any() );
921         }
922 
923         _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
924         return true;
925     }
926     return false;
927 }
928 //__________________________________________________________________________________________________
importVerticalAlignProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)929 bool ImportContext::importVerticalAlignProperty(
930     OUString const & rPropName, OUString const & rAttrName,
931     Reference< xml::input::XAttributes > const & xAttributes )
932 {
933     OUString aAlign(
934         xAttributes->getValueByUidName(
935             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
936     if (aAlign.getLength())
937     {
938         style::VerticalAlignment eAlign;
939 
940         if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top") ))
941         {
942             eAlign = style::VerticalAlignment_TOP;
943         }
944         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") ))
945         {
946             eAlign = style::VerticalAlignment_MIDDLE;
947         }
948         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom") ))
949         {
950             eAlign = style::VerticalAlignment_BOTTOM;
951         }
952         else
953         {
954             throw xml::sax::SAXException(
955                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid vertical align value!") ),
956                 Reference< XInterface >(), Any() );
957         }
958 
959         _xControlModel->setPropertyValue( rPropName, makeAny( eAlign ) );
960         return true;
961     }
962     return false;
963 }
964 //__________________________________________________________________________________________________
importImageAlignProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)965 bool ImportContext::importImageAlignProperty(
966     OUString const & rPropName, OUString const & rAttrName,
967     Reference< xml::input::XAttributes > const & xAttributes )
968 {
969     OUString aAlign(
970         xAttributes->getValueByUidName(
971             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
972     if (aAlign.getLength())
973     {
974         sal_Int16 nAlign;
975         if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left") ))
976         {
977             nAlign = 0;
978         }
979         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top") ))
980         {
981             nAlign = 1;
982         }
983         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right") ))
984         {
985             nAlign = 2;
986         }
987         else if (aAlign.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom") ))
988         {
989             nAlign = 3;
990         }
991         else
992         {
993             throw xml::sax::SAXException(
994                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid image align value!") ),
995                 Reference< XInterface >(), Any() );
996         }
997 
998         _xControlModel->setPropertyValue( rPropName, makeAny( nAlign ) );
999         return true;
1000     }
1001     return false;
1002 }
1003 //__________________________________________________________________________________________________
importImagePositionProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1004 bool ImportContext::importImagePositionProperty(
1005     OUString const & rPropName, OUString const & rAttrName,
1006     Reference< xml::input::XAttributes > const & xAttributes )
1007 {
1008     OUString aPosition(
1009         xAttributes->getValueByUidName(
1010             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1011     if (aPosition.getLength())
1012     {
1013         sal_Int16 nPosition;
1014         if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-top") ))
1015         {
1016             nPosition = awt::ImagePosition::LeftTop;
1017         }
1018         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-center") ))
1019         {
1020             nPosition = awt::ImagePosition::LeftCenter;
1021         }
1022         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("left-bottom") ))
1023         {
1024             nPosition = awt::ImagePosition::LeftBottom;
1025         }
1026         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-top") ))
1027         {
1028             nPosition = awt::ImagePosition::RightTop;
1029         }
1030         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-center") ))
1031         {
1032             nPosition = awt::ImagePosition::RightCenter;
1033         }
1034         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("right-bottom") ))
1035         {
1036             nPosition = awt::ImagePosition::RightBottom;
1037         }
1038         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-left") ))
1039         {
1040             nPosition = awt::ImagePosition::AboveLeft;
1041         }
1042         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-center") ))
1043         {
1044             nPosition = awt::ImagePosition::AboveCenter;
1045         }
1046         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("top-right") ))
1047         {
1048             nPosition = awt::ImagePosition::AboveRight;
1049         }
1050         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-left") ))
1051         {
1052             nPosition = awt::ImagePosition::BelowLeft;
1053         }
1054         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-center") ))
1055         {
1056             nPosition = awt::ImagePosition::BelowCenter;
1057         }
1058         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("bottom-right") ))
1059         {
1060             nPosition = awt::ImagePosition::BelowRight;
1061         }
1062         else if (aPosition.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("center") ))
1063         {
1064             nPosition = awt::ImagePosition::Centered;
1065         }
1066         else
1067         {
1068             throw xml::sax::SAXException(
1069                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid image position value!") ),
1070                 Reference< XInterface >(), Any() );
1071         }
1072 
1073         _xControlModel->setPropertyValue( rPropName, makeAny( nPosition ) );
1074         return true;
1075     }
1076     return false;
1077 }
1078 //__________________________________________________________________________________________________
importButtonTypeProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1079 bool ImportContext::importButtonTypeProperty(
1080     OUString const & rPropName, OUString const & rAttrName,
1081     Reference< xml::input::XAttributes > const & xAttributes )
1082 {
1083     OUString buttonType(
1084         xAttributes->getValueByUidName(
1085             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1086     if (buttonType.getLength())
1087     {
1088         sal_Int16 nButtonType;
1089         if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("standard") ))
1090         {
1091             nButtonType = awt::PushButtonType_STANDARD;
1092         }
1093         else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ok") ))
1094         {
1095             nButtonType = awt::PushButtonType_OK;
1096         }
1097         else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("cancel") ))
1098         {
1099             nButtonType = awt::PushButtonType_CANCEL;
1100         }
1101         else if (buttonType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("help") ))
1102         {
1103             nButtonType = awt::PushButtonType_HELP;
1104         }
1105         else
1106         {
1107             throw xml::sax::SAXException(
1108                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid button-type value!") ),
1109                 Reference< XInterface >(), Any() );
1110         }
1111 
1112         _xControlModel->setPropertyValue( rPropName, makeAny( nButtonType ) );
1113         return true;
1114     }
1115     return false;
1116 }
1117 //__________________________________________________________________________________________________
importDateFormatProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1118 bool ImportContext::importDateFormatProperty(
1119     OUString const & rPropName, OUString const & rAttrName,
1120     Reference< xml::input::XAttributes > const & xAttributes )
1121 {
1122     OUString aFormat(
1123         xAttributes->getValueByUidName(
1124             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1125     if (aFormat.getLength())
1126     {
1127         sal_Int16 nFormat;
1128         if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short") ))
1129         {
1130             nFormat = 0;
1131         }
1132         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short_YY") ))
1133         {
1134             nFormat = 1;
1135         }
1136         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_short_YYYY") ))
1137         {
1138             nFormat = 2;
1139         }
1140         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("system_long") ))
1141         {
1142             nFormat = 3;
1143         }
1144         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_DDMMYY") ))
1145         {
1146             nFormat = 4;
1147         }
1148         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_MMDDYY") ))
1149         {
1150             nFormat = 5;
1151         }
1152         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYMMDD") ))
1153         {
1154             nFormat = 6;
1155         }
1156         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_DDMMYYYY") ))
1157         {
1158             nFormat = 7;
1159         }
1160         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_MMDDYYYY") ))
1161         {
1162             nFormat = 8;
1163         }
1164         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYYYMMDD") ))
1165         {
1166             nFormat = 9;
1167         }
1168         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYMMDD_DIN5008") ))
1169         {
1170             nFormat = 10;
1171         }
1172         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short_YYYYMMDD_DIN5008") ))
1173         {
1174             nFormat = 11;
1175         }
1176         else
1177         {
1178             throw xml::sax::SAXException(
1179                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid date-format value!") ),
1180                 Reference< XInterface >(), Any() );
1181         }
1182 
1183         _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1184         return true;
1185     }
1186     return false;
1187 }
1188 //__________________________________________________________________________________________________
importTimeFormatProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1189 bool ImportContext::importTimeFormatProperty(
1190     OUString const & rPropName, OUString const & rAttrName,
1191     Reference< xml::input::XAttributes > const & xAttributes )
1192 {
1193     OUString aFormat(
1194         xAttributes->getValueByUidName(
1195             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1196     if (aFormat.getLength())
1197     {
1198         sal_Int16 nFormat;
1199         if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("24h_short") ))
1200         {
1201             nFormat = 0;
1202         }
1203         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("24h_long") ))
1204         {
1205             nFormat = 1;
1206         }
1207         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("12h_short") ))
1208         {
1209             nFormat = 2;
1210         }
1211         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("12h_long") ))
1212         {
1213             nFormat = 3;
1214         }
1215         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Duration_short") ))
1216         {
1217             nFormat = 4;
1218         }
1219         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Duration_long") ))
1220         {
1221             nFormat = 5;
1222         }
1223         else
1224         {
1225             throw xml::sax::SAXException(
1226                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid time-format value!") ),
1227                 Reference< XInterface >(), Any() );
1228         }
1229 
1230         _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1231         return true;
1232     }
1233     return false;
1234 }
1235 //__________________________________________________________________________________________________
importOrientationProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1236 bool ImportContext::importOrientationProperty(
1237     OUString const & rPropName, OUString const & rAttrName,
1238     Reference< xml::input::XAttributes > const & xAttributes )
1239 {
1240     OUString aOrient(
1241         xAttributes->getValueByUidName(
1242             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1243     if (aOrient.getLength())
1244     {
1245         sal_Int32 nOrient;
1246         if (aOrient.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("horizontal") ))
1247         {
1248             nOrient = 0;
1249         }
1250         else if (aOrient.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("vertical") ))
1251         {
1252             nOrient = 1;
1253         }
1254         else
1255         {
1256             throw xml::sax::SAXException(
1257                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid orientation value!") ),
1258                 Reference< XInterface >(), Any() );
1259         }
1260 
1261         _xControlModel->setPropertyValue( rPropName, makeAny( nOrient ) );
1262         return true;
1263     }
1264     return false;
1265 }
1266 //__________________________________________________________________________________________________
importLineEndFormatProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1267 bool ImportContext::importLineEndFormatProperty(
1268     OUString const & rPropName, OUString const & rAttrName,
1269     Reference< xml::input::XAttributes > const & xAttributes )
1270 {
1271     OUString aFormat(
1272         xAttributes->getValueByUidName(
1273             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1274     if (aFormat.getLength())
1275     {
1276         sal_Int16 nFormat;
1277         if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("carriage-return") ))
1278         {
1279             nFormat = awt::LineEndFormat::CARRIAGE_RETURN;
1280         }
1281         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("line-feed") ))
1282         {
1283             nFormat = awt::LineEndFormat::LINE_FEED;
1284         }
1285         else if (aFormat.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("carriage-return-line-feed") ))
1286         {
1287             nFormat = awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED;
1288         }
1289         else
1290         {
1291             throw xml::sax::SAXException(
1292                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid line end format value!") ),
1293                 Reference< XInterface >(), Any() );
1294         }
1295 
1296         _xControlModel->setPropertyValue( rPropName, makeAny( nFormat ) );
1297         return true;
1298     }
1299     return false;
1300 }
1301 //__________________________________________________________________________________________________
importSelectionTypeProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1302 bool ImportContext::importSelectionTypeProperty(
1303     OUString const & rPropName, OUString const & rAttrName,
1304     Reference< xml::input::XAttributes > const & xAttributes )
1305 {
1306     OUString aSelectionType(
1307         xAttributes->getValueByUidName(
1308             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1309     if (aSelectionType.getLength())
1310     {
1311         view::SelectionType eSelectionType;
1312 
1313         if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
1314         {
1315             eSelectionType = view::SelectionType_NONE;
1316         }
1317         else if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("single") ))
1318         {
1319             eSelectionType = view::SelectionType_SINGLE;
1320         }
1321         else if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("multi") ))
1322         {
1323             eSelectionType = view::SelectionType_MULTI;
1324         }
1325         else  if (aSelectionType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("range") ))
1326         {
1327             eSelectionType = view::SelectionType_RANGE;
1328         }
1329         else
1330         {
1331             throw xml::sax::SAXException(
1332                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid selection type value!") ),
1333                 Reference< XInterface >(), Any() );
1334         }
1335 
1336         _xControlModel->setPropertyValue( rPropName, makeAny( eSelectionType ) );
1337         return true;
1338     }
1339     return false;
1340 }
1341 
1342 //__________________________________________________________________________________________________
importImageScaleModeProperty(OUString const & rPropName,OUString const & rAttrName,Reference<xml::input::XAttributes> const & xAttributes)1343 bool ImportContext::importImageScaleModeProperty(
1344     OUString const & rPropName, OUString const & rAttrName,
1345     Reference< xml::input::XAttributes > const & xAttributes )
1346 {
1347     OUString aImageScaleMode(
1348         xAttributes->getValueByUidName(
1349             _pImport->XMLNS_DIALOGS_UID, rAttrName ) );
1350     if (!aImageScaleMode.isEmpty())
1351     {
1352         sal_Int16 nImageScaleMode;
1353 
1354         if (aImageScaleMode.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("none") ))
1355         {
1356             nImageScaleMode = awt::ImageScaleMode::NONE;
1357         }
1358         else if (aImageScaleMode.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("isotropic") ))
1359         {
1360             nImageScaleMode = awt::ImageScaleMode::ISOTROPIC;
1361         }
1362         else if (aImageScaleMode.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("anisotropic") ))
1363         {
1364             nImageScaleMode = awt::ImageScaleMode::ANISOTROPIC;
1365         }
1366         else
1367         {
1368             throw xml::sax::SAXException(
1369                 OUString( RTL_CONSTASCII_USTRINGPARAM("invalid scale image mode value!") ),
1370                 Reference< XInterface >(), Any() );
1371         }
1372 
1373         _xControlModel->setPropertyValue( rPropName, makeAny( nImageScaleMode ) );
1374         return true;
1375     }
1376     return false;
1377 }
1378 
1379 //==================================================================================================
1380 struct StringTriple
1381 {
1382     char const * first;
1383     char const * second;
1384     char const * third;
1385 };
1386 static StringTriple const s_aEventTranslations[] =
1387 {
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     { 0, 0, 0 }
1424 };
1425 extern StringTriple const * const g_pEventTranslations;
1426 StringTriple const * const g_pEventTranslations = s_aEventTranslations;
1427 
1428 //__________________________________________________________________________________________________
importEvents(::std::vector<Reference<xml::input::XElement>> const & rEvents)1429 void ImportContext::importEvents(
1430     ::std::vector< Reference< xml::input::XElement > > const & rEvents )
1431 {
1432     Reference< script::XScriptEventsSupplier > xSupplier(
1433         _xControlModel, UNO_QUERY );
1434     if (xSupplier.is())
1435     {
1436         Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1437         if (xEvents.is())
1438         {
1439             for ( size_t nPos = 0; nPos < rEvents.size(); ++nPos )
1440             {
1441                 script::ScriptEventDescriptor descr;
1442 
1443                 EventElement * pEventElement = static_cast< EventElement * >( rEvents[ nPos ].get() );
1444                 sal_Int32 nUid = pEventElement->getUid();
1445                 OUString aLocalName( pEventElement->getLocalName() );
1446                 Reference< xml::input::XAttributes > xAttributes(
1447                     pEventElement->getAttributes() );
1448 
1449                 // nowadays script events
1450                 if (_pImport->XMLNS_SCRIPT_UID == nUid)
1451                 {
1452                     if (!getStringAttr( &descr.ScriptType,
1453                                         OUString( RTL_CONSTASCII_USTRINGPARAM(
1454                                                       "language") ),
1455                                         xAttributes,
1456                                         _pImport->XMLNS_SCRIPT_UID ) ||
1457                         !getStringAttr( &descr.ScriptCode,
1458                                         OUString( RTL_CONSTASCII_USTRINGPARAM(
1459                                                       "macro-name") ),
1460                                         xAttributes,
1461                                         _pImport->XMLNS_SCRIPT_UID ))
1462                     {
1463                         throw xml::sax::SAXException(
1464                             OUString( RTL_CONSTASCII_USTRINGPARAM(
1465                                           "missing language or macro-name "
1466                                           "attribute(s) of event!") ),
1467                             Reference< XInterface >(), Any() );
1468                     }
1469                     if ( descr.ScriptType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" ) ) ) )
1470                     {
1471                         OUString aLocation;
1472                         if (getStringAttr( &aLocation,
1473                                            OUString( RTL_CONSTASCII_USTRINGPARAM(
1474                                                          "location") ),
1475                                            xAttributes,
1476                                            _pImport->XMLNS_SCRIPT_UID ))
1477                         {
1478                             // prepend location
1479                             ::rtl::OUStringBuffer buf;
1480                             buf.append( aLocation );
1481                             buf.append( (sal_Unicode)':' );
1482                             buf.append( descr.ScriptCode );
1483                             descr.ScriptCode = buf.makeStringAndClear();
1484                         }
1485                     }
1486                     else if ( descr.ScriptType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM( "Script" ) ) ) )
1487                     {
1488                         // Check if there is a protocol, if not assume
1489                         // this is an early scripting framework url ( without
1490                         // the protocol ) and fix it up!!
1491                         if ( descr.ScriptCode.indexOf( ':' ) == -1 )
1492                         {
1493                             ::rtl::OUStringBuffer buf;
1494                             buf.append( OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.script:" ) ) );
1495                             buf.append( descr.ScriptCode );
1496                             descr.ScriptCode = buf.makeStringAndClear();
1497                         }
1498                     }
1499 
1500                     // script:event element
1501                     if (aLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("event") ))
1502                     {
1503                         OUString aEventName;
1504                         if (! getStringAttr(
1505                                 &aEventName,
1506                                 OUString(
1507                                     RTL_CONSTASCII_USTRINGPARAM("event-name") ),
1508                                 xAttributes,
1509                                 _pImport->XMLNS_SCRIPT_UID ))
1510                         {
1511                             throw xml::sax::SAXException(
1512                                 OUString(
1513                                     RTL_CONSTASCII_USTRINGPARAM(
1514                                         "missing event-name attribute!") ),
1515                                 Reference< XInterface >(), Any() );
1516                         }
1517 
1518                         // lookup in table
1519                         ::rtl::OString str(
1520                             ::rtl::OUStringToOString(
1521                                 aEventName, RTL_TEXTENCODING_ASCII_US ) );
1522                         StringTriple const * p = g_pEventTranslations;
1523                         while (p->first)
1524                         {
1525                             if (0 == ::rtl_str_compare( p->third, str.getStr() ))
1526                             {
1527                                 descr.ListenerType = OUString(
1528                                     p->first, ::rtl_str_getLength( p->first ),
1529                                     RTL_TEXTENCODING_ASCII_US );
1530                                 descr.EventMethod = OUString(
1531                                     p->second, ::rtl_str_getLength( p->second ),
1532                                     RTL_TEXTENCODING_ASCII_US );
1533                                 break;
1534                             }
1535                             ++p;
1536                         }
1537 
1538                         if (! p->first)
1539                         {
1540                             throw xml::sax::SAXException(
1541                                 OUString( RTL_CONSTASCII_USTRINGPARAM("no matching event-name found!") ),
1542                                 Reference< XInterface >(), Any() );
1543                         }
1544                     }
1545                     else // script:listener-event element
1546                     {
1547                         OSL_ASSERT( aLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("listener-event") ) );
1548 
1549                         if (!getStringAttr(
1550                                 &descr.ListenerType,
1551                                 OUString( RTL_CONSTASCII_USTRINGPARAM(
1552                                               "listener-type") ),
1553                                 xAttributes,
1554                                 _pImport->XMLNS_SCRIPT_UID ) ||
1555                             !getStringAttr(
1556                                 &descr.EventMethod,
1557                                 OUString( RTL_CONSTASCII_USTRINGPARAM(
1558                                               "listener-method") ),
1559                                 xAttributes, _pImport->XMLNS_SCRIPT_UID ))
1560                         {
1561                             throw xml::sax::SAXException(
1562                                 OUString(
1563                                     RTL_CONSTASCII_USTRINGPARAM(
1564                                         "missing listener-type or "
1565                                         "listener-method attribute(s)!") ),
1566                                 Reference< XInterface >(), Any() );
1567                         }
1568                         // optional listener param
1569                         getStringAttr(
1570                             &descr.AddListenerParam,
1571                             OUString( RTL_CONSTASCII_USTRINGPARAM(
1572                                           "listener-param") ),
1573                             xAttributes, _pImport->XMLNS_SCRIPT_UID );
1574                     }
1575                 }
1576                 else // deprecated dlg:event element
1577                 {
1578                     OSL_ASSERT(
1579                         _pImport->XMLNS_DIALOGS_UID == nUid &&
1580                         aLocalName.equalsAsciiL(
1581                             RTL_CONSTASCII_STRINGPARAM("event") ) );
1582 
1583                     if (!getStringAttr( &descr.ListenerType,
1584                                         OUString( RTL_CONSTASCII_USTRINGPARAM(
1585                                                       "listener-type") ),
1586                                         xAttributes,
1587                                         _pImport->XMLNS_DIALOGS_UID ) ||
1588                         !getStringAttr( &descr.EventMethod,
1589                                         OUString( RTL_CONSTASCII_USTRINGPARAM(
1590                                                       "event-method") ),
1591                                         xAttributes,
1592                                         _pImport->XMLNS_DIALOGS_UID ))
1593                     {
1594                         throw xml::sax::SAXException(
1595                             OUString( RTL_CONSTASCII_USTRINGPARAM("missing listener-type or event-method attribute(s)!") ),
1596                             Reference< XInterface >(), Any() );
1597                     }
1598 
1599                     getStringAttr(
1600                         &descr.ScriptType,
1601                         OUString( RTL_CONSTASCII_USTRINGPARAM("script-type") ),
1602                         xAttributes, _pImport->XMLNS_DIALOGS_UID );
1603                     getStringAttr(
1604                         &descr.ScriptCode,
1605                         OUString( RTL_CONSTASCII_USTRINGPARAM("script-code") ),
1606                         xAttributes, _pImport->XMLNS_DIALOGS_UID );
1607                     getStringAttr(
1608                         &descr.AddListenerParam,
1609                         OUString( RTL_CONSTASCII_USTRINGPARAM("param") ),
1610                         xAttributes, _pImport->XMLNS_DIALOGS_UID );
1611                 }
1612 
1613                 ::rtl::OUStringBuffer buf;
1614                 buf.append( descr.ListenerType );
1615                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("::") );
1616                 buf.append( descr.EventMethod );
1617                 xEvents->insertByName( buf.makeStringAndClear(), makeAny( descr ) );
1618             }
1619         }
1620     }
1621 }
1622 //__________________________________________________________________________________________________
importDefaults(sal_Int32 nBaseX,sal_Int32 nBaseY,Reference<xml::input::XAttributes> const & xAttributes,bool supportPrintable)1623 void ImportContext::importDefaults(
1624     sal_Int32 nBaseX, sal_Int32 nBaseY,
1625     Reference< xml::input::XAttributes > const & xAttributes,
1626     bool supportPrintable )
1627 {
1628     _xControlModel->setPropertyValue(
1629         OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ),
1630         makeAny( _aId ) );
1631 
1632     importShortProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("TabIndex") ),
1633                          OUString( RTL_CONSTASCII_USTRINGPARAM("tab-index") ),
1634                          xAttributes );
1635 
1636     sal_Bool bDisable = sal_False;
1637     if (getBoolAttr(
1638             &bDisable, OUString( RTL_CONSTASCII_USTRINGPARAM("disabled") ),
1639             xAttributes, _pImport->XMLNS_DIALOGS_UID ) &&
1640         bDisable)
1641     {
1642         _xControlModel->setPropertyValue(
1643             OUString( RTL_CONSTASCII_USTRINGPARAM("Enabled") ), makeAny( sal_False ) );
1644     }
1645 
1646     sal_Bool bVisible = sal_True;
1647     if (getBoolAttr(
1648             &bVisible, OUString( RTL_CONSTASCII_USTRINGPARAM("visible") ),
1649             xAttributes, _pImport->XMLNS_DIALOGS_UID ) && !bVisible)
1650     {
1651     try
1652     {
1653 
1654             _xControlModel->setPropertyValue(
1655                     OUString( RTL_CONSTASCII_USTRINGPARAM("EnableVisible") ), makeAny( sal_False ) );
1656     }
1657     catch( Exception& )
1658     {
1659         DBG_UNHANDLED_EXCEPTION();
1660     }
1661     }
1662 
1663     if (!importLongProperty( nBaseX,
1664                              OUString( RTL_CONSTASCII_USTRINGPARAM("PositionX") ),
1665                              OUString( RTL_CONSTASCII_USTRINGPARAM("left") ),
1666                              xAttributes ) ||
1667         !importLongProperty( nBaseY,
1668                              OUString( RTL_CONSTASCII_USTRINGPARAM("PositionY") ),
1669                              OUString( RTL_CONSTASCII_USTRINGPARAM("top") ),
1670                              xAttributes ) ||
1671         !importLongProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ),
1672                              OUString( RTL_CONSTASCII_USTRINGPARAM("width") ),
1673                              xAttributes ) ||
1674         !importLongProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ),
1675                              OUString( RTL_CONSTASCII_USTRINGPARAM("height") ),
1676                              xAttributes ))
1677     {
1678         throw xml::sax::SAXException(
1679             OUString( RTL_CONSTASCII_USTRINGPARAM("missing pos size attribute(s)!") ),
1680             Reference< XInterface >(), Any() );
1681     }
1682 
1683     if (supportPrintable)
1684     {
1685         importBooleanProperty(
1686             OUString( RTL_CONSTASCII_USTRINGPARAM("Printable") ),
1687             OUString( RTL_CONSTASCII_USTRINGPARAM("printable") ),
1688             xAttributes );
1689     }
1690 
1691     sal_Int32 nLong;
1692     if (! getLongAttr(
1693             &nLong,
1694             OUString( RTL_CONSTASCII_USTRINGPARAM("page") ),
1695             xAttributes, _pImport->XMLNS_DIALOGS_UID ))
1696     {
1697         nLong = 0;
1698     }
1699     _xControlModel->setPropertyValue(
1700         OUString( RTL_CONSTASCII_USTRINGPARAM("Step") ),
1701         makeAny( nLong ) );
1702 
1703     importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("Tag") ),
1704                           OUString( RTL_CONSTASCII_USTRINGPARAM("tag") ),
1705                           xAttributes );
1706     importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpText") ),
1707                           OUString( RTL_CONSTASCII_USTRINGPARAM("help-text") ),
1708                           xAttributes );
1709     importStringProperty( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpURL") ),
1710                           OUString( RTL_CONSTASCII_USTRINGPARAM("help-url") ),
1711                           xAttributes );
1712 }
1713 
1714 //##################################################################################################
1715 
1716 //__________________________________________________________________________________________________
getParent()1717 Reference< xml::input::XElement > ElementBase::getParent()
1718 {
1719     return static_cast< xml::input::XElement * >( _pParent );
1720 }
1721 //__________________________________________________________________________________________________
getLocalName()1722 OUString ElementBase::getLocalName()
1723 {
1724     return _aLocalName;
1725 }
1726 //__________________________________________________________________________________________________
getUid()1727 sal_Int32 ElementBase::getUid()
1728 {
1729     return _nUid;
1730 }
1731 //__________________________________________________________________________________________________
getAttributes()1732 Reference< xml::input::XAttributes > ElementBase::getAttributes()
1733 {
1734     return _xAttributes;
1735 }
1736 //__________________________________________________________________________________________________
ignorableWhitespace(OUString const &)1737 void ElementBase::ignorableWhitespace(
1738     OUString const & /*rWhitespaces*/ )
1739 {
1740     // not used
1741 }
1742 //__________________________________________________________________________________________________
characters(OUString const &)1743 void ElementBase::characters( OUString const & /*rChars*/ )
1744 {
1745     // not used, all characters ignored
1746 }
1747 //__________________________________________________________________________________________________
endElement()1748 void ElementBase::endElement()
1749 {
1750 }
1751 //______________________________________________________________________________
processingInstruction(OUString const &,OUString const &)1752 void ElementBase::processingInstruction(
1753     OUString const & /*Target*/, OUString const & /*Data*/ )
1754 {
1755 }
1756 //__________________________________________________________________________________________________
startChildElement(sal_Int32,OUString const &,Reference<xml::input::XAttributes> const &)1757 Reference< xml::input::XElement > ElementBase::startChildElement(
1758     sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
1759     Reference< xml::input::XAttributes > const & /*xAttributes*/ )
1760 {
1761     throw xml::sax::SAXException(
1762         OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
1763         Reference< XInterface >(), Any() );
1764 }
1765 
1766 //__________________________________________________________________________________________________
ElementBase(sal_Int32 nUid,OUString const & rLocalName,Reference<xml::input::XAttributes> const & xAttributes,ElementBase * pParent,DialogImport * pImport)1767 ElementBase::ElementBase(
1768     sal_Int32 nUid, OUString const & rLocalName,
1769     Reference< xml::input::XAttributes > const & xAttributes,
1770     ElementBase * pParent, DialogImport * pImport )
1771     SAL_THROW( () )
1772     : _pImport( pImport )
1773     , _pParent( pParent )
1774     , _nUid( nUid )
1775     , _aLocalName( rLocalName )
1776     , _xAttributes( xAttributes )
1777 {
1778     _pImport->acquire();
1779 
1780     if (_pParent)
1781     {
1782         _pParent->acquire();
1783     }
1784 }
1785 //__________________________________________________________________________________________________
~ElementBase()1786 ElementBase::~ElementBase()
1787     SAL_THROW( () )
1788 {
1789     _pImport->release();
1790 
1791     if (_pParent)
1792     {
1793         _pParent->release();
1794     }
1795 
1796 #if OSL_DEBUG_LEVEL > 1
1797     ::rtl::OString aStr( ::rtl::OUStringToOString(
1798                              _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
1799     OSL_TRACE( "ElementBase::~ElementBase(): %s\n", aStr.getStr() );
1800 #endif
1801 }
1802 
1803 //##################################################################################################
1804 
1805 // XRoot
1806 //
1807 
1808 //______________________________________________________________________________
startDocument(Reference<xml::input::XNamespaceMapping> const & xNamespaceMapping)1809 void DialogImport::startDocument(
1810     Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
1811 {
1812     XMLNS_DIALOGS_UID = xNamespaceMapping->getUidByUri(
1813         OUSTR(XMLNS_DIALOGS_URI) );
1814     XMLNS_SCRIPT_UID = xNamespaceMapping->getUidByUri(
1815         OUSTR(XMLNS_SCRIPT_URI) );
1816 }
1817 //__________________________________________________________________________________________________
endDocument()1818 void DialogImport::endDocument()
1819 {
1820     // ignored
1821 }
1822 //__________________________________________________________________________________________________
processingInstruction(OUString const &,OUString const &)1823 void DialogImport::processingInstruction(
1824     OUString const & /*rTarget*/, OUString const & /*rData*/ )
1825 {
1826     // ignored for now: xxx todo
1827 }
1828 //__________________________________________________________________________________________________
setDocumentLocator(Reference<xml::sax::XLocator> const &)1829 void DialogImport::setDocumentLocator(
1830     Reference< xml::sax::XLocator > const & /*xLocator*/ )
1831 {
1832     // ignored for now: xxx todo
1833 }
1834 //__________________________________________________________________________________________________
startRootElement(sal_Int32 nUid,OUString const & rLocalName,Reference<xml::input::XAttributes> const & xAttributes)1835 Reference< xml::input::XElement > DialogImport::startRootElement(
1836     sal_Int32 nUid, OUString const & rLocalName,
1837     Reference< xml::input::XAttributes > const & xAttributes )
1838 {
1839     if (XMLNS_DIALOGS_UID != nUid)
1840     {
1841         throw xml::sax::SAXException(
1842             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
1843             Reference< XInterface >(), Any() );
1844     }
1845     // window
1846     else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("window") ))
1847     {
1848         return new WindowElement( rLocalName, xAttributes, 0, this );
1849     }
1850     else
1851     {
1852         throw xml::sax::SAXException(
1853             OUString( RTL_CONSTASCII_USTRINGPARAM(
1854                           "illegal root element (expected window) given: ") ) +
1855             rLocalName, Reference< XInterface >(), Any() );
1856     }
1857 }
1858 //__________________________________________________________________________________________________
~DialogImport()1859 DialogImport::~DialogImport()
1860     SAL_THROW( () )
1861 {
1862 #if OSL_DEBUG_LEVEL > 1
1863     OSL_TRACE( "DialogImport::~DialogImport().\n" );
1864 #endif
1865 }
1866 //__________________________________________________________________________________________________
getNumberFormatsSupplier()1867 Reference< util::XNumberFormatsSupplier > const & DialogImport::getNumberFormatsSupplier()
1868 {
1869     if (! _xSupplier.is())
1870     {
1871         Reference< XComponentContext > xContext( getComponentContext() );
1872         Reference< util::XNumberFormatsSupplier > xSupplier(
1873             xContext->getServiceManager()->createInstanceWithContext(
1874                 OUString( RTL_CONSTASCII_USTRINGPARAM(
1875                               "com.sun.star.util.NumberFormatsSupplier") ),
1876                 xContext ), UNO_QUERY );
1877 
1878         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1879         if (! _xSupplier.is())
1880         {
1881             _xSupplier = xSupplier;
1882         }
1883     }
1884     return _xSupplier;
1885 }
1886 
1887 //__________________________________________________________________________________________________
addStyle(OUString const & rStyleId,Reference<xml::input::XElement> const & xStyle)1888 void DialogImport::addStyle(
1889     OUString const & rStyleId,
1890     Reference< xml::input::XElement > const & xStyle )
1891     SAL_THROW( () )
1892 {
1893     _styleNames.push_back( rStyleId );
1894     _styles.push_back( xStyle );
1895 }
1896 //__________________________________________________________________________________________________
getStyle(OUString const & rStyleId) const1897 Reference< xml::input::XElement > DialogImport::getStyle(
1898     OUString const & rStyleId ) const
1899     SAL_THROW( () )
1900 {
1901     for ( size_t nPos = 0; nPos < _styleNames.size(); ++nPos )
1902     {
1903         if (_styleNames[ nPos ] == rStyleId)
1904         {
1905             return _styles[ nPos ];
1906         }
1907     }
1908     return 0;
1909 }
1910 
1911 //##################################################################################################
1912 
1913 //==================================================================================================
importDialogModel(Reference<container::XNameContainer> const & xDialogModel,Reference<XComponentContext> const & xContext)1914 Reference< xml::sax::XDocumentHandler > SAL_CALL importDialogModel(
1915     Reference< container::XNameContainer > const & xDialogModel,
1916     Reference< XComponentContext > const & xContext )
1917 {
1918     return ::xmlscript::createDocumentHandler(
1919         static_cast< xml::input::XRoot * >(
1920             new DialogImport( xContext, xDialogModel ) ) );
1921 }
1922 
1923 }
1924