Bump for 3.6-28
[LibreOffice.git] / xmlscript / source / xmldlg_imexp / xmldlg_export.cxx
blobbbfc4eb1bcae08d5e9fb128d80b3c8944b7feb49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "exp_share.hxx"
31 #include <rtl/ustrbuf.hxx>
32 #include <tools/diagnose_ex.h>
34 #include <com/sun/star/awt/CharSet.hpp>
35 #include <com/sun/star/awt/FontFamily.hpp>
36 #include <com/sun/star/awt/FontPitch.hpp>
37 #include <com/sun/star/awt/FontSlant.hpp>
38 #include <com/sun/star/awt/FontStrikeout.hpp>
39 #include <com/sun/star/awt/FontType.hpp>
40 #include <com/sun/star/awt/FontUnderline.hpp>
41 #include <com/sun/star/awt/FontWeight.hpp>
42 #include <com/sun/star/awt/FontWidth.hpp>
43 #include <com/sun/star/awt/ImagePosition.hpp>
44 #include <com/sun/star/awt/LineEndFormat.hpp>
45 #include <com/sun/star/awt/PushButtonType.hpp>
46 #include <com/sun/star/awt/VisualEffect.hpp>
48 #include <com/sun/star/io/XPersistObject.hpp>
50 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
51 #include <com/sun/star/script/ScriptEventDescriptor.hpp>
53 #include <com/sun/star/style/VerticalAlignment.hpp>
55 #include <com/sun/star/lang/XServiceInfo.hpp>
56 #include <com/sun/star/lang/Locale.hpp>
57 #include <com/sun/star/util/NumberFormat.hpp>
59 #include <com/sun/star/view/SelectionType.hpp>
61 #include <com/sun/star/form/binding/XListEntrySink.hpp>
62 #include <com/sun/star/form/binding/XBindableValue.hpp>
63 #include <com/sun/star/form/binding/XValueBinding.hpp>
64 #include <com/sun/star/table/CellAddress.hpp>
65 #include <com/sun/star/table/CellRangeAddress.hpp>
66 #include <com/sun/star/document/XStorageBasedDocument.hpp>
67 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
69 #include <comphelper/componentcontext.hxx>
70 #include <comphelper/processfactory.hxx>
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
74 using ::rtl::OUString;
75 using ::rtl::OUStringBuffer;
77 namespace xmlscript
80 //__________________________________________________________________________________________________
81 Reference< xml::sax::XAttributeList > Style::createElement()
83 ElementDescriptor * pStyle = new ElementDescriptor(
84 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":style") ) );
86 // style-id
87 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":style-id") ), _id );
89 // background-color
90 if (_set & 0x1)
92 OUStringBuffer buf( 16 );
93 buf.append( (sal_Unicode)'0' );
94 buf.append( (sal_Unicode)'x' );
95 buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_backgroundColor, 16 ) );
96 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":background-color") ),
97 buf.makeStringAndClear() );
100 // text-color
101 if (_set & 0x2)
103 OUStringBuffer buf( 16 );
104 buf.append( (sal_Unicode)'0' );
105 buf.append( (sal_Unicode)'x' );
106 buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_textColor, 16 ) );
107 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":text-color") ),
108 buf.makeStringAndClear() );
111 // textline-color
112 if (_set & 0x20)
114 OUStringBuffer buf( 16 );
115 buf.append( (sal_Unicode)'0' );
116 buf.append( (sal_Unicode)'x' );
117 buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_textLineColor, 16 ) );
118 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":textline-color") ),
119 buf.makeStringAndClear() );
122 // fill-color
123 if (_set & 0x10)
125 OUStringBuffer buf( 16 );
126 buf.append( (sal_Unicode)'0' );
127 buf.append( (sal_Unicode)'x' );
128 buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_fillColor, 16 ) );
129 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":fill-color") ),
130 buf.makeStringAndClear() );
133 // border
134 if (_set & 0x4)
136 switch (_border)
138 case BORDER_NONE:
139 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":border"),
140 OUSTR("none") );
141 break;
142 case BORDER_3D:
143 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":border"),
144 OUSTR("3d") );
145 break;
146 case BORDER_SIMPLE:
147 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":border"),
148 OUSTR("simple") );
149 break;
150 case BORDER_SIMPLE_COLOR: {
151 OUStringBuffer buf;
152 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("0x") );
153 buf.append( OUString::valueOf(
154 (sal_Int64)(sal_uInt64)_borderColor, 16 ) );
155 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":border"),
156 buf.makeStringAndClear() );
157 break;
159 default:
160 OSL_FAIL( "### unexpected border value!" );
161 break;
165 // visual effect (look)
166 if (_set & 0x40)
168 switch (_visualEffect)
170 case awt::VisualEffect::NONE:
171 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":look"),
172 OUSTR("none") );
173 break;
174 case awt::VisualEffect::LOOK3D:
175 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":look"),
176 OUSTR("3d") );
177 break;
178 case awt::VisualEffect::FLAT:
179 pStyle->addAttribute( OUSTR(XMLNS_DIALOGS_PREFIX ":look"),
180 OUSTR("simple") );
181 break;
182 default:
183 OSL_FAIL( "### unexpected visual effect value!" );
184 break;
188 // font-
189 if (_set & 0x8)
191 awt::FontDescriptor def_descr;
193 // dialog:font-name CDATA #IMPLIED
194 if (def_descr.Name != _descr.Name)
196 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-name") ),
197 _descr.Name );
199 // dialog:font-height %numeric; #IMPLIED
200 if (def_descr.Height != _descr.Height)
202 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-height") ),
203 OUString::valueOf( (sal_Int32)_descr.Height ) );
205 // dialog:font-width %numeric; #IMPLIED
206 if (def_descr.Width != _descr.Width)
208 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-width") ),
209 OUString::valueOf( (sal_Int32)_descr.Width ) );
211 // dialog:font-stylename CDATA #IMPLIED
212 if (def_descr.StyleName != _descr.StyleName)
214 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-stylename") ),
215 _descr.StyleName );
217 // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
218 if (def_descr.Family != _descr.Family)
220 switch (_descr.Family)
222 case awt::FontFamily::DECORATIVE:
223 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
224 OUString( RTL_CONSTASCII_USTRINGPARAM("decorative") ) );
225 break;
226 case awt::FontFamily::MODERN:
227 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
228 OUString( RTL_CONSTASCII_USTRINGPARAM("modern") ) );
229 break;
230 case awt::FontFamily::ROMAN:
231 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
232 OUString( RTL_CONSTASCII_USTRINGPARAM("roman") ) );
233 break;
234 case awt::FontFamily::SCRIPT:
235 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
236 OUString( RTL_CONSTASCII_USTRINGPARAM("script") ) );
237 break;
238 case awt::FontFamily::SWISS:
239 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
240 OUString( RTL_CONSTASCII_USTRINGPARAM("swiss") ) );
241 break;
242 case awt::FontFamily::SYSTEM:
243 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-family") ),
244 OUString( RTL_CONSTASCII_USTRINGPARAM("system") ) );
245 break;
246 default:
247 OSL_FAIL( "### unexpected font-family!" );
248 break;
251 // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
252 if (def_descr.CharSet != _descr.CharSet)
254 switch (_descr.CharSet)
256 case awt::CharSet::ANSI:
257 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
258 OUString( RTL_CONSTASCII_USTRINGPARAM("ansi") ) );
259 break;
260 case awt::CharSet::MAC:
261 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
262 OUString( RTL_CONSTASCII_USTRINGPARAM("mac") ) );
263 break;
264 case awt::CharSet::IBMPC_437:
265 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
266 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_437") ) );
267 break;
268 case awt::CharSet::IBMPC_850:
269 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
270 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_850") ) );
271 break;
272 case awt::CharSet::IBMPC_860:
273 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
274 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_860") ) );
275 break;
276 case awt::CharSet::IBMPC_861:
277 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
278 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_861") ) );
279 break;
280 case awt::CharSet::IBMPC_863:
281 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
282 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_863") ) );
283 break;
284 case awt::CharSet::IBMPC_865:
285 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
286 OUString( RTL_CONSTASCII_USTRINGPARAM("ibmpc_865") ) );
287 break;
288 case awt::CharSet::SYSTEM:
289 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
290 OUString( RTL_CONSTASCII_USTRINGPARAM("system") ) );
291 break;
292 case awt::CharSet::SYMBOL:
293 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charset") ),
294 OUString( RTL_CONSTASCII_USTRINGPARAM("symbol") ) );
295 break;
296 default:
297 OSL_FAIL( "### unexpected font-charset!" );
298 break;
301 // dialog:font-pitch "(fixed|variable)" #IMPLIED
302 if (def_descr.Pitch != _descr.Pitch)
304 switch (_descr.Pitch)
306 case awt::FontPitch::FIXED:
307 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-pitch") ),
308 OUString( RTL_CONSTASCII_USTRINGPARAM("fixed") ) );
309 break;
310 case awt::FontPitch::VARIABLE:
311 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-pitch") ),
312 OUString( RTL_CONSTASCII_USTRINGPARAM("variable") ) );
313 break;
314 default:
315 OSL_FAIL( "### unexpected font-pitch!" );
316 break;
319 // dialog:font-charwidth CDATA #IMPLIED
320 if (def_descr.CharacterWidth != _descr.CharacterWidth)
322 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-charwidth") ),
323 OUString::valueOf( (float)_descr.CharacterWidth ) );
325 // dialog:font-weight CDATA #IMPLIED
326 if (def_descr.Weight != _descr.Weight)
328 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-weight") ),
329 OUString::valueOf( (float)_descr.Weight ) );
331 // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
332 if (def_descr.Slant != _descr.Slant)
334 switch (_descr.Slant)
336 case awt::FontSlant_OBLIQUE:
337 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-slant") ),
338 OUString( RTL_CONSTASCII_USTRINGPARAM("oblique") ) );
339 break;
340 case awt::FontSlant_ITALIC:
341 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-slant") ),
342 OUString( RTL_CONSTASCII_USTRINGPARAM("italic") ) );
343 break;
344 case awt::FontSlant_REVERSE_OBLIQUE:
345 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-slant") ),
346 OUString( RTL_CONSTASCII_USTRINGPARAM("reverse_oblique") ) );
347 break;
348 case awt::FontSlant_REVERSE_ITALIC:
349 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-slant") ),
350 OUString( RTL_CONSTASCII_USTRINGPARAM("reverse_italic") ) );
351 break;
352 default:
353 OSL_FAIL( "### unexpected font-slant!" );
354 break;
357 // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
358 if (def_descr.Underline != _descr.Underline)
360 switch (_descr.Underline)
362 case awt::FontUnderline::SINGLE:
363 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
364 OUString( RTL_CONSTASCII_USTRINGPARAM("single") ) );
365 break;
366 case awt::FontUnderline::DOUBLE:
367 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
368 OUString( RTL_CONSTASCII_USTRINGPARAM("double") ) );
369 break;
370 case awt::FontUnderline::DOTTED:
371 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
372 OUString( RTL_CONSTASCII_USTRINGPARAM("dotted") ) );
373 break;
374 case awt::FontUnderline::DASH:
375 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
376 OUString( RTL_CONSTASCII_USTRINGPARAM("dash") ) );
377 break;
378 case awt::FontUnderline::LONGDASH:
379 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
380 OUString( RTL_CONSTASCII_USTRINGPARAM("longdash") ) );
381 break;
382 case awt::FontUnderline::DASHDOT:
383 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
384 OUString( RTL_CONSTASCII_USTRINGPARAM("dashdot") ) );
385 break;
386 case awt::FontUnderline::DASHDOTDOT:
387 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
388 OUString( RTL_CONSTASCII_USTRINGPARAM("dashdotdot") ) );
389 break;
390 case awt::FontUnderline::SMALLWAVE:
391 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
392 OUString( RTL_CONSTASCII_USTRINGPARAM("smallwave") ) );
393 break;
394 case awt::FontUnderline::WAVE:
395 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
396 OUString( RTL_CONSTASCII_USTRINGPARAM("wave") ) );
397 break;
398 case awt::FontUnderline::DOUBLEWAVE:
399 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
400 OUString( RTL_CONSTASCII_USTRINGPARAM("doublewave") ) );
401 break;
402 case awt::FontUnderline::BOLD:
403 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
404 OUString( RTL_CONSTASCII_USTRINGPARAM("bold") ) );
405 break;
406 case awt::FontUnderline::BOLDDOTTED:
407 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
408 OUString( RTL_CONSTASCII_USTRINGPARAM("bolddotted") ) );
409 break;
410 case awt::FontUnderline::BOLDDASH:
411 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
412 OUString( RTL_CONSTASCII_USTRINGPARAM("bolddash") ) );
413 break;
414 case awt::FontUnderline::BOLDLONGDASH:
415 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
416 OUString( RTL_CONSTASCII_USTRINGPARAM("boldlongdash") ) );
417 break;
418 case awt::FontUnderline::BOLDDASHDOT:
419 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
420 OUString( RTL_CONSTASCII_USTRINGPARAM("bolddashdot") ) );
421 break;
422 case awt::FontUnderline::BOLDDASHDOTDOT:
423 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
424 OUString( RTL_CONSTASCII_USTRINGPARAM("bolddashdotdot") ) );
425 break;
426 case awt::FontUnderline::BOLDWAVE:
427 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-underline") ),
428 OUString( RTL_CONSTASCII_USTRINGPARAM("boldwave") ) );
429 break;
430 default:
431 OSL_FAIL( "### unexpected font-underline!" );
432 break;
435 // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
436 if (def_descr.Strikeout != _descr.Strikeout)
438 switch (_descr.Strikeout)
440 case awt::FontStrikeout::SINGLE:
441 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-strikeout") ),
442 OUString( RTL_CONSTASCII_USTRINGPARAM("single") ) );
443 break;
444 case awt::FontStrikeout::DOUBLE:
445 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-strikeout") ),
446 OUString( RTL_CONSTASCII_USTRINGPARAM("double") ) );
447 break;
448 case awt::FontStrikeout::BOLD:
449 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-strikeout") ),
450 OUString( RTL_CONSTASCII_USTRINGPARAM("bold") ) );
451 break;
452 case awt::FontStrikeout::SLASH:
453 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-strikeout") ),
454 OUString( RTL_CONSTASCII_USTRINGPARAM("slash") ) );
455 break;
456 case awt::FontStrikeout::X:
457 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-strikeout") ),
458 OUString( RTL_CONSTASCII_USTRINGPARAM("x") ) );
459 break;
460 default:
461 OSL_FAIL( "### unexpected font-strikeout!" );
462 break;
465 // dialog:font-orientation CDATA #IMPLIED
466 if (def_descr.Orientation != _descr.Orientation)
468 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-orientation") ),
469 OUString::valueOf( (float)_descr.Orientation ) );
471 // dialog:font-kerning %boolean; #IMPLIED
472 if ((def_descr.Kerning != sal_False) != (_descr.Kerning != sal_False))
474 pStyle->addBoolAttr( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-kerning") ),
475 _descr.Kerning );
477 // dialog:font-wordlinemode %boolean; #IMPLIED
478 if ((def_descr.WordLineMode != sal_False) != (_descr.WordLineMode != sal_False))
480 pStyle->addBoolAttr( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-wordlinemode") ),
481 _descr.WordLineMode );
483 // dialog:font-type "(raster|device|scalable)" #IMPLIED
484 if (def_descr.Type != _descr.Type)
486 switch (_descr.Type)
488 case awt::FontType::RASTER:
489 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-type") ),
490 OUString( RTL_CONSTASCII_USTRINGPARAM("raster") ) );
491 break;
492 case awt::FontType::DEVICE:
493 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-type") ),
494 OUString( RTL_CONSTASCII_USTRINGPARAM("device") ) );
495 break;
496 case awt::FontType::SCALABLE:
497 pStyle->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-type") ),
498 OUString( RTL_CONSTASCII_USTRINGPARAM("scalable") ) );
499 break;
500 default:
501 OSL_FAIL( "### unexpected font-type!" );
502 break;
506 // additional attributes not in FontDescriptor struct
507 // dialog:font-relief (none|embossed|engraved) #IMPLIED
508 switch (_fontRelief)
510 case awt::FontRelief::NONE: // dont export default
511 break;
512 case awt::FontRelief::EMBOSSED:
513 pStyle->addAttribute(
514 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-relief") ),
515 OUString( RTL_CONSTASCII_USTRINGPARAM("embossed") ) );
516 break;
517 case awt::FontRelief::ENGRAVED:
518 pStyle->addAttribute(
519 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-relief") ),
520 OUString( RTL_CONSTASCII_USTRINGPARAM("engraved") ) );
521 break;
522 default:
523 OSL_FAIL( "### unexpected font-relief!" );
524 break;
526 // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
527 switch (_fontEmphasisMark)
529 case awt::FontEmphasisMark::NONE: // dont export default
530 break;
531 case awt::FontEmphasisMark::DOT:
532 pStyle->addAttribute(
533 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
534 OUString( RTL_CONSTASCII_USTRINGPARAM("dot") ) );
535 break;
536 case awt::FontEmphasisMark::CIRCLE:
537 pStyle->addAttribute(
538 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
539 OUString( RTL_CONSTASCII_USTRINGPARAM("circle") ) );
540 break;
541 case awt::FontEmphasisMark::DISC:
542 pStyle->addAttribute(
543 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
544 OUString( RTL_CONSTASCII_USTRINGPARAM("disc") ) );
545 break;
546 case awt::FontEmphasisMark::ACCENT:
547 pStyle->addAttribute(
548 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
549 OUString( RTL_CONSTASCII_USTRINGPARAM("accent") ) );
550 break;
551 case awt::FontEmphasisMark::ABOVE:
552 pStyle->addAttribute(
553 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
554 OUString( RTL_CONSTASCII_USTRINGPARAM("above") ) );
555 break;
556 case awt::FontEmphasisMark::BELOW:
557 pStyle->addAttribute(
558 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":font-emphasismark") ),
559 OUString( RTL_CONSTASCII_USTRINGPARAM("below") ) );
560 break;
561 default:
562 OSL_FAIL( "### unexpected font-emphasismark!" );
563 break;
567 return pStyle;
570 //##################################################################################################
572 //__________________________________________________________________________________________________
573 void ElementDescriptor::addNumberFormatAttr(
574 Reference< beans::XPropertySet > const & xFormatProperties )
576 Reference< beans::XPropertyState > xState( xFormatProperties, UNO_QUERY );
577 OUString sFormat;
578 lang::Locale locale;
579 OSL_VERIFY( xFormatProperties->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("FormatString") ) ) >>= sFormat );
580 OSL_VERIFY( xFormatProperties->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Locale") ) ) >>= locale );
582 addAttribute(
583 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":format-code") ),
584 sFormat );
586 // format-locale
587 OUStringBuffer buf( 48 );
588 buf.append( locale.Language );
589 if (!locale.Country.isEmpty())
591 buf.append( (sal_Unicode)';' );
592 buf.append( locale.Country );
593 if (!locale.Variant.isEmpty())
595 buf.append( (sal_Unicode)';' );
596 buf.append( locale.Variant );
599 addAttribute(
600 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":format-locale") ),
601 buf.makeStringAndClear() );
603 //__________________________________________________________________________________________________
604 Any ElementDescriptor::readProp( OUString const & rPropName )
606 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
608 return _xProps->getPropertyValue( rPropName );
610 return Any();
613 //______________________________________________________________________________
614 void ElementDescriptor::readStringAttr(
615 OUString const & rPropName, OUString const & rAttrName )
617 if (beans::PropertyState_DEFAULT_VALUE !=
618 _xPropState->getPropertyState( rPropName ))
620 Any a( _xProps->getPropertyValue( rPropName ) );
621 OUString v;
622 if (a >>= v)
623 addAttribute( rAttrName, v );
624 else
625 OSL_FAIL( "### unexpected property type!" );
629 //__________________________________________________________________________________________________
630 void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
632 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
634 Any a( _xProps->getPropertyValue( rPropName ) );
635 if (a.getValueTypeClass() == TypeClass_LONG)
637 OUStringBuffer buf( 16 );
638 buf.append( (sal_Unicode)'0' );
639 buf.append( (sal_Unicode)'x' );
640 buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)*(sal_uInt32 *)a.getValue(), 16 ) );
641 addAttribute( rAttrName, buf.makeStringAndClear() );
646 //__________________________________________________________________________________________________
647 void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
649 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
651 Any a( _xProps->getPropertyValue( rPropName ) );
652 if (a.getValueTypeClass() == TypeClass_SHORT)
654 switch (*(sal_Int16 const *)a.getValue())
656 case 0:
657 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("system_short") ) );
658 break;
659 case 1:
660 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("system_short_YY") ) );
661 break;
662 case 2:
663 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("system_short_YYYY") ) );
664 break;
665 case 3:
666 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("system_long") ) );
667 break;
668 case 4:
669 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_DDMMYY") ) );
670 break;
671 case 5:
672 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_MMDDYY") ) );
673 break;
674 case 6:
675 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_YYMMDD") ) );
676 break;
677 case 7:
678 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_DDMMYYYY") ) );
679 break;
680 case 8:
681 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_MMDDYYYY") ) );
682 break;
683 case 9:
684 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_YYYYMMDD") ) );
685 break;
686 case 10:
687 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_YYMMDD_DIN5008") ) );
688 break;
689 case 11:
690 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("short_YYYYMMDD_DIN5008") ) );
691 break;
692 default:
693 OSL_FAIL( "### unexpected date format!" );
694 break;
699 //__________________________________________________________________________________________________
700 void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
702 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
704 Any a( _xProps->getPropertyValue( rPropName ) );
705 if (a.getValueTypeClass() == TypeClass_SHORT)
707 switch (*(sal_Int16 const *)a.getValue())
709 case 0:
710 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("24h_short") ) );
711 break;
712 case 1:
713 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("24h_long") ) );
714 break;
715 case 2:
716 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("12h_short") ) );
717 break;
718 case 3:
719 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("12h_long") ) );
720 break;
721 case 4:
722 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("Duration_short") ) );
723 break;
724 case 5:
725 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("Duration_long") ) );
726 break;
727 default:
728 OSL_FAIL( "### unexpected time format!" );
729 break;
734 //__________________________________________________________________________________________________
735 void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
737 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
739 Any a( _xProps->getPropertyValue( rPropName ) );
740 if (a.getValueTypeClass() == TypeClass_SHORT)
742 switch (*(sal_Int16 const *)a.getValue())
744 case 0:
745 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("left") ) );
746 break;
747 case 1:
748 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("center") ) );
749 break;
750 case 2:
751 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("right") ) );
752 break;
753 default:
754 OSL_FAIL( "### illegal alignment value!" );
755 break;
760 //__________________________________________________________________________________________________
761 void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
763 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
765 Any a( _xProps->getPropertyValue( rPropName ) );
766 if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == ::getCppuType( (style::VerticalAlignment*)0 ))
768 style::VerticalAlignment eAlign;
769 a >>= eAlign;
770 switch (eAlign)
772 case style::VerticalAlignment_TOP:
773 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("top") ) );
774 break;
775 case style::VerticalAlignment_MIDDLE:
776 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("center") ) );
777 break;
778 case style::VerticalAlignment_BOTTOM:
779 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("bottom") ) );
780 break;
781 default:
782 OSL_FAIL( "### illegal vertical alignment value!" );
783 break;
788 //__________________________________________________________________________________________________
789 void ElementDescriptor::readImageURLAttr( OUString const & rPropName, OUString const & rAttrName )
791 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
793 rtl::OUString sURL;
794 _xProps->getPropertyValue( rPropName ) >>= sURL;
796 if ( !sURL.isEmpty() && sURL.compareToAscii( XMLSCRIPT_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( XMLSCRIPT_GRAPHOBJ_URLPREFIX ) ) == 0 )
798 Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
799 if ( xDocStorage.is() )
801 uno::Sequence< Any > aArgs( 1 );
802 aArgs[ 0 ] <<= xDocStorage->getDocumentStorage();
804 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
805 uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
806 aContext.createComponentWithArguments( OUSTR( "com.sun.star.comp.Svx.GraphicExportHelper" ), aArgs, xGraphicResolver );
807 if ( xGraphicResolver.is() )
808 sURL = xGraphicResolver->resolveGraphicObjectURL( sURL );
811 if ( !sURL.isEmpty() )
812 addAttribute( rAttrName, sURL );
815 //__________________________________________________________________________________________________
816 void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
818 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
820 Any a( _xProps->getPropertyValue( rPropName ) );
821 if (a.getValueTypeClass() == TypeClass_SHORT)
823 switch (*(sal_Int16 const *)a.getValue())
825 case 0:
826 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("left") ) );
827 break;
828 case 1:
829 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("top") ) );
830 break;
831 case 2:
832 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("right") ) );
833 break;
834 case 3:
835 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("bottom") ) );
836 break;
837 default:
838 OSL_FAIL( "### illegal image alignment value!" );
839 break;
844 //__________________________________________________________________________________________________
845 void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
847 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
849 Any a( _xProps->getPropertyValue( rPropName ) );
850 if (a.getValueTypeClass() == TypeClass_SHORT)
852 switch (*(sal_Int16 const *)a.getValue())
854 case awt::ImagePosition::LeftTop:
855 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("left-top") ) );
856 break;
857 case awt::ImagePosition::LeftCenter:
858 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("left-center") ) );
859 break;
860 case awt::ImagePosition::LeftBottom:
861 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("left-bottom") ) );
862 break;
863 case awt::ImagePosition::RightTop:
864 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("right-top") ) );
865 break;
866 case awt::ImagePosition::RightCenter:
867 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("right-center") ) );
868 break;
869 case awt::ImagePosition::RightBottom:
870 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("right-bottom") ) );
871 break;
872 case awt::ImagePosition::AboveLeft:
873 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("top-left") ) );
874 break;
875 case awt::ImagePosition::AboveCenter:
876 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("top-center") ) );
877 break;
878 case awt::ImagePosition::AboveRight:
879 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("top-right") ) );
880 break;
881 case awt::ImagePosition::BelowLeft:
882 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("bottom-left") ) );
883 break;
884 case awt::ImagePosition::BelowCenter:
885 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("bottom-center") ) );
886 break;
887 case awt::ImagePosition::BelowRight:
888 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("bottom-right") ) );
889 break;
890 case awt::ImagePosition::Centered:
891 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("center") ) );
892 break;
893 default:
894 OSL_FAIL( "### illegal image position value!" );
895 break;
900 //__________________________________________________________________________________________________
901 void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
903 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
905 Any a( _xProps->getPropertyValue( rPropName ) );
906 if (a.getValueTypeClass() == TypeClass_SHORT)
908 switch (*(sal_Int16 const *)a.getValue())
910 case awt::PushButtonType_STANDARD:
911 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("standard") ) );
912 break;
913 case awt::PushButtonType_OK:
914 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("ok") ) );
915 break;
916 case awt::PushButtonType_CANCEL:
917 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("cancel") ) );
918 break;
919 case awt::PushButtonType_HELP:
920 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("help") ) );
921 break;
922 default:
923 OSL_FAIL( "### illegal button-type value!" );
924 break;
929 //__________________________________________________________________________________________________
930 void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
932 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
934 Any a( _xProps->getPropertyValue( rPropName ) );
935 if (a.getValueTypeClass() == TypeClass_LONG)
937 switch (*(sal_Int32 const *)a.getValue())
939 case 0:
940 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("horizontal") ) );
941 break;
942 case 1:
943 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("vertical") ) );
944 break;
945 default:
946 OSL_FAIL( "### illegal orientation value!" );
947 break;
952 //__________________________________________________________________________________________________
953 void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
955 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
957 Any a( _xProps->getPropertyValue( rPropName ) );
958 if (a.getValueTypeClass() == TypeClass_SHORT)
960 switch (*(sal_Int16 const *)a.getValue())
962 case awt::LineEndFormat::CARRIAGE_RETURN:
963 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("carriage-return") ) );
964 break;
965 case awt::LineEndFormat::LINE_FEED:
966 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("line-feed") ) );
967 break;
968 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
969 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("carriage-return-line-feed") ) );
970 break;
971 default:
972 OSL_FAIL( "### illegal line end format value!" );
973 break;
978 //__________________________________________________________________________________________________
979 void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
981 Reference< lang::XMultiServiceFactory > xFac;
982 if ( _xDocument.is() )
983 xFac.set( _xDocument, uno::UNO_QUERY );
985 Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
987 if ( xFac.is() && xBinding.is() && rAttrName.equals( OUSTR(XMLNS_DIALOGS_PREFIX ":linked-cell") ) )
991 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( OUSTR( "com.sun.star.table.CellAddressConversion" )), uno::UNO_QUERY );
992 Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
993 if ( xBindable.is() )
995 table::CellAddress aAddress;
996 xBindable->getPropertyValue( OUSTR("BoundCell") ) >>= aAddress;
997 xConvertor->setPropertyValue( OUSTR("Address"), makeAny( aAddress ) );
998 rtl::OUString sAddress;
999 xConvertor->getPropertyValue( OUSTR("PersistentRepresentation") ) >>= sAddress;
1000 if ( !sAddress.isEmpty() )
1001 addAttribute( rAttrName, sAddress );
1003 OSL_TRACE( "*** Bindable value %s", rtl::OUStringToOString( sAddress, RTL_TEXTENCODING_UTF8 ).getStr() );
1007 catch( uno::Exception& )
1011 Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
1012 if ( xEntrySink.is() && rAttrName.equals( OUSTR( XMLNS_DIALOGS_PREFIX ":source-cell-range") ) )
1014 Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
1015 if ( xListSource.is() )
1019 Reference< beans::XPropertySet > xConvertor( xFac->createInstance( OUSTR( "com.sun.star.table.CellRangeAddressConversion" )), uno::UNO_QUERY );
1021 table::CellRangeAddress aAddress;
1022 xListSource->getPropertyValue( OUSTR( "CellRange" ) ) >>= aAddress;
1024 rtl::OUString sAddress;
1025 xConvertor->setPropertyValue( OUSTR("Address"), makeAny( aAddress ) );
1026 xConvertor->getPropertyValue( OUSTR("PersistentRepresentation") ) >>= sAddress;
1027 OSL_TRACE("**** cell range source list %s",
1028 rtl::OUStringToOString( sAddress, RTL_TEXTENCODING_UTF8 ).getStr() );
1029 if ( !sAddress.isEmpty() )
1030 addAttribute( rAttrName, sAddress );
1032 catch( uno::Exception& )
1038 //__________________________________________________________________________________________________
1039 void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
1041 if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
1043 Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
1045 if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == ::getCppuType( (::view::SelectionType*)0 ))
1047 ::view::SelectionType eSelectionType;
1048 aSelectionType >>= eSelectionType;
1050 switch (eSelectionType)
1052 case ::view::SelectionType_NONE:
1053 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("none") ) );
1054 break;
1055 case ::view::SelectionType_SINGLE:
1056 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("single") ) );
1057 break;
1058 case ::view::SelectionType_MULTI:
1059 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("multi") ) );
1060 break;
1061 case ::view::SelectionType_RANGE:
1062 addAttribute( rAttrName, OUString( RTL_CONSTASCII_USTRINGPARAM("range") ) );
1063 break;
1064 default:
1065 OSL_FAIL( "### illegal selection type value!" );
1066 break;
1071 //__________________________________________________________________________________________________
1072 void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
1074 Any a( _xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ) ) );
1076 // The following is a hack to allow 'form' controls to override the default
1077 // control supported by dialogs. This should work well for both vba support and
1078 // normal openoffice ( when normal 'Dialogs' decide to support form control models )
1079 // In the future VBA support might require custom models ( and not the just the form
1080 // variant of a control that we currently use ) In this case the door is still open,
1081 // we just need to define a new way for the 'ServiceName' to be extracted from the
1082 // incomming model. E.g. the use of supporting service
1083 // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1084 // is only an implementation detail here, in the future some other
1085 // method ( perhaps a custom prop ) could be used instead.
1086 Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1087 if ( xSrvInfo.is() && xSrvInfo->supportsService( OUSTR("com.sun.star.form.FormComponent" ) ) )
1089 Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1090 if ( xPersist.is() )
1092 OUString sCtrlName = xPersist->getServiceName();
1093 if ( !sCtrlName.isEmpty() )
1094 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":control-implementation") ), sCtrlName );
1097 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":id") ),
1098 * reinterpret_cast< const OUString * >( a.getValue() ) );
1099 readShortAttr( OUString( RTL_CONSTASCII_USTRINGPARAM("TabIndex") ),
1100 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":tab-index") ) );
1102 sal_Bool bEnabled = sal_False;
1103 if (_xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Enabled") ) ) >>= bEnabled)
1105 if (! bEnabled)
1107 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":disabled") ),
1108 OUString( RTL_CONSTASCII_USTRINGPARAM("true") ) );
1111 else
1113 OSL_FAIL( "unexpected property type for \"Enabled\": not bool!" );
1116 sal_Bool bVisible = sal_True;
1117 if (supportVisible) try
1119 if (_xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("EnableVisible") ) ) >>= bVisible)
1122 // only write out the non default case
1123 if (! bVisible)
1125 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":visible") ),
1126 OUString( RTL_CONSTASCII_USTRINGPARAM("false") ) );
1130 catch( Exception& )
1132 DBG_UNHANDLED_EXCEPTION();
1134 // force writing of pos/size
1135 a = _xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PositionX") ) );
1136 if (a.getValueTypeClass() == TypeClass_LONG)
1138 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":left") ),
1139 OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1141 a = _xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("PositionY") ) );
1142 if (a.getValueTypeClass() == TypeClass_LONG)
1144 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":top") ),
1145 OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1147 a = _xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Width") ) );
1148 if (a.getValueTypeClass() == TypeClass_LONG)
1150 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":width") ),
1151 OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1153 a = _xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Height") ) );
1154 if (a.getValueTypeClass() == TypeClass_LONG)
1156 addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":height") ),
1157 OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1160 if (supportPrintable)
1162 readBoolAttr(
1163 OUString( RTL_CONSTASCII_USTRINGPARAM("Printable") ),
1164 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":printable") ) );
1166 readLongAttr( OUString( RTL_CONSTASCII_USTRINGPARAM("Step") ),
1167 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":page") ) );
1168 readStringAttr( OUString( RTL_CONSTASCII_USTRINGPARAM("Tag") ),
1169 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":tag") ) );
1170 readStringAttr( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpText") ),
1171 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":help-text") ) );
1172 readStringAttr( OUString( RTL_CONSTASCII_USTRINGPARAM("HelpURL") ),
1173 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":help-url") ) );
1176 struct StringTriple
1178 char const * first;
1179 char const * second;
1180 char const * third;
1182 extern StringTriple const * const g_pEventTranslations;
1184 //__________________________________________________________________________________________________
1185 void ElementDescriptor::readEvents()
1186 SAL_THROW( (Exception) )
1188 Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1189 if (xSupplier.is())
1191 Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1192 if (xEvents.is())
1194 Sequence< OUString > aNames( xEvents->getElementNames() );
1195 OUString const * pNames = aNames.getConstArray();
1196 for ( sal_Int32 nPos = 0; nPos < aNames.getLength(); ++nPos )
1198 script::ScriptEventDescriptor descr;
1199 if (xEvents->getByName( pNames[ nPos ] ) >>= descr)
1201 OSL_ENSURE( !descr.ListenerType.isEmpty() &&
1202 !descr.EventMethod.isEmpty() &&
1203 !descr.ScriptCode.isEmpty() &&
1204 !descr.ScriptType.isEmpty() ,
1205 "### invalid event descr!" );
1207 OUString aEventName;
1209 if (descr.AddListenerParam.isEmpty())
1211 // detection of event-name
1212 ::rtl::OString listenerType(
1213 ::rtl::OUStringToOString(
1214 descr.ListenerType,
1215 RTL_TEXTENCODING_ASCII_US ) );
1216 ::rtl::OString eventMethod(
1217 ::rtl::OUStringToOString(
1218 descr.EventMethod,
1219 RTL_TEXTENCODING_ASCII_US ) );
1220 StringTriple const * p = g_pEventTranslations;
1221 while (p->first)
1223 if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1224 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1226 aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1227 break;
1229 ++p;
1233 ElementDescriptor * pElem;
1234 Reference< xml::sax::XAttributeList > xElem;
1236 if (!aEventName.isEmpty()) // script:event
1238 pElem = new ElementDescriptor(
1239 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":event") ) );
1240 xElem = pElem;
1242 pElem->addAttribute(
1243 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":event-name") ),
1244 aEventName );
1246 else // script:listener-event
1248 pElem = new ElementDescriptor(
1249 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":listener-event") ) );
1250 xElem = pElem;
1252 pElem->addAttribute(
1253 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":listener-type") ),
1254 descr.ListenerType );
1255 pElem->addAttribute(
1256 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":listener-method") ),
1257 descr.EventMethod );
1259 if (!descr.AddListenerParam.isEmpty())
1261 pElem->addAttribute(
1262 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":listener-param") ),
1263 descr.AddListenerParam );
1266 if ( descr.ScriptType == "StarBasic" )
1268 // separate optional location
1269 sal_Int32 nIndex = descr.ScriptCode.indexOf( (sal_Unicode)':' );
1270 if (nIndex >= 0)
1272 pElem->addAttribute(
1273 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":location") ),
1274 descr.ScriptCode.copy( 0, nIndex ) );
1275 pElem->addAttribute(
1276 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":macro-name") ),
1277 descr.ScriptCode.copy( nIndex +1 ) );
1279 else
1281 pElem->addAttribute(
1282 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":macro-name") ),
1283 descr.ScriptCode );
1286 else
1288 pElem->addAttribute(
1289 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":macro-name") ),
1290 descr.ScriptCode );
1293 // language
1294 pElem->addAttribute(
1295 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_SCRIPT_PREFIX ":language") ),
1296 descr.ScriptType );
1298 addSubElement( xElem );
1300 else
1302 OSL_FAIL( "### unexpected event type in container!" );
1309 //##################################################################################################
1311 inline bool equalFont( Style const & style1, Style const & style2 )
1313 awt::FontDescriptor const & f1 = style1._descr;
1314 awt::FontDescriptor const & f2 = style2._descr;
1315 return (
1316 f1.Name == f2.Name &&
1317 f1.Height == f2.Height &&
1318 f1.Width == f2.Width &&
1319 f1.StyleName == f2.StyleName &&
1320 f1.Family == f2.Family &&
1321 f1.CharSet == f2.CharSet &&
1322 f1.Pitch == f2.CharSet &&
1323 f1.CharacterWidth == f2.CharacterWidth &&
1324 f1.Weight == f2.Weight &&
1325 f1.Slant == f2.Slant &&
1326 f1.Underline == f2.Underline &&
1327 f1.Strikeout == f2.Strikeout &&
1328 f1.Orientation == f2.Orientation &&
1329 (f1.Kerning != sal_False) == (f2.Kerning != sal_False) &&
1330 (f1.WordLineMode != sal_False) == (f2.WordLineMode != sal_False) &&
1331 f1.Type == f2.Type &&
1332 style1._fontRelief == style2._fontRelief &&
1333 style1._fontEmphasisMark == style2._fontEmphasisMark
1336 //__________________________________________________________________________________________________
1337 OUString StyleBag::getStyleId( Style const & rStyle )
1338 SAL_THROW(())
1340 if (! rStyle._set) // nothin set
1342 return OUString(); // everything default: no need to export a specific style
1345 // lookup existing style
1346 for ( size_t nStylesPos = 0; nStylesPos < _styles.size(); ++nStylesPos )
1348 Style * pStyle = _styles[ nStylesPos ];
1350 short demanded_defaults = ~rStyle._set & rStyle._all;
1351 // test, if defaults are not set
1352 if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1353 (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1355 short bset = rStyle._set & pStyle->_set;
1356 if ((bset & 0x1) &&
1357 rStyle._backgroundColor != pStyle->_backgroundColor)
1358 continue;
1359 if ((bset & 0x2) &&
1360 rStyle._textColor != pStyle->_textColor)
1361 continue;
1362 if ((bset & 0x20) &&
1363 rStyle._textLineColor != pStyle->_textLineColor)
1364 continue;
1365 if ((bset & 0x10) &&
1366 rStyle._fillColor != pStyle->_fillColor)
1367 continue;
1368 if ((bset & 0x4) &&
1369 (rStyle._border != pStyle->_border ||
1370 (rStyle._border == BORDER_SIMPLE_COLOR &&
1371 rStyle._borderColor != pStyle->_borderColor)))
1372 continue;
1373 if ((bset & 0x8) &&
1374 !equalFont( rStyle, *pStyle ))
1375 continue;
1376 if ((bset & 0x40) &&
1377 rStyle._visualEffect != pStyle->_visualEffect)
1378 continue;
1380 // merge in
1381 short bnset = rStyle._set & ~pStyle->_set;
1382 if (bnset & 0x1)
1383 pStyle->_backgroundColor = rStyle._backgroundColor;
1384 if (bnset & 0x2)
1385 pStyle->_textColor = rStyle._textColor;
1386 if (bnset & 0x20)
1387 pStyle->_textLineColor = rStyle._textLineColor;
1388 if (bnset & 0x10)
1389 pStyle->_fillColor = rStyle._fillColor;
1390 if (bnset & 0x4) {
1391 pStyle->_border = rStyle._border;
1392 pStyle->_borderColor = rStyle._borderColor;
1394 if (bnset & 0x8) {
1395 pStyle->_descr = rStyle._descr;
1396 pStyle->_fontRelief = rStyle._fontRelief;
1397 pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1399 if (bnset & 0x40)
1400 pStyle->_visualEffect = rStyle._visualEffect;
1402 pStyle->_all |= rStyle._all;
1403 pStyle->_set |= rStyle._set;
1405 return pStyle->_id;
1409 // no appr style found, append new
1410 Style * pStyle = new Style( rStyle );
1411 pStyle->_id = OUString::valueOf( (sal_Int32)_styles.size() );
1412 _styles.push_back( pStyle );
1413 return pStyle->_id;
1415 //__________________________________________________________________________________________________
1416 StyleBag::~StyleBag() SAL_THROW(())
1418 for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1420 delete _styles[ nPos ];
1423 //__________________________________________________________________________________________________
1424 void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1426 if (! _styles.empty())
1428 OUString aStylesName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":styles") );
1429 xOut->ignorableWhitespace( OUString() );
1430 xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1431 // export styles
1432 for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1434 Reference< xml::sax::XAttributeList > xAttr( _styles[ nPos ]->createElement() );
1435 static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1437 xOut->ignorableWhitespace( OUString() );
1438 xOut->endElement( aStylesName );
1442 //##################################################################################################
1444 //==================================================================================================
1445 void SAL_CALL exportDialogModel(
1446 Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1447 Reference< container::XNameContainer > const & xDialogModel,
1448 Reference< frame::XModel > const & xDocument )
1449 SAL_THROW( (Exception) )
1451 StyleBag all_styles;
1452 // window
1453 Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1454 OSL_ASSERT( xProps.is() );
1455 Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1456 OSL_ASSERT( xPropState.is() );
1458 ElementDescriptor * pElem = new ElementDescriptor(
1459 xProps, xPropState,
1460 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":bulletinboard") ), xDocument );
1461 Reference< xml::sax::XAttributeList > xElem( pElem );
1462 pElem->readBullitinBoard( &all_styles );
1464 xOut->startDocument();
1466 OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
1467 "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1468 " \"dialog.dtd\">" ) );
1469 xOut->unknown( aDocTypeStr );
1470 xOut->ignorableWhitespace( OUString() );
1473 OUString aWindowName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":window") );
1474 ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1475 Reference< xml::sax::XAttributeList > xWindow( pWindow );
1476 pWindow->readDialogModel( &all_styles );
1477 xOut->ignorableWhitespace( OUString() );
1478 xOut->startElement( aWindowName, xWindow );
1479 // dump out events
1480 pWindow->dumpSubElements( xOut.get() );
1481 // dump out stylebag
1482 all_styles.dump( xOut );
1484 if ( xDialogModel->getElementNames().getLength() )
1486 // open up bulletinboard
1487 OUString aBBoardName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_DIALOGS_PREFIX ":bulletinboard") );
1488 xOut->ignorableWhitespace( OUString() );
1489 xOut->startElement( aBBoardName, xElem );
1491 pElem->dumpSubElements( xOut.get() );
1492 // end bulletinboard
1493 xOut->ignorableWhitespace( OUString() );
1494 xOut->endElement( aBBoardName );
1497 // end window
1498 xOut->ignorableWhitespace( OUString() );
1499 xOut->endElement( aWindowName );
1501 xOut->endDocument();
1506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */