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

Generated by: LCOV version 1.10