bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / xmlbahdl.cxx
blob6c93da92755fe4f1558d158b40fd38000b608c47
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmlbahdl.hxx>
22 #include <tools/debug.hxx>
23 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <xmloff/xmltoken.hxx>
28 using namespace ::com::sun::star::uno;
29 using namespace ::xmloff::token;
31 static void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes )
33 switch( nBytes )
35 case 1:
36 if( nValue < SCHAR_MIN )
37 nValue = SCHAR_MIN;
38 else if( nValue > SCHAR_MAX )
39 nValue = SCHAR_MAX;
40 rValue <<= (sal_Int8)nValue;
41 break;
42 case 2:
43 if( nValue < SHRT_MIN )
44 nValue = SHRT_MIN;
45 else if( nValue > SHRT_MAX )
46 nValue = SHRT_MAX;
47 rValue <<= (sal_Int16)nValue;
48 break;
49 case 4:
50 rValue <<= nValue;
51 break;
55 static bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue,
56 sal_Int8 nBytes )
58 bool bRet = false;
60 switch( nBytes )
62 case 1:
64 sal_Int8 nValue8 = 0;
65 bRet = rValue >>= nValue8;
66 nValue = nValue8;
68 break;
69 case 2:
71 sal_Int16 nValue16 = 0;
72 bRet = rValue >>= nValue16;
73 nValue = nValue16;
75 break;
76 case 4:
77 bRet = rValue >>= nValue;
78 break;
81 return bRet;
84 // class XMLNumberPropHdl
86 XMLNumberPropHdl::~XMLNumberPropHdl()
88 // nothing to do
91 bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
93 sal_Int32 nValue = 0;
94 bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
95 lcl_xmloff_setAny( rValue, nValue, nBytes );
97 return bRet;
100 bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
102 bool bRet = false;
103 sal_Int32 nValue;
104 OUStringBuffer aOut;
106 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
108 ::sax::Converter::convertNumber( aOut, nValue );
109 rStrExpValue = aOut.makeStringAndClear();
111 bRet = true;
114 return bRet;
117 // class XMLNumberNonePropHdl
119 XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) :
120 sZeroStr( GetXMLToken(XML_NO_LIMIT) ),
121 nBytes( nB )
125 XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) :
126 sZeroStr( GetXMLToken( eZeroString ) ),
127 nBytes( nB )
131 XMLNumberNonePropHdl::~XMLNumberNonePropHdl()
133 // nothing to do
136 bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
138 bool bRet = false;
140 sal_Int32 nValue = 0;
141 if( rStrImpValue == sZeroStr )
143 bRet = true;
145 else
147 bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
149 lcl_xmloff_setAny( rValue, nValue, nBytes );
151 return bRet;
154 bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
156 bool bRet = false;
157 sal_Int32 nValue;
159 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
161 OUStringBuffer aOut;
163 if( nValue == 0 )
165 aOut.append( sZeroStr );
167 else
169 ::sax::Converter::convertNumber( aOut, nValue );
172 rStrExpValue = aOut.makeStringAndClear();
174 bRet = true;
177 return bRet;
180 // class XMLMeasurePropHdl
182 XMLMeasurePropHdl::~XMLMeasurePropHdl()
184 // nothing to do
187 bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
189 sal_Int32 nValue = 0;
190 bool bRet = rUnitConverter.convertMeasureToCore( nValue, rStrImpValue );
191 lcl_xmloff_setAny( rValue, nValue, nBytes );
192 return bRet;
195 bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
197 bool bRet = false;
198 sal_Int32 nValue;
199 OUStringBuffer aOut;
201 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
203 rUnitConverter.convertMeasureToXML( aOut, nValue );
204 rStrExpValue = aOut.makeStringAndClear();
206 bRet = true;
209 return bRet;
212 // class XMLBoolFalsePropHdl
214 XMLBoolFalsePropHdl::~XMLBoolFalsePropHdl()
216 // nothing to do
219 bool XMLBoolFalsePropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
221 return false;
224 bool XMLBoolFalsePropHdl::exportXML( OUString& rStrExpValue, const Any& /*rValue*/, const SvXMLUnitConverter& rCnv) const
226 return XMLBoolPropHdl::exportXML( rStrExpValue, makeAny( sal_False ), rCnv );
229 // class XMLBoolPropHdl
231 XMLBoolPropHdl::~XMLBoolPropHdl()
233 // nothing to do
236 bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
238 bool bValue(false);
239 bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
240 rValue <<= bValue;
242 return bRet;
245 bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
247 bool bRet = false;
248 bool bValue;
250 if (rValue >>= bValue)
252 OUStringBuffer aOut;
253 ::sax::Converter::convertBool( aOut, bValue );
254 rStrExpValue = aOut.makeStringAndClear();
256 bRet = true;
259 return bRet;
262 // class XMLNBoolPropHdl
264 XMLNBoolPropHdl::~XMLNBoolPropHdl()
266 // nothing to do
269 bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
271 bool bValue(false);
272 bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
273 rValue <<= !bValue;
275 return bRet;
278 bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
280 bool bRet = false;
281 bool bValue;
283 if (rValue >>= bValue)
285 OUStringBuffer aOut;
286 ::sax::Converter::convertBool( aOut, !bValue );
287 rStrExpValue = aOut.makeStringAndClear();
289 bRet = true;
292 return bRet;
295 // class XMLPercentPropHdl
297 XMLPercentPropHdl::~XMLPercentPropHdl()
299 // nothing to do
302 bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
304 sal_Int32 nValue = 0;
305 bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
306 lcl_xmloff_setAny( rValue, nValue, nBytes );
308 return bRet;
311 bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
313 bool bRet = false;
314 sal_Int32 nValue;
315 OUStringBuffer aOut;
317 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
319 ::sax::Converter::convertPercent( aOut, nValue );
320 rStrExpValue = aOut.makeStringAndClear();
322 bRet = true;
325 return bRet;
328 // class XMLDoublePercentPropHdl
330 bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
332 bool bRet = false;
334 double fValue = 1.0;
336 if( rStrImpValue.indexOf( (sal_Unicode)'%' ) == -1 )
338 fValue = rStrImpValue.toDouble();
340 else
342 sal_Int32 nValue = 0;
343 bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
344 fValue = ((double)nValue) / 100.0;
346 rValue <<= fValue;
348 return bRet;
351 bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
353 bool bRet = false;
354 double fValue = 0;
356 if( rValue >>= fValue )
358 fValue *= 100.0;
359 if( fValue > 0 ) fValue += 0.5; else fValue -= 0.5;
361 sal_Int32 nValue = (sal_Int32)fValue;
363 OUStringBuffer aOut;
364 ::sax::Converter::convertPercent( aOut, nValue );
365 rStrExpValue = aOut.makeStringAndClear();
367 bRet = true;
370 return bRet;
373 // class XMLNegPercentPropHdl
375 XMLNegPercentPropHdl::~XMLNegPercentPropHdl()
377 // nothing to do
380 bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
382 sal_Int32 nValue = 0;
383 bool const bRet = ::sax::Converter::convertPercent( nValue, rStrImpValue );
384 lcl_xmloff_setAny( rValue, 100-nValue, nBytes );
386 return bRet;
389 bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
391 bool bRet = false;
392 sal_Int32 nValue;
393 OUStringBuffer aOut;
395 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
397 ::sax::Converter::convertPercent( aOut, 100-nValue );
398 rStrExpValue = aOut.makeStringAndClear();
400 bRet = true;
403 return bRet;
406 // class XMLMeasurePxPropHdl
407 XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl()
409 // nothing to do
412 bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
414 sal_Int32 nValue = 0;
415 bool bRet = ::sax::Converter::convertMeasurePx( nValue, rStrImpValue );
416 lcl_xmloff_setAny( rValue, nValue, nBytes );
417 return bRet;
420 bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
422 bool bRet = false;
423 sal_Int32 nValue;
424 OUStringBuffer aOut;
426 if( lcl_xmloff_getAny( rValue, nValue, nBytes ) )
428 ::sax::Converter::convertMeasurePx( aOut, nValue );
429 rStrExpValue = aOut.makeStringAndClear();
431 bRet = true;
434 return bRet;
437 // class XMLColorPropHdl
439 XMLColorPropHdl::~XMLColorPropHdl()
441 // Nothing to do
444 bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
446 bool bRet = false;
448 const OUString astrHSL( "hsl" );
449 if( rStrImpValue.matchIgnoreAsciiCase( astrHSL ) )
451 sal_Int32 nOpen = rStrImpValue.indexOf( '(' );
452 sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' );
454 if( (nOpen != -1) && (nClose > nOpen) )
456 const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) );
458 sal_Int32 nIndex = 0;
460 Sequence< double > aHSL(3);
461 aHSL[0] = aTmp.getToken( 0, ',', nIndex ).toDouble();
462 aHSL[1] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
463 aHSL[2] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0;
464 rValue <<= aHSL;
465 bRet = true;
468 else
470 sal_Int32 nColor(0);
471 bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
472 rValue <<= nColor;
475 return bRet;
478 bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
480 bool bRet = false;
481 sal_Int32 nColor = 0;
483 OUStringBuffer aOut;
484 if( rValue >>= nColor )
486 ::sax::Converter::convertColor( aOut, nColor );
487 rStrExpValue = aOut.makeStringAndClear();
489 bRet = true;
491 else
493 Sequence< double > aHSL;
494 if( (rValue >>= aHSL) && (aHSL.getLength() == 3) )
496 aOut.append( "hsl(" + OUString::number(aHSL[0]) + "," + OUString::number(aHSL[1] * 100.0) + "%," + OUString::number(aHSL[2] * 100.0) + "%)" );
497 rStrExpValue = aOut.makeStringAndClear();
499 bRet = true;
503 return bRet;
506 // class XMLHexPropHdl
508 XMLHexPropHdl::~XMLHexPropHdl()
510 // Nothing to do
513 bool XMLHexPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
515 bool bRet = false;
516 sal_uInt32 nRsid;
518 bRet = SvXMLUnitConverter::convertHex( nRsid, rStrImpValue );
519 rValue <<= nRsid;
521 return bRet;
524 bool XMLHexPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
526 bool bRet = false;
527 sal_uInt32 nRsid = 0;
529 OUStringBuffer aOut;
530 if( rValue >>= nRsid )
532 SvXMLUnitConverter::convertHex( aOut, nRsid );
533 rStrExpValue = aOut.makeStringAndClear();
535 bRet = true;
537 else
539 bRet = false;
542 return bRet;
545 // class XMLStringPropHdl
547 XMLStringPropHdl::~XMLStringPropHdl()
549 // Nothing to do
552 bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
554 rValue <<= rStrImpValue;
555 return true;
558 bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
560 bool bRet = false;
562 if( rValue >>= rStrExpValue )
563 bRet = true;
565 return bRet;
568 // class XMLStyleNamePropHdl
570 XMLStyleNamePropHdl::~XMLStyleNamePropHdl()
572 // Nothing to do
575 bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
577 bool bRet = false;
579 if( rValue >>= rStrExpValue )
581 rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue );
582 bRet = true;
585 return bRet;
588 // class XMLDoublePropHdl
590 XMLDoublePropHdl::~XMLDoublePropHdl()
592 // Nothing to do
595 bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
597 double fDblValue(0.0);
598 bool const bRet = ::sax::Converter::convertDouble(fDblValue, rStrImpValue);
599 rValue <<= fDblValue;
600 return bRet;
603 bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
605 bool bRet = false;
607 double fValue = 0;
609 if( rValue >>= fValue )
611 OUStringBuffer aOut;
612 ::sax::Converter::convertDouble( aOut, fValue );
613 rStrExpValue = aOut.makeStringAndClear();
614 bRet = true;
617 return bRet;
620 // class XMLColorTransparentPropHdl
622 XMLColorTransparentPropHdl::XMLColorTransparentPropHdl(
623 enum XMLTokenEnum eTransparent ) :
624 sTransparent( GetXMLToken(
625 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) )
627 // Nothing to do
630 XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl()
632 // Nothing to do
635 bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
637 bool bRet = false;
639 if( rStrImpValue != sTransparent )
641 sal_Int32 nColor(0);
642 bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
643 rValue <<= nColor;
646 return bRet;
649 bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
651 bool bRet = false;
652 sal_Int32 nColor = 0;
654 if( rStrExpValue == sTransparent )
655 bRet = false;
656 else if( rValue >>= nColor )
658 OUStringBuffer aOut;
659 ::sax::Converter::convertColor( aOut, nColor );
660 rStrExpValue = aOut.makeStringAndClear();
662 bRet = true;
665 return bRet;
668 // class XMLIsTransparentPropHdl
670 XMLIsTransparentPropHdl::XMLIsTransparentPropHdl(
671 enum XMLTokenEnum eTransparent, bool bTransPropVal ) :
672 sTransparent( GetXMLToken(
673 eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ),
674 bTransPropValue( bTransPropVal )
678 XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl()
680 // Nothing to do
683 bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
685 bool bValue = ( (bool) (rStrImpValue == sTransparent) == bTransPropValue);
686 rValue <<= bValue;
688 return true;
691 bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
693 bool bRet = false;
695 // MIB: This looks a bit strange, because bTransPropValue == bValue should
696 // do the same, but this only applies if 'true' is represented by the same
697 // 8 bit value in bValue and bTransPropValue. Who will ensure this?
698 bool bValue = *static_cast<sal_Bool const *>(rValue.getValue());
699 bool bIsTrans = bTransPropValue ? bValue : !bValue;
701 if( bIsTrans )
703 rStrExpValue = sTransparent;
704 bRet = true;
707 return bRet;
710 // class XMLColorAutoPropHdl
712 XMLColorAutoPropHdl::XMLColorAutoPropHdl()
714 // Nothing to do
717 XMLColorAutoPropHdl::~XMLColorAutoPropHdl()
719 // Nothing to do
722 bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
724 bool bRet = false;
726 // This is a multi property: the value might be set to AUTO_COLOR
727 // already by the XMLIsAutoColorPropHdl!
728 sal_Int32 nColor = 0;
729 if( !(rValue >>= nColor) || -1 != nColor )
731 bRet = ::sax::Converter::convertColor( nColor, rStrImpValue );
732 if( bRet )
733 rValue <<= nColor;
736 return bRet;
739 bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
741 bool bRet = false;
743 sal_Int32 nColor = 0;
744 if( (rValue >>= nColor) && -1 != nColor )
746 OUStringBuffer aOut;
747 ::sax::Converter::convertColor( aOut, nColor );
748 rStrExpValue = aOut.makeStringAndClear();
750 bRet = true;
753 return bRet;
756 // class XMLIsAutoColorPropHdl
758 XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl()
762 XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl()
764 // Nothing to do
767 bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
769 // An auto color overrides any other color set!
770 bool bValue;
771 bool const bRet = ::sax::Converter::convertBool( bValue, rStrImpValue );
772 if( bRet && bValue )
773 rValue <<= (sal_Int32)-1;
775 return true;
778 bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
780 bool bRet = false;
781 sal_Int32 nColor = 0;
783 if( (rValue >>= nColor) && -1 == nColor )
785 OUStringBuffer aOut;
786 ::sax::Converter::convertBool( aOut, true );
787 rStrExpValue = aOut.makeStringAndClear();
789 bRet = true;
792 return bRet;
795 // class XMLCompareOnlyPropHdl
797 XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl()
799 // Nothing to do
802 bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const
804 DBG_ASSERT( false, "importXML called for compare-only-property" );
805 return false;
808 bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const
810 DBG_ASSERT( false, "exportXML called for compare-only-property" );
811 return false;
814 // class XMLNumberWithoutZeroPropHdl
816 XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) :
817 nBytes( nB )
821 XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl()
825 bool XMLNumberWithoutZeroPropHdl::importXML(
826 const OUString& rStrImpValue,
827 Any& rValue,
828 const SvXMLUnitConverter& ) const
830 sal_Int32 nValue = 0;
831 bool const bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
832 if( bRet )
833 lcl_xmloff_setAny( rValue, nValue, nBytes );
834 return bRet;
837 bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
840 sal_Int32 nValue = 0;
841 bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes );
842 bRet &= nValue != 0;
844 if( bRet )
846 OUStringBuffer aBuffer;
847 ::sax::Converter::convertNumber( aBuffer, nValue );
848 rStrExpValue = aBuffer.makeStringAndClear();
851 return bRet;
854 // class XMLNumberWithAutoInsteadZeroPropHdl
856 XMLNumberWithAutoInsteadZeroPropHdl::~XMLNumberWithAutoInsteadZeroPropHdl()
860 bool XMLNumberWithAutoInsteadZeroPropHdl::importXML(
861 const OUString& rStrImpValue,
862 Any& rValue,
863 const SvXMLUnitConverter& ) const
865 sal_Int32 nValue = 0;
866 bool bRet = ::sax::Converter::convertNumber( nValue, rStrImpValue );
867 if( bRet )
868 lcl_xmloff_setAny( rValue, nValue, 2 );
869 else if( rStrImpValue == GetXMLToken( XML_AUTO ) )
871 rValue.clear(); // void
872 bRet = true;
874 return bRet;
877 bool XMLNumberWithAutoInsteadZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
880 sal_Int32 nValue = 0;
881 bool bRet = lcl_xmloff_getAny( rValue, nValue, 2 );
882 bRet &= nValue != 0;
884 // FIXME: 0 is not a valid value - write "auto" instead
885 if (!bRet)
886 rStrExpValue = GetXMLToken( XML_AUTO );
887 else
889 OUStringBuffer aBuffer;
890 ::sax::Converter::convertNumber( aBuffer, nValue );
891 rStrExpValue = aBuffer.makeStringAndClear();
894 return true;
897 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */