LCOV - code coverage report
Current view: top level - sc/source/filter/ftools - fprogressbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 72 116 62.1 %
Date: 2012-08-25 Functions: 15 23 65.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 92 33.7 %

           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                 :            : #include "fprogressbar.hxx"
      30                 :            : #include "global.hxx"
      31                 :            : #include "progress.hxx"
      32                 :            : 
      33                 :            : // ============================================================================
      34                 :            : 
      35                 :        116 : ScfProgressBar::ScfProgressSegment::ScfProgressSegment( sal_Size nSize ) :
      36                 :            :     mxProgress( 0 ),
      37                 :            :     mnSize( nSize ),
      38                 :        116 :     mnPos( 0 )
      39                 :            : {
      40                 :        116 : }
      41                 :            : 
      42                 :        116 : ScfProgressBar::ScfProgressSegment::~ScfProgressSegment()
      43                 :            : {
      44                 :        116 : }
      45                 :            : 
      46                 :            : // ============================================================================
      47                 :            : 
      48                 :          0 : ScfProgressBar::ScfProgressBar( SfxObjectShell* pDocShell, const String& rText ) :
      49 [ #  # ][ #  # ]:          0 :     maText( rText )
      50                 :            : {
      51                 :          0 :     Init( pDocShell );
      52                 :          0 : }
      53                 :            : 
      54                 :        116 : ScfProgressBar::ScfProgressBar( SfxObjectShell* pDocShell, sal_uInt16 nResId ) :
      55 [ +  - ][ +  - ]:        116 :     maText( ScGlobal::GetRscString( nResId ) )
                 [ +  - ]
      56                 :            : {
      57                 :        116 :     Init( pDocShell );
      58                 :        116 : }
      59                 :            : 
      60 [ #  # ][ #  # ]:          0 : ScfProgressBar::ScfProgressBar( ScfProgressBar& rParProgress, ScfProgressSegment* pParSegment )
      61                 :            : {
      62                 :          0 :     Init( rParProgress.mpDocShell );
      63                 :          0 :     mpParentProgress = &rParProgress;
      64                 :          0 :     mpParentSegment = pParSegment;
      65                 :          0 : }
      66                 :            : 
      67 [ +  - ][ +  - ]:        116 : ScfProgressBar::~ScfProgressBar()
                 [ +  - ]
      68                 :            : {
      69         [ -  + ]:        143 : }
      70                 :            : 
      71                 :        116 : void ScfProgressBar::Init( SfxObjectShell* pDocShell )
      72                 :            : {
      73                 :        116 :     mpDocShell = pDocShell;
      74                 :        116 :     mpParentProgress = 0;
      75                 :        116 :     mpParentSegment = mpCurrSegment = 0;
      76                 :        116 :     mnTotalSize = mnTotalPos = mnUnitSize = mnNextUnitPos = 0;
      77                 :        116 :     mnSysProgressScale = 1;     // used to workaround the ULONG_MAX/100 limit
      78                 :        116 :     mbInProgress = false;
      79                 :        116 : }
      80                 :            : 
      81                 :        116 : ScfProgressBar::ScfProgressSegment* ScfProgressBar::GetSegment( sal_Int32 nSegment )
      82                 :            : {
      83         [ -  + ]:        116 :     if( nSegment < 0 )
      84                 :          0 :         return 0;
      85                 :        116 :     return &(maSegments.at( nSegment ));
      86                 :            : }
      87                 :            : 
      88                 :        116 : void ScfProgressBar::SetCurrSegment( ScfProgressSegment* pSegment )
      89                 :            : {
      90         [ +  - ]:        116 :     if( mpCurrSegment != pSegment )
      91                 :            :     {
      92                 :        116 :         mpCurrSegment = pSegment;
      93                 :            : 
      94 [ -  + ][ #  # ]:        116 :         if( mpParentProgress && mpParentSegment )
      95                 :            :         {
      96                 :          0 :             mpParentProgress->SetCurrSegment( mpParentSegment );
      97                 :            :         }
      98 [ +  - ][ +  - ]:        116 :         else if( !mxSysProgress.get() && (mnTotalSize > 0) )
                 [ +  - ]
      99                 :            :         {
     100                 :            :             // System progress has an internal limit of ULONG_MAX/100.
     101                 :        116 :             mnSysProgressScale = 1;
     102                 :        116 :             sal_uLong nSysTotalSize = static_cast< sal_uLong >( mnTotalSize );
     103         [ -  + ]:        116 :             while( nSysTotalSize >= ULONG_MAX / 100 )
     104                 :            :             {
     105                 :          0 :                 nSysTotalSize /= 2;
     106                 :          0 :                 mnSysProgressScale *= 2;
     107                 :            :             }
     108         [ +  - ]:        116 :             mxSysProgress.reset( new ScProgress( mpDocShell, maText, nSysTotalSize ) );
     109                 :            :         }
     110                 :            : 
     111 [ +  - ][ +  - ]:        116 :         if( !mbInProgress && mpCurrSegment && (mnTotalSize > 0) )
                 [ +  - ]
     112                 :            :         {
     113                 :        116 :             mnUnitSize = mnTotalSize / 256 + 1;   // at most 256 calls of system progress
     114                 :        116 :             mnNextUnitPos = 0;
     115                 :        116 :             mbInProgress = true;
     116                 :            :         }
     117                 :            :     }
     118                 :        116 : }
     119                 :            : 
     120                 :      36960 : void ScfProgressBar::IncreaseProgressBar( sal_Size nDelta )
     121                 :            : {
     122                 :      36960 :     sal_Size nNewPos = mnTotalPos + nDelta;
     123                 :            : 
     124                 :            :     // call back to parent progress bar
     125 [ -  + ][ #  # ]:      36960 :     if( mpParentProgress && mpParentSegment )
     126                 :            :     {
     127                 :            :         // calculate new position of parent progress bar
     128                 :            :         sal_Size nParentPos = static_cast< sal_Size >(
     129                 :          0 :             static_cast< double >( nNewPos ) * mpParentSegment->mnSize / mnTotalSize );
     130                 :          0 :         mpParentProgress->ProgressAbs( nParentPos );
     131                 :            :     }
     132                 :            :     // modify system progress bar
     133         [ +  - ]:      36960 :     else if( mxSysProgress.get() )
     134                 :            :     {
     135         [ +  + ]:      36960 :         if( nNewPos >= mnNextUnitPos )
     136                 :            :         {
     137                 :      10554 :             mnNextUnitPos = nNewPos + mnUnitSize;
     138                 :      10554 :             mxSysProgress->SetState( static_cast< sal_uLong >( nNewPos / mnSysProgressScale ) );
     139                 :            :         }
     140                 :            :     }
     141                 :            :     else
     142                 :            :     {
     143                 :            :         OSL_FAIL( "ScfProgressBar::IncreaseProgressBar - no progress bar found" );
     144                 :            :     }
     145                 :            : 
     146                 :      36960 :     mnTotalPos = nNewPos;
     147                 :      36960 : }
     148                 :            : 
     149                 :        116 : sal_Int32 ScfProgressBar::AddSegment( sal_Size nSize )
     150                 :            : {
     151                 :            :     OSL_ENSURE( !mbInProgress, "ScfProgressBar::AddSegment - already in progress mode" );
     152         [ -  + ]:        116 :     if( nSize == 0 )
     153                 :          0 :         return SCF_INV_SEGMENT;
     154                 :            : 
     155         [ +  - ]:        116 :     maSegments.push_back( new ScfProgressSegment( nSize ) );
     156                 :        116 :     mnTotalSize += nSize;
     157                 :        116 :     return static_cast< sal_Int32 >( maSegments.size() - 1 );
     158                 :            : }
     159                 :            : 
     160                 :          0 : ScfProgressBar& ScfProgressBar::GetSegmentProgressBar( sal_Int32 nSegment )
     161                 :            : {
     162                 :          0 :     ScfProgressSegment* pSegment = GetSegment( nSegment );
     163                 :            :     OSL_ENSURE( !pSegment || (pSegment->mnPos == 0), "ScfProgressBar::GetSegmentProgressBar - segment already started" );
     164 [ #  # ][ #  # ]:          0 :     if( pSegment && (pSegment->mnPos == 0) )
     165                 :            :     {
     166         [ #  # ]:          0 :         if( !pSegment->mxProgress.get() )
     167         [ #  # ]:          0 :             pSegment->mxProgress.reset( new ScfProgressBar( *this, pSegment ) );
     168                 :          0 :         return *pSegment->mxProgress;
     169                 :            :     }
     170                 :          0 :     return *this;
     171                 :            : }
     172                 :            : 
     173                 :          0 : bool ScfProgressBar::IsFull() const
     174                 :            : {
     175                 :            :     OSL_ENSURE( mbInProgress && mpCurrSegment, "ScfProgressBar::IsFull - no segment started" );
     176 [ #  # ][ #  # ]:          0 :     return mpCurrSegment && (mpCurrSegment->mnPos >= mpCurrSegment->mnSize);
     177                 :            : }
     178                 :            : 
     179                 :        116 : void ScfProgressBar::ActivateSegment( sal_Int32 nSegment )
     180                 :            : {
     181                 :            :     OSL_ENSURE( mnTotalSize > 0, "ScfProgressBar::ActivateSegment - progress range is zero" );
     182         [ +  - ]:        116 :     if( mnTotalSize > 0 )
     183                 :        116 :         SetCurrSegment( GetSegment( nSegment ) );
     184                 :        116 : }
     185                 :            : 
     186                 :      36960 : void ScfProgressBar::ProgressAbs( sal_Size nPos )
     187                 :            : {
     188                 :            :     OSL_ENSURE( mbInProgress && mpCurrSegment, "ScfProgressBar::ProgressAbs - no segment started" );
     189         [ +  - ]:      36960 :     if( mpCurrSegment )
     190                 :            :     {
     191                 :            :         OSL_ENSURE( mpCurrSegment->mnPos <= nPos, "ScfProgressBar::ProgressAbs - delta pos < 0" );
     192                 :            :         OSL_ENSURE( nPos <= mpCurrSegment->mnSize, "ScfProgressBar::ProgressAbs - segment overflow" );
     193 [ +  - ][ +  - ]:      36960 :         if( (mpCurrSegment->mnPos < nPos) && (nPos <= mpCurrSegment->mnSize) )
     194                 :            :         {
     195                 :      36960 :             IncreaseProgressBar( nPos - mpCurrSegment->mnPos );
     196                 :      36960 :             mpCurrSegment->mnPos = nPos;
     197                 :            :         }
     198                 :            :     }
     199                 :      36960 : }
     200                 :            : 
     201                 :        127 : void ScfProgressBar::Progress( sal_Size nDelta )
     202                 :            : {
     203         [ +  - ]:        127 :     ProgressAbs( mpCurrSegment ? (mpCurrSegment->mnPos + nDelta) : 0 );
     204                 :        127 : }
     205                 :            : 
     206                 :            : // ============================================================================
     207                 :            : 
     208                 :          0 : ScfSimpleProgressBar::ScfSimpleProgressBar( sal_Size nSize, SfxObjectShell* pDocShell, const String& rText ) :
     209                 :          0 :     maProgress( pDocShell, rText )
     210                 :            : {
     211         [ #  # ]:          0 :     Init( nSize );
     212                 :          0 : }
     213                 :            : 
     214                 :         89 : ScfSimpleProgressBar::ScfSimpleProgressBar( sal_Size nSize, SfxObjectShell* pDocShell, sal_uInt16 nResId ) :
     215                 :         89 :     maProgress( pDocShell, nResId )
     216                 :            : {
     217         [ +  - ]:         89 :     Init( nSize );
     218                 :         89 : }
     219                 :            : 
     220                 :         89 : void ScfSimpleProgressBar::Init( sal_Size nSize )
     221                 :            : {
     222                 :         89 :     sal_Int32 nSegment = maProgress.AddSegment( nSize );
     223         [ +  - ]:         89 :     if( nSegment >= 0 )
     224                 :         89 :         maProgress.ActivateSegment( nSegment );
     225                 :         89 : }
     226                 :            : 
     227                 :          0 : ScfStreamProgressBar::ScfStreamProgressBar( SvStream& rStrm, SfxObjectShell* pDocShell, sal_uInt16 nResId ) :
     228                 :          0 :     mrStrm( rStrm )
     229                 :            : {
     230 [ #  # ][ #  # ]:          0 :     Init( pDocShell, ScGlobal::GetRscString( nResId ) );
     231                 :          0 : }
     232                 :            : 
     233                 :          0 : void ScfStreamProgressBar::Progress()
     234                 :            : {
     235                 :          0 :     mxProgress->ProgressAbs( mrStrm.Tell() );
     236                 :          0 : }
     237                 :            : 
     238                 :          0 : void ScfStreamProgressBar::Init( SfxObjectShell* pDocShell, const String& rText )
     239                 :            : {
     240                 :          0 :     sal_Size nPos = mrStrm.Tell();
     241                 :          0 :     mrStrm.Seek( STREAM_SEEK_TO_END );
     242                 :          0 :     sal_Size nSize = mrStrm.Tell();
     243                 :          0 :     mrStrm.Seek( nPos );
     244                 :            : 
     245         [ #  # ]:          0 :     mxProgress.reset( new ScfSimpleProgressBar( nSize, pDocShell, rText ) );
     246                 :          0 :     Progress();
     247                 :          0 : }
     248                 :            : 
     249                 :            : // ============================================================================
     250                 :            : 
     251                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10