LCOV - code coverage report
Current view: top level - sw/source/core/doc - list.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 105 0.0 %
Date: 2014-04-14 Functions: 0 21 0.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             :         const OUString GetListId() const;
      39             : 
      40             :         const OUString GetDefaultListStyleName() const;
      41             : 
      42             :         void InsertListItem( SwNodeNum& rNodeNum,
      43             :                              const int nLevel );
      44             :         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           0 : SwListImpl::SwListImpl( const OUString& sListId,
      71             :                         SwNumRule& rDefaultListStyle,
      72             :                         const SwNodes& rNodes )
      73             :     : msListId( sListId ),
      74             :       msDefaultListStyleName( rDefaultListStyle.GetName() ),
      75             :       maListTrees(),
      76           0 :       mnMarkedListLevel( MAXLEVEL )
      77             : {
      78             :     // create empty list trees for the document ranges
      79           0 :     const SwNode* pNode = rNodes[0];
      80           0 :     do
      81             :     {
      82           0 :         SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
      83             : 
      84           0 :         SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
      85           0 :         SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
      86           0 :         tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
      87           0 :         maListTrees.push_back( aListTreeForRange );
      88             : 
      89           0 :         pNode = pNode->EndOfSectionNode();
      90           0 :         if (pNode != &rNodes.GetEndOfContent())
      91             :         {
      92           0 :             sal_uLong nIndex = pNode->GetIndex();
      93           0 :             nIndex++;
      94           0 :             pNode = rNodes[nIndex];
      95           0 :         }
      96             :     }
      97           0 :     while ( pNode != &rNodes.GetEndOfContent() );
      98           0 : }
      99             : 
     100           0 : SwListImpl::~SwListImpl()
     101             : {
     102           0 :     tListTrees::iterator aNumberTreeIter;
     103           0 :     for ( aNumberTreeIter = maListTrees.begin();
     104           0 :           aNumberTreeIter != maListTrees.end();
     105             :           ++aNumberTreeIter )
     106             :     {
     107           0 :         SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
     108           0 :         delete (*aNumberTreeIter).first;
     109           0 :         delete (*aNumberTreeIter).second;
     110             :     }
     111           0 : }
     112             : 
     113           0 : const OUString SwListImpl::GetListId() const
     114             : {
     115           0 :     return msListId;
     116             : }
     117             : 
     118           0 : const OUString SwListImpl::GetDefaultListStyleName() const
     119             : {
     120           0 :     return msDefaultListStyleName;
     121             : }
     122             : 
     123           0 : void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
     124             :                                  const int nLevel )
     125             : {
     126           0 :     const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
     127           0 :     const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
     128             : 
     129           0 :     tListTrees::const_iterator aNumberTreeIter;
     130           0 :     for ( aNumberTreeIter = maListTrees.begin();
     131           0 :           aNumberTreeIter != maListTrees.end();
     132             :           ++aNumberTreeIter )
     133             :     {
     134           0 :         const SwPosition* pStart = (*aNumberTreeIter).second->Start();
     135           0 :         const SwPosition* pEnd = (*aNumberTreeIter).second->End();
     136           0 :         const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
     137             : 
     138           0 :         if ( pRangeNodes == pNodesOfNodeNum &&
     139           0 :              *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
     140             :         {
     141           0 :             (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
     142             : 
     143           0 :             break;
     144             :         }
     145           0 :     }
     146           0 : }
     147             : 
     148           0 : void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
     149             : {
     150           0 :     rNodeNum.RemoveMe();
     151           0 : }
     152             : 
     153           0 : void SwListImpl::InvalidateListTree()
     154             : {
     155           0 :     tListTrees::iterator aNumberTreeIter;
     156           0 :     for ( aNumberTreeIter = maListTrees.begin();
     157           0 :           aNumberTreeIter != maListTrees.end();
     158             :           ++aNumberTreeIter )
     159             :     {
     160           0 :         (*aNumberTreeIter).first->InvalidateTree();
     161             :     }
     162           0 : }
     163             : 
     164           0 : void SwListImpl::ValidateListTree()
     165             : {
     166           0 :     tListTrees::iterator aNumberTreeIter;
     167           0 :     for ( aNumberTreeIter = maListTrees.begin();
     168           0 :           aNumberTreeIter != maListTrees.end();
     169             :           ++aNumberTreeIter )
     170             :     {
     171           0 :         (*aNumberTreeIter).first->NotifyInvalidChildren();
     172             :     }
     173           0 : }
     174             : 
     175           0 : void SwListImpl::MarkListLevel( const int nListLevel,
     176             :                                 const bool bValue )
     177             : {
     178           0 :     if ( bValue )
     179             :     {
     180           0 :         if ( nListLevel != mnMarkedListLevel )
     181             :         {
     182           0 :             if ( mnMarkedListLevel != MAXLEVEL )
     183             :             {
     184             :                 // notify former marked list nodes
     185           0 :                 NotifyItemsOnListLevel( mnMarkedListLevel );
     186             :             }
     187             : 
     188           0 :             mnMarkedListLevel = nListLevel;
     189             : 
     190             :             // notify new marked list nodes
     191           0 :             NotifyItemsOnListLevel( mnMarkedListLevel );
     192             :         }
     193             :     }
     194             :     else
     195             :     {
     196           0 :         if ( mnMarkedListLevel != MAXLEVEL )
     197             :         {
     198             :             // notify former marked list nodes
     199           0 :             NotifyItemsOnListLevel( mnMarkedListLevel );
     200             :         }
     201             : 
     202           0 :         mnMarkedListLevel = MAXLEVEL;
     203             :     }
     204           0 : }
     205             : 
     206           0 : bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
     207             : {
     208           0 :     return nListLevel == mnMarkedListLevel;
     209             : }
     210             : 
     211           0 : void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
     212             : {
     213           0 :     tListTrees::iterator aNumberTreeIter;
     214           0 :     for ( aNumberTreeIter = maListTrees.begin();
     215           0 :           aNumberTreeIter != maListTrees.end();
     216             :           ++aNumberTreeIter )
     217             :     {
     218           0 :         (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
     219             :     }
     220           0 : }
     221             : 
     222             : // SwList ---------------------------------------------------------------------
     223           0 : SwList::SwList( const OUString& sListId,
     224             :                 SwNumRule& rDefaultListStyle,
     225             :                 const SwNodes& rNodes )
     226           0 :     : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
     227             : {
     228           0 : }
     229             : 
     230           0 : SwList::~SwList()
     231             : {
     232           0 :     delete mpListImpl;
     233           0 : }
     234             : 
     235           0 : const OUString SwList::GetListId() const
     236             : {
     237           0 :     return mpListImpl->GetListId();
     238             : }
     239             : 
     240           0 : const OUString SwList::GetDefaultListStyleName() const
     241             : {
     242           0 :     return mpListImpl->GetDefaultListStyleName();
     243             : }
     244             : 
     245           0 : void SwList::InsertListItem( SwNodeNum& rNodeNum,
     246             :                              const int nLevel )
     247             : {
     248           0 :     mpListImpl->InsertListItem( rNodeNum, nLevel );
     249           0 : }
     250             : 
     251           0 : void SwList::RemoveListItem( SwNodeNum& rNodeNum )
     252             : {
     253           0 :     mpListImpl->RemoveListItem( rNodeNum );
     254           0 : }
     255             : 
     256           0 : void SwList::InvalidateListTree()
     257             : {
     258           0 :     mpListImpl->InvalidateListTree();
     259           0 : }
     260             : 
     261           0 : void SwList::ValidateListTree()
     262             : {
     263           0 :     mpListImpl->ValidateListTree();
     264           0 : }
     265             : 
     266           0 : void SwList::MarkListLevel( const int nListLevel,
     267             :                                   const bool bValue )
     268             : {
     269           0 :     mpListImpl->MarkListLevel( nListLevel, bValue );
     270           0 : }
     271             : 
     272           0 : bool SwList::IsListLevelMarked( const int nListLevel ) const
     273             : {
     274           0 :     return mpListImpl->IsListLevelMarked( nListLevel );
     275             : }
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10