LCOV - code coverage report
Current view: top level - editeng/source/outliner - paralist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 68 122 55.7 %
Date: 2012-08-25 Functions: 16 23 69.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 27 92 29.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <paralist.hxx>
      31                 :            : 
      32                 :            : #include <editeng/outliner.hxx>  // only because of Paragraph, this must be changed!
      33                 :            : #include <editeng/numdef.hxx>
      34                 :            : 
      35                 :            : #include <osl/diagnose.h>
      36                 :            : #include <tools/debug.hxx>
      37                 :            : 
      38                 :            : DBG_NAME(Paragraph)
      39                 :            : 
      40                 :     354248 : ParagraphData::ParagraphData()
      41                 :            : : nDepth( -1 )
      42                 :            : , mnNumberingStartValue( -1 )
      43                 :     354248 : , mbParaIsNumberingRestart( sal_False )
      44                 :            : {
      45                 :     354248 : }
      46                 :            : 
      47                 :      58755 : ParagraphData::ParagraphData( const ParagraphData& r )
      48                 :            : : nDepth( r.nDepth )
      49                 :            : , mnNumberingStartValue( r.mnNumberingStartValue )
      50                 :      58755 : , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
      51                 :            : {
      52                 :      58755 : }
      53                 :            : 
      54                 :      58754 : ParagraphData& ParagraphData::operator=( const ParagraphData& r)
      55                 :            : {
      56                 :      58754 :     nDepth = r.nDepth;
      57                 :      58754 :     mnNumberingStartValue = r.mnNumberingStartValue;
      58                 :      58754 :     mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
      59                 :      58754 :     return *this;
      60                 :            : }
      61                 :            : 
      62                 :        810 : bool ParagraphData::operator==(const ParagraphData& rCandidate) const
      63                 :            : {
      64                 :            :     return (nDepth == rCandidate.nDepth
      65                 :            :         && mnNumberingStartValue == rCandidate.mnNumberingStartValue
      66 [ +  - ][ +  + ]:        810 :         && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
                 [ +  + ]
      67                 :            : }
      68                 :            : 
      69                 :     159297 : Paragraph::Paragraph( sal_Int16 nDDepth )
      70                 :     159297 : : aBulSize( -1, -1)
      71                 :            : {
      72                 :            :     DBG_CTOR( Paragraph, 0 );
      73                 :            : 
      74                 :            :     DBG_ASSERT(  ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
      75                 :            : 
      76                 :     159297 :     nDepth = nDDepth;
      77                 :     159297 :     nFlags = 0;
      78                 :     159297 :     bVisible = sal_True;
      79                 :     159297 : }
      80                 :            : 
      81                 :          0 : Paragraph::Paragraph( const Paragraph& rPara )
      82                 :            : : ParagraphData( rPara )
      83                 :            : , aBulText( rPara.aBulText )
      84                 :          0 : , aBulSize( rPara.aBulSize )
      85                 :            : {
      86                 :            :     DBG_CTOR( Paragraph, 0 );
      87                 :            : 
      88                 :          0 :     nDepth = rPara.nDepth;
      89                 :          0 :     nFlags = rPara.nFlags;
      90                 :          0 :     bVisible = rPara.bVisible;
      91                 :          0 : }
      92                 :            : 
      93                 :     136014 : Paragraph::Paragraph( const ParagraphData& rData )
      94                 :            : : nFlags( 0 )
      95                 :            : , aBulSize( -1, -1)
      96                 :     136014 : , bVisible( sal_True )
      97                 :            : {
      98                 :            :     DBG_CTOR( Paragraph, 0 );
      99                 :            : 
     100                 :     136014 :     nDepth = rData.nDepth;
     101                 :     136014 :     mnNumberingStartValue = rData.mnNumberingStartValue;
     102                 :     136014 :     mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
     103                 :     136014 : }
     104                 :            : 
     105                 :     295086 : Paragraph::~Paragraph()
     106                 :            : {
     107                 :            :     DBG_DTOR( Paragraph, 0 );
     108                 :     295086 : }
     109                 :            : 
     110                 :          8 : void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue )
     111                 :            : {
     112                 :          8 :     mnNumberingStartValue = nNumberingStartValue;
     113         [ +  - ]:          8 :     if( mnNumberingStartValue != -1 )
     114                 :          8 :         mbParaIsNumberingRestart = true;
     115                 :          8 : }
     116                 :            : 
     117                 :          8 : void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart )
     118                 :            : {
     119                 :          8 :     mbParaIsNumberingRestart = bParaIsNumberingRestart;
     120         [ +  + ]:          8 :     if( !mbParaIsNumberingRestart )
     121                 :          4 :         mnNumberingStartValue = -1;
     122                 :          8 : }
     123                 :            : 
     124                 :     284472 : void ParagraphList::Clear( sal_Bool bDestroyParagraphs )
     125                 :            : {
     126         [ +  - ]:     284472 :     if ( bDestroyParagraphs )
     127                 :            :     {
     128                 :     284472 :         std::vector<Paragraph*>::iterator iter;
     129 [ +  - ][ +  + ]:     579231 :         for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
     130         [ +  - ]:     294759 :             delete *iter;
     131                 :            :     }
     132                 :            : 
     133                 :     284472 :     maEntries.clear();
     134                 :     284472 : }
     135                 :            : 
     136                 :     294090 : void ParagraphList::Append( Paragraph* pPara)
     137                 :            : {
     138                 :     294090 :     maEntries.push_back(pPara);
     139                 :     294090 : }
     140                 :            : 
     141                 :       1221 : void ParagraphList::Insert( Paragraph* pPara, sal_uLong nAbsPos)
     142                 :            : {
     143                 :            :     OSL_ASSERT(nAbsPos != ULONG_MAX && nAbsPos <= maEntries.size());
     144                 :            : 
     145 [ +  - ][ +  - ]:       1221 :     maEntries.insert(maEntries.begin()+nAbsPos,pPara);
     146                 :       1221 : }
     147                 :            : 
     148                 :        327 : void ParagraphList::Remove( sal_uLong nPara )
     149                 :            : {
     150                 :            :     OSL_ASSERT(nPara < maEntries.size());
     151                 :            : 
     152 [ +  - ][ +  - ]:        327 :     maEntries.erase(maEntries.begin() + nPara );
     153                 :        327 : }
     154                 :            : 
     155                 :          0 : void ParagraphList::MoveParagraphs( sal_uLong nStart, sal_uLong nDest, sal_uLong _nCount )
     156                 :            : {
     157                 :            :     OSL_ASSERT(nStart < maEntries.size() && nDest < maEntries.size());
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :     if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
     160                 :            :     {
     161         [ #  # ]:          0 :         std::vector<Paragraph*> aParas;
     162         [ #  # ]:          0 :         std::vector<Paragraph*>::iterator iterBeg = maEntries.begin() + nStart;
     163         [ #  # ]:          0 :         std::vector<Paragraph*>::iterator iterEnd = iterBeg + _nCount;
     164                 :            : 
     165 [ #  # ][ #  # ]:          0 :         std::copy(iterBeg,iterEnd,std::back_inserter(aParas));
     166                 :            : 
     167         [ #  # ]:          0 :         maEntries.erase(iterBeg,iterEnd);
     168                 :            : 
     169         [ #  # ]:          0 :         if ( nDest > nStart )
     170                 :          0 :             nDest -= _nCount;
     171                 :            : 
     172         [ #  # ]:          0 :         std::vector<Paragraph*>::iterator iterIns = maEntries.begin() + nDest;
     173                 :            : 
     174 [ #  # ][ #  # ]:          0 :         std::copy(aParas.begin(),aParas.end(),std::inserter(maEntries,iterIns));
     175                 :            :     }
     176                 :            :     else
     177                 :            :     {
     178                 :            :         OSL_FAIL( "MoveParagraphs: Invalid Parameters" );
     179                 :            :     }
     180                 :          0 : }
     181                 :            : 
     182                 :        420 : sal_Bool ParagraphList::HasChildren( Paragraph* pParagraph ) const
     183                 :            : {
     184                 :        420 :     sal_uLong n = GetAbsPos( pParagraph );
     185                 :        420 :     Paragraph* pNext = GetParagraph( ++n );
     186 [ +  - ][ +  + ]:        420 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
     187                 :            : }
     188                 :            : 
     189                 :          0 : sal_Bool ParagraphList::HasHiddenChildren( Paragraph* pParagraph ) const
     190                 :            : {
     191                 :          0 :     sal_uLong n = GetAbsPos( pParagraph );
     192                 :          0 :     Paragraph* pNext = GetParagraph( ++n );
     193 [ #  # ][ #  # ]:          0 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? sal_True : sal_False;
                 [ #  # ]
     194                 :            : }
     195                 :            : 
     196                 :        360 : sal_Bool ParagraphList::HasVisibleChildren( Paragraph* pParagraph ) const
     197                 :            : {
     198                 :        360 :     sal_uLong n = GetAbsPos( pParagraph );
     199                 :        360 :     Paragraph* pNext = GetParagraph( ++n );
     200 [ +  - ][ +  - ]:        360 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? sal_True : sal_False;
                 [ +  - ]
     201                 :            : }
     202                 :            : 
     203                 :          0 : sal_uLong ParagraphList::GetChildCount( Paragraph* pParent ) const
     204                 :            : {
     205                 :          0 :     sal_uLong nChildCount = 0;
     206                 :          0 :     sal_uLong n = GetAbsPos( pParent );
     207                 :          0 :     Paragraph* pPara = GetParagraph( ++n );
     208 [ #  # ][ #  # ]:          0 :     while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
                 [ #  # ]
     209                 :            :     {
     210                 :          0 :         nChildCount++;
     211                 :          0 :         pPara = GetParagraph( ++n );
     212                 :            :     }
     213                 :          0 :     return nChildCount;
     214                 :            : }
     215                 :            : 
     216                 :          0 : Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, sal_uInt16& rRelPos */ ) const
     217                 :            : {
     218                 :            :     /* rRelPos = 0 */;
     219                 :          0 :     sal_uLong n = GetAbsPos( pParagraph );
     220                 :          0 :     Paragraph* pPrev = GetParagraph( --n );
     221 [ #  # ][ #  # ]:          0 :     while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
                 [ #  # ]
     222                 :            :     {
     223                 :            : //      if ( pPrev->GetDepth() == pParagraph->GetDepth() )
     224                 :            : //          rRelPos++;
     225                 :          0 :         pPrev = GetParagraph( --n );
     226                 :            :     }
     227                 :            : 
     228                 :          0 :     return pPrev;
     229                 :            : }
     230                 :            : 
     231                 :          0 : void ParagraphList::Expand( Paragraph* pParent )
     232                 :            : {
     233                 :          0 :     sal_uLong nChildCount = GetChildCount( pParent );
     234                 :          0 :     sal_uLong nPos = GetAbsPos( pParent );
     235                 :            : 
     236         [ #  # ]:          0 :     for ( sal_uLong n = 1; n <= nChildCount; n++  )
     237                 :            :     {
     238                 :          0 :         Paragraph* pPara = GetParagraph( nPos+n );
     239         [ #  # ]:          0 :         if ( !( pPara->IsVisible() ) )
     240                 :            :         {
     241                 :          0 :             pPara->bVisible = sal_True;
     242                 :          0 :             aVisibleStateChangedHdl.Call( pPara );
     243                 :            :         }
     244                 :            :     }
     245                 :          0 : }
     246                 :            : 
     247                 :          0 : void ParagraphList::Collapse( Paragraph* pParent )
     248                 :            : {
     249                 :          0 :     sal_uLong nChildCount = GetChildCount( pParent );
     250                 :          0 :     sal_uLong nPos = GetAbsPos( pParent );
     251                 :            : 
     252         [ #  # ]:          0 :     for ( sal_uLong n = 1; n <= nChildCount; n++  )
     253                 :            :     {
     254                 :          0 :         Paragraph* pPara = GetParagraph( nPos+n );
     255         [ #  # ]:          0 :         if ( pPara->IsVisible() )
     256                 :            :         {
     257                 :          0 :             pPara->bVisible = sal_False;
     258                 :          0 :             aVisibleStateChangedHdl.Call( pPara );
     259                 :            :         }
     260                 :            :     }
     261                 :          0 : }
     262                 :            : 
     263                 :      47780 : sal_uLong ParagraphList::GetAbsPos( Paragraph* pParent ) const
     264                 :            : {
     265                 :      47780 :     sal_uLong pos = 0;
     266                 :      47780 :     std::vector<Paragraph*>::const_iterator iter;
     267 [ +  - ][ +  - ]:      50294 :     for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++pos)
     268                 :            :     {
     269         [ +  + ]:      50294 :         if (*iter == pParent)
     270                 :      47780 :             return pos;
     271                 :            :     }
     272                 :            : 
     273                 :      47780 :     return ~0;
     274                 :            : }
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10