LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextNumRuleInfo.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 22 78 28.2 %
Date: 2014-11-03 Functions: 2 3 66.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             : 
      21             : #include <tools/debug.hxx>
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/container/XIndexReplace.hpp>
      25             : #include <com/sun/star/style/NumberingType.hpp>
      26             : #include <com/sun/star/container/XNamed.hpp>
      27             : #include "XMLTextNumRuleInfo.hxx"
      28             : #include <xmloff/XMLTextListAutoStylePool.hxx>
      29             : 
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::beans;
      33             : using namespace ::com::sun::star::container;
      34             : using namespace ::com::sun::star::style;
      35             : 
      36             : // Complete refactoring of the class and enhancement of the class for lists.
      37        3800 : XMLTextNumRuleInfo::XMLTextNumRuleInfo()
      38             :     : msNumberingRules("NumberingRules")
      39             :     , msNumberingLevel("NumberingLevel")
      40             :     , msNumberingStartValue("NumberingStartValue")
      41             :     , msParaIsNumberingRestart("ParaIsNumberingRestart")
      42             :     , msNumberingIsNumber("NumberingIsNumber")
      43             :     , msNumberingIsOutline("NumberingIsOutline")
      44             :     , msPropNameListId("ListId")
      45             :     , msPropNameStartWith("StartWith")
      46             :     , msContinueingPreviousSubTree("ContinueingPreviousSubTree")
      47             :     , msListLabelStringProp("ListLabelString")
      48             :     , mxNumRules()
      49             :     , msNumRulesName()
      50             :     , msListId()
      51             :     , mnListStartValue( -1 )
      52             :     , mnListLevel( 0 )
      53             :     , mbIsNumbered( false )
      54             :     , mbIsRestart( false )
      55             :     , mnListLevelStartValue( -1 )
      56        3800 :     , mbOutlineStyleAsNormalListStyle( false )
      57             : {
      58        3800 :     Reset();
      59        3800 : }
      60             : 
      61             : // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
      62         812 : void XMLTextNumRuleInfo::Set(
      63             :         const ::com::sun::star::uno::Reference <
      64             :                         ::com::sun::star::text::XTextContent > & xTextContent,
      65             :         const bool bOutlineStyleAsNormalListStyle,
      66             :         const XMLTextListAutoStylePool& rListAutoPool,
      67             :         const bool bExportTextNumberElement )
      68             : {
      69         812 :     Reset();
      70             :     // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
      71         812 :     mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
      72             : 
      73         812 :     Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
      74        1384 :     Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
      75             : 
      76             :     // check if this paragraph supports a numbering
      77         812 :     if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) )
      78         240 :         return;
      79             : 
      80         572 :     if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel )
      81             :     {
      82         384 :         if( xPropSetInfo->hasPropertyByName( msNumberingRules ) )
      83             :         {
      84         384 :             xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules;
      85             :         }
      86             :     }
      87             :     else
      88             :     {
      89             :         // in applications using the outliner we always have a numbering rule,
      90             :         // so a void property no numbering
      91         188 :         mnListLevel = 0;
      92             :     }
      93             : 
      94             :     // Assertion saving writer document (#i97312#)
      95         572 :     if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
      96             :     {
      97             :         DBG_ASSERT( false,
      98             :                     "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
      99           0 :         Reset();
     100           0 :         return;
     101             :     }
     102             : 
     103         572 :     if ( mnListLevel < 0 )
     104             :     {
     105             :         DBG_ASSERT( false,
     106             :                     "<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
     107           0 :         Reset();
     108           0 :         return;
     109             :     }
     110             : 
     111             :     // Written OpenDocument file format doesn't fit to the created text document (#i69627#)
     112         572 :     bool bSuppressListStyle( false );
     113         572 :     if ( mxNumRules.is() )
     114             :     {
     115           0 :         if ( !mbOutlineStyleAsNormalListStyle )
     116             :         {
     117           0 :             bool bIsOutline = false;
     118           0 :             Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
     119           0 :             if ( xNumRulesProps.is() &&
     120           0 :                  xNumRulesProps->getPropertySetInfo()->
     121           0 :                                     hasPropertyByName( msNumberingIsOutline ) )
     122             :             {
     123           0 :                 xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline;
     124           0 :                 bSuppressListStyle = bIsOutline;
     125           0 :             }
     126             :         }
     127             :     }
     128             : 
     129         572 :     if( mxNumRules.is() && !bSuppressListStyle )
     130             :     {
     131             :         // First try to find the numbering rules in the list auto style pool.
     132             :         // If not found, the numbering rules instance has to be named.
     133           0 :         msNumRulesName = rListAutoPool.Find( mxNumRules );
     134           0 :         if ( msNumRulesName.isEmpty() )
     135             :         {
     136           0 :             Reference < XNamed > xNamed( mxNumRules, UNO_QUERY );
     137             :             DBG_ASSERT( xNamed.is(),
     138             :                         "<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." );
     139           0 :             if( xNamed.is() )
     140             :             {
     141           0 :                 msNumRulesName = xNamed->getName();
     142           0 :             }
     143             :         }
     144             :         DBG_ASSERT( !msNumRulesName.isEmpty(),
     145             :                     "<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
     146             : 
     147           0 :         if( xPropSetInfo->hasPropertyByName( msPropNameListId ) )
     148             :         {
     149           0 :             xPropSet->getPropertyValue( msPropNameListId ) >>= msListId;
     150             :         }
     151             : 
     152           0 :         mbContinueingPreviousSubTree = false;
     153           0 :         if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) )
     154             :         {
     155           0 :             xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree;
     156             :         }
     157             : 
     158           0 :         mbIsNumbered = true;
     159           0 :         if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
     160             :         {
     161           0 :             if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) )
     162             :             {
     163             :                 OSL_FAIL( "numbered paragraph without number info" );
     164           0 :                 mbIsNumbered = false;
     165             :             }
     166             :         }
     167             : 
     168           0 :         if( mbIsNumbered )
     169             :         {
     170           0 :             if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) )
     171             :             {
     172           0 :                 xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart;
     173             :             }
     174           0 :             if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) )
     175             :             {
     176           0 :                 xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue;
     177             :             }
     178             :         }
     179             : 
     180             :         OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
     181           0 :         if( mnListLevel >= mxNumRules->getCount() )
     182             :         {
     183           0 :             Reset();
     184           0 :             return;
     185             :         }
     186             : 
     187           0 :         Sequence<PropertyValue> aProps;
     188           0 :         mxNumRules->getByIndex( mnListLevel ) >>= aProps;
     189             : 
     190           0 :         const PropertyValue* pPropArray = aProps.getConstArray();
     191           0 :         sal_Int32 nCount = aProps.getLength();
     192           0 :         for( sal_Int32 i=0; i<nCount; i++ )
     193             :         {
     194           0 :           const PropertyValue& rProp = pPropArray[i];
     195             : 
     196           0 :             if ( rProp.Name == msPropNameStartWith )
     197             :             {
     198           0 :                 rProp.Value >>= mnListLevelStartValue;
     199           0 :                 break;
     200             :             }
     201             :         }
     202             : 
     203           0 :         msListLabelString = OUString();
     204           0 :         if ( bExportTextNumberElement &&
     205           0 :              xPropSetInfo->hasPropertyByName( msListLabelStringProp ) )
     206             :         {
     207           0 :             xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString;
     208             :         }
     209             : 
     210             :         // paragraph's list level range is [0..9] representing list levels [1..10]
     211           0 :         ++mnListLevel;
     212             :     }
     213             :     else
     214             :     {
     215         572 :         mnListLevel = 0;
     216         572 :     }
     217             : }
     218             : 
     219           0 : bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const
     220             : {
     221           0 :     bool bRet( true );
     222             :     // Currently only the text documents support <ListId>.
     223           0 :     if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
     224             :     {
     225           0 :         bRet = rCmp.msListId == msListId;
     226             :     }
     227             :     else
     228             :     {
     229           0 :         bRet = HasSameNumRules( rCmp );
     230             :     }
     231             : 
     232           0 :     return bRet;
     233             : }
     234             : 
     235             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10