LCOV - code coverage report
Current view: top level - xmloff/source/style - PageMasterPropHdl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 93 158 58.9 %
Date: 2014-04-11 Functions: 23 30 76.7 %
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 "PageMasterPropHdl.hxx"
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : 
      24             : #include <xmloff/xmltoken.hxx>
      25             : #include <xmloff/xmluconv.hxx>
      26             : #include <xmloff/xmlnumi.hxx>
      27             : #include <xmloff/xmlnume.hxx>
      28             : #include <rtl/ustrbuf.hxx>
      29             : #include <com/sun/star/uno/Any.hxx>
      30             : #include <com/sun/star/style/PageStyleLayout.hpp>
      31             : #include <comphelper/types.hxx>
      32             : #include <comphelper/extract.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::style;
      37             : using namespace ::comphelper;
      38             : using namespace ::xmloff::token;
      39             : 
      40             : #define DEFAULT_PAPERTRAY   (sal_Int32(-1))
      41             : 
      42             : // property handler for style:page-usage (style::PageStyleLayout)
      43             : 
      44         676 : XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
      45             : {
      46         676 : }
      47             : 
      48           6 : bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
      49             : {
      50             :     style::PageStyleLayout eLayout1, eLayout2;
      51           6 :     return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : false;
      52             : }
      53             : 
      54          30 : bool XMLPMPropHdl_PageStyleLayout::importXML(
      55             :         const OUString& rStrImpValue,
      56             :         Any& rValue,
      57             :         const SvXMLUnitConverter& ) const
      58             : {
      59          30 :     bool bRet = true;
      60             : 
      61          30 :     if( IsXMLToken( rStrImpValue, XML_ALL ) )
      62           0 :         rValue <<= PageStyleLayout_ALL;
      63          30 :     else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
      64           2 :         rValue <<= PageStyleLayout_LEFT;
      65          28 :     else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
      66           2 :         rValue <<= PageStyleLayout_RIGHT;
      67          26 :     else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
      68          26 :         rValue <<= PageStyleLayout_MIRRORED;
      69             :     else
      70           0 :         bRet = false;
      71             : 
      72          30 :     return bRet;
      73             : }
      74             : 
      75          25 : bool XMLPMPropHdl_PageStyleLayout::exportXML(
      76             :         OUString& rStrExpValue,
      77             :         const Any& rValue,
      78             :         const SvXMLUnitConverter& ) const
      79             : {
      80          25 :     bool bRet = false;
      81             :     PageStyleLayout eLayout;
      82             : 
      83          25 :     if( rValue >>= eLayout )
      84             :     {
      85          25 :         bRet = true;
      86          25 :         switch( eLayout )
      87             :         {
      88             :             case PageStyleLayout_ALL:
      89          21 :                 rStrExpValue = GetXMLToken( XML_ALL );
      90          21 :             break;
      91             :             case PageStyleLayout_LEFT:
      92           0 :                 rStrExpValue = GetXMLToken( XML_LEFT );
      93           0 :             break;
      94             :             case PageStyleLayout_RIGHT:
      95           0 :                 rStrExpValue = GetXMLToken( XML_RIGHT );
      96           0 :             break;
      97             :             case PageStyleLayout_MIRRORED:
      98           4 :                 rStrExpValue = GetXMLToken( XML_MIRRORED );
      99           4 :             break;
     100             :             default:
     101           0 :                 bRet = false;
     102             :         }
     103             :     }
     104             : 
     105          25 :     return bRet;
     106             : }
     107             : 
     108             : // property handler for style:num-format (style::NumberingType)
     109             : 
     110         646 : XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
     111             : {
     112         646 : }
     113             : 
     114         164 : bool XMLPMPropHdl_NumFormat::importXML(
     115             :         const OUString& rStrImpValue,
     116             :         Any& rValue,
     117             :         const SvXMLUnitConverter& rUnitConverter ) const
     118             : {
     119         164 :     sal_Int16 nSync = sal_Int16();
     120         164 :     sal_Int16 nNumType = NumberingType::NUMBER_NONE;
     121         164 :     rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(), true );
     122             : 
     123         164 :     if( !(rValue >>= nSync) )
     124         164 :         nSync = NumberingType::NUMBER_NONE;
     125             : 
     126             :     // if num-letter-sync appears before num-format, the function
     127             :     // XMLPMPropHdl_NumLetterSync::importXML() sets the value
     128             :     // NumberingType::CHARS_LOWER_LETTER_N
     129         164 :     if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
     130             :     {
     131           0 :         switch( nNumType )
     132             :         {
     133             :             case NumberingType::CHARS_LOWER_LETTER:
     134           0 :                 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
     135           0 :             break;
     136             :             case NumberingType::CHARS_UPPER_LETTER:
     137           0 :                 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
     138           0 :             break;
     139             :         }
     140             :     }
     141         164 :     rValue <<= nNumType;
     142             : 
     143         164 :     return true;
     144             : }
     145             : 
     146          25 : bool XMLPMPropHdl_NumFormat::exportXML(
     147             :         OUString& rStrExpValue,
     148             :         const Any& rValue,
     149             :         const SvXMLUnitConverter& rUnitConverter ) const
     150             : {
     151          25 :     bool bRet = false;
     152          25 :     sal_Int16   nNumType = sal_Int16();
     153             : 
     154          25 :     if( rValue >>= nNumType )
     155             :     {
     156          25 :         OUStringBuffer aBuffer( 10 );
     157          25 :         rUnitConverter.convertNumFormat( aBuffer, nNumType );
     158          25 :         rStrExpValue = aBuffer.makeStringAndClear();
     159          25 :         bRet = true;
     160             :     }
     161          25 :     return bRet;
     162             : }
     163             : 
     164             : // property handler for style:num-letter-sync (style::NumberingType)
     165             : 
     166         646 : XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
     167             : {
     168         646 : }
     169             : 
     170           0 : bool XMLPMPropHdl_NumLetterSync::importXML(
     171             :         const OUString& rStrImpValue,
     172             :         Any& rValue,
     173             :         const SvXMLUnitConverter& rUnitConverter ) const
     174             : {
     175             :     sal_Int16 nNumType;
     176           0 :     sal_Int16 nSync = NumberingType::NUMBER_NONE;
     177             :     rUnitConverter.convertNumFormat( nSync, rStrImpValue,
     178           0 :                                      GetXMLToken( XML_A ), true );
     179             : 
     180           0 :     if( !(rValue >>= nNumType) )
     181           0 :         nNumType = NumberingType::NUMBER_NONE;
     182             : 
     183           0 :     if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
     184             :     {
     185           0 :         switch( nNumType )
     186             :         {
     187             :             case NumberingType::CHARS_LOWER_LETTER:
     188           0 :                 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
     189           0 :             break;
     190             :             case NumberingType::CHARS_UPPER_LETTER:
     191           0 :                 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
     192           0 :             break;
     193             :         }
     194             :     }
     195           0 :     rValue <<= nNumType;
     196             : 
     197           0 :     return true;
     198             : }
     199             : 
     200          25 : bool XMLPMPropHdl_NumLetterSync::exportXML(
     201             :         OUString& rStrExpValue,
     202             :         const Any& rValue,
     203             :         const SvXMLUnitConverter& rUnitConverter ) const
     204             : {
     205          25 :     bool        bRet = false;
     206          25 :     sal_Int16   nNumType = sal_Int16();
     207             : 
     208          25 :     if( rValue >>= nNumType )
     209             :     {
     210          25 :         OUStringBuffer aBuffer( 5 );
     211          25 :         rUnitConverter.convertNumLetterSync( aBuffer, nNumType );
     212          25 :         rStrExpValue = aBuffer.makeStringAndClear();
     213          25 :         bRet = !rStrExpValue.isEmpty();
     214             :     }
     215          25 :     return bRet;
     216             : }
     217             : 
     218             : // property handler for style:paper-tray-number
     219             : 
     220           0 : XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
     221             : {
     222           0 : }
     223             : 
     224           0 : bool XMLPMPropHdl_PaperTrayNumber::importXML(
     225             :         const OUString& rStrImpValue,
     226             :         Any& rValue,
     227             :         const SvXMLUnitConverter& ) const
     228             : {
     229           0 :     bool bRet = false;
     230             : 
     231           0 :     if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
     232             :     {
     233           0 :         rValue <<= DEFAULT_PAPERTRAY;
     234           0 :         bRet = true;
     235             :     }
     236             :     else
     237             :     {
     238             :         sal_Int32 nPaperTray;
     239           0 :         if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
     240             :         {
     241           0 :             rValue <<= nPaperTray;
     242           0 :             bRet = true;
     243             :         }
     244             :     }
     245             : 
     246           0 :     return bRet;
     247             : }
     248             : 
     249           0 : bool XMLPMPropHdl_PaperTrayNumber::exportXML(
     250             :         OUString& rStrExpValue,
     251             :         const Any& rValue,
     252             :         const SvXMLUnitConverter& ) const
     253             : {
     254           0 :     bool        bRet = false;
     255           0 :     sal_Int32   nPaperTray = 0;
     256             : 
     257           0 :     if( rValue >>= nPaperTray )
     258             :     {
     259           0 :         if( nPaperTray == DEFAULT_PAPERTRAY )
     260           0 :             rStrExpValue = GetXMLToken( XML_DEFAULT );
     261             :         else
     262             :         {
     263           0 :             OUStringBuffer aBuffer;
     264           0 :             ::sax::Converter::convertNumber( aBuffer, nPaperTray );
     265           0 :             rStrExpValue = aBuffer.makeStringAndClear();
     266             :         }
     267           0 :         bRet = true;
     268             :     }
     269           0 :     return bRet;
     270             : }
     271             : 
     272             : // property handler for style:print
     273             : 
     274        2584 : XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
     275        2584 :     sAttrValue( GetXMLToken( eValue ) )
     276             : {
     277        2584 : }
     278             : 
     279        5168 : XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
     280             : {
     281        5168 : }
     282             : 
     283          64 : bool XMLPMPropHdl_Print::importXML(
     284             :         const OUString& rStrImpValue,
     285             :         Any& rValue,
     286             :         const SvXMLUnitConverter& ) const
     287             : {
     288          64 :     sal_Unicode cToken  = ' ';
     289          64 :     sal_Int32   nTokenIndex = 0;
     290          64 :     bool        bFound  = false;
     291             : 
     292         228 :     do
     293             :     {
     294         228 :         bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
     295             :     }
     296         421 :     while ( (nTokenIndex >= 0) && !bFound );
     297             : 
     298          64 :     setBOOL( rValue, bFound );
     299          64 :     return true;
     300             : }
     301             : 
     302           4 : bool XMLPMPropHdl_Print::exportXML(
     303             :         OUString& rStrExpValue,
     304             :         const Any& rValue,
     305             :         const SvXMLUnitConverter& ) const
     306             : {
     307           4 :     if( getBOOL( rValue ) )
     308             :     {
     309           4 :         if( !rStrExpValue.isEmpty() )
     310           3 :             rStrExpValue += " ";
     311           4 :         rStrExpValue += sAttrValue;
     312             :     }
     313             : 
     314           4 :     return true;
     315             : }
     316             : 
     317             : // property handler for style:table-centering
     318             : 
     319         646 : XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
     320             : {
     321         646 : }
     322             : 
     323           2 : bool XMLPMPropHdl_CenterHorizontal::importXML(
     324             :         const OUString& rStrImpValue,
     325             :         Any& rValue,
     326             :         const SvXMLUnitConverter& ) const
     327             : {
     328           2 :     bool bRet = false;
     329             : 
     330           2 :     if (!rStrImpValue.isEmpty())
     331           4 :         if (IsXMLToken( rStrImpValue, XML_BOTH) ||
     332           2 :             IsXMLToken( rStrImpValue, XML_HORIZONTAL))
     333             :         {
     334           2 :             rValue <<= true;
     335           2 :             bRet = true;
     336             :         }
     337             : 
     338           2 :     return bRet;
     339             : }
     340             : 
     341           0 : bool XMLPMPropHdl_CenterHorizontal::exportXML(
     342             :         OUString& rStrExpValue,
     343             :         const Any& rValue,
     344             :         const SvXMLUnitConverter& ) const
     345             : {
     346           0 :     bool bRet = false;
     347             : 
     348           0 :     if ( ::cppu::any2bool( rValue ) )
     349             :     {
     350           0 :         bRet = true;
     351           0 :         if (!rStrExpValue.isEmpty())
     352           0 :             rStrExpValue = GetXMLToken(XML_BOTH);
     353             :         else
     354           0 :             rStrExpValue = GetXMLToken(XML_HORIZONTAL);
     355             :     }
     356             : 
     357           0 :     return bRet;
     358             : }
     359             : 
     360         646 : XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
     361             : {
     362         646 : }
     363             : 
     364           2 : bool XMLPMPropHdl_CenterVertical::importXML(
     365             :         const OUString& rStrImpValue,
     366             :         Any& rValue,
     367             :         const SvXMLUnitConverter& ) const
     368             : {
     369           2 :     bool bRet = false;
     370             : 
     371           2 :     if (!rStrImpValue.isEmpty())
     372           4 :         if (IsXMLToken(rStrImpValue, XML_BOTH) ||
     373           2 :             IsXMLToken(rStrImpValue, XML_VERTICAL) )
     374             :         {
     375           0 :             rValue <<= true;
     376           0 :             bRet = true;
     377             :         }
     378             : 
     379           2 :     return bRet;
     380             : }
     381             : 
     382           0 : bool XMLPMPropHdl_CenterVertical::exportXML(
     383             :         OUString& rStrExpValue,
     384             :         const Any& rValue,
     385             :         const SvXMLUnitConverter& ) const
     386             : {
     387           0 :     bool bRet = false;
     388             : 
     389           0 :     if ( ::cppu::any2bool( rValue ) )
     390             :     {
     391           0 :         bRet = true;
     392           0 :         if (!rStrExpValue.isEmpty())
     393           0 :             rStrExpValue = GetXMLToken(XML_BOTH);
     394             :         else
     395           0 :             rStrExpValue = GetXMLToken(XML_VERTICAL);
     396             :     }
     397             : 
     398           0 :     return bRet;
     399             : }
     400             : 
     401             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10