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

Generated by: LCOV version 1.11