LCOV - code coverage report
Current view: top level - sw/source/core/doc - list.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 84 104 80.8 %
Date: 2015-06-13 12:38:46 Functions: 20 23 87.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 <list.hxx>
      21             : 
      22             : #include <vector>
      23             : #include <numrule.hxx>
      24             : #include <ndarr.hxx>
      25             : #include <node.hxx>
      26             : #include <pam.hxx>
      27             : #include <SwNodeNum.hxx>
      28             : 
      29             : // implementation class for SwList
      30             : class SwListImpl
      31             : {
      32             :     public:
      33             :         SwListImpl( const OUString& sListId,
      34             :                     SwNumRule& rDefaultListStyle,
      35             :                     const SwNodes& rNodes );
      36             :         ~SwListImpl();
      37             : 
      38       22615 :         const OUString GetListId() const { return msListId;}
      39             : 
      40        2914 :         const OUString GetDefaultListStyleName() const { return msDefaultListStyleName;}
      41             : 
      42             :         void InsertListItem( SwNodeNum& rNodeNum,
      43             :                              const int nLevel );
      44             :         static void RemoveListItem( SwNodeNum& rNodeNum );
      45             : 
      46             :         void InvalidateListTree();
      47             :         void ValidateListTree();
      48             : 
      49             :         void MarkListLevel( const int nListLevel,
      50             :                             const bool bValue );
      51             : 
      52             :         bool IsListLevelMarked( const int nListLevel ) const;
      53             : 
      54             :     private:
      55             :         // unique identifier of the list
      56             :         const OUString msListId;
      57             :         // default list style for the list items, identified by the list style name
      58             :         OUString msDefaultListStyleName;
      59             : 
      60             :         // list trees for certain document ranges
      61             :         typedef std::pair<SwNodeNum*, SwPaM*> tListTreeForRange;
      62             :         typedef std::vector<tListTreeForRange> tListTrees;
      63             :         tListTrees maListTrees;
      64             : 
      65             :         int mnMarkedListLevel;
      66             : 
      67             :         void NotifyItemsOnListLevel( const int nLevel );
      68             : };
      69             : 
      70       22589 : SwListImpl::SwListImpl( const OUString& sListId,
      71             :                         SwNumRule& rDefaultListStyle,
      72             :                         const SwNodes& rNodes )
      73             :     : msListId( sListId ),
      74             :       msDefaultListStyleName( rDefaultListStyle.GetName() ),
      75             :       maListTrees(),
      76       22589 :       mnMarkedListLevel( MAXLEVEL )
      77             : {
      78             :     // create empty list trees for the document ranges
      79       22589 :     const SwNode* pNode = rNodes[0];
      80      112945 :     do
      81             :     {
      82      112945 :         SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
      83             : 
      84      112945 :         SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
      85      112945 :         SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
      86      112945 :         tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
      87      112945 :         maListTrees.push_back( aListTreeForRange );
      88             : 
      89      112945 :         pNode = pNode->EndOfSectionNode();
      90      112945 :         if (pNode != &rNodes.GetEndOfContent())
      91             :         {
      92       90356 :             sal_uLong nIndex = pNode->GetIndex();
      93       90356 :             nIndex++;
      94       90356 :             pNode = rNodes[nIndex];
      95      112945 :         }
      96             :     }
      97      112945 :     while ( pNode != &rNodes.GetEndOfContent() );
      98       22589 : }
      99             : 
     100       45160 : SwListImpl::~SwListImpl()
     101             : {
     102       22580 :     tListTrees::iterator aNumberTreeIter;
     103      406440 :     for ( aNumberTreeIter = maListTrees.begin();
     104      270960 :           aNumberTreeIter != maListTrees.end();
     105             :           ++aNumberTreeIter )
     106             :     {
     107      112900 :         SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
     108      112900 :         delete (*aNumberTreeIter).first;
     109      112900 :         delete (*aNumberTreeIter).second;
     110             :     }
     111       22580 : }
     112             : 
     113             : 
     114             : 
     115        5620 : void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
     116             :                                  const int nLevel )
     117             : {
     118        5620 :     const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
     119        5620 :     const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
     120             : 
     121        5620 :     tListTrees::const_iterator aNumberTreeIter;
     122       84165 :     for ( aNumberTreeIter = maListTrees.begin();
     123       56110 :           aNumberTreeIter != maListTrees.end();
     124             :           ++aNumberTreeIter )
     125             :     {
     126       28055 :         const SwPosition* pStart = (*aNumberTreeIter).second->Start();
     127       28055 :         const SwPosition* pEnd = (*aNumberTreeIter).second->End();
     128       28055 :         const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
     129             : 
     130       56110 :         if ( pRangeNodes == pNodesOfNodeNum &&
     131       56110 :              *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
     132             :         {
     133        5620 :             (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
     134             : 
     135        5620 :             break;
     136             :         }
     137        5620 :     }
     138        5620 : }
     139             : 
     140        5620 : void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
     141             : {
     142        5620 :     rNodeNum.RemoveMe();
     143        5620 : }
     144             : 
     145         352 : void SwListImpl::InvalidateListTree()
     146             : {
     147         352 :     tListTrees::iterator aNumberTreeIter;
     148        6336 :     for ( aNumberTreeIter = maListTrees.begin();
     149        4224 :           aNumberTreeIter != maListTrees.end();
     150             :           ++aNumberTreeIter )
     151             :     {
     152        1760 :         (*aNumberTreeIter).first->InvalidateTree();
     153             :     }
     154         352 : }
     155             : 
     156         263 : void SwListImpl::ValidateListTree()
     157             : {
     158         263 :     tListTrees::iterator aNumberTreeIter;
     159        4734 :     for ( aNumberTreeIter = maListTrees.begin();
     160        3156 :           aNumberTreeIter != maListTrees.end();
     161             :           ++aNumberTreeIter )
     162             :     {
     163        1315 :         (*aNumberTreeIter).first->NotifyInvalidChildren();
     164             :     }
     165         263 : }
     166             : 
     167           0 : void SwListImpl::MarkListLevel( const int nListLevel,
     168             :                                 const bool bValue )
     169             : {
     170           0 :     if ( bValue )
     171             :     {
     172           0 :         if ( nListLevel != mnMarkedListLevel )
     173             :         {
     174           0 :             if ( mnMarkedListLevel != MAXLEVEL )
     175             :             {
     176             :                 // notify former marked list nodes
     177           0 :                 NotifyItemsOnListLevel( mnMarkedListLevel );
     178             :             }
     179             : 
     180           0 :             mnMarkedListLevel = nListLevel;
     181             : 
     182             :             // notify new marked list nodes
     183           0 :             NotifyItemsOnListLevel( mnMarkedListLevel );
     184             :         }
     185             :     }
     186             :     else
     187             :     {
     188           0 :         if ( mnMarkedListLevel != MAXLEVEL )
     189             :         {
     190             :             // notify former marked list nodes
     191           0 :             NotifyItemsOnListLevel( mnMarkedListLevel );
     192             :         }
     193             : 
     194           0 :         mnMarkedListLevel = MAXLEVEL;
     195             :     }
     196           0 : }
     197             : 
     198         621 : bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
     199             : {
     200         621 :     return nListLevel == mnMarkedListLevel;
     201             : }
     202             : 
     203           0 : void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
     204             : {
     205           0 :     tListTrees::iterator aNumberTreeIter;
     206           0 :     for ( aNumberTreeIter = maListTrees.begin();
     207           0 :           aNumberTreeIter != maListTrees.end();
     208             :           ++aNumberTreeIter )
     209             :     {
     210           0 :         (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
     211             :     }
     212           0 : }
     213             : 
     214       22589 : SwList::SwList( const OUString& sListId,
     215             :                 SwNumRule& rDefaultListStyle,
     216             :                 const SwNodes& rNodes )
     217       22589 :     : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
     218             : {
     219       22589 : }
     220             : 
     221       22580 : SwList::~SwList()
     222             : {
     223       22580 :     delete mpListImpl;
     224       22580 : }
     225             : 
     226       22615 : const OUString SwList::GetListId() const
     227             : {
     228       22615 :     return mpListImpl->GetListId();
     229             : }
     230             : 
     231        2914 : const OUString SwList::GetDefaultListStyleName() const
     232             : {
     233        2914 :     return mpListImpl->GetDefaultListStyleName();
     234             : }
     235             : 
     236        5620 : void SwList::InsertListItem( SwNodeNum& rNodeNum,
     237             :                              const int nLevel )
     238             : {
     239        5620 :     mpListImpl->InsertListItem( rNodeNum, nLevel );
     240        5620 : }
     241             : 
     242        5620 : void SwList::RemoveListItem( SwNodeNum& rNodeNum )
     243             : {
     244        5620 :     SwListImpl::RemoveListItem( rNodeNum );
     245        5620 : }
     246             : 
     247         352 : void SwList::InvalidateListTree()
     248             : {
     249         352 :     mpListImpl->InvalidateListTree();
     250         352 : }
     251             : 
     252         263 : void SwList::ValidateListTree()
     253             : {
     254         263 :     mpListImpl->ValidateListTree();
     255         263 : }
     256             : 
     257           0 : void SwList::MarkListLevel( const int nListLevel,
     258             :                                   const bool bValue )
     259             : {
     260           0 :     mpListImpl->MarkListLevel( nListLevel, bValue );
     261           0 : }
     262             : 
     263         621 : bool SwList::IsListLevelMarked( const int nListLevel ) const
     264             : {
     265         621 :     return mpListImpl->IsListLevelMarked( nListLevel );
     266         177 : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11