bump product version to 5.0.4.1
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_export.cxx
blob129d87b34b45e4468369a6a6bf8205275205d37b
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 "exp_share.hxx"
22 #include <rtl/ustrbuf.hxx>
23 #include <sal/log.hxx>
24 #include <tools/diagnose_ex.h>
26 #include <com/sun/star/awt/CharSet.hpp>
27 #include <com/sun/star/awt/FontFamily.hpp>
28 #include <com/sun/star/awt/FontPitch.hpp>
29 #include <com/sun/star/awt/FontSlant.hpp>
30 #include <com/sun/star/awt/FontStrikeout.hpp>
31 #include <com/sun/star/awt/FontType.hpp>
32 #include <com/sun/star/awt/FontUnderline.hpp>
33 #include <com/sun/star/awt/FontWeight.hpp>
34 #include <com/sun/star/awt/FontWidth.hpp>
35 #include <com/sun/star/awt/ImagePosition.hpp>
36 #include <com/sun/star/awt/ImageScaleMode.hpp>
37 #include <com/sun/star/awt/LineEndFormat.hpp>
38 #include <com/sun/star/awt/PushButtonType.hpp>
39 #include <com/sun/star/awt/VisualEffect.hpp>
40 #include <com/sun/star/util/Date.hpp>
41 #include <com/sun/star/util/Time.hpp>
42 #include <tools/date.hxx>
43 #include <tools/time.hxx>
45 #include <com/sun/star/io/XPersistObject.hpp>
47 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
48 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
50 #include <com/sun/star/style/VerticalAlignment.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include <com/sun/star/lang/Locale.hpp>
55 #include <com/sun/star/util/NumberFormat.hpp>
57 #include <com/sun/star/view/SelectionType.hpp>
59 #include <com/sun/star/form/binding/XListEntrySink.hpp>
60 #include <com/sun/star/form/binding/XBindableValue.hpp>
61 #include <com/sun/star/form/binding/XValueBinding.hpp>
62 #include <com/sun/star/table/CellAddress.hpp>
63 #include <com/sun/star/table/CellRangeAddress.hpp>
64 #include <com/sun/star/document/XStorageBasedDocument.hpp>
65 #include <com/sun/star/document/GraphicObjectResolver.hpp>
67 #include <comphelper/processfactory.hxx>
68 #include <i18nlangtag/languagetag.hxx>
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
73 namespace xmlscript
76 Reference< xml::sax::XAttributeList > Style::createElement()
78 ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" );
80 // style-id
81 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id );
83 // background-color
84 if (_set & 0x1)
86 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":background-color", "0x" + OUString::number(_backgroundColor,16));
89 // text-color
90 if (_set & 0x2)
92 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":text-color", "0x" + OUString::number(_textColor,16));
95 // textline-color
96 if (_set & 0x20)
98 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":textline-color", "0x" + OUString::number(_textLineColor,16));
101 // fill-color
102 if (_set & 0x10)
104 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":fill-color", "0x" + OUString::number(_fillColor,16));
107 // border
108 if (_set & 0x4)
110 switch (_border)
112 case BORDER_NONE:
113 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "none" );
114 break;
115 case BORDER_3D:
116 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "3d" );
117 break;
118 case BORDER_SIMPLE:
119 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "simple" );
120 break;
121 case BORDER_SIMPLE_COLOR: {
122 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "0x" + OUString::number(_borderColor,16));
123 break;
125 default:
126 SAL_WARN( "xmlscript.xmldlg", "### unexpected border value!" );
127 break;
131 // visual effect (look)
132 if (_set & 0x40)
134 switch (_visualEffect)
136 case awt::VisualEffect::NONE:
137 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "none" );
138 break;
139 case awt::VisualEffect::LOOK3D:
140 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "3d" );
141 break;
142 case awt::VisualEffect::FLAT:
143 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "simple" );
144 break;
145 default:
146 SAL_WARN( "xmlscript.xmldlg", "### unexpected visual effect value!" );
147 break;
151 // font-
152 if (_set & 0x8)
154 awt::FontDescriptor def_descr;
156 // dialog:font-name CDATA #IMPLIED
157 if (def_descr.Name != _descr.Name)
159 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-name", _descr.Name );
161 // dialog:font-height %numeric; #IMPLIED
162 if (def_descr.Height != _descr.Height)
164 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-height", OUString::number( _descr.Height ) );
166 // dialog:font-width %numeric; #IMPLIED
167 if (def_descr.Width != _descr.Width)
169 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-width", OUString::number( _descr.Width ) );
171 // dialog:font-stylename CDATA #IMPLIED
172 if (def_descr.StyleName != _descr.StyleName)
174 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-stylename", _descr.StyleName );
176 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
177 if (def_descr.Family != _descr.Family)
179 switch (_descr.Family)
181 case awt::FontFamily::DECORATIVE:
182 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "decorative" );
183 break;
184 case awt::FontFamily::MODERN:
185 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "modern" );
186 break;
187 case awt::FontFamily::ROMAN:
188 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "roman" );
189 break;
190 case awt::FontFamily::SCRIPT:
191 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "script" );
192 break;
193 case awt::FontFamily::SWISS:
194 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "swiss" );
195 break;
196 case awt::FontFamily::SYSTEM:
197 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "system" );
198 break;
199 default:
200 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-family!" );
201 break;
204 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
205 if (def_descr.CharSet != _descr.CharSet)
207 switch (_descr.CharSet)
209 case awt::CharSet::ANSI:
210 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ansi" );
211 break;
212 case awt::CharSet::MAC:
213 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "mac" );
214 break;
215 case awt::CharSet::IBMPC_437:
216 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_437" );
217 break;
218 case awt::CharSet::IBMPC_850:
219 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_850" );
220 break;
221 case awt::CharSet::IBMPC_860:
222 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_860" );
223 break;
224 case awt::CharSet::IBMPC_861:
225 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_861" );
226 break;
227 case awt::CharSet::IBMPC_863:
228 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_863" );
229 break;
230 case awt::CharSet::IBMPC_865:
231 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_865" );
232 break;
233 case awt::CharSet::SYSTEM:
234 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "system" );
235 break;
236 case awt::CharSet::SYMBOL:
237 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "symbol" );
238 break;
239 default:
240 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-charset!" );
241 break;
244 // dialog:font-pitch "(fixed|variable)" #IMPLIED
245 if (def_descr.Pitch != _descr.Pitch)
247 switch (_descr.Pitch)
249 case awt::FontPitch::FIXED:
250 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "fixed" );
251 break;
252 case awt::FontPitch::VARIABLE:
253 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "variable" );
254 break;
255 default:
256 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-pitch!" );
257 break;
260 // dialog:font-charwidth CDATA #IMPLIED
261 if (def_descr.CharacterWidth != _descr.CharacterWidth)
263 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charwidth", OUString::number( (float)_descr.CharacterWidth ) );
265 // dialog:font-weight CDATA #IMPLIED
266 if (def_descr.Weight != _descr.Weight)
268 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-weight", OUString::number( (float)_descr.Weight ) );
270 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
271 if (def_descr.Slant != _descr.Slant)
273 switch (_descr.Slant)
275 case awt::FontSlant_OBLIQUE:
276 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "oblique" );
277 break;
278 case awt::FontSlant_ITALIC:
279 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "italic" );
280 break;
281 case awt::FontSlant_REVERSE_OBLIQUE:
282 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_oblique" );
283 break;
284 case awt::FontSlant_REVERSE_ITALIC:
285 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_italic" );
286 break;
287 default:
288 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-slant!" );
289 break;
292 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
293 if (def_descr.Underline != _descr.Underline)
295 switch (_descr.Underline)
297 case awt::FontUnderline::SINGLE:
298 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "single" );
299 break;
300 case awt::FontUnderline::DOUBLE:
301 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "double" );
302 break;
303 case awt::FontUnderline::DOTTED:
304 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dotted" );
305 break;
306 case awt::FontUnderline::DASH:
307 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dash" );
308 break;
309 case awt::FontUnderline::LONGDASH:
310 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "longdash" );
311 break;
312 case awt::FontUnderline::DASHDOT:
313 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdot" );
314 break;
315 case awt::FontUnderline::DASHDOTDOT:
316 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdotdot" );
317 break;
318 case awt::FontUnderline::SMALLWAVE:
319 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "smallwave" );
320 break;
321 case awt::FontUnderline::WAVE:
322 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "wave" );
323 break;
324 case awt::FontUnderline::DOUBLEWAVE:
325 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "doublewave" );
326 break;
327 case awt::FontUnderline::BOLD:
328 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bold" );
329 break;
330 case awt::FontUnderline::BOLDDOTTED:
331 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddotted" );
332 break;
333 case awt::FontUnderline::BOLDDASH:
334 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddash" );
335 break;
336 case awt::FontUnderline::BOLDLONGDASH:
337 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldlongdash" );
338 break;
339 case awt::FontUnderline::BOLDDASHDOT:
340 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdot" );
341 break;
342 case awt::FontUnderline::BOLDDASHDOTDOT:
343 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdotdot" );
344 break;
345 case awt::FontUnderline::BOLDWAVE:
346 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldwave" );
347 break;
348 default:
349 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-underline!" );
350 break;
353 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
354 if (def_descr.Strikeout != _descr.Strikeout)
356 switch (_descr.Strikeout)
358 case awt::FontStrikeout::SINGLE:
359 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "single" );
360 break;
361 case awt::FontStrikeout::DOUBLE:
362 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "double" );
363 break;
364 case awt::FontStrikeout::BOLD:
365 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "bold" );
366 break;
367 case awt::FontStrikeout::SLASH:
368 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "slash" );
369 break;
370 case awt::FontStrikeout::X:
371 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "x" );
372 break;
373 default:
374 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-strikeout!" );
375 break;
378 // dialog:font-orientation CDATA #IMPLIED
379 if (def_descr.Orientation != _descr.Orientation)
381 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::number( (float)_descr.Orientation ) );
383 // dialog:font-kerning %boolean; #IMPLIED
384 if ((def_descr.Kerning != sal_False) != (_descr.Kerning != sal_False))
386 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
388 // dialog:font-wordlinemode %boolean; #IMPLIED
389 if ((def_descr.WordLineMode != sal_False) != (_descr.WordLineMode != sal_False))
391 pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
393 // dialog:font-type "(raster|device|scalable)" #IMPLIED
394 if (def_descr.Type != _descr.Type)
396 switch (_descr.Type)
398 case awt::FontType::RASTER:
399 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "raster" );
400 break;
401 case awt::FontType::DEVICE:
402 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "device" );
403 break;
404 case awt::FontType::SCALABLE:
405 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "scalable" );
406 break;
407 default:
408 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-type!" );
409 break;
413 // additional attributes not in FontDescriptor struct
414 // dialog:font-relief (none|embossed|engraved) #IMPLIED
415 switch (_fontRelief)
417 case awt::FontRelief::NONE: // dont export default
418 break;
419 case awt::FontRelief::EMBOSSED:
420 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "embossed" );
421 break;
422 case awt::FontRelief::ENGRAVED:
423 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "engraved" );
424 break;
425 default:
426 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-relief!" );
427 break;
429 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
430 switch (_fontEmphasisMark)
432 case awt::FontEmphasisMark::NONE: // dont export default
433 break;
434 case awt::FontEmphasisMark::DOT:
435 pStyle->addAttribute(XMLNS_DIALOGS_PREFIX ":font-emphasismark", "dot" );
436 break;
437 case awt::FontEmphasisMark::CIRCLE:
438 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "circle" );
439 break;
440 case awt::FontEmphasisMark::DISC:
441 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "disc" );
442 break;
443 case awt::FontEmphasisMark::ACCENT:
444 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "accent" );
445 break;
446 case awt::FontEmphasisMark::ABOVE:
447 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "above" );
448 break;
449 case awt::FontEmphasisMark::BELOW:
450 pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "below" );
451 break;
452 default:
453 SAL_WARN( "xmlscript.xmldlg", "### unexpected font-emphasismark!" );
454 break;
458 return pStyle;
461 void ElementDescriptor::addNumberFormatAttr(
462 Reference< beans::XPropertySet > const & xFormatProperties )
464 Reference< beans::XPropertyState > xState( xFormatProperties, UNO_QUERY );
465 OUString sFormat;
466 lang::Locale locale;
467 OSL_VERIFY( xFormatProperties->getPropertyValue( "FormatString" ) >>= sFormat );
468 OSL_VERIFY( xFormatProperties->getPropertyValue( "Locale" ) >>= locale );
470 addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
472 // format-locale
473 LanguageTag aLanguageTag( locale);
474 OUString aStr;
475 if (aLanguageTag.isIsoLocale())
477 // Old style "lll;CC" for compatibility, I really don't know what may
478 // consume this.
479 if (aLanguageTag.getCountry().isEmpty())
480 aStr = aLanguageTag.getLanguage();
481 else
482 aStr = aLanguageTag.getLanguage() + ";" + aLanguageTag.getCountry();
484 else
486 aStr = aLanguageTag.getBcp47( false);
488 addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", aStr );
491 Any ElementDescriptor::readProp( OUString const & rPropName )
493 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
495 return _xProps->getPropertyValue( rPropName );
497 return Any();
500 void ElementDescriptor::readStringAttr(
501 OUString const & rPropName, OUString const & rAttrName )
503 if (beans::PropertyState_DEFAULT_VALUE !=
504 _xPropState->getPropertyState( rPropName ))
506 Any a( _xProps->getPropertyValue( rPropName ) );
507 OUString v;
508 if (a >>= v)
509 addAttribute( rAttrName, v );
510 else
511 SAL_WARN( "xmlscript.xmldlg", "### unexpected property type!" );
515 void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
517 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
519 Any a( _xProps->getPropertyValue( rPropName ) );
520 if (a.getValueTypeClass() == TypeClass_LONG)
522 addAttribute( rAttrName, "0x" + OUString::number((sal_Int64)(sal_uInt64)*static_cast<sal_uInt32 const *>(a.getValue()),16) );
527 void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
529 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
531 Any a( _xProps->getPropertyValue( rPropName ) );
532 if (a.getValueTypeClass() == TypeClass_SHORT)
534 switch (*static_cast<sal_Int16 const *>(a.getValue()))
536 case 0:
537 addAttribute( rAttrName, "system_short" );
538 break;
539 case 1:
540 addAttribute( rAttrName, "system_short_YY" );
541 break;
542 case 2:
543 addAttribute( rAttrName, "system_short_YYYY" );
544 break;
545 case 3:
546 addAttribute( rAttrName, "system_long" );
547 break;
548 case 4:
549 addAttribute( rAttrName, "short_DDMMYY" );
550 break;
551 case 5:
552 addAttribute( rAttrName, "short_MMDDYY" );
553 break;
554 case 6:
555 addAttribute( rAttrName, "short_YYMMDD" );
556 break;
557 case 7:
558 addAttribute( rAttrName, "short_DDMMYYYY" );
559 break;
560 case 8:
561 addAttribute( rAttrName, "short_MMDDYYYY" );
562 break;
563 case 9:
564 addAttribute( rAttrName, "short_YYYYMMDD" );
565 break;
566 case 10:
567 addAttribute( rAttrName, "short_YYMMDD_DIN5008" );
568 break;
569 case 11:
570 addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" );
571 break;
572 default:
573 SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" );
574 break;
577 else
578 OSL_FAIL( "### unexpected property type!" );
582 void ElementDescriptor::readDateAttr( OUString const & rPropName, OUString const & rAttrName )
584 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
586 Any a( _xProps->getPropertyValue( rPropName ) );
587 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get())
589 util::Date aUDate;
590 if (a >>= aUDate)
592 ::Date aTDate(aUDate);
593 addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) );
595 else
596 OSL_FAIL( "### internal error" );
598 else
599 OSL_FAIL( "### unexpected property type!" );
603 void ElementDescriptor::readTimeAttr( OUString const & rPropName, OUString const & rAttrName )
605 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
607 Any a( _xProps->getPropertyValue( rPropName ) );
608 if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get())
610 util::Time aUTime;
611 if (a >>= aUTime)
613 ::tools::Time aTTime(aUTime);
614 addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) );
616 else
617 OSL_FAIL( "### internal error" );
619 else
620 OSL_FAIL( "### unexpected property type!" );
624 void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
626 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
628 Any a( _xProps->getPropertyValue( rPropName ) );
629 if (a.getValueTypeClass() == TypeClass_SHORT)
631 switch (*static_cast<sal_Int16 const *>(a.getValue()))
633 case 0:
634 addAttribute( rAttrName, "24h_short" );
635 break;
636 case 1:
637 addAttribute( rAttrName, "24h_long" );
638 break;
639 case 2:
640 addAttribute( rAttrName, "12h_short" );
641 break;
642 case 3:
643 addAttribute( rAttrName, "12h_long" );
644 break;
645 case 4:
646 addAttribute( rAttrName, "Duration_short" );
647 break;
648 case 5:
649 addAttribute( rAttrName, "Duration_long" );
650 break;
651 default:
652 SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" );
653 break;
656 else
657 OSL_FAIL( "### unexpected property type!" );
661 void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
663 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
665 Any a( _xProps->getPropertyValue( rPropName ) );
666 if (a.getValueTypeClass() == TypeClass_SHORT)
668 switch (*static_cast<sal_Int16 const *>(a.getValue()))
670 case 0:
671 addAttribute( rAttrName, "left" );
672 break;
673 case 1:
674 addAttribute( rAttrName, "center" );
675 break;
676 case 2:
677 addAttribute( rAttrName, "right" );
678 break;
679 default:
680 SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" );
681 break;
684 else
685 OSL_FAIL( "### unexpected property type!" );
689 void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
691 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
693 Any a( _xProps->getPropertyValue( rPropName ) );
694 if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get())
696 style::VerticalAlignment eAlign;
697 a >>= eAlign;
698 switch (eAlign)
700 case style::VerticalAlignment_TOP:
701 addAttribute( rAttrName, "top" );
702 break;
703 case style::VerticalAlignment_MIDDLE:
704 addAttribute( rAttrName, "center" );
705 break;
706 case style::VerticalAlignment_BOTTOM:
707 addAttribute( rAttrName, "bottom" );
708 break;
709 default:
710 SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" );
711 break;
714 else
715 OSL_FAIL( "### unexpected property type!" );
719 void ElementDescriptor::readImageURLAttr( OUString const & rPropName, OUString const & rAttrName )
721 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
723 OUString sURL;
724 _xProps->getPropertyValue( rPropName ) >>= sURL;
726 if ( sURL.startsWith( XMLSCRIPT_GRAPHOBJ_URLPREFIX ) )
728 Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
729 if ( xDocStorage.is() )
731 Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
732 uno::Reference< document::XGraphicObjectResolver > xGraphicResolver =
733 document::GraphicObjectResolver::createWithStorage( xContext, xDocStorage->getDocumentStorage() );
734 sURL = xGraphicResolver->resolveGraphicObjectURL( sURL );
737 if ( !sURL.isEmpty() )
738 addAttribute( rAttrName, sURL );
742 void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
744 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
746 Any a( _xProps->getPropertyValue( rPropName ) );
747 if (a.getValueTypeClass() == TypeClass_SHORT)
749 switch (*static_cast<sal_Int16 const *>(a.getValue()))
751 case 0:
752 addAttribute( rAttrName, "left" );
753 break;
754 case 1:
755 addAttribute( rAttrName, "top" );
756 break;
757 case 2:
758 addAttribute( rAttrName, "right" );
759 break;
760 case 3:
761 addAttribute( rAttrName, "bottom" );
762 break;
763 default:
764 SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" );
765 break;
768 else
769 OSL_FAIL( "### unexpected property type!" );
773 void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
775 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
777 Any a( _xProps->getPropertyValue( rPropName ) );
778 if (a.getValueTypeClass() == TypeClass_SHORT)
780 switch (*static_cast<sal_Int16 const *>(a.getValue()))
782 case awt::ImagePosition::LeftTop:
783 addAttribute( rAttrName, "left-top" );
784 break;
785 case awt::ImagePosition::LeftCenter:
786 addAttribute( rAttrName, "left-center" );
787 break;
788 case awt::ImagePosition::LeftBottom:
789 addAttribute( rAttrName, "left-bottom" );
790 break;
791 case awt::ImagePosition::RightTop:
792 addAttribute( rAttrName, "right-top" );
793 break;
794 case awt::ImagePosition::RightCenter:
795 addAttribute( rAttrName, "right-center" );
796 break;
797 case awt::ImagePosition::RightBottom:
798 addAttribute( rAttrName, "right-bottom" );
799 break;
800 case awt::ImagePosition::AboveLeft:
801 addAttribute( rAttrName, "top-left" );
802 break;
803 case awt::ImagePosition::AboveCenter:
804 addAttribute( rAttrName, "top-center" );
805 break;
806 case awt::ImagePosition::AboveRight:
807 addAttribute( rAttrName, "top-right" );
808 break;
809 case awt::ImagePosition::BelowLeft:
810 addAttribute( rAttrName, "bottom-left" );
811 break;
812 case awt::ImagePosition::BelowCenter:
813 addAttribute( rAttrName, "bottom-center" );
814 break;
815 case awt::ImagePosition::BelowRight:
816 addAttribute( rAttrName, "bottom-right" );
817 break;
818 case awt::ImagePosition::Centered:
819 addAttribute( rAttrName, "center" );
820 break;
821 default:
822 SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" );
823 break;
829 void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
831 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
833 Any a( _xProps->getPropertyValue( rPropName ) );
834 if (a.getValueTypeClass() == TypeClass_SHORT)
836 switch (*static_cast<sal_Int16 const *>(a.getValue()))
838 case awt::PushButtonType_STANDARD:
839 addAttribute( rAttrName, "standard" );
840 break;
841 case awt::PushButtonType_OK:
842 addAttribute( rAttrName, "ok" );
843 break;
844 case awt::PushButtonType_CANCEL:
845 addAttribute( rAttrName, "cancel" );
846 break;
847 case awt::PushButtonType_HELP:
848 addAttribute( rAttrName, "help" );
849 break;
850 default:
851 SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" );
852 break;
858 void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
860 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
862 Any a( _xProps->getPropertyValue( rPropName ) );
863 if (a.getValueTypeClass() == TypeClass_LONG)
865 switch (*static_cast<sal_Int32 const *>(a.getValue()))
867 case 0:
868 addAttribute( rAttrName, "horizontal" );
869 break;
870 case 1:
871 addAttribute( rAttrName, "vertical" );
872 break;
873 default:
874 SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" );
875 break;
881 void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
883 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
885 Any a( _xProps->getPropertyValue( rPropName ) );
886 if (a.getValueTypeClass() == TypeClass_SHORT)
888 switch (*static_cast<sal_Int16 const *>(a.getValue()))
890 case awt::LineEndFormat::CARRIAGE_RETURN:
891 addAttribute( rAttrName, "carriage-return" );
892 break;
893 case awt::LineEndFormat::LINE_FEED:
894 addAttribute( rAttrName, "line-feed" );
895 break;
896 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
897 addAttribute( rAttrName, "carriage-return-line-feed" );
898 break;
899 default:
900 SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" );
901 break;
907 void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
909 Reference< lang::XMultiServiceFactory > xFac;
910 if ( _xDocument.is() )
911 xFac.set( _xDocument, uno::UNO_QUERY );
913 Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
915 if ( xFac.is() && xBinding.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":linked-cell" )
919 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
920 Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
921 if ( xBindable.is() )
923 table::CellAddress aAddress;
924 xBindable->getPropertyValue( "BoundCell" ) >>= aAddress;
925 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
926 OUString sAddress;
927 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
928 if ( !sAddress.isEmpty() )
929 addAttribute( rAttrName, sAddress );
931 SAL_INFO("xmlscript.xmldlg", "*** Bindable value " << sAddress );
935 catch( uno::Exception& )
939 Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
940 if ( xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range" )
942 Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
943 if ( xListSource.is() )
947 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
949 table::CellRangeAddress aAddress;
950 xListSource->getPropertyValue( "CellRange" ) >>= aAddress;
952 OUString sAddress;
953 xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
954 xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
955 SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress );
956 if ( !sAddress.isEmpty() )
957 addAttribute( rAttrName, sAddress );
959 catch( uno::Exception& )
966 void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
968 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
970 Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
972 if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get())
974 ::view::SelectionType eSelectionType;
975 aSelectionType >>= eSelectionType;
977 switch (eSelectionType)
979 case ::view::SelectionType_NONE:
980 addAttribute( rAttrName, "none" );
981 break;
982 case ::view::SelectionType_SINGLE:
983 addAttribute( rAttrName, "single" );
984 break;
985 case ::view::SelectionType_MULTI:
986 addAttribute( rAttrName, "multi" );
987 break;
988 case ::view::SelectionType_RANGE:
989 addAttribute( rAttrName, "range" );
990 break;
991 default:
992 SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" );
993 break;
999 void ElementDescriptor::readScrollableSettings()
1001 readLongAttr( "ScrollHeight",
1002 XMLNS_DIALOGS_PREFIX ":scrollheight" );
1003 readLongAttr( "ScrollWidth",
1004 XMLNS_DIALOGS_PREFIX ":scrollwidth" );
1005 readLongAttr( "ScrollTop",
1006 XMLNS_DIALOGS_PREFIX ":scrolltop" );
1007 readLongAttr( "ScrollLeft",
1008 XMLNS_DIALOGS_PREFIX ":scrollleft" );
1009 readBoolAttr( "HScroll",
1010 XMLNS_DIALOGS_PREFIX ":hscroll" );
1011 readBoolAttr( "VScroll",
1012 XMLNS_DIALOGS_PREFIX ":vscroll" );
1015 void ElementDescriptor::readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName )
1017 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
1019 Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) );
1021 if (aImageScaleMode.getValueTypeClass() == TypeClass_SHORT)
1023 sal_Int16 nImageScaleMode;
1024 aImageScaleMode >>= nImageScaleMode;
1026 switch(nImageScaleMode)
1028 case ::awt::ImageScaleMode::NONE:
1029 addAttribute( rAttrName, OUString( "none") );
1030 break;
1031 case ::awt::ImageScaleMode::ISOTROPIC:
1032 addAttribute( rAttrName, OUString( "isotropic") );
1033 break;
1034 case ::awt::ImageScaleMode::ANISOTROPIC:
1035 addAttribute( rAttrName, OUString( "anisotropic" ) );
1036 break;
1037 default:
1038 OSL_ENSURE( false, "### illegal image scale mode value.");
1039 break;
1045 void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
1047 Any a( _xProps->getPropertyValue( "Name" ) );
1049 // The following is a hack to allow 'form' controls to override the default
1050 // control supported by dialogs. This should work well for both vba support and
1051 // normal openoffice ( when normal 'Dialogs' decide to support form control models )
1052 // In the future VBA support might require custom models ( and not the just the form
1053 // variant of a control that we currently use ) In this case the door is still open,
1054 // we just need to define a new way for the 'ServiceName' to be extracted from the
1055 // incoming model. E.g. the use of supporting service
1056 // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1057 // is only an implementation detail here, in the future some other
1058 // method ( perhaps a custom prop ) could be used instead.
1059 Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1060 if ( xSrvInfo.is() && xSrvInfo->supportsService( "com.sun.star.form.FormComponent" ) )
1062 Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1063 if ( xPersist.is() )
1065 OUString sCtrlName = xPersist->getServiceName();
1066 if ( !sCtrlName.isEmpty() )
1067 addAttribute( XMLNS_DIALOGS_PREFIX ":control-implementation", sCtrlName );
1070 addAttribute( XMLNS_DIALOGS_PREFIX ":id", * static_cast< const OUString * >( a.getValue() ) );
1071 readShortAttr( "TabIndex", XMLNS_DIALOGS_PREFIX ":tab-index" );
1073 bool bEnabled = false;
1074 if (_xProps->getPropertyValue( "Enabled" ) >>= bEnabled)
1076 if (! bEnabled)
1078 addAttribute( XMLNS_DIALOGS_PREFIX ":disabled", "true" );
1081 else
1083 SAL_WARN( "xmlscript.xmldlg", "unexpected property type for \"Enabled\": not bool!" );
1086 if (supportVisible) try
1088 bool bVisible = true;
1089 if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible)
1092 // only write out the non default case
1093 if (! bVisible)
1095 addAttribute( XMLNS_DIALOGS_PREFIX ":visible", "false" );
1099 catch( Exception& )
1101 DBG_UNHANDLED_EXCEPTION();
1103 // force writing of pos/size
1104 a = _xProps->getPropertyValue( "PositionX" );
1105 if (a.getValueTypeClass() == TypeClass_LONG)
1107 addAttribute( XMLNS_DIALOGS_PREFIX ":left", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1109 a = _xProps->getPropertyValue( "PositionY" );
1110 if (a.getValueTypeClass() == TypeClass_LONG)
1112 addAttribute( XMLNS_DIALOGS_PREFIX ":top", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1114 a = _xProps->getPropertyValue( "Width" );
1115 if (a.getValueTypeClass() == TypeClass_LONG)
1117 addAttribute( XMLNS_DIALOGS_PREFIX ":width", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1119 a = _xProps->getPropertyValue( "Height" );
1120 if (a.getValueTypeClass() == TypeClass_LONG)
1122 addAttribute( XMLNS_DIALOGS_PREFIX ":height", OUString::number( *static_cast<sal_Int32 const *>(a.getValue()) ) );
1125 if (supportPrintable)
1127 readBoolAttr( "Printable", XMLNS_DIALOGS_PREFIX ":printable" );
1129 readLongAttr( "Step", XMLNS_DIALOGS_PREFIX ":page" );
1130 readStringAttr( "Tag", XMLNS_DIALOGS_PREFIX ":tag" );
1131 readStringAttr( "HelpText", XMLNS_DIALOGS_PREFIX ":help-text" );
1132 readStringAttr( "HelpURL", XMLNS_DIALOGS_PREFIX ":help-url" );
1135 struct StringTriple
1137 char const * first;
1138 char const * second;
1139 char const * third;
1141 extern StringTriple const * const g_pEventTranslations;
1143 void ElementDescriptor::readEvents()
1145 Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1146 if (xSupplier.is())
1148 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1149 if (xEvents.is())
1151 Sequence< OUString > aNames( xEvents->getElementNames() );
1152 OUString const * pNames = aNames.getConstArray();
1153 for ( sal_Int32 nPos = 0; nPos < aNames.getLength(); ++nPos )
1155 script::ScriptEventDescriptor descr;
1156 if (xEvents->getByName( pNames[ nPos ] ) >>= descr)
1158 SAL_WARN_IF( descr.ListenerType.isEmpty() ||
1159 descr.EventMethod.isEmpty() ||
1160 descr.ScriptCode.isEmpty() ||
1161 descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" );
1163 OUString aEventName;
1165 if (descr.AddListenerParam.isEmpty())
1167 // detection of event-name
1168 OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) );
1169 OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) );
1170 StringTriple const * p = g_pEventTranslations;
1171 while (p->first)
1173 if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1174 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1176 aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1177 break;
1179 ++p;
1183 ElementDescriptor * pElem;
1184 Reference< xml::sax::XAttributeList > xElem;
1186 if (!aEventName.isEmpty()) // script:event
1188 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" );
1189 xElem = pElem;
1191 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName );
1193 else // script:listener-event
1195 pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" );
1196 xElem = pElem;
1198 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType );
1199 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod );
1201 if (!descr.AddListenerParam.isEmpty())
1203 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam );
1206 if ( descr.ScriptType == "StarBasic" )
1208 // separate optional location
1209 sal_Int32 nIndex = descr.ScriptCode.indexOf( (sal_Unicode)':' );
1210 if (nIndex >= 0)
1212 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) );
1213 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) );
1215 else
1217 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1220 else
1222 pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1225 // language
1226 pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType );
1228 addSubElement( xElem );
1230 else
1232 SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" );
1239 inline bool equalFont( Style const & style1, Style const & style2 )
1241 awt::FontDescriptor const & f1 = style1._descr;
1242 awt::FontDescriptor const & f2 = style2._descr;
1243 return (
1244 f1.Name == f2.Name &&
1245 f1.Height == f2.Height &&
1246 f1.Width == f2.Width &&
1247 f1.StyleName == f2.StyleName &&
1248 f1.Family == f2.Family &&
1249 f1.CharSet == f2.CharSet &&
1250 f1.Pitch == f2.CharSet &&
1251 f1.CharacterWidth == f2.CharacterWidth &&
1252 f1.Weight == f2.Weight &&
1253 f1.Slant == f2.Slant &&
1254 f1.Underline == f2.Underline &&
1255 f1.Strikeout == f2.Strikeout &&
1256 f1.Orientation == f2.Orientation &&
1257 (f1.Kerning != sal_False) == (f2.Kerning != sal_False) &&
1258 (f1.WordLineMode != sal_False) == (f2.WordLineMode != sal_False) &&
1259 f1.Type == f2.Type &&
1260 style1._fontRelief == style2._fontRelief &&
1261 style1._fontEmphasisMark == style2._fontEmphasisMark
1265 OUString StyleBag::getStyleId( Style const & rStyle )
1267 if (! rStyle._set) // nothin set
1269 return OUString(); // everything default: no need to export a specific style
1272 // lookup existing style
1273 for ( size_t nStylesPos = 0; nStylesPos < _styles.size(); ++nStylesPos )
1275 Style * pStyle = _styles[ nStylesPos ];
1277 short demanded_defaults = ~rStyle._set & rStyle._all;
1278 // test, if defaults are not set
1279 if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1280 (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1282 short bset = rStyle._set & pStyle->_set;
1283 if ((bset & 0x1) &&
1284 rStyle._backgroundColor != pStyle->_backgroundColor)
1285 continue;
1286 if ((bset & 0x2) &&
1287 rStyle._textColor != pStyle->_textColor)
1288 continue;
1289 if ((bset & 0x20) &&
1290 rStyle._textLineColor != pStyle->_textLineColor)
1291 continue;
1292 if ((bset & 0x10) &&
1293 rStyle._fillColor != pStyle->_fillColor)
1294 continue;
1295 if ((bset & 0x4) &&
1296 (rStyle._border != pStyle->_border ||
1297 (rStyle._border == BORDER_SIMPLE_COLOR &&
1298 rStyle._borderColor != pStyle->_borderColor)))
1299 continue;
1300 if ((bset & 0x8) &&
1301 !equalFont( rStyle, *pStyle ))
1302 continue;
1303 if ((bset & 0x40) &&
1304 rStyle._visualEffect != pStyle->_visualEffect)
1305 continue;
1307 // merge in
1308 short bnset = rStyle._set & ~pStyle->_set;
1309 if (bnset & 0x1)
1310 pStyle->_backgroundColor = rStyle._backgroundColor;
1311 if (bnset & 0x2)
1312 pStyle->_textColor = rStyle._textColor;
1313 if (bnset & 0x20)
1314 pStyle->_textLineColor = rStyle._textLineColor;
1315 if (bnset & 0x10)
1316 pStyle->_fillColor = rStyle._fillColor;
1317 if (bnset & 0x4) {
1318 pStyle->_border = rStyle._border;
1319 pStyle->_borderColor = rStyle._borderColor;
1321 if (bnset & 0x8) {
1322 pStyle->_descr = rStyle._descr;
1323 pStyle->_fontRelief = rStyle._fontRelief;
1324 pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1326 if (bnset & 0x40)
1327 pStyle->_visualEffect = rStyle._visualEffect;
1329 pStyle->_all |= rStyle._all;
1330 pStyle->_set |= rStyle._set;
1332 return pStyle->_id;
1336 // no appr style found, append new
1337 Style * pStyle = new Style( rStyle );
1338 pStyle->_id = OUString::number( _styles.size() );
1339 _styles.push_back( pStyle );
1340 return pStyle->_id;
1343 StyleBag::~StyleBag()
1345 for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1347 delete _styles[ nPos ];
1351 void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1353 if (! _styles.empty())
1355 OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" );
1356 xOut->ignorableWhitespace( OUString() );
1357 xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1358 // export styles
1359 for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1361 Reference< xml::sax::XAttributeList > xAttr( _styles[ nPos ]->createElement() );
1362 static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1364 xOut->ignorableWhitespace( OUString() );
1365 xOut->endElement( aStylesName );
1369 void SAL_CALL exportDialogModel(
1370 Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1371 Reference< container::XNameContainer > const & xDialogModel,
1372 Reference< frame::XModel > const & xDocument )
1374 StyleBag all_styles;
1375 // window
1376 Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1377 OSL_ASSERT( xProps.is() );
1378 Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1379 OSL_ASSERT( xPropState.is() );
1381 ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument );
1382 Reference< xml::sax::XAttributeList > xElem( pElem );
1383 pElem->readBullitinBoard( &all_styles );
1385 xOut->startDocument();
1387 OUString aDocTypeStr(
1388 "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1389 " \"dialog.dtd\">" );
1390 xOut->unknown( aDocTypeStr );
1391 xOut->ignorableWhitespace( OUString() );
1393 OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" );
1394 ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1395 Reference< xml::sax::XAttributeList > xWindow( pWindow );
1396 pWindow->readDialogModel( &all_styles );
1397 xOut->ignorableWhitespace( OUString() );
1398 xOut->startElement( aWindowName, xWindow );
1399 // dump out events
1400 pWindow->dumpSubElements( xOut.get() );
1401 // dump out stylebag
1402 all_styles.dump( xOut );
1404 if ( xDialogModel->getElementNames().getLength() )
1406 // open up bulletinboard
1407 OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" );
1408 xOut->ignorableWhitespace( OUString() );
1409 xOut->startElement( aBBoardName, xElem );
1411 pElem->dumpSubElements( xOut.get() );
1412 // end bulletinboard
1413 xOut->ignorableWhitespace( OUString() );
1414 xOut->endElement( aBBoardName );
1417 // end window
1418 xOut->ignorableWhitespace( OUString() );
1419 xOut->endElement( aWindowName );
1421 xOut->endDocument();
1426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */