LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextListItemContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 66 60.6 %
Date: 2015-06-13 12:38:46 Functions: 5 10 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 <xmloff/xmlimp.hxx>
      21             : #include <xmloff/nmspmap.hxx>
      22             : #include <xmloff/xmlnmspe.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include "txtparai.hxx"
      25             : #include "txtlists.hxx"
      26             : #include "XMLTextListBlockContext.hxx"
      27             : #include <xmloff/txtimp.hxx>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <com/sun/star/style/XStyle.hpp>
      30             : #include <xmloff/xmlnumi.hxx>
      31             : #include "XMLTextListItemContext.hxx"
      32             : 
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::xmloff::token;
      37             : 
      38           0 : TYPEINIT1( XMLTextListItemContext, SvXMLImportContext );
      39             : 
      40         267 : XMLTextListItemContext::XMLTextListItemContext(
      41             :                         SvXMLImport& rImport,
      42             :                         XMLTextImportHelper& rTxtImp,
      43             :                         const sal_uInt16 nPrfx,
      44             :                         const OUString& rLName,
      45             :                         const Reference< xml::sax::XAttributeList > & xAttrList,
      46             :                         const bool bIsHeader )
      47             :     : SvXMLImportContext( rImport, nPrfx, rLName ),
      48             :       rTxtImport( rTxtImp ),
      49             :       nStartValue( -1 ),
      50             :       mnSubListCount( 0 ),
      51         267 :       mxNumRulesOverride()
      52             : {
      53             :     static const char s_NumberingRules[] = "NumberingRules";
      54         267 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      55         279 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      56             :     {
      57          12 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      58          24 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      59             : 
      60          24 :         OUString aLocalName;
      61             :         sal_uInt16 nPrefix =
      62          12 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      63          12 :                                                             &aLocalName );
      64          24 :         if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
      65          12 :             IsXMLToken( aLocalName, XML_START_VALUE ) )
      66             :         {
      67          12 :             sal_Int32 nTmp = rValue.toInt32();
      68          12 :             if( nTmp >= 0 && nTmp <= SHRT_MAX )
      69          12 :                 nStartValue = (sal_Int16)nTmp;
      70             :         }
      71           0 :         else if ( nPrefix == XML_NAMESPACE_TEXT &&
      72           0 :                   IsXMLToken( aLocalName, XML_STYLE_OVERRIDE ) )
      73             :         {
      74           0 :             const OUString sListStyleOverrideName = rValue;
      75           0 :             if ( !sListStyleOverrideName.isEmpty() )
      76             :             {
      77             :                 OUString sDisplayStyleName(
      78           0 :                         GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
      79           0 :                                                          sListStyleOverrideName ) );
      80             :                 const Reference < container::XNameContainer >& rNumStyles =
      81           0 :                                                     rTxtImp.GetNumberingStyles();
      82           0 :                 if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
      83             :                 {
      84           0 :                     Reference < style::XStyle > xStyle;
      85           0 :                     Any aAny = rNumStyles->getByName( sDisplayStyleName );
      86           0 :                     aAny >>= xStyle;
      87             : 
      88           0 :                     uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
      89           0 :                     aAny = xPropSet->getPropertyValue(s_NumberingRules);
      90           0 :                     aAny >>= mxNumRulesOverride;
      91             :                 }
      92             :                 else
      93             :                 {
      94             :                     const SvxXMLListStyleContext* pListStyle =
      95           0 :                                         rTxtImp.FindAutoListStyle( sListStyleOverrideName );
      96           0 :                     if( pListStyle )
      97             :                     {
      98           0 :                         mxNumRulesOverride = pListStyle->GetNumRules();
      99           0 :                         if( !mxNumRulesOverride.is() )
     100             :                         {
     101           0 :                             pListStyle->CreateAndInsertAuto();
     102           0 :                             mxNumRulesOverride = pListStyle->GetNumRules();
     103             :                         }
     104             :                     }
     105           0 :                 }
     106           0 :             }
     107             :         }
     108           0 :         else if ( (XML_NAMESPACE_XML == nPrefix) &&
     109           0 :              IsXMLToken(aLocalName, XML_ID)   )
     110             :         {
     111             :             (void) rValue;
     112             : //FIXME: there is no UNO API for list items
     113             :         }
     114          12 :     }
     115             : 
     116             :     // If this is a <text:list-item> element, then remember it as a sign
     117             :     // that a bullet has to be generated.
     118         267 :     if( !bIsHeader ) {
     119         226 :         rTxtImport.GetTextListHelper().SetListItem( this );
     120             :     }
     121             : 
     122         267 : }
     123             : 
     124         534 : XMLTextListItemContext::~XMLTextListItemContext()
     125             : {
     126         534 : }
     127             : 
     128         267 : void XMLTextListItemContext::EndElement()
     129             : {
     130             :     // finish current list item
     131         267 :     rTxtImport.GetTextListHelper().SetListItem( 0 );
     132         267 : }
     133             : 
     134         301 : SvXMLImportContext *XMLTextListItemContext::CreateChildContext(
     135             :         sal_uInt16 nPrefix,
     136             :         const OUString& rLocalName,
     137             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     138             : {
     139         301 :     SvXMLImportContext *pContext = 0;
     140             : 
     141         301 :     const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
     142         301 :     bool bHeading = false;
     143         301 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     144             :     {
     145             :     case XML_TOK_TEXT_H:
     146           4 :         bHeading = true;
     147             :     case XML_TOK_TEXT_P:
     148         262 :         pContext = new XMLParaContext( GetImport(),
     149             :                                        nPrefix, rLocalName,
     150         262 :                                        xAttrList, bHeading );
     151         262 :         if (rTxtImport.IsProgress())
     152         223 :             GetImport().GetProgressBarHelper()->Increment();
     153             : 
     154         262 :         break;
     155             :     case XML_TOK_TEXT_LIST:
     156          39 :         ++mnSubListCount;
     157          39 :         pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
     158             :                                                 nPrefix, rLocalName,
     159             :                                                 xAttrList,
     160          39 :                                                 (mnSubListCount > 1) );
     161          39 :         break;
     162             :     }
     163             : 
     164         301 :     if( !pContext )
     165           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     166             : 
     167         301 :     return pContext;
     168             : }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11