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 :
21 : #include <xmlbahdl.hxx>
22 :
23 : #include <tools/debug.hxx>
24 : #include <sax/tools/converter.hxx>
25 : #include <xmloff/xmluconv.hxx>
26 : #include <com/sun/star/uno/Any.hxx>
27 : #include <xmloff/xmltoken.hxx>
28 :
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::xmloff::token;
32 :
33 5445 : static void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes )
34 : {
35 5445 : switch( nBytes )
36 : {
37 : case 1:
38 29 : if( nValue < SCHAR_MIN )
39 0 : nValue = SCHAR_MIN;
40 29 : else if( nValue > SCHAR_MAX )
41 0 : nValue = SCHAR_MAX;
42 29 : rValue <<= (sal_Int8)nValue;
43 29 : break;
44 : case 2:
45 1032 : if( nValue < SHRT_MIN )
46 0 : nValue = SHRT_MIN;
47 1032 : else if( nValue > SHRT_MAX )
48 0 : nValue = SHRT_MAX;
49 1032 : rValue <<= (sal_Int16)nValue;
50 1032 : break;
51 : case 4:
52 4384 : rValue <<= nValue;
53 4384 : break;
54 : }
55 5445 : }
56 :
57 1139 : static sal_Bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue,
58 : sal_Int8 nBytes )
59 : {
60 1139 : sal_Bool bRet = sal_False;
61 :
62 1139 : switch( nBytes )
63 : {
64 : case 1:
65 : {
66 26 : sal_Int8 nValue8 = 0;
67 26 : bRet = rValue >>= nValue8;
68 26 : nValue = nValue8;
69 : }
70 26 : break;
71 : case 2:
72 : {
73 73 : sal_Int16 nValue16 = 0;
74 73 : bRet = rValue >>= nValue16;
75 73 : nValue = nValue16;
76 : }
77 73 : break;
78 : case 4:
79 1040 : bRet = rValue >>= nValue;
80 1040 : break;
81 : }
82 :
83 1139 : return bRet;
84 : }
85 :
86 : ///////////////////////////////////////////////////////////////////////////////
87 : //
88 : // class XMLNumberPropHdl
89 : //
90 :
91 12722 : XMLNumberPropHdl::~XMLNumberPropHdl()
92 : {
93 : // nothing to do
94 12722 : }
95 :
96 197 : sal_Bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
97 : {
98 197 : sal_Int32 nValue = 0;
99 197 : bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
100 197 : lcl_xmloff_setAny( rValue, nValue, nBytes );
101 :
102 197 : return bRet;
103 : }
104 :
105 90 : sal_Bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
106 : {
107 90 : sal_Bool bRet = sal_False;
108 : sal_Int32 nValue;
109 90 : OUStringBuffer aOut;
110 :
111 90 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
112 : {
113 72 : ::sax::Converter::convertNumber( aOut, nValue );
114 72 : rStrExpValue = aOut.makeStringAndClear();
115 :
116 72 : bRet = sal_True;
117 : }
118 :
119 90 : return bRet;
120 : }
121 :
122 : ///////////////////////////////////////////////////////////////////////////////
123 : // class XMLNumberNonePropHdl
124 : //
125 :
126 1438 : XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) :
127 1438 : sZeroStr( GetXMLToken(XML_NO_LIMIT) ),
128 2876 : nBytes( nB )
129 : {
130 1438 : }
131 :
132 154 : XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) :
133 154 : sZeroStr( GetXMLToken( eZeroString ) ),
134 308 : nBytes( nB )
135 : {
136 154 : }
137 :
138 3174 : XMLNumberNonePropHdl::~XMLNumberNonePropHdl()
139 : {
140 : // nothing to do
141 3174 : }
142 :
143 62 : sal_Bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
144 : {
145 62 : sal_Bool bRet = sal_False;
146 :
147 62 : sal_Int32 nValue = 0;
148 62 : if( rStrImpValue == sZeroStr )
149 : {
150 61 : bRet = sal_True;
151 : }
152 : else
153 : {
154 1 : bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
155 : }
156 62 : lcl_xmloff_setAny( rValue, nValue, nBytes );
157 :
158 62 : return bRet;
159 : }
160 :
161 18 : sal_Bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
162 : {
163 18 : sal_Bool bRet = sal_False;
164 : sal_Int32 nValue;
165 :
166 18 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
167 : {
168 18 : OUStringBuffer aOut;
169 :
170 18 : if( nValue == 0 )
171 : {
172 18 : aOut.append( sZeroStr );
173 : }
174 : else
175 : {
176 0 : ::sax::Converter::convertNumber( aOut, nValue );
177 : }
178 :
179 18 : rStrExpValue = aOut.makeStringAndClear();
180 :
181 18 : bRet = sal_True;
182 : }
183 :
184 18 : return bRet;
185 : }
186 :
187 : ///////////////////////////////////////////////////////////////////////////////
188 : //
189 : // class XMLMeasurePropHdl
190 : //
191 :
192 10532 : XMLMeasurePropHdl::~XMLMeasurePropHdl()
193 : {
194 : // nothing to do
195 10532 : }
196 :
197 4155 : sal_Bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
198 : {
199 4155 : sal_Bool bRet = sal_False;
200 :
201 4155 : sal_Int32 nValue = 0;
202 4155 : bRet = rUnitConverter.convertMeasureToCore( nValue, rStrImpValue );
203 4155 : lcl_xmloff_setAny( rValue, nValue, nBytes );
204 :
205 4155 : return bRet;
206 : }
207 :
208 977 : sal_Bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
209 : {
210 977 : sal_Bool bRet = sal_False;
211 : sal_Int32 nValue;
212 977 : OUStringBuffer aOut;
213 :
214 977 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
215 : {
216 977 : rUnitConverter.convertMeasureToXML( aOut, nValue );
217 977 : rStrExpValue = aOut.makeStringAndClear();
218 :
219 977 : bRet = sal_True;
220 : }
221 :
222 977 : return bRet;
223 : }
224 :
225 : ///////////////////////////////////////////////////////////////////////////////
226 : //
227 : // class XMLBoolFalsePropHdl
228 : //
229 :
230 0 : XMLBoolFalsePropHdl::~XMLBoolFalsePropHdl()
231 : {
232 : // nothing to do
233 0 : }
234 :
235 0 : sal_Bool XMLBoolFalsePropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
236 : {
237 0 : return sal_False;
238 : }
239 :
240 0 : sal_Bool XMLBoolFalsePropHdl::exportXML( OUString& rStrExpValue, const Any& /*rValue*/, const SvXMLUnitConverter& rCnv) const
241 : {
242 0 : return XMLBoolPropHdl::exportXML( rStrExpValue, makeAny( sal_False ), rCnv );
243 : }
244 :
245 : ///////////////////////////////////////////////////////////////////////////////
246 : //
247 : // class XMLBoolPropHdl
248 : //
249 :
250 9590 : XMLBoolPropHdl::~XMLBoolPropHdl()
251 : {
252 : // nothing to do
253 9590 : }
254 :
255 1376 : sal_Bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
256 : {
257 1376 : bool bValue(false);
258 1376 : bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
259 1376 : rValue <<= sal_Bool(bValue);
260 :
261 1376 : return bRet;
262 : }
263 :
264 401 : sal_Bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
265 : {
266 401 : sal_Bool bRet = sal_False;
267 401 : OUStringBuffer aOut;
268 401 : sal_Bool bValue = sal_Bool();
269 :
270 401 : if (rValue >>= bValue)
271 : {
272 401 : ::sax::Converter::convertBool( aOut, bValue );
273 401 : rStrExpValue = aOut.makeStringAndClear();
274 :
275 401 : bRet = sal_True;
276 : }
277 :
278 401 : return bRet;
279 : }
280 :
281 : ///////////////////////////////////////////////////////////////////////////////
282 : //
283 : // class XMLNBoolPropHdl
284 : //
285 :
286 66 : XMLNBoolPropHdl::~XMLNBoolPropHdl()
287 : {
288 : // nothing to do
289 66 : }
290 :
291 0 : sal_Bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
292 : {
293 0 : bool bValue(false);
294 0 : bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
295 0 : rValue <<= sal_Bool(!bValue);
296 :
297 0 : return bRet;
298 : }
299 :
300 0 : sal_Bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
301 : {
302 0 : sal_Bool bRet = sal_False;
303 0 : OUStringBuffer aOut;
304 0 : sal_Bool bValue = sal_Bool();
305 :
306 0 : if (rValue >>= bValue)
307 : {
308 0 : ::sax::Converter::convertBool( aOut, !bValue );
309 0 : rStrExpValue = aOut.makeStringAndClear();
310 :
311 0 : bRet = sal_True;
312 : }
313 :
314 0 : return bRet;
315 : }
316 :
317 : ///////////////////////////////////////////////////////////////////////////////
318 : //
319 : // class XMLPercentPropHdl
320 : //
321 :
322 12368 : XMLPercentPropHdl::~XMLPercentPropHdl()
323 : {
324 : // nothing to do
325 12368 : }
326 :
327 898 : sal_Bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
328 : {
329 898 : sal_Int32 nValue = 0;
330 898 : bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
331 898 : lcl_xmloff_setAny( rValue, nValue, nBytes );
332 :
333 898 : return bRet;
334 : }
335 :
336 16 : sal_Bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
337 : {
338 16 : sal_Bool bRet = sal_False;
339 : sal_Int32 nValue;
340 16 : OUStringBuffer aOut;
341 :
342 16 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
343 : {
344 16 : ::sax::Converter::convertPercent( aOut, nValue );
345 16 : rStrExpValue = aOut.makeStringAndClear();
346 :
347 16 : bRet = sal_True;
348 : }
349 :
350 16 : return bRet;
351 : }
352 :
353 : ///////////////////////////////////////////////////////////////////////////////
354 : //
355 : // class XMLDoublePercentPropHdl
356 : //
357 :
358 11 : sal_Bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
359 : {
360 11 : sal_Bool bRet = sal_False;
361 :
362 11 : double fValue = 1.0;
363 :
364 11 : if( rStrImpValue.indexOf( (sal_Unicode)'%' ) == -1 )
365 : {
366 0 : fValue = rStrImpValue.toDouble();
367 : }
368 : else
369 : {
370 11 : sal_Int32 nValue = 0;
371 11 : bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
372 11 : fValue = ((double)nValue) / 100.0;
373 : }
374 11 : rValue <<= fValue;
375 :
376 11 : return bRet;
377 : }
378 :
379 0 : sal_Bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
380 : {
381 0 : sal_Bool bRet = sal_False;
382 0 : double fValue = 0;
383 :
384 0 : if( rValue >>= fValue )
385 : {
386 0 : fValue *= 100.0;
387 0 : if( fValue > 0 ) fValue += 0.5; else fValue -= 0.5;
388 :
389 0 : sal_Int32 nValue = (sal_Int32)fValue;
390 :
391 0 : OUStringBuffer aOut;
392 0 : ::sax::Converter::convertPercent( aOut, nValue );
393 0 : rStrExpValue = aOut.makeStringAndClear();
394 :
395 0 : bRet = sal_True;
396 : }
397 :
398 0 : return bRet;
399 : }
400 :
401 :
402 : ///////////////////////////////////////////////////////////////////////////////
403 : //
404 : // class XMLNegPercentPropHdl
405 : //
406 :
407 3662 : XMLNegPercentPropHdl::~XMLNegPercentPropHdl()
408 : {
409 : // nothing to do
410 3662 : }
411 :
412 24 : sal_Bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
413 : {
414 24 : sal_Int32 nValue = 0;
415 24 : bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
416 24 : lcl_xmloff_setAny( rValue, 100-nValue, nBytes );
417 :
418 24 : return bRet;
419 : }
420 :
421 0 : sal_Bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
422 : {
423 0 : sal_Bool bRet = sal_False;
424 : sal_Int32 nValue;
425 0 : OUStringBuffer aOut;
426 :
427 0 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
428 : {
429 0 : ::sax::Converter::convertPercent( aOut, 100-nValue );
430 0 : rStrExpValue = aOut.makeStringAndClear();
431 :
432 0 : bRet = sal_True;
433 : }
434 :
435 0 : return bRet;
436 : }
437 :
438 :
439 : ///////////////////////////////////////////////////////////////////////////////
440 : //
441 : // class XMLMeasurePxPropHdl
442 : //
443 :
444 2512 : XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
445 : {
446 : // nothing to do
447 2512 : }
448 :
449 0 : sal_Bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
450 : {
451 0 : sal_Bool bRet = sal_False;
452 :
453 0 : sal_Int32 nValue = 0;
454 0 : bRet = ::sax::Converter::convertMeasurePx( nValue, rStrImpValue );
455 0 : lcl_xmloff_setAny( rValue, nValue, nBytes );
456 :
457 0 : return bRet;
458 : }
459 :
460 0 : sal_Bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
461 : {
462 0 : sal_Bool bRet = sal_False;
463 : sal_Int32 nValue;
464 0 : OUStringBuffer aOut;
465 :
466 0 : if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
467 : {
468 0 : ::sax::Converter::convertMeasurePx( aOut, nValue );
469 0 : rStrExpValue = aOut.makeStringAndClear();
470 :
471 0 : bRet = sal_True;
472 : }
473 :
474 0 : return bRet;
475 : }
476 :
477 : ///////////////////////////////////////////////////////////////////////////////
478 : //
479 : // class XMLColorPropHdl
480 : //
481 :
482 5750 : XMLColorPropHdl::~XMLColorPropHdl()
483 : {
484 : // Nothing to do
485 5750 : }
486 :
487 439 : sal_Bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
488 : {
489 439 : sal_Bool bRet = sal_False;
490 :
491 439 : const OUString astrHSL( "hsl" );
492 439 : if( rStrImpValue.matchIgnoreAsciiCase( astrHSL ) )
493 : {
494 0 : sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
495 0 : sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
496 :
497 0 : if( (nOpen != -1) && (nClose > nOpen) )
498 : {
499 0 : const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) );
500 :
501 0 : sal_Int32 nIndex = 0;
502 :
503 0 : Sequence< double > aHSL(3);
504 0 : aHSL[0] = aTmp.getToken( 0, ',', nIndex ).toDouble();
505 0 : aHSL[1] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
506 0 : aHSL[2] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
507 0 : rValue <<= aHSL;
508 0 : bRet = true;
509 : }
510 : }
511 : else
512 : {
513 439 : sal_Int32 nColor(0);
514 439 : bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
515 439 : rValue <<= nColor;
516 : }
517 :
518 439 : return bRet;
519 : }
520 :
521 171 : sal_Bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
522 : {
523 171 : sal_Bool bRet = sal_False;
524 171 : sal_Int32 nColor = 0;
525 :
526 171 : OUStringBuffer aOut;
527 171 : if( rValue >>= nColor )
528 : {
529 171 : ::sax::Converter::convertColor( aOut, nColor );
530 171 : rStrExpValue = aOut.makeStringAndClear();
531 :
532 171 : bRet = sal_True;
533 : }
534 : else
535 : {
536 0 : Sequence< double > aHSL;
537 0 : if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
538 : {
539 0 : aOut.append( OUString("hsl(") );
540 0 : aOut.append( aHSL[0] );
541 0 : aOut.append( OUString(",") );
542 0 : aOut.append( aHSL[1] * 100.0 );
543 0 : aOut.append( OUString("%,") );
544 0 : aOut.append( aHSL[2] * 100.0 );
545 0 : aOut.append( OUString("%)") );
546 0 : rStrExpValue = aOut.makeStringAndClear();
547 :
548 0 : bRet = sal_True;
549 0 : }
550 : }
551 :
552 171 : return bRet;
553 : }
554 :
555 : ///////////////////////////////////////////////////////////////////////////////
556 : //
557 : // class XMLHexPropHdl
558 : //
559 :
560 3862 : XMLHexPropHdl::~XMLHexPropHdl()
561 : {
562 : // Nothing to do
563 3862 : }
564 :
565 42 : sal_Bool XMLHexPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
566 : {
567 42 : sal_Bool bRet = sal_False;
568 : sal_uInt32 nRsid;
569 :
570 42 : bRet = SvXMLUnitConverter::convertHex( nRsid, rStrImpValue );
571 42 : rValue <<= nRsid;
572 :
573 42 : return bRet;
574 : }
575 :
576 2 : sal_Bool XMLHexPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
577 : {
578 2 : sal_Bool bRet = sal_False;
579 2 : sal_uInt32 nRsid = 0;
580 :
581 2 : OUStringBuffer aOut;
582 2 : if( rValue >>= nRsid )
583 : {
584 2 : SvXMLUnitConverter::convertHex( aOut, nRsid );
585 2 : rStrExpValue = aOut.makeStringAndClear();
586 :
587 2 : bRet = sal_True;
588 : }
589 : else
590 : {
591 0 : bRet = sal_False;
592 : }
593 :
594 2 : return bRet;
595 : }
596 :
597 : ///////////////////////////////////////////////////////////////////////////////
598 : //
599 : // class XMLStringPropHdl
600 : //
601 :
602 11685 : XMLStringPropHdl::~XMLStringPropHdl()
603 : {
604 : // Nothing to do
605 11685 : }
606 :
607 80 : sal_Bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
608 : {
609 80 : sal_Bool bRet = sal_False;
610 :
611 80 : rValue <<= rStrImpValue;
612 80 : bRet = sal_True;
613 :
614 80 : return bRet;
615 : }
616 :
617 326 : sal_Bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
618 : {
619 326 : sal_Bool bRet = sal_False;
620 :
621 326 : if( rValue >>= rStrExpValue )
622 326 : bRet = sal_True;
623 :
624 326 : return bRet;
625 : }
626 :
627 : ///////////////////////////////////////////////////////////////////////////////
628 : //
629 : // class XMLStyleNamePropHdl
630 : //
631 :
632 5686 : XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
633 : {
634 : // Nothing to do
635 5686 : }
636 :
637 20 : sal_Bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
638 : {
639 20 : sal_Bool bRet = sal_False;
640 :
641 20 : if( rValue >>= rStrExpValue )
642 : {
643 20 : rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
644 20 : bRet = sal_True;
645 : }
646 :
647 20 : return bRet;
648 : }
649 :
650 :
651 : ///////////////////////////////////////////////////////////////////////////////
652 : //
653 : // class XMLDoublePropHdl
654 : //
655 :
656 78 : XMLDoublePropHdl::~XMLDoublePropHdl()
657 : {
658 : // Nothing to do
659 78 : }
660 :
661 58 : sal_Bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
662 : {
663 58 : double fDblValue(0.0);
664 58 : bool const bRet = ::sax::Converter::convertDouble(fDblValue, rStrImpValue);
665 58 : rValue <<= fDblValue;
666 58 : return bRet;
667 : }
668 :
669 0 : sal_Bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
670 : {
671 0 : sal_Bool bRet = sal_False;
672 :
673 0 : double fValue = 0;
674 :
675 0 : if( rValue >>= fValue )
676 : {
677 0 : OUStringBuffer aOut;
678 0 : ::sax::Converter::convertDouble( aOut, fValue );
679 0 : rStrExpValue = aOut.makeStringAndClear();
680 0 : bRet = sal_True;
681 : }
682 :
683 0 : return bRet;
684 : }
685 :
686 : ///////////////////////////////////////////////////////////////////////////////
687 : //
688 : // class XMLColorTransparentPropHdl
689 : //
690 :
691 7684 : XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
692 : enum XMLTokenEnum eTransparent ) :
693 : sTransparent( GetXMLToken(
694 7684 : eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
695 : {
696 : // Nothing to do
697 7684 : }
698 :
699 15338 : XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
700 : {
701 : // Nothing to do
702 15338 : }
703 :
704 287 : sal_Bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
705 : {
706 287 : sal_Bool bRet = sal_False;
707 :
708 287 : if( rStrImpValue != sTransparent )
709 : {
710 161 : sal_Int32 nColor(0);
711 161 : bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
712 161 : rValue <<= nColor;
713 : }
714 :
715 287 : return bRet;
716 : }
717 :
718 40 : sal_Bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
719 : {
720 40 : sal_Bool bRet = sal_False;
721 40 : sal_Int32 nColor = 0;
722 :
723 40 : if( rStrExpValue == sTransparent )
724 0 : bRet = sal_False;
725 40 : else if( rValue >>= nColor )
726 : {
727 40 : OUStringBuffer aOut;
728 40 : ::sax::Converter::convertColor( aOut, nColor );
729 40 : rStrExpValue = aOut.makeStringAndClear();
730 :
731 40 : bRet = sal_True;
732 : }
733 :
734 40 : return bRet;
735 : }
736 :
737 :
738 : ///////////////////////////////////////////////////////////////////////////////
739 : //
740 : // class XMLIsTransparentPropHdl
741 : //
742 :
743 7651 : XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
744 : enum XMLTokenEnum eTransparent, sal_Bool bTransPropVal ) :
745 : sTransparent( GetXMLToken(
746 7651 : eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
747 15302 : bTransPropValue( bTransPropVal )
748 : {
749 7651 : }
750 :
751 15272 : XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
752 : {
753 : // Nothing to do
754 15272 : }
755 :
756 287 : sal_Bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
757 : {
758 287 : sal_Bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue);
759 287 : rValue.setValue( &bValue, ::getBooleanCppuType() );
760 :
761 287 : return sal_True;
762 : }
763 :
764 40 : sal_Bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
765 : {
766 40 : sal_Bool bRet = sal_False;
767 :
768 : // MIB: This looks a bit strange, because bTransPropValue == bValue should
769 : // do the same, but this only applies if 'true' is represented by the same
770 : // 8 bit value in bValue and bTransPropValue. Who will ensure this?
771 40 : sal_Bool bValue = *(sal_Bool *)rValue.getValue();
772 40 : sal_Bool bIsTrans = bTransPropValue ? bValue : !bValue;
773 :
774 40 : if( bIsTrans )
775 : {
776 24 : rStrExpValue = sTransparent;
777 24 : bRet = sal_True;
778 : }
779 :
780 40 : return bRet;
781 : }
782 :
783 : ///////////////////////////////////////////////////////////////////////////////
784 : //
785 : // class XMLColorAutoPropHdl
786 : //
787 :
788 2272 : XMLColorAutoPropHdl::XMLColorAutoPropHdl()
789 : {
790 : // Nothing to do
791 2272 : }
792 :
793 4534 : XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
794 : {
795 : // Nothing to do
796 4534 : }
797 :
798 81 : sal_Bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
799 : {
800 81 : sal_Bool bRet = sal_False;
801 :
802 : // This is a multi property: the value might be set to AUTO_COLOR
803 : // already by the XMLIsAutoColorPropHdl!
804 81 : sal_Int32 nColor = 0;
805 81 : if( !(rValue >>= nColor) || -1 != nColor )
806 : {
807 81 : bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
808 81 : if( bRet )
809 81 : rValue <<= nColor;
810 : }
811 :
812 81 : return bRet;
813 : }
814 :
815 71 : sal_Bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
816 : {
817 71 : sal_Bool bRet = sal_False;
818 :
819 71 : sal_Int32 nColor = 0;
820 71 : if( (rValue >>= nColor) && -1 != nColor )
821 : {
822 6 : OUStringBuffer aOut;
823 6 : ::sax::Converter::convertColor( aOut, nColor );
824 6 : rStrExpValue = aOut.makeStringAndClear();
825 :
826 6 : bRet = sal_True;
827 : }
828 :
829 71 : return bRet;
830 : }
831 :
832 : ///////////////////////////////////////////////////////////////////////////////
833 : //
834 : // class XMLIsAutoColorPropHdl
835 : //
836 :
837 1936 : XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
838 : {
839 1936 : }
840 :
841 3862 : XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
842 : {
843 : // Nothing to do
844 3862 : }
845 :
846 154 : sal_Bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
847 : {
848 : // An auto color overrides any other color set!
849 : bool bValue;
850 154 : bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
851 154 : if( bRet && bValue )
852 154 : rValue <<= (sal_Int32)-1;
853 :
854 154 : return sal_True;
855 : }
856 :
857 63 : sal_Bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
858 : {
859 63 : sal_Bool bRet = sal_False;
860 63 : sal_Int32 nColor = 0;
861 :
862 63 : if( (rValue >>= nColor) && -1 == nColor )
863 : {
864 57 : OUStringBuffer aOut;
865 57 : ::sax::Converter::convertBool( aOut, true );
866 57 : rStrExpValue = aOut.makeStringAndClear();
867 :
868 57 : bRet = sal_True;
869 : }
870 :
871 63 : return bRet;
872 : }
873 :
874 : ///////////////////////////////////////////////////////////////////////////////
875 : //
876 : // class XMLCompareOnlyPropHdl
877 : //
878 :
879 7338 : XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
880 : {
881 : // Nothing to do
882 7338 : }
883 :
884 0 : sal_Bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
885 : {
886 : DBG_ASSERT( !this, "importXML called for compare-only-property" );
887 0 : return sal_False;
888 : }
889 :
890 0 : sal_Bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
891 : {
892 : DBG_ASSERT( !this, "exportXML called for compare-only-property" );
893 0 : return sal_False;
894 : }
895 :
896 : ///////////////////////////////////////////////////////////////////////////////
897 : // class XMLNumberWithoutZeroPropHdl
898 : //
899 :
900 2876 : XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
901 2876 : nBytes( nB )
902 : {
903 2876 : }
904 :
905 4299 : XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
906 : {
907 4299 : }
908 :
909 108 : sal_Bool XMLNumberWithoutZeroPropHdl::importXML(
910 : const OUString& rStrImpValue,
911 : Any& rValue,
912 : const SvXMLUnitConverter& ) const
913 : {
914 108 : sal_Int32 nValue = 0;
915 108 : bool const bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
916 108 : if( bRet )
917 108 : lcl_xmloff_setAny( rValue, nValue, nBytes );
918 108 : return bRet;
919 : }
920 :
921 32 : sal_Bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
922 : {
923 :
924 32 : sal_Int32 nValue = 0;
925 32 : sal_Bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
926 32 : bRet &= nValue != 0;
927 :
928 32 : if( bRet )
929 : {
930 32 : OUStringBuffer aBuffer;
931 32 : ::sax::Converter::convertNumber( aBuffer, nValue );
932 32 : rStrExpValue = aBuffer.makeStringAndClear();
933 : }
934 :
935 32 : return bRet;
936 : }
937 :
938 : ///////////////////////////////////////////////////////////////////////////////
939 : // class XMLNumberWithAutoInsteadZeroPropHdl
940 : //
941 :
942 2866 : XMLNumberWithAutoInsteadZeroPropHdl::~XMLNumberWithAutoInsteadZeroPropHdl()
943 : {
944 2866 : }
945 :
946 23 : sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::importXML(
947 : const OUString& rStrImpValue,
948 : Any& rValue,
949 : const SvXMLUnitConverter& ) const
950 : {
951 23 : sal_Int32 nValue = 0;
952 23 : bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
953 23 : if( bRet )
954 1 : lcl_xmloff_setAny( rValue, nValue, 2 );
955 22 : else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
956 : {
957 22 : rValue <<= (sal_Int16)nValue;
958 22 : bRet = sal_True;
959 : }
960 23 : return bRet;
961 : }
962 :
963 6 : sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
964 : {
965 :
966 6 : sal_Int32 nValue = 0;
967 6 : lcl_xmloff_getAny( rValue, nValue, 2 );
968 :
969 6 : if( 0 == nValue )
970 6 : rStrExpValue = GetXMLToken( XML_AUTO );
971 : else
972 : {
973 0 : OUStringBuffer aBuffer;
974 0 : ::sax::Converter::convertNumber( aBuffer, nValue );
975 0 : rStrExpValue = aBuffer.makeStringAndClear();
976 : }
977 :
978 6 : return sal_True;
979 : }
980 :
981 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|