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

Generated by: LCOV version 1.11