LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextListItemContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 41 67 61.2 %
Date: 2014-11-03 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         284 : 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         284 :       mxNumRulesOverride()
      52             : {
      53         284 :     static OUString s_NumberingRules("NumberingRules");
      54         284 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      55         294 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      56             :     {
      57          10 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      58          20 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      59             : 
      60          20 :         OUString aLocalName;
      61             :         sal_uInt16 nPrefix =
      62          10 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      63          10 :                                                             &aLocalName );
      64          20 :         if( !bIsHeader && XML_NAMESPACE_TEXT == nPrefix &&
      65          10 :             IsXMLToken( aLocalName, XML_START_VALUE ) )
      66             :         {
      67          10 :             sal_Int32 nTmp = rValue.toInt32();
      68          10 :             if( nTmp >= 0 && nTmp <= SHRT_MAX )
      69          10 :                 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          10 :     }
     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         284 :     if( !bIsHeader ) {
     119         248 :         rTxtImport.GetTextListHelper().SetListItem( this );
     120             :     }
     121             : 
     122         284 : }
     123             : 
     124         568 : XMLTextListItemContext::~XMLTextListItemContext()
     125             : {
     126         568 : }
     127             : 
     128         284 : void XMLTextListItemContext::EndElement()
     129             : {
     130             :     // finish current list item
     131         284 :     rTxtImport.GetTextListHelper().SetListItem( 0 );
     132         284 : }
     133             : 
     134         340 : SvXMLImportContext *XMLTextListItemContext::CreateChildContext(
     135             :         sal_uInt16 nPrefix,
     136             :         const OUString& rLocalName,
     137             :         const Reference< xml::sax::XAttributeList > & xAttrList )
     138             : {
     139         340 :     SvXMLImportContext *pContext = 0;
     140             : 
     141         340 :     const SvXMLTokenMap& rTokenMap = rTxtImport.GetTextElemTokenMap();
     142         340 :     bool bHeading = false;
     143         340 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     144             :     {
     145             :     case XML_TOK_TEXT_H:
     146           8 :         bHeading = true;
     147             :     case XML_TOK_TEXT_P:
     148         272 :         pContext = new XMLParaContext( GetImport(),
     149             :                                        nPrefix, rLocalName,
     150         272 :                                        xAttrList, bHeading );
     151         272 :         if (rTxtImport.IsProgress())
     152         206 :             GetImport().GetProgressBarHelper()->Increment();
     153             : 
     154         272 :         break;
     155             :     case XML_TOK_TEXT_LIST:
     156          68 :         ++mnSubListCount;
     157          68 :         pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
     158             :                                                 nPrefix, rLocalName,
     159             :                                                 xAttrList,
     160          68 :                                                 (mnSubListCount > 1) );
     161          68 :         break;
     162             :     }
     163             : 
     164         340 :     if( !pContext )
     165           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     166             : 
     167         340 :     return pContext;
     168             : }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10