LCOV - code coverage report
Current view: top level - editeng/source/outliner - paralist.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 68 128 53.1 %
Date: 2014-11-03 Functions: 17 25 68.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 <paralist.hxx>
      22             : 
      23             : #include <editeng/outliner.hxx>
      24             : #include <editeng/numdef.hxx>
      25             : 
      26             : #include <osl/diagnose.h>
      27             : #include <tools/debug.hxx>
      28             : 
      29      503621 : ParagraphData::ParagraphData()
      30             : : nDepth( -1 )
      31             : , mnNumberingStartValue( -1 )
      32      503621 : , mbParaIsNumberingRestart( false )
      33             : {
      34      503621 : }
      35             : 
      36      237988 : ParagraphData::ParagraphData( const ParagraphData& r )
      37             : : nDepth( r.nDepth )
      38             : , mnNumberingStartValue( r.mnNumberingStartValue )
      39      237988 : , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
      40             : {
      41      237988 : }
      42             : 
      43      108263 : ParagraphData& ParagraphData::operator=( const ParagraphData& r)
      44             : {
      45      108263 :     nDepth = r.nDepth;
      46      108263 :     mnNumberingStartValue = r.mnNumberingStartValue;
      47      108263 :     mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
      48      108263 :     return *this;
      49             : }
      50             : 
      51        2153 : bool ParagraphData::operator==(const ParagraphData& rCandidate) const
      52             : {
      53        2153 :     return (nDepth == rCandidate.nDepth
      54        2153 :         && mnNumberingStartValue == rCandidate.mnNumberingStartValue
      55        4306 :         && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
      56             : }
      57             : 
      58      218151 : Paragraph::Paragraph( sal_Int16 nDDepth )
      59      218151 : : aBulSize( -1, -1)
      60             : {
      61             : 
      62             :     DBG_ASSERT(  ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
      63             : 
      64      218151 :     nDepth = nDDepth;
      65      218151 :     nFlags = 0;
      66      218151 :     bVisible = true;
      67      218151 : }
      68             : 
      69           0 : Paragraph::Paragraph( const Paragraph& rPara )
      70             : : ParagraphData( rPara )
      71             : , aBulText( rPara.aBulText )
      72           0 : , aBulSize( rPara.aBulSize )
      73             : {
      74             : 
      75           0 :     nDepth = rPara.nDepth;
      76           0 :     nFlags = rPara.nFlags;
      77           0 :     bVisible = rPara.bVisible;
      78           0 : }
      79             : 
      80      177007 : Paragraph::Paragraph( const ParagraphData& rData )
      81             : : nFlags( 0 )
      82             : , aBulSize( -1, -1)
      83      177007 : , bVisible( true )
      84             : {
      85      177007 :     nDepth = rData.nDepth;
      86      177007 :     mnNumberingStartValue = rData.mnNumberingStartValue;
      87      177007 :     mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
      88      177007 : }
      89             : 
      90      394790 : Paragraph::~Paragraph()
      91             : {
      92      394790 : }
      93             : 
      94           0 : void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue )
      95             : {
      96           0 :     mnNumberingStartValue = nNumberingStartValue;
      97           0 :     if( mnNumberingStartValue != -1 )
      98           0 :         mbParaIsNumberingRestart = true;
      99           0 : }
     100             : 
     101           8 : void Paragraph::SetParaIsNumberingRestart( bool bParaIsNumberingRestart )
     102             : {
     103           8 :     mbParaIsNumberingRestart = bParaIsNumberingRestart;
     104           8 :     if( !mbParaIsNumberingRestart )
     105           4 :         mnNumberingStartValue = -1;
     106           8 : }
     107             : 
     108      374041 : void ParagraphList::Clear( bool bDestroyParagraphs )
     109             : {
     110      374041 :     if ( bDestroyParagraphs )
     111             :     {
     112      374041 :         std::vector<Paragraph*>::iterator iter;
     113      766719 :         for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
     114      392678 :             delete *iter;
     115             :     }
     116             : 
     117      374041 :     maEntries.clear();
     118      374041 : }
     119             : 
     120      395156 : void ParagraphList::Append( Paragraph* pPara)
     121             : {
     122             :     SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Append - overflow");
     123      395156 :     maEntries.push_back(pPara);
     124      395156 : }
     125             : 
     126        7116 : void ParagraphList::Insert( Paragraph* pPara, sal_Int32 nAbsPos)
     127             : {
     128             :     SAL_WARN_IF( nAbsPos < 0 || (maEntries.size() < static_cast<size_t>(nAbsPos) && nAbsPos != EE_PARA_APPEND),
     129             :             "editeng", "ParagraphList::Insert - bad insert position " << nAbsPos);
     130             :     SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Insert - overflow");
     131             : 
     132        7116 :     if (nAbsPos < 0 || maEntries.size() <= static_cast<size_t>(nAbsPos))
     133        7114 :         Append( pPara);
     134             :     else
     135           2 :         maEntries.insert(maEntries.begin()+nAbsPos,pPara);
     136        7116 : }
     137             : 
     138        2112 : void ParagraphList::Remove( sal_Int32 nPara )
     139             : {
     140        2112 :     if (nPara < 0 || maEntries.size() <= static_cast<size_t>(nPara))
     141             :     {
     142             :         SAL_WARN( "editeng", "ParagraphList::Remove - out of bounds " << nPara);
     143        2112 :         return;
     144             :     }
     145             : 
     146        2112 :     maEntries.erase(maEntries.begin() + nPara );
     147             : }
     148             : 
     149           0 : void ParagraphList::MoveParagraphs( sal_Int32 nStart, sal_Int32 nDest, sal_Int32 _nCount )
     150             : {
     151             :     OSL_ASSERT(static_cast<size_t>(nStart) < maEntries.size() && static_cast<size_t>(nDest) < maEntries.size());
     152             : 
     153           0 :     if ( (( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) )) && nStart >= 0 && nDest >= 0 && _nCount >= 0 )
     154             :     {
     155           0 :         std::vector<Paragraph*> aParas;
     156           0 :         std::vector<Paragraph*>::iterator iterBeg = maEntries.begin() + nStart;
     157           0 :         std::vector<Paragraph*>::iterator iterEnd = iterBeg + _nCount;
     158             : 
     159           0 :         std::copy(iterBeg,iterEnd,std::back_inserter(aParas));
     160             : 
     161           0 :         maEntries.erase(iterBeg,iterEnd);
     162             : 
     163           0 :         if ( nDest > nStart )
     164           0 :             nDest -= _nCount;
     165             : 
     166           0 :         std::vector<Paragraph*>::iterator iterIns = maEntries.begin() + nDest;
     167             : 
     168           0 :         std::copy(aParas.begin(),aParas.end(),std::inserter(maEntries,iterIns));
     169             :     }
     170             :     else
     171             :     {
     172             :         OSL_FAIL( "MoveParagraphs: Invalid Parameters" );
     173             :     }
     174           0 : }
     175             : 
     176        1051 : bool ParagraphList::HasChildren( Paragraph* pParagraph ) const
     177             : {
     178        1051 :     sal_Int32 n = GetAbsPos( pParagraph );
     179        1051 :     Paragraph* pNext = GetParagraph( ++n );
     180        1051 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
     181             : }
     182             : 
     183           0 : bool ParagraphList::HasHiddenChildren( Paragraph* pParagraph ) const
     184             : {
     185           0 :     sal_Int32 n = GetAbsPos( pParagraph );
     186           0 :     Paragraph* pNext = GetParagraph( ++n );
     187           0 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? sal_True : sal_False;
     188             : }
     189             : 
     190         870 : bool ParagraphList::HasVisibleChildren( Paragraph* pParagraph ) const
     191             : {
     192         870 :     sal_Int32 n = GetAbsPos( pParagraph );
     193         870 :     Paragraph* pNext = GetParagraph( ++n );
     194         870 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? sal_True : sal_False;
     195             : }
     196             : 
     197           0 : sal_Int32 ParagraphList::GetChildCount( Paragraph* pParent ) const
     198             : {
     199           0 :     sal_Int32 nChildCount = 0;
     200           0 :     sal_Int32 n = GetAbsPos( pParent );
     201           0 :     Paragraph* pPara = GetParagraph( ++n );
     202           0 :     while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
     203             :     {
     204           0 :         nChildCount++;
     205           0 :         pPara = GetParagraph( ++n );
     206             :     }
     207           0 :     return nChildCount;
     208             : }
     209             : 
     210           0 : Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, sal_uInt16& rRelPos */ ) const
     211             : {
     212             :     /* rRelPos = 0 */;
     213           0 :     sal_Int32 n = GetAbsPos( pParagraph );
     214           0 :     Paragraph* pPrev = GetParagraph( --n );
     215           0 :     while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
     216             :     {
     217             : //      if ( pPrev->GetDepth() == pParagraph->GetDepth() )
     218             : //          rRelPos++;
     219           0 :         pPrev = GetParagraph( --n );
     220             :     }
     221             : 
     222           0 :     return pPrev;
     223             : }
     224             : 
     225           0 : void ParagraphList::Expand( Paragraph* pParent )
     226             : {
     227           0 :     sal_Int32 nChildCount = GetChildCount( pParent );
     228           0 :     sal_Int32 nPos = GetAbsPos( pParent );
     229             : 
     230           0 :     for ( sal_Int32 n = 1; n <= nChildCount; n++  )
     231             :     {
     232           0 :         Paragraph* pPara = GetParagraph( nPos+n );
     233           0 :         if ( !( pPara->IsVisible() ) )
     234             :         {
     235           0 :             pPara->bVisible = true;
     236           0 :             aVisibleStateChangedHdl.Call( pPara );
     237             :         }
     238             :     }
     239           0 : }
     240             : 
     241           0 : void ParagraphList::Collapse( Paragraph* pParent )
     242             : {
     243           0 :     sal_Int32 nChildCount = GetChildCount( pParent );
     244           0 :     sal_Int32 nPos = GetAbsPos( pParent );
     245             : 
     246           0 :     for ( sal_Int32 n = 1; n <= nChildCount; n++  )
     247             :     {
     248           0 :         Paragraph* pPara = GetParagraph( nPos+n );
     249           0 :         if ( pPara->IsVisible() )
     250             :         {
     251           0 :             pPara->bVisible = false;
     252           0 :             aVisibleStateChangedHdl.Call( pPara );
     253             :         }
     254             :     }
     255           0 : }
     256             : 
     257       54251 : sal_Int32 ParagraphList::GetAbsPos( Paragraph* pParent ) const
     258             : {
     259       54251 :     sal_Int32 pos = 0;
     260       54251 :     std::vector<Paragraph*>::const_iterator iter;
     261      118899 :     for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++pos)
     262             :     {
     263      118899 :         if (*iter == pParent)
     264       54251 :             return pos;
     265             :     }
     266             : 
     267           0 :     return EE_PARA_NOT_FOUND;
     268         669 : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10