Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "exp_share.hxx"
21 :
22 : #include <rtl/ustrbuf.hxx>
23 : #include <tools/diagnose_ex.h>
24 :
25 : #include <com/sun/star/awt/CharSet.hpp>
26 : #include <com/sun/star/awt/FontFamily.hpp>
27 : #include <com/sun/star/awt/FontPitch.hpp>
28 : #include <com/sun/star/awt/FontSlant.hpp>
29 : #include <com/sun/star/awt/FontStrikeout.hpp>
30 : #include <com/sun/star/awt/FontType.hpp>
31 : #include <com/sun/star/awt/FontUnderline.hpp>
32 : #include <com/sun/star/awt/FontWeight.hpp>
33 : #include <com/sun/star/awt/FontWidth.hpp>
34 : #include <com/sun/star/awt/ImagePosition.hpp>
35 : #include <com/sun/star/awt/LineEndFormat.hpp>
36 : #include <com/sun/star/awt/PushButtonType.hpp>
37 : #include <com/sun/star/awt/VisualEffect.hpp>
38 :
39 : #include <com/sun/star/io/XPersistObject.hpp>
40 :
41 : #include <com/sun/star/script/XScriptEventsSupplier.hpp>
42 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
43 :
44 : #include <com/sun/star/style/VerticalAlignment.hpp>
45 :
46 : #include <com/sun/star/lang/XServiceInfo.hpp>
47 : #include <com/sun/star/lang/Locale.hpp>
48 : #include <com/sun/star/util/NumberFormat.hpp>
49 :
50 : #include <com/sun/star/view/SelectionType.hpp>
51 :
52 : #include <com/sun/star/form/binding/XListEntrySink.hpp>
53 : #include <com/sun/star/form/binding/XBindableValue.hpp>
54 : #include <com/sun/star/form/binding/XValueBinding.hpp>
55 : #include <com/sun/star/table/CellAddress.hpp>
56 : #include <com/sun/star/table/CellRangeAddress.hpp>
57 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
58 : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
59 :
60 : #include <comphelper/componentcontext.hxx>
61 : #include <comphelper/processfactory.hxx>
62 :
63 : using namespace ::com::sun::star;
64 : using namespace ::com::sun::star::uno;
65 : using ::rtl::OUString;
66 : using ::rtl::OUStringBuffer;
67 :
68 : namespace xmlscript
69 : {
70 :
71 : //__________________________________________________________________________________________________
72 0 : Reference< xml::sax::XAttributeList > Style::createElement()
73 : {
74 0 : ElementDescriptor * pStyle = new ElementDescriptor( XMLNS_DIALOGS_PREFIX ":style" );
75 :
76 : // style-id
77 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":style-id", _id );
78 :
79 : // background-color
80 0 : if (_set & 0x1)
81 : {
82 0 : OUStringBuffer buf( 16 );
83 0 : buf.append( (sal_Unicode)'0' );
84 0 : buf.append( (sal_Unicode)'x' );
85 0 : buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_backgroundColor, 16 ) );
86 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":background-color", buf.makeStringAndClear() );
87 : }
88 :
89 : // text-color
90 0 : if (_set & 0x2)
91 : {
92 0 : OUStringBuffer buf( 16 );
93 0 : buf.append( (sal_Unicode)'0' );
94 0 : buf.append( (sal_Unicode)'x' );
95 0 : buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_textColor, 16 ) );
96 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":text-color", buf.makeStringAndClear() );
97 : }
98 :
99 : // textline-color
100 0 : if (_set & 0x20)
101 : {
102 0 : OUStringBuffer buf( 16 );
103 0 : buf.append( (sal_Unicode)'0' );
104 0 : buf.append( (sal_Unicode)'x' );
105 0 : buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_textLineColor, 16 ) );
106 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":textline-color", buf.makeStringAndClear() );
107 : }
108 :
109 : // fill-color
110 0 : if (_set & 0x10)
111 : {
112 0 : OUStringBuffer buf( 16 );
113 0 : buf.append( (sal_Unicode)'0' );
114 0 : buf.append( (sal_Unicode)'x' );
115 0 : buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)_fillColor, 16 ) );
116 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":fill-color", buf.makeStringAndClear() );
117 : }
118 :
119 : // border
120 0 : if (_set & 0x4)
121 : {
122 0 : switch (_border)
123 : {
124 : case BORDER_NONE:
125 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "none" );
126 0 : break;
127 : case BORDER_3D:
128 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "3d" );
129 0 : break;
130 : case BORDER_SIMPLE:
131 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", "simple" );
132 0 : break;
133 : case BORDER_SIMPLE_COLOR: {
134 0 : OUStringBuffer buf;
135 0 : buf.appendAscii( "0x" );
136 0 : buf.append( OUString::valueOf((sal_Int64)(sal_uInt64)_borderColor, 16 ) );
137 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":border", buf.makeStringAndClear() );
138 0 : break;
139 : }
140 : default:
141 : OSL_FAIL( "### unexpected border value!" );
142 0 : break;
143 : }
144 : }
145 :
146 : // visual effect (look)
147 0 : if (_set & 0x40)
148 : {
149 0 : switch (_visualEffect)
150 : {
151 : case awt::VisualEffect::NONE:
152 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "none" );
153 0 : break;
154 : case awt::VisualEffect::LOOK3D:
155 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "3d" );
156 0 : break;
157 : case awt::VisualEffect::FLAT:
158 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":look", "simple" );
159 0 : break;
160 : default:
161 : OSL_FAIL( "### unexpected visual effect value!" );
162 0 : break;
163 : }
164 : }
165 :
166 : // font-
167 0 : if (_set & 0x8)
168 : {
169 0 : awt::FontDescriptor def_descr;
170 :
171 : // dialog:font-name CDATA #IMPLIED
172 0 : if (def_descr.Name != _descr.Name)
173 : {
174 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-name", _descr.Name );
175 : }
176 : // dialog:font-height %numeric; #IMPLIED
177 0 : if (def_descr.Height != _descr.Height)
178 : {
179 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-height", OUString::valueOf( (sal_Int32)_descr.Height ) );
180 : }
181 : // dialog:font-width %numeric; #IMPLIED
182 0 : if (def_descr.Width != _descr.Width)
183 : {
184 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-width", OUString::valueOf( (sal_Int32)_descr.Width ) );
185 : }
186 : // dialog:font-stylename CDATA #IMPLIED
187 0 : if (def_descr.StyleName != _descr.StyleName)
188 : {
189 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-stylename", _descr.StyleName );
190 : }
191 : // dialog:font-family "(decorative|modern|roman|script|swiss|system)" #IMPLIED
192 0 : if (def_descr.Family != _descr.Family)
193 : {
194 0 : switch (_descr.Family)
195 : {
196 : case awt::FontFamily::DECORATIVE:
197 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "decorative" );
198 0 : break;
199 : case awt::FontFamily::MODERN:
200 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "modern" );
201 0 : break;
202 : case awt::FontFamily::ROMAN:
203 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "roman" );
204 0 : break;
205 : case awt::FontFamily::SCRIPT:
206 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "script" );
207 0 : break;
208 : case awt::FontFamily::SWISS:
209 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "swiss" );
210 0 : break;
211 : case awt::FontFamily::SYSTEM:
212 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-family", "system" );
213 0 : break;
214 : default:
215 : OSL_FAIL( "### unexpected font-family!" );
216 0 : break;
217 : }
218 : }
219 : // dialog:font-charset "(ansi|mac|ibmpc_437|ibmpc_850|ibmpc_860|ibmpc_861|ibmpc_863|ibmpc_865|system|symbol)" #IMPLIED
220 0 : if (def_descr.CharSet != _descr.CharSet)
221 : {
222 0 : switch (_descr.CharSet)
223 : {
224 : case awt::CharSet::ANSI:
225 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ansi" );
226 0 : break;
227 : case awt::CharSet::MAC:
228 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "mac" );
229 0 : break;
230 : case awt::CharSet::IBMPC_437:
231 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_437" );
232 0 : break;
233 : case awt::CharSet::IBMPC_850:
234 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_850" );
235 0 : break;
236 : case awt::CharSet::IBMPC_860:
237 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_860" );
238 0 : break;
239 : case awt::CharSet::IBMPC_861:
240 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_861" );
241 0 : break;
242 : case awt::CharSet::IBMPC_863:
243 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_863" );
244 0 : break;
245 : case awt::CharSet::IBMPC_865:
246 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "ibmpc_865" );
247 0 : break;
248 : case awt::CharSet::SYSTEM:
249 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "system" );
250 0 : break;
251 : case awt::CharSet::SYMBOL:
252 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charset", "symbol" );
253 0 : break;
254 : default:
255 : OSL_FAIL( "### unexpected font-charset!" );
256 0 : break;
257 : }
258 : }
259 : // dialog:font-pitch "(fixed|variable)" #IMPLIED
260 0 : if (def_descr.Pitch != _descr.Pitch)
261 : {
262 0 : switch (_descr.Pitch)
263 : {
264 : case awt::FontPitch::FIXED:
265 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "fixed" );
266 0 : break;
267 : case awt::FontPitch::VARIABLE:
268 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-pitch", "variable" );
269 0 : break;
270 : default:
271 : OSL_FAIL( "### unexpected font-pitch!" );
272 0 : break;
273 : }
274 : }
275 : // dialog:font-charwidth CDATA #IMPLIED
276 0 : if (def_descr.CharacterWidth != _descr.CharacterWidth)
277 : {
278 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-charwidth", OUString::valueOf( (float)_descr.CharacterWidth ) );
279 : }
280 : // dialog:font-weight CDATA #IMPLIED
281 0 : if (def_descr.Weight != _descr.Weight)
282 : {
283 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-weight", OUString::valueOf( (float)_descr.Weight ) );
284 : }
285 : // dialog:font-slant "(oblique|italic|reverse_oblique|reverse_italic)" #IMPLIED
286 0 : if (def_descr.Slant != _descr.Slant)
287 : {
288 0 : switch (_descr.Slant)
289 : {
290 : case awt::FontSlant_OBLIQUE:
291 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "oblique" );
292 0 : break;
293 : case awt::FontSlant_ITALIC:
294 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "italic" );
295 0 : break;
296 : case awt::FontSlant_REVERSE_OBLIQUE:
297 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_oblique" );
298 0 : break;
299 : case awt::FontSlant_REVERSE_ITALIC:
300 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-slant", "reverse_italic" );
301 0 : break;
302 : default:
303 : OSL_FAIL( "### unexpected font-slant!" );
304 0 : break;
305 : }
306 : }
307 : // dialog:font-underline "(single|double|dotted|dash|longdash|dashdot|dashdotdot|smallwave|wave|doublewave|bold|bolddotted|bolddash|boldlongdash|bolddashdot|bolddashdotdot|boldwave)" #IMPLIED
308 0 : if (def_descr.Underline != _descr.Underline)
309 : {
310 0 : switch (_descr.Underline)
311 : {
312 : case awt::FontUnderline::SINGLE:
313 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "single" );
314 0 : break;
315 : case awt::FontUnderline::DOUBLE:
316 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "double" );
317 0 : break;
318 : case awt::FontUnderline::DOTTED:
319 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dotted" );
320 0 : break;
321 : case awt::FontUnderline::DASH:
322 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dash" );
323 0 : break;
324 : case awt::FontUnderline::LONGDASH:
325 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "longdash" );
326 0 : break;
327 : case awt::FontUnderline::DASHDOT:
328 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdot" );
329 0 : break;
330 : case awt::FontUnderline::DASHDOTDOT:
331 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "dashdotdot" );
332 0 : break;
333 : case awt::FontUnderline::SMALLWAVE:
334 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "smallwave" );
335 0 : break;
336 : case awt::FontUnderline::WAVE:
337 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "wave" );
338 0 : break;
339 : case awt::FontUnderline::DOUBLEWAVE:
340 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "doublewave" );
341 0 : break;
342 : case awt::FontUnderline::BOLD:
343 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bold" );
344 0 : break;
345 : case awt::FontUnderline::BOLDDOTTED:
346 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddotted" );
347 0 : break;
348 : case awt::FontUnderline::BOLDDASH:
349 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddash" );
350 0 : break;
351 : case awt::FontUnderline::BOLDLONGDASH:
352 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldlongdash" );
353 0 : break;
354 : case awt::FontUnderline::BOLDDASHDOT:
355 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdot" );
356 0 : break;
357 : case awt::FontUnderline::BOLDDASHDOTDOT:
358 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "bolddashdotdot" );
359 0 : break;
360 : case awt::FontUnderline::BOLDWAVE:
361 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-underline", "boldwave" );
362 0 : break;
363 : default:
364 : OSL_FAIL( "### unexpected font-underline!" );
365 0 : break;
366 : }
367 : }
368 : // dialog:font-strikeout "(single|double|bold|slash|x)" #IMPLIED
369 0 : if (def_descr.Strikeout != _descr.Strikeout)
370 : {
371 0 : switch (_descr.Strikeout)
372 : {
373 : case awt::FontStrikeout::SINGLE:
374 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "single" );
375 0 : break;
376 : case awt::FontStrikeout::DOUBLE:
377 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "double" );
378 0 : break;
379 : case awt::FontStrikeout::BOLD:
380 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "bold" );
381 0 : break;
382 : case awt::FontStrikeout::SLASH:
383 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "slash" );
384 0 : break;
385 : case awt::FontStrikeout::X:
386 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-strikeout", "x" );
387 0 : break;
388 : default:
389 : OSL_FAIL( "### unexpected font-strikeout!" );
390 0 : break;
391 : }
392 : }
393 : // dialog:font-orientation CDATA #IMPLIED
394 0 : if (def_descr.Orientation != _descr.Orientation)
395 : {
396 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::valueOf( (float)_descr.Orientation ) );
397 : }
398 : // dialog:font-kerning %boolean; #IMPLIED
399 0 : if ((def_descr.Kerning != sal_False) != (_descr.Kerning != sal_False))
400 : {
401 0 : pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
402 : }
403 : // dialog:font-wordlinemode %boolean; #IMPLIED
404 0 : if ((def_descr.WordLineMode != sal_False) != (_descr.WordLineMode != sal_False))
405 : {
406 0 : pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
407 : }
408 : // dialog:font-type "(raster|device|scalable)" #IMPLIED
409 0 : if (def_descr.Type != _descr.Type)
410 : {
411 0 : switch (_descr.Type)
412 : {
413 : case awt::FontType::RASTER:
414 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "raster" );
415 0 : break;
416 : case awt::FontType::DEVICE:
417 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "device" );
418 0 : break;
419 : case awt::FontType::SCALABLE:
420 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-type", "scalable" );
421 0 : break;
422 : default:
423 : OSL_FAIL( "### unexpected font-type!" );
424 0 : break;
425 : }
426 : }
427 :
428 : // additional attributes not in FontDescriptor struct
429 : // dialog:font-relief (none|embossed|engraved) #IMPLIED
430 0 : switch (_fontRelief)
431 : {
432 : case awt::FontRelief::NONE: // dont export default
433 0 : break;
434 : case awt::FontRelief::EMBOSSED:
435 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "embossed" );
436 0 : break;
437 : case awt::FontRelief::ENGRAVED:
438 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-relief", "engraved" );
439 0 : break;
440 : default:
441 : OSL_FAIL( "### unexpected font-relief!" );
442 0 : break;
443 : }
444 : // dialog:font-emphasismark (none|dot|circle|disc|accent|above|below) #IMPLIED
445 0 : switch (_fontEmphasisMark)
446 : {
447 : case awt::FontEmphasisMark::NONE: // dont export default
448 0 : break;
449 : case awt::FontEmphasisMark::DOT:
450 0 : pStyle->addAttribute(XMLNS_DIALOGS_PREFIX ":font-emphasismark", "dot" );
451 0 : break;
452 : case awt::FontEmphasisMark::CIRCLE:
453 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "circle" );
454 0 : break;
455 : case awt::FontEmphasisMark::DISC:
456 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "disc" );
457 0 : break;
458 : case awt::FontEmphasisMark::ACCENT:
459 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "accent" );
460 0 : break;
461 : case awt::FontEmphasisMark::ABOVE:
462 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "above" );
463 0 : break;
464 : case awt::FontEmphasisMark::BELOW:
465 0 : pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-emphasismark", "below" );
466 0 : break;
467 : default:
468 : OSL_FAIL( "### unexpected font-emphasismark!" );
469 0 : break;
470 0 : }
471 : }
472 :
473 0 : return pStyle;
474 : }
475 :
476 : //##################################################################################################
477 :
478 : //__________________________________________________________________________________________________
479 0 : void ElementDescriptor::addNumberFormatAttr(
480 : Reference< beans::XPropertySet > const & xFormatProperties )
481 : {
482 0 : Reference< beans::XPropertyState > xState( xFormatProperties, UNO_QUERY );
483 0 : OUString sFormat;
484 0 : lang::Locale locale;
485 0 : OSL_VERIFY( xFormatProperties->getPropertyValue( "FormatString" ) >>= sFormat );
486 0 : OSL_VERIFY( xFormatProperties->getPropertyValue( "Locale" ) >>= locale );
487 :
488 0 : addAttribute(XMLNS_DIALOGS_PREFIX ":format-code", sFormat );
489 :
490 : // format-locale
491 0 : OUStringBuffer buf( 48 );
492 0 : buf.append( locale.Language );
493 0 : if (!locale.Country.isEmpty())
494 : {
495 0 : buf.append( (sal_Unicode)';' );
496 0 : buf.append( locale.Country );
497 0 : if (!locale.Variant.isEmpty())
498 : {
499 0 : buf.append( (sal_Unicode)';' );
500 0 : buf.append( locale.Variant );
501 : }
502 : }
503 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":format-locale", buf.makeStringAndClear() );
504 0 : }
505 : //__________________________________________________________________________________________________
506 0 : Any ElementDescriptor::readProp( OUString const & rPropName )
507 : {
508 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
509 : {
510 0 : return _xProps->getPropertyValue( rPropName );
511 : }
512 0 : return Any();
513 : }
514 :
515 : //______________________________________________________________________________
516 0 : void ElementDescriptor::readStringAttr(
517 : OUString const & rPropName, OUString const & rAttrName )
518 : {
519 0 : if (beans::PropertyState_DEFAULT_VALUE !=
520 0 : _xPropState->getPropertyState( rPropName ))
521 : {
522 0 : Any a( _xProps->getPropertyValue( rPropName ) );
523 0 : OUString v;
524 0 : if (a >>= v)
525 0 : addAttribute( rAttrName, v );
526 : else
527 0 : OSL_FAIL( "### unexpected property type!" );
528 : }
529 0 : }
530 :
531 : //__________________________________________________________________________________________________
532 0 : void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString const & rAttrName )
533 : {
534 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
535 : {
536 0 : Any a( _xProps->getPropertyValue( rPropName ) );
537 0 : if (a.getValueTypeClass() == TypeClass_LONG)
538 : {
539 0 : OUStringBuffer buf( 16 );
540 0 : buf.append( (sal_Unicode)'0' );
541 0 : buf.append( (sal_Unicode)'x' );
542 0 : buf.append( OUString::valueOf( (sal_Int64)(sal_uInt64)*(sal_uInt32 *)a.getValue(), 16 ) );
543 0 : addAttribute( rAttrName, buf.makeStringAndClear() );
544 0 : }
545 : }
546 0 : }
547 :
548 : //__________________________________________________________________________________________________
549 0 : void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName )
550 : {
551 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
552 : {
553 0 : Any a( _xProps->getPropertyValue( rPropName ) );
554 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
555 : {
556 0 : switch (*(sal_Int16 const *)a.getValue())
557 : {
558 : case 0:
559 0 : addAttribute( rAttrName, "system_short" );
560 0 : break;
561 : case 1:
562 0 : addAttribute( rAttrName, "system_short_YY" );
563 0 : break;
564 : case 2:
565 0 : addAttribute( rAttrName, "system_short_YYYY" );
566 0 : break;
567 : case 3:
568 0 : addAttribute( rAttrName, "system_long" );
569 0 : break;
570 : case 4:
571 0 : addAttribute( rAttrName, "short_DDMMYY" );
572 0 : break;
573 : case 5:
574 0 : addAttribute( rAttrName, "short_MMDDYY" );
575 0 : break;
576 : case 6:
577 0 : addAttribute( rAttrName, "short_YYMMDD" );
578 0 : break;
579 : case 7:
580 0 : addAttribute( rAttrName, "short_DDMMYYYY" );
581 0 : break;
582 : case 8:
583 0 : addAttribute( rAttrName, "short_MMDDYYYY" );
584 0 : break;
585 : case 9:
586 0 : addAttribute( rAttrName, "short_YYYYMMDD" );
587 0 : break;
588 : case 10:
589 0 : addAttribute( rAttrName, "short_YYMMDD_DIN5008" );
590 0 : break;
591 : case 11:
592 0 : addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" );
593 0 : break;
594 : default:
595 : OSL_FAIL( "### unexpected date format!" );
596 0 : break;
597 : }
598 0 : }
599 : }
600 0 : }
601 : //__________________________________________________________________________________________________
602 0 : void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName )
603 : {
604 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
605 : {
606 0 : Any a( _xProps->getPropertyValue( rPropName ) );
607 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
608 : {
609 0 : switch (*(sal_Int16 const *)a.getValue())
610 : {
611 : case 0:
612 0 : addAttribute( rAttrName, "24h_short" );
613 0 : break;
614 : case 1:
615 0 : addAttribute( rAttrName, "24h_long" );
616 0 : break;
617 : case 2:
618 0 : addAttribute( rAttrName, "12h_short" );
619 0 : break;
620 : case 3:
621 0 : addAttribute( rAttrName, "12h_long" );
622 0 : break;
623 : case 4:
624 0 : addAttribute( rAttrName, "Duration_short" );
625 0 : break;
626 : case 5:
627 0 : addAttribute( rAttrName, "Duration_long" );
628 0 : break;
629 : default:
630 : OSL_FAIL( "### unexpected time format!" );
631 0 : break;
632 : }
633 0 : }
634 : }
635 0 : }
636 : //__________________________________________________________________________________________________
637 0 : void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName )
638 : {
639 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
640 : {
641 0 : Any a( _xProps->getPropertyValue( rPropName ) );
642 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
643 : {
644 0 : switch (*(sal_Int16 const *)a.getValue())
645 : {
646 : case 0:
647 0 : addAttribute( rAttrName, "left" );
648 0 : break;
649 : case 1:
650 0 : addAttribute( rAttrName, "center" );
651 0 : break;
652 : case 2:
653 0 : addAttribute( rAttrName, "right" );
654 0 : break;
655 : default:
656 : OSL_FAIL( "### illegal alignment value!" );
657 0 : break;
658 : }
659 0 : }
660 : }
661 0 : }
662 : //__________________________________________________________________________________________________
663 0 : void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName )
664 : {
665 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
666 : {
667 0 : Any a( _xProps->getPropertyValue( rPropName ) );
668 0 : if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == ::getCppuType( (style::VerticalAlignment*)0 ))
669 : {
670 : style::VerticalAlignment eAlign;
671 0 : a >>= eAlign;
672 0 : switch (eAlign)
673 : {
674 : case style::VerticalAlignment_TOP:
675 0 : addAttribute( rAttrName, "top" );
676 0 : break;
677 : case style::VerticalAlignment_MIDDLE:
678 0 : addAttribute( rAttrName, "center" );
679 0 : break;
680 : case style::VerticalAlignment_BOTTOM:
681 0 : addAttribute( rAttrName, "bottom" );
682 0 : break;
683 : default:
684 : OSL_FAIL( "### illegal vertical alignment value!" );
685 0 : break;
686 : }
687 0 : }
688 : }
689 0 : }
690 : //__________________________________________________________________________________________________
691 0 : void ElementDescriptor::readImageURLAttr( OUString const & rPropName, OUString const & rAttrName )
692 : {
693 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
694 : {
695 0 : OUString sURL;
696 0 : _xProps->getPropertyValue( rPropName ) >>= sURL;
697 :
698 0 : if ( !sURL.isEmpty() && sURL.compareToAscii( XMLSCRIPT_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( XMLSCRIPT_GRAPHOBJ_URLPREFIX ) ) == 0 )
699 : {
700 0 : Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY );
701 0 : if ( xDocStorage.is() )
702 : {
703 0 : uno::Sequence< Any > aArgs( 1 );
704 0 : aArgs[ 0 ] <<= xDocStorage->getDocumentStorage();
705 :
706 0 : ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
707 0 : uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
708 0 : aContext.createComponentWithArguments( "com.sun.star.comp.Svx.GraphicExportHelper" , aArgs, xGraphicResolver );
709 0 : if ( xGraphicResolver.is() )
710 0 : sURL = xGraphicResolver->resolveGraphicObjectURL( sURL );
711 0 : }
712 : }
713 0 : if ( !sURL.isEmpty() )
714 0 : addAttribute( rAttrName, sURL );
715 : }
716 0 : }
717 : //__________________________________________________________________________________________________
718 0 : void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName )
719 : {
720 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
721 : {
722 0 : Any a( _xProps->getPropertyValue( rPropName ) );
723 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
724 : {
725 0 : switch (*(sal_Int16 const *)a.getValue())
726 : {
727 : case 0:
728 0 : addAttribute( rAttrName, "left" );
729 0 : break;
730 : case 1:
731 0 : addAttribute( rAttrName, "top" );
732 0 : break;
733 : case 2:
734 0 : addAttribute( rAttrName, "right" );
735 0 : break;
736 : case 3:
737 0 : addAttribute( rAttrName, "bottom" );
738 0 : break;
739 : default:
740 : OSL_FAIL( "### illegal image alignment value!" );
741 0 : break;
742 : }
743 0 : }
744 : }
745 0 : }
746 : //__________________________________________________________________________________________________
747 0 : void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName )
748 : {
749 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
750 : {
751 0 : Any a( _xProps->getPropertyValue( rPropName ) );
752 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
753 : {
754 0 : switch (*(sal_Int16 const *)a.getValue())
755 : {
756 : case awt::ImagePosition::LeftTop:
757 0 : addAttribute( rAttrName, "left-top" );
758 0 : break;
759 : case awt::ImagePosition::LeftCenter:
760 0 : addAttribute( rAttrName, "left-center" );
761 0 : break;
762 : case awt::ImagePosition::LeftBottom:
763 0 : addAttribute( rAttrName, "left-bottom" );
764 0 : break;
765 : case awt::ImagePosition::RightTop:
766 0 : addAttribute( rAttrName, "right-top" );
767 0 : break;
768 : case awt::ImagePosition::RightCenter:
769 0 : addAttribute( rAttrName, "right-center" );
770 0 : break;
771 : case awt::ImagePosition::RightBottom:
772 0 : addAttribute( rAttrName, "right-bottom" );
773 0 : break;
774 : case awt::ImagePosition::AboveLeft:
775 0 : addAttribute( rAttrName, "top-left" );
776 0 : break;
777 : case awt::ImagePosition::AboveCenter:
778 0 : addAttribute( rAttrName, "top-center" );
779 0 : break;
780 : case awt::ImagePosition::AboveRight:
781 0 : addAttribute( rAttrName, "top-right" );
782 0 : break;
783 : case awt::ImagePosition::BelowLeft:
784 0 : addAttribute( rAttrName, "bottom-left" );
785 0 : break;
786 : case awt::ImagePosition::BelowCenter:
787 0 : addAttribute( rAttrName, "bottom-center" );
788 0 : break;
789 : case awt::ImagePosition::BelowRight:
790 0 : addAttribute( rAttrName, "bottom-right" );
791 0 : break;
792 : case awt::ImagePosition::Centered:
793 0 : addAttribute( rAttrName, "center" );
794 0 : break;
795 : default:
796 : OSL_FAIL( "### illegal image position value!" );
797 0 : break;
798 : }
799 0 : }
800 : }
801 0 : }
802 : //__________________________________________________________________________________________________
803 0 : void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName )
804 : {
805 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
806 : {
807 0 : Any a( _xProps->getPropertyValue( rPropName ) );
808 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
809 : {
810 0 : switch (*(sal_Int16 const *)a.getValue())
811 : {
812 : case awt::PushButtonType_STANDARD:
813 0 : addAttribute( rAttrName, "standard" );
814 0 : break;
815 : case awt::PushButtonType_OK:
816 0 : addAttribute( rAttrName, "ok" );
817 0 : break;
818 : case awt::PushButtonType_CANCEL:
819 0 : addAttribute( rAttrName, "cancel" );
820 0 : break;
821 : case awt::PushButtonType_HELP:
822 0 : addAttribute( rAttrName, "help" );
823 0 : break;
824 : default:
825 : OSL_FAIL( "### illegal button-type value!" );
826 0 : break;
827 : }
828 0 : }
829 : }
830 0 : }
831 : //__________________________________________________________________________________________________
832 0 : void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName )
833 : {
834 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
835 : {
836 0 : Any a( _xProps->getPropertyValue( rPropName ) );
837 0 : if (a.getValueTypeClass() == TypeClass_LONG)
838 : {
839 0 : switch (*(sal_Int32 const *)a.getValue())
840 : {
841 : case 0:
842 0 : addAttribute( rAttrName, "horizontal" );
843 0 : break;
844 : case 1:
845 0 : addAttribute( rAttrName, "vertical" );
846 0 : break;
847 : default:
848 : OSL_FAIL( "### illegal orientation value!" );
849 0 : break;
850 : }
851 0 : }
852 : }
853 0 : }
854 : //__________________________________________________________________________________________________
855 0 : void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName )
856 : {
857 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
858 : {
859 0 : Any a( _xProps->getPropertyValue( rPropName ) );
860 0 : if (a.getValueTypeClass() == TypeClass_SHORT)
861 : {
862 0 : switch (*(sal_Int16 const *)a.getValue())
863 : {
864 : case awt::LineEndFormat::CARRIAGE_RETURN:
865 0 : addAttribute( rAttrName, "carriage-return" );
866 0 : break;
867 : case awt::LineEndFormat::LINE_FEED:
868 0 : addAttribute( rAttrName, "line-feed" );
869 0 : break;
870 : case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED:
871 0 : addAttribute( rAttrName, "carriage-return-line-feed" );
872 0 : break;
873 : default:
874 : OSL_FAIL( "### illegal line end format value!" );
875 0 : break;
876 : }
877 0 : }
878 : }
879 0 : }
880 : //__________________________________________________________________________________________________
881 0 : void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName )
882 : {
883 0 : Reference< lang::XMultiServiceFactory > xFac;
884 0 : if ( _xDocument.is() )
885 0 : xFac.set( _xDocument, uno::UNO_QUERY );
886 :
887 0 : Reference< form::binding::XBindableValue > xBinding( _xProps, UNO_QUERY );
888 :
889 0 : if ( xFac.is() && xBinding.is() && rAttrName.equals( XMLNS_DIALOGS_PREFIX ":linked-cell" ) )
890 : {
891 : try
892 : {
893 0 : Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellAddressConversion" ), uno::UNO_QUERY );
894 0 : Reference< beans::XPropertySet > xBindable( xBinding->getValueBinding(), UNO_QUERY );
895 0 : if ( xBindable.is() )
896 : {
897 0 : table::CellAddress aAddress;
898 0 : xBindable->getPropertyValue( "BoundCell" ) >>= aAddress;
899 0 : xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
900 0 : OUString sAddress;
901 0 : xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
902 0 : if ( !sAddress.isEmpty() )
903 0 : addAttribute( rAttrName, sAddress );
904 :
905 0 : OSL_TRACE( "*** Bindable value %s", OUStringToOString( sAddress, RTL_TEXTENCODING_UTF8 ).getStr() );
906 :
907 0 : }
908 : }
909 0 : catch( uno::Exception& )
910 : {
911 : }
912 : }
913 0 : Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY );
914 0 : if ( xEntrySink.is() && rAttrName.equals( XMLNS_DIALOGS_PREFIX ":source-cell-range" ) )
915 : {
916 0 : Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY );
917 0 : if ( xListSource.is() )
918 : {
919 : try
920 : {
921 0 : Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY );
922 :
923 0 : table::CellRangeAddress aAddress;
924 0 : xListSource->getPropertyValue( "CellRange" ) >>= aAddress;
925 :
926 0 : OUString sAddress;
927 0 : xConvertor->setPropertyValue( "Address", makeAny( aAddress ) );
928 0 : xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress;
929 : OSL_TRACE("**** cell range source list %s", OUStringToOString( sAddress, RTL_TEXTENCODING_UTF8 ).getStr() );
930 0 : if ( !sAddress.isEmpty() )
931 0 : addAttribute( rAttrName, sAddress );
932 : }
933 0 : catch( uno::Exception& )
934 : {
935 : }
936 0 : }
937 0 : }
938 0 : }
939 : //__________________________________________________________________________________________________
940 0 : void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName )
941 : {
942 0 : if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName ))
943 : {
944 0 : Any aSelectionType ( _xProps->getPropertyValue( rPropName ) );
945 :
946 0 : if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == ::getCppuType( (::view::SelectionType*)0 ))
947 : {
948 : ::view::SelectionType eSelectionType;
949 0 : aSelectionType >>= eSelectionType;
950 :
951 0 : switch (eSelectionType)
952 : {
953 : case ::view::SelectionType_NONE:
954 0 : addAttribute( rAttrName, "none" );
955 0 : break;
956 : case ::view::SelectionType_SINGLE:
957 0 : addAttribute( rAttrName, "single" );
958 0 : break;
959 : case ::view::SelectionType_MULTI:
960 0 : addAttribute( rAttrName, "multi" );
961 0 : break;
962 : case ::view::SelectionType_RANGE:
963 0 : addAttribute( rAttrName, "range" );
964 0 : break;
965 : default:
966 : OSL_FAIL( "### illegal selection type value!" );
967 0 : break;
968 : }
969 0 : }
970 : }
971 0 : }
972 : //__________________________________________________________________________________________________
973 0 : void ElementDescriptor::readScrollableSettings()
974 : {
975 : readLongAttr( "ScrollHeight",
976 0 : XMLNS_DIALOGS_PREFIX ":scrollheight" );
977 : readLongAttr( "ScrollWidth",
978 0 : XMLNS_DIALOGS_PREFIX ":scrollwidth" );
979 : readLongAttr( "ScrollTop",
980 0 : XMLNS_DIALOGS_PREFIX ":scrolltop" );
981 : readLongAttr( "ScrollLeft",
982 0 : XMLNS_DIALOGS_PREFIX ":scrollleft" );
983 : readBoolAttr( "HScroll",
984 0 : XMLNS_DIALOGS_PREFIX ":hscroll" );
985 : readBoolAttr( "VScroll",
986 0 : XMLNS_DIALOGS_PREFIX ":vscroll" );
987 0 : }
988 :
989 0 : void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible )
990 : {
991 0 : Any a( _xProps->getPropertyValue( "Name" ) );
992 :
993 : // The following is a hack to allow 'form' controls to override the default
994 : // control supported by dialogs. This should work well for both vba support and
995 : // normal openoffice ( when normal 'Dialogs' decide to support form control models )
996 : // In the future VBA support might require custom models ( and not the just the form
997 : // variant of a control that we currently use ) In this case the door is still open,
998 : // we just need to define a new way for the 'ServiceName' to be extracted from the
999 : // incomming model. E.g. the use of supporting service
1000 : // "com.sun.star.form.FormComponent", 'ServiceName' and XPersistObject
1001 : // is only an implementation detail here, in the future some other
1002 : // method ( perhaps a custom prop ) could be used instead.
1003 0 : Reference< lang::XServiceInfo > xSrvInfo( _xProps, UNO_QUERY );
1004 0 : if ( xSrvInfo.is() && xSrvInfo->supportsService( "com.sun.star.form.FormComponent" ) )
1005 : {
1006 0 : Reference< io::XPersistObject > xPersist( _xProps, UNO_QUERY );
1007 0 : if ( xPersist.is() )
1008 : {
1009 0 : OUString sCtrlName = xPersist->getServiceName();
1010 0 : if ( !sCtrlName.isEmpty() )
1011 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":control-implementation", sCtrlName );
1012 0 : }
1013 : }
1014 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":id", * reinterpret_cast< const OUString * >( a.getValue() ) );
1015 0 : readShortAttr( "TabIndex", XMLNS_DIALOGS_PREFIX ":tab-index" );
1016 :
1017 0 : sal_Bool bEnabled = sal_False;
1018 0 : if (_xProps->getPropertyValue( "Enabled" ) >>= bEnabled)
1019 : {
1020 0 : if (! bEnabled)
1021 : {
1022 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":disabled", "true" );
1023 : }
1024 : }
1025 : else
1026 : {
1027 : OSL_FAIL( "unexpected property type for \"Enabled\": not bool!" );
1028 : }
1029 :
1030 0 : sal_Bool bVisible = sal_True;
1031 0 : if (supportVisible) try
1032 : {
1033 0 : if (_xProps->getPropertyValue("EnableVisible" ) >>= bVisible)
1034 : {
1035 :
1036 : // only write out the non default case
1037 0 : if (! bVisible)
1038 : {
1039 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":visible", "false" );
1040 : }
1041 : }
1042 : }
1043 0 : catch( Exception& )
1044 : {
1045 : DBG_UNHANDLED_EXCEPTION();
1046 : }
1047 : // force writing of pos/size
1048 0 : a = _xProps->getPropertyValue( "PositionX" );
1049 0 : if (a.getValueTypeClass() == TypeClass_LONG)
1050 : {
1051 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":left", OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1052 : }
1053 0 : a = _xProps->getPropertyValue( "PositionY" );
1054 0 : if (a.getValueTypeClass() == TypeClass_LONG)
1055 : {
1056 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":top", OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1057 : }
1058 0 : a = _xProps->getPropertyValue( "Width" );
1059 0 : if (a.getValueTypeClass() == TypeClass_LONG)
1060 : {
1061 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":width", OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1062 : }
1063 0 : a = _xProps->getPropertyValue( "Height" );
1064 0 : if (a.getValueTypeClass() == TypeClass_LONG)
1065 : {
1066 0 : addAttribute( XMLNS_DIALOGS_PREFIX ":height", OUString::valueOf( *(sal_Int32 const *)a.getValue() ) );
1067 : }
1068 :
1069 0 : if (supportPrintable)
1070 : {
1071 0 : readBoolAttr( "Printable", XMLNS_DIALOGS_PREFIX ":printable" );
1072 : }
1073 0 : readLongAttr( "Step", XMLNS_DIALOGS_PREFIX ":page" );
1074 0 : readStringAttr( "Tag", XMLNS_DIALOGS_PREFIX ":tag" );
1075 0 : readStringAttr( "HelpText", XMLNS_DIALOGS_PREFIX ":help-text" );
1076 0 : readStringAttr( "HelpURL", XMLNS_DIALOGS_PREFIX ":help-url" );
1077 0 : }
1078 :
1079 : struct StringTriple
1080 : {
1081 : char const * first;
1082 : char const * second;
1083 : char const * third;
1084 : };
1085 : extern StringTriple const * const g_pEventTranslations;
1086 :
1087 : //__________________________________________________________________________________________________
1088 0 : void ElementDescriptor::readEvents()
1089 : SAL_THROW( (Exception) )
1090 : {
1091 0 : Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY );
1092 0 : if (xSupplier.is())
1093 : {
1094 0 : Reference< container::XNameContainer > xEvents( xSupplier->getEvents() );
1095 0 : if (xEvents.is())
1096 : {
1097 0 : Sequence< OUString > aNames( xEvents->getElementNames() );
1098 0 : OUString const * pNames = aNames.getConstArray();
1099 0 : for ( sal_Int32 nPos = 0; nPos < aNames.getLength(); ++nPos )
1100 : {
1101 0 : script::ScriptEventDescriptor descr;
1102 0 : if (xEvents->getByName( pNames[ nPos ] ) >>= descr)
1103 : {
1104 : OSL_ENSURE( !descr.ListenerType.isEmpty() &&
1105 : !descr.EventMethod.isEmpty() &&
1106 : !descr.ScriptCode.isEmpty() &&
1107 : !descr.ScriptType.isEmpty() ,
1108 : "### invalid event descr!" );
1109 :
1110 0 : OUString aEventName;
1111 :
1112 0 : if (descr.AddListenerParam.isEmpty())
1113 : {
1114 : // detection of event-name
1115 0 : OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) );
1116 0 : OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) );
1117 0 : StringTriple const * p = g_pEventTranslations;
1118 0 : while (p->first)
1119 : {
1120 0 : if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) &&
1121 0 : 0 == ::rtl_str_compare( p->first, listenerType.getStr() ))
1122 : {
1123 0 : aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US );
1124 0 : break;
1125 : }
1126 0 : ++p;
1127 0 : }
1128 : }
1129 :
1130 : ElementDescriptor * pElem;
1131 0 : Reference< xml::sax::XAttributeList > xElem;
1132 :
1133 0 : if (!aEventName.isEmpty()) // script:event
1134 : {
1135 0 : pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" );
1136 0 : xElem = pElem;
1137 :
1138 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName );
1139 : }
1140 : else // script:listener-event
1141 : {
1142 0 : pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" );
1143 0 : xElem = pElem;
1144 :
1145 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType );
1146 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod );
1147 :
1148 0 : if (!descr.AddListenerParam.isEmpty())
1149 : {
1150 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam );
1151 : }
1152 : }
1153 0 : if ( descr.ScriptType == "StarBasic" )
1154 : {
1155 : // separate optional location
1156 0 : sal_Int32 nIndex = descr.ScriptCode.indexOf( (sal_Unicode)':' );
1157 0 : if (nIndex >= 0)
1158 : {
1159 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) );
1160 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) );
1161 : }
1162 : else
1163 : {
1164 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1165 : }
1166 : }
1167 : else
1168 : {
1169 0 : pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode );
1170 : }
1171 :
1172 : // language
1173 0 : pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType );
1174 :
1175 0 : addSubElement( xElem );
1176 : }
1177 : else
1178 : {
1179 : OSL_FAIL( "### unexpected event type in container!" );
1180 : }
1181 0 : }
1182 0 : }
1183 0 : }
1184 0 : }
1185 :
1186 : //##################################################################################################
1187 :
1188 0 : inline bool equalFont( Style const & style1, Style const & style2 )
1189 : {
1190 0 : awt::FontDescriptor const & f1 = style1._descr;
1191 0 : awt::FontDescriptor const & f2 = style2._descr;
1192 : return (
1193 0 : f1.Name == f2.Name &&
1194 : f1.Height == f2.Height &&
1195 : f1.Width == f2.Width &&
1196 0 : f1.StyleName == f2.StyleName &&
1197 : f1.Family == f2.Family &&
1198 : f1.CharSet == f2.CharSet &&
1199 : f1.Pitch == f2.CharSet &&
1200 : f1.CharacterWidth == f2.CharacterWidth &&
1201 : f1.Weight == f2.Weight &&
1202 : f1.Slant == f2.Slant &&
1203 : f1.Underline == f2.Underline &&
1204 : f1.Strikeout == f2.Strikeout &&
1205 : f1.Orientation == f2.Orientation &&
1206 : (f1.Kerning != sal_False) == (f2.Kerning != sal_False) &&
1207 : (f1.WordLineMode != sal_False) == (f2.WordLineMode != sal_False) &&
1208 : f1.Type == f2.Type &&
1209 : style1._fontRelief == style2._fontRelief &&
1210 : style1._fontEmphasisMark == style2._fontEmphasisMark
1211 0 : );
1212 : }
1213 : //__________________________________________________________________________________________________
1214 0 : OUString StyleBag::getStyleId( Style const & rStyle )
1215 : SAL_THROW(())
1216 : {
1217 0 : if (! rStyle._set) // nothin set
1218 : {
1219 0 : return OUString(); // everything default: no need to export a specific style
1220 : }
1221 :
1222 : // lookup existing style
1223 0 : for ( size_t nStylesPos = 0; nStylesPos < _styles.size(); ++nStylesPos )
1224 : {
1225 0 : Style * pStyle = _styles[ nStylesPos ];
1226 :
1227 0 : short demanded_defaults = ~rStyle._set & rStyle._all;
1228 : // test, if defaults are not set
1229 0 : if ((~pStyle->_set & demanded_defaults) == demanded_defaults &&
1230 : (rStyle._set & (pStyle->_all & ~pStyle->_set)) == 0)
1231 : {
1232 0 : short bset = rStyle._set & pStyle->_set;
1233 0 : if ((bset & 0x1) &&
1234 : rStyle._backgroundColor != pStyle->_backgroundColor)
1235 0 : continue;
1236 0 : if ((bset & 0x2) &&
1237 : rStyle._textColor != pStyle->_textColor)
1238 0 : continue;
1239 0 : if ((bset & 0x20) &&
1240 : rStyle._textLineColor != pStyle->_textLineColor)
1241 0 : continue;
1242 0 : if ((bset & 0x10) &&
1243 : rStyle._fillColor != pStyle->_fillColor)
1244 0 : continue;
1245 0 : if ((bset & 0x4) &&
1246 : (rStyle._border != pStyle->_border ||
1247 : (rStyle._border == BORDER_SIMPLE_COLOR &&
1248 : rStyle._borderColor != pStyle->_borderColor)))
1249 0 : continue;
1250 0 : if ((bset & 0x8) &&
1251 0 : !equalFont( rStyle, *pStyle ))
1252 0 : continue;
1253 0 : if ((bset & 0x40) &&
1254 : rStyle._visualEffect != pStyle->_visualEffect)
1255 0 : continue;
1256 :
1257 : // merge in
1258 0 : short bnset = rStyle._set & ~pStyle->_set;
1259 0 : if (bnset & 0x1)
1260 0 : pStyle->_backgroundColor = rStyle._backgroundColor;
1261 0 : if (bnset & 0x2)
1262 0 : pStyle->_textColor = rStyle._textColor;
1263 0 : if (bnset & 0x20)
1264 0 : pStyle->_textLineColor = rStyle._textLineColor;
1265 0 : if (bnset & 0x10)
1266 0 : pStyle->_fillColor = rStyle._fillColor;
1267 0 : if (bnset & 0x4) {
1268 0 : pStyle->_border = rStyle._border;
1269 0 : pStyle->_borderColor = rStyle._borderColor;
1270 : }
1271 0 : if (bnset & 0x8) {
1272 0 : pStyle->_descr = rStyle._descr;
1273 0 : pStyle->_fontRelief = rStyle._fontRelief;
1274 0 : pStyle->_fontEmphasisMark = rStyle._fontEmphasisMark;
1275 : }
1276 0 : if (bnset & 0x40)
1277 0 : pStyle->_visualEffect = rStyle._visualEffect;
1278 :
1279 0 : pStyle->_all |= rStyle._all;
1280 0 : pStyle->_set |= rStyle._set;
1281 :
1282 0 : return pStyle->_id;
1283 : }
1284 : }
1285 :
1286 : // no appr style found, append new
1287 0 : Style * pStyle = new Style( rStyle );
1288 0 : pStyle->_id = OUString::valueOf( (sal_Int32)_styles.size() );
1289 0 : _styles.push_back( pStyle );
1290 0 : return pStyle->_id;
1291 : }
1292 : //__________________________________________________________________________________________________
1293 0 : StyleBag::~StyleBag() SAL_THROW(())
1294 : {
1295 0 : for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1296 : {
1297 0 : delete _styles[ nPos ];
1298 : }
1299 0 : }
1300 : //__________________________________________________________________________________________________
1301 0 : void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut )
1302 : {
1303 0 : if (! _styles.empty())
1304 : {
1305 0 : OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" );
1306 0 : xOut->ignorableWhitespace( OUString() );
1307 0 : xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() );
1308 : // export styles
1309 0 : for ( size_t nPos = 0; nPos < _styles.size(); ++nPos )
1310 : {
1311 0 : Reference< xml::sax::XAttributeList > xAttr( _styles[ nPos ]->createElement() );
1312 0 : static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() );
1313 0 : }
1314 0 : xOut->ignorableWhitespace( OUString() );
1315 0 : xOut->endElement( aStylesName );
1316 : }
1317 0 : }
1318 :
1319 : //##################################################################################################
1320 :
1321 : //==================================================================================================
1322 0 : void SAL_CALL exportDialogModel(
1323 : Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
1324 : Reference< container::XNameContainer > const & xDialogModel,
1325 : Reference< frame::XModel > const & xDocument )
1326 : SAL_THROW( (Exception) )
1327 : {
1328 0 : StyleBag all_styles;
1329 : // window
1330 0 : Reference< beans::XPropertySet > xProps( xDialogModel, UNO_QUERY );
1331 : OSL_ASSERT( xProps.is() );
1332 0 : Reference< beans::XPropertyState > xPropState( xProps, UNO_QUERY );
1333 : OSL_ASSERT( xPropState.is() );
1334 :
1335 0 : ElementDescriptor * pElem = new ElementDescriptor( xProps, xPropState, XMLNS_DIALOGS_PREFIX ":bulletinboard", xDocument );
1336 0 : Reference< xml::sax::XAttributeList > xElem( pElem );
1337 0 : pElem->readBullitinBoard( &all_styles );
1338 :
1339 0 : xOut->startDocument();
1340 :
1341 : OUString aDocTypeStr(
1342 : "<!DOCTYPE dlg:window PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
1343 0 : " \"dialog.dtd\">" );
1344 0 : xOut->unknown( aDocTypeStr );
1345 0 : xOut->ignorableWhitespace( OUString() );
1346 :
1347 :
1348 0 : OUString aWindowName( XMLNS_DIALOGS_PREFIX ":window" );
1349 0 : ElementDescriptor * pWindow = new ElementDescriptor( xProps, xPropState, aWindowName, xDocument );
1350 0 : Reference< xml::sax::XAttributeList > xWindow( pWindow );
1351 0 : pWindow->readDialogModel( &all_styles );
1352 0 : xOut->ignorableWhitespace( OUString() );
1353 0 : xOut->startElement( aWindowName, xWindow );
1354 : // dump out events
1355 0 : pWindow->dumpSubElements( xOut.get() );
1356 : // dump out stylebag
1357 0 : all_styles.dump( xOut );
1358 :
1359 0 : if ( xDialogModel->getElementNames().getLength() )
1360 : {
1361 : // open up bulletinboard
1362 0 : OUString aBBoardName( XMLNS_DIALOGS_PREFIX ":bulletinboard" );
1363 0 : xOut->ignorableWhitespace( OUString() );
1364 0 : xOut->startElement( aBBoardName, xElem );
1365 :
1366 0 : pElem->dumpSubElements( xOut.get() );
1367 : // end bulletinboard
1368 0 : xOut->ignorableWhitespace( OUString() );
1369 0 : xOut->endElement( aBBoardName );
1370 : }
1371 :
1372 : // end window
1373 0 : xOut->ignorableWhitespace( OUString() );
1374 0 : xOut->endElement( aWindowName );
1375 :
1376 0 : xOut->endDocument();
1377 0 : }
1378 :
1379 : }
1380 :
1381 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|