LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - xmltabi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 81 98 82.7 %
Date: 2013-07-09 Functions: 11 22 50.0 %
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 <com/sun/star/style/TabAlign.hpp>
      21             : #include <rtl/ustrbuf.hxx>
      22             : #include <xmloff/xmltkmap.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include "xmloff/xmlnmspe.hxx"
      25             : #include <xmloff/xmlimp.hxx>
      26             : #include <com/sun/star/style/TabStop.hpp>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include "xmloff/i18nmap.hxx"
      29             : #include <xmloff/xmluconv.hxx>
      30             : #include "xmltabi.hxx"
      31             : 
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::xmloff::token;
      35             : 
      36             : enum SvXMLTokenMapAttrs
      37             : {
      38             :     XML_TOK_TABSTOP_POSITION,
      39             :     XML_TOK_TABSTOP_TYPE,
      40             :     XML_TOK_TABSTOP_CHAR,
      41             :     XML_TOK_TABSTOP_LEADER_STYLE,
      42             :     XML_TOK_TABSTOP_LEADER_TEXT,
      43             :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      44             : };
      45             : 
      46             : static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
      47             : {
      48             :     { XML_NAMESPACE_STYLE, XML_POSITION,     XML_TOK_TABSTOP_POSITION },
      49             :     { XML_NAMESPACE_STYLE, XML_TYPE,         XML_TOK_TABSTOP_TYPE },
      50             :     { XML_NAMESPACE_STYLE, XML_CHAR,         XML_TOK_TABSTOP_CHAR },
      51             :     { XML_NAMESPACE_STYLE, XML_LEADER_TEXT,  XML_TOK_TABSTOP_LEADER_TEXT },
      52             :     { XML_NAMESPACE_STYLE, XML_LEADER_STYLE,  XML_TOK_TABSTOP_LEADER_STYLE },
      53             :     XML_TOKEN_MAP_END
      54             : };
      55             : 
      56             : // ---
      57             : 
      58             : class SvxXMLTabStopContext_Impl : public SvXMLImportContext
      59             : {
      60             : private:
      61             :      style::TabStop aTabStop;
      62             : 
      63             : public:
      64             :     TYPEINFO();
      65             : 
      66             :     SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
      67             :                                const OUString& rLName,
      68             :                                const uno::Reference< xml::sax::XAttributeList > & xAttrList );
      69             : 
      70             :     virtual ~SvxXMLTabStopContext_Impl();
      71             : 
      72             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
      73             :                                    const OUString& rLocalName,
      74             :                                    const uno::Reference< xml::sax::XAttributeList > & xAttrList );
      75             : 
      76          70 :     const style::TabStop& getTabStop() const { return aTabStop; }
      77             : };
      78             : 
      79           0 : TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );
      80             : 
      81          35 : SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
      82             :                                SvXMLImport& rImport, sal_uInt16 nPrfx,
      83             :                                const OUString& rLName,
      84             :                                const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      85          35 : : SvXMLImportContext( rImport, nPrfx, rLName )
      86             : {
      87          35 :     aTabStop.Position = 0;
      88          35 :     aTabStop.Alignment = style::TabAlign_LEFT;
      89          35 :     aTabStop.DecimalChar = sal_Unicode( ',' );
      90          35 :     aTabStop.FillChar = sal_Unicode( ' ' );
      91          35 :     sal_Unicode cTextFillChar = 0;
      92             : 
      93          35 :     SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );
      94             : 
      95          35 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      96         109 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      97             :     {
      98          74 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      99         148 :         OUString aLocalName;
     100             :         sal_uInt16 nPrefix =
     101          74 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     102          74 :                                                             &aLocalName );
     103         148 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     104             : 
     105             :         sal_Int32 nVal;
     106          74 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
     107             :         {
     108             :         case XML_TOK_TABSTOP_POSITION:
     109          35 :             if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     110             :                     nVal, rValue))
     111             :             {
     112          35 :                 aTabStop.Position = nVal;
     113             :             }
     114          35 :             break;
     115             :         case XML_TOK_TABSTOP_TYPE:
     116          33 :             if( IsXMLToken( rValue, XML_LEFT ) )
     117             :             {
     118           0 :                 aTabStop.Alignment = style::TabAlign_LEFT;
     119             :             }
     120          33 :             else if( IsXMLToken( rValue, XML_RIGHT ) )
     121             :             {
     122          19 :                 aTabStop.Alignment = style::TabAlign_RIGHT;
     123             :             }
     124          14 :             else if( IsXMLToken( rValue, XML_CENTER ) )
     125             :             {
     126          14 :                 aTabStop.Alignment = style::TabAlign_CENTER;
     127             :             }
     128           0 :             else if( IsXMLToken( rValue, XML_CHAR ) )
     129             :             {
     130           0 :                 aTabStop.Alignment = style::TabAlign_DECIMAL;
     131             :             }
     132           0 :             else if( IsXMLToken( rValue, XML_DEFAULT ) )
     133             :             {
     134           0 :                 aTabStop.Alignment = style::TabAlign_DEFAULT;
     135             :             }
     136          33 :             break;
     137             :         case XML_TOK_TABSTOP_CHAR:
     138           0 :             if( !rValue.isEmpty() )
     139           0 :                 aTabStop.DecimalChar = rValue[0];
     140           0 :             break;
     141             :         case XML_TOK_TABSTOP_LEADER_STYLE:
     142           3 :             if( IsXMLToken( rValue, XML_NONE ) )
     143           0 :                 aTabStop.FillChar = ' ';
     144           3 :             else if( IsXMLToken( rValue, XML_DOTTED ) )
     145           3 :                 aTabStop.FillChar = '.';
     146             :             else
     147           0 :                 aTabStop.FillChar = '_';
     148           3 :             break;
     149             :         case XML_TOK_TABSTOP_LEADER_TEXT:
     150           3 :             if( !rValue.isEmpty() )
     151           3 :                 cTextFillChar = rValue[0];
     152           3 :             break;
     153             :         }
     154          74 :     }
     155             : 
     156          35 :     if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
     157           3 :         aTabStop.FillChar = cTextFillChar;
     158          35 : }
     159             : 
     160          70 : SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
     161             : {
     162          70 : }
     163             : 
     164           0 : SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
     165             :                                    sal_uInt16 nPrefix,
     166             :                                    const OUString& rLocalName,
     167             :                                    const uno::Reference< xml::sax::XAttributeList > & )
     168             : {
     169           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     170             : }
     171             : 
     172             : 
     173             : 
     174             : 
     175          38 : class SvxXMLTabStopArray_Impl : public std::vector<SvxXMLTabStopContext_Impl *> {};
     176             : 
     177             : 
     178             : // ---
     179             : 
     180           0 : TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );
     181             : 
     182          95 : SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
     183             :                                 SvXMLImport& rImport, sal_uInt16 nPrfx,
     184             :                                 const OUString& rLName,
     185             :                                 const XMLPropertyState& rProp,
     186             :                                  ::std::vector< XMLPropertyState > &rProps )
     187             : : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
     188          95 :   mpTabStops( NULL )
     189             : {
     190          95 : }
     191             : 
     192         285 : SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
     193             : {
     194          95 :     if( mpTabStops )
     195             :     {
     196          73 :         while( !mpTabStops->empty() )
     197             :         {
     198          35 :             SvxXMLTabStopContext_Impl *pTabStop = mpTabStops->back();
     199          35 :             mpTabStops->pop_back();
     200          35 :             pTabStop->ReleaseRef();
     201             :         }
     202             :     }
     203             : 
     204          95 :     delete mpTabStops;
     205         190 : }
     206             : 
     207          35 : SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
     208             :                                    sal_uInt16 nPrefix,
     209             :                                    const OUString& rLocalName,
     210             :                                    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     211             : {
     212          35 :     SvXMLImportContext *pContext = 0;
     213             : 
     214          35 :     if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
     215             :     {
     216             :         // create new tabstop import context
     217             :         SvxXMLTabStopContext_Impl *pTabStopContext =
     218          35 :             new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
     219          35 :                                            xAttrList );
     220             : 
     221             :         // add new tabstop to array of tabstops
     222          35 :         if( !mpTabStops )
     223          19 :             mpTabStops = new SvxXMLTabStopArray_Impl;
     224             : 
     225          35 :         mpTabStops->push_back( pTabStopContext );
     226          35 :         pTabStopContext->AddRef();
     227             : 
     228          35 :         pContext = pTabStopContext;
     229             :     }
     230             :     else
     231             :     {
     232           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     233             :     }
     234             : 
     235          35 :     return pContext;
     236             : }
     237             : 
     238          95 : void SvxXMLTabStopImportContext::EndElement( )
     239             : {
     240          95 :     sal_uInt16 nCount = mpTabStops ? mpTabStops->size() : 0;
     241          95 :     uno::Sequence< style::TabStop> aSeq( nCount );
     242             : 
     243          95 :     if( mpTabStops )
     244             :     {
     245          19 :         sal_uInt16 nNewCount = 0;
     246             : 
     247          19 :         style::TabStop* pTabStops = aSeq.getArray();
     248          54 :         for( sal_uInt16 i=0; i < nCount; i++ )
     249             :         {
     250          35 :             SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
     251          35 :             const style::TabStop& rTabStop = pTabStopContext->getTabStop();
     252          35 :             sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
     253          35 :             if( !bDflt || 0==i )
     254             :             {
     255          35 :                 *pTabStops++ = pTabStopContext->getTabStop();
     256          35 :                 nNewCount++;
     257             :             }
     258          35 :             if( bDflt && 0==i )
     259           0 :                 break;
     260             :         }
     261             : 
     262          19 :         if( nCount != nNewCount )
     263           0 :             aSeq.realloc( nNewCount );
     264             :     }
     265          95 :     aProp.maValue <<= aSeq;
     266             : 
     267          95 :     SetInsert( sal_True );
     268          95 :     XMLElementPropertyContext::EndElement();
     269             : 
     270          95 : }
     271             : 
     272             : 
     273             : 
     274             : 
     275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10