LCOV - code coverage report
Current view: top level - editeng/source/outliner - paralist.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 127 0.0 %
Date: 2014-04-14 Functions: 0 23 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             : 
      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           0 : ParagraphData::ParagraphData()
      30             : : nDepth( -1 )
      31             : , mnNumberingStartValue( -1 )
      32           0 : , mbParaIsNumberingRestart( false )
      33             : {
      34           0 : }
      35             : 
      36           0 : ParagraphData::ParagraphData( const ParagraphData& r )
      37             : : nDepth( r.nDepth )
      38             : , mnNumberingStartValue( r.mnNumberingStartValue )
      39           0 : , mbParaIsNumberingRestart( r.mbParaIsNumberingRestart )
      40             : {
      41           0 : }
      42             : 
      43           0 : ParagraphData& ParagraphData::operator=( const ParagraphData& r)
      44             : {
      45           0 :     nDepth = r.nDepth;
      46           0 :     mnNumberingStartValue = r.mnNumberingStartValue;
      47           0 :     mbParaIsNumberingRestart = r.mbParaIsNumberingRestart;
      48           0 :     return *this;
      49             : }
      50             : 
      51           0 : bool ParagraphData::operator==(const ParagraphData& rCandidate) const
      52             : {
      53           0 :     return (nDepth == rCandidate.nDepth
      54           0 :         && mnNumberingStartValue == rCandidate.mnNumberingStartValue
      55           0 :         && mbParaIsNumberingRestart == rCandidate.mbParaIsNumberingRestart);
      56             : }
      57             : 
      58           0 : Paragraph::Paragraph( sal_Int16 nDDepth )
      59           0 : : aBulSize( -1, -1)
      60             : {
      61             : 
      62             :     DBG_ASSERT(  ( nDDepth >= -1 ) && ( nDDepth < SVX_MAX_NUM ), "Paragraph-CTOR: nDepth invalid!" );
      63             : 
      64           0 :     nDepth = nDDepth;
      65           0 :     nFlags = 0;
      66           0 :     bVisible = true;
      67           0 : }
      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           0 : Paragraph::Paragraph( const ParagraphData& rData )
      81             : : nFlags( 0 )
      82             : , aBulSize( -1, -1)
      83           0 : , bVisible( true )
      84             : {
      85           0 :     nDepth = rData.nDepth;
      86           0 :     mnNumberingStartValue = rData.mnNumberingStartValue;
      87           0 :     mbParaIsNumberingRestart = rData.mbParaIsNumberingRestart;
      88           0 : }
      89             : 
      90           0 : Paragraph::~Paragraph()
      91             : {
      92           0 : }
      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           0 : void Paragraph::SetParaIsNumberingRestart( bool bParaIsNumberingRestart )
     102             : {
     103           0 :     mbParaIsNumberingRestart = bParaIsNumberingRestart;
     104           0 :     if( !mbParaIsNumberingRestart )
     105           0 :         mnNumberingStartValue = -1;
     106           0 : }
     107             : 
     108           0 : void ParagraphList::Clear( sal_Bool bDestroyParagraphs )
     109             : {
     110           0 :     if ( bDestroyParagraphs )
     111             :     {
     112           0 :         std::vector<Paragraph*>::iterator iter;
     113           0 :         for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
     114           0 :             delete *iter;
     115             :     }
     116             : 
     117           0 :     maEntries.clear();
     118           0 : }
     119             : 
     120           0 : void ParagraphList::Append( Paragraph* pPara)
     121             : {
     122             :     SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Append - overflow");
     123           0 :     maEntries.push_back(pPara);
     124           0 : }
     125             : 
     126           0 : 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           0 :     if (nAbsPos < 0 || maEntries.size() <= static_cast<size_t>(nAbsPos))
     133           0 :         Append( pPara);
     134             :     else
     135           0 :         maEntries.insert(maEntries.begin()+nAbsPos,pPara);
     136           0 : }
     137             : 
     138           0 : void ParagraphList::Remove( sal_Int32 nPara )
     139             : {
     140           0 :     if (nPara < 0 || maEntries.size() <= static_cast<size_t>(nPara))
     141             :     {
     142             :         SAL_WARN( "editeng", "ParagraphList::Remove - out of bounds " << nPara);
     143           0 :         return;
     144             :     }
     145             : 
     146           0 :     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           0 : sal_Bool ParagraphList::HasChildren( Paragraph* pParagraph ) const
     177             : {
     178           0 :     sal_Int32 n = GetAbsPos( pParagraph );
     179           0 :     Paragraph* pNext = GetParagraph( ++n );
     180           0 :     return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
     181             : }
     182             : 
     183           0 : sal_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           0 : sal_Bool ParagraphList::HasVisibleChildren( Paragraph* pParagraph ) const
     191             : {
     192           0 :     sal_Int32 n = GetAbsPos( pParagraph );
     193           0 :     Paragraph* pNext = GetParagraph( ++n );
     194           0 :     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           0 : sal_Int32 ParagraphList::GetAbsPos( Paragraph* pParent ) const
     258             : {
     259           0 :     sal_Int32 pos = 0;
     260           0 :     std::vector<Paragraph*>::const_iterator iter;
     261           0 :     for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++pos)
     262             :     {
     263           0 :         if (*iter == pParent)
     264           0 :             return pos;
     265             :     }
     266             : 
     267           0 :     return EE_PARA_NOT_FOUND;
     268             : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10