LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlbahdl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 346 412 84.0 %
Date: 2014-04-11 Functions: 84 94 89.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10