LCOV - code coverage report
Current view: top level - oox/source/helper - progressbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 52 80.8 %
Date: 2012-08-25 Functions: 15 21 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 28 35.7 %

           Branch data     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                 :            : #include "oox/helper/progressbar.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/task/XStatusIndicator.hpp>
      23                 :            : #include "oox/helper/helper.hxx"
      24                 :            : 
      25                 :            : namespace oox {
      26                 :            : 
      27                 :            : // ============================================================================
      28                 :            : 
      29                 :            : using namespace ::com::sun::star::task;
      30                 :            : using namespace ::com::sun::star::uno;
      31                 :            : 
      32                 :            : using ::rtl::OUString;
      33                 :            : 
      34                 :            : namespace {
      35                 :            : 
      36                 :            : const sal_Int32 PROGRESS_RANGE      = 1000000;
      37                 :            : 
      38                 :            : } // namespace
      39                 :            : 
      40                 :            : // ============================================================================
      41                 :            : 
      42                 :        460 : IProgressBar::~IProgressBar()
      43                 :            : {
      44         [ -  + ]:        460 : }
      45                 :            : 
      46                 :            : // ----------------------------------------------------------------------------
      47                 :            : 
      48                 :        420 : ISegmentProgressBar::~ISegmentProgressBar()
      49                 :            : {
      50         [ -  + ]:        420 : }
      51                 :            : 
      52                 :            : // ============================================================================
      53                 :            : // ============================================================================
      54                 :            : 
      55                 :         40 : ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
      56                 :            :     mxIndicator( rxIndicator ),
      57                 :         40 :     mfPosition( 0 )
      58                 :            : {
      59         [ -  + ]:         40 :     if( mxIndicator.is() )
      60 [ #  # ][ #  # ]:          0 :         mxIndicator->start( rText, PROGRESS_RANGE );
      61                 :         40 : }
      62                 :            : 
      63                 :         40 : ProgressBar::~ProgressBar()
      64                 :            : {
      65         [ -  + ]:         40 :     if( mxIndicator.is() )
      66 [ #  # ][ #  # ]:          0 :         mxIndicator->end();
      67         [ -  + ]:         40 : }
      68                 :            : 
      69                 :          0 : double ProgressBar::getPosition() const
      70                 :            : {
      71                 :          0 :     return mfPosition;
      72                 :            : }
      73                 :            : 
      74                 :       1205 : void ProgressBar::setPosition( double fPosition )
      75                 :            : {
      76                 :            :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" );
      77                 :       1205 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
      78         [ -  + ]:       1205 :     if( mxIndicator.is() )
      79                 :          0 :         mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
      80                 :       1205 : }
      81                 :            : 
      82                 :            : // ============================================================================
      83                 :            : 
      84                 :            : namespace prv {
      85                 :            : 
      86         [ -  + ]:        760 : class SubSegment : public ISegmentProgressBar
      87                 :            : {
      88                 :            : public:
      89                 :            :     explicit            SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
      90                 :            : 
      91                 :            :     virtual double      getPosition() const;
      92                 :            :     virtual void        setPosition( double fPosition );
      93                 :            : 
      94                 :            :     virtual double      getFreeLength() const;
      95                 :            :     virtual ISegmentProgressBarRef createSegment( double fLength );
      96                 :            : 
      97                 :            : private:
      98                 :            :     IProgressBar&       mrParentProgress;
      99                 :            :     double              mfStartPos;
     100                 :            :     double              mfLength;
     101                 :            :     double              mfPosition;
     102                 :            :     double              mfFreeStart;
     103                 :            : };
     104                 :            : 
     105                 :            : // ----------------------------------------------------------------------------
     106                 :            : 
     107                 :        380 : SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
     108                 :            :     mrParentProgress( rParentProgress ),
     109                 :            :     mfStartPos( fStartPos ),
     110                 :            :     mfLength( fLength ),
     111                 :            :     mfPosition( 0.0 ),
     112                 :        380 :     mfFreeStart( 0.0 )
     113                 :            : {
     114                 :        380 : }
     115                 :            : 
     116                 :        405 : double SubSegment::getPosition() const
     117                 :            : {
     118                 :        405 :     return mfPosition;
     119                 :            : }
     120                 :            : 
     121                 :       2110 : void SubSegment::setPosition( double fPosition )
     122                 :            : {
     123                 :            :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" );
     124                 :       2110 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
     125                 :       2110 :     mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
     126                 :       2110 : }
     127                 :            : 
     128                 :        200 : double SubSegment::getFreeLength() const
     129                 :            : {
     130                 :        200 :     return 1.0 - mfFreeStart;
     131                 :            : }
     132                 :            : 
     133                 :        200 : ISegmentProgressBarRef SubSegment::createSegment( double fLength )
     134                 :            : {
     135                 :            :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" );
     136                 :        200 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     137         [ +  - ]:        200 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
     138                 :        200 :     mfFreeStart += fLength;
     139                 :        200 :     return xSegment;
     140                 :            : }
     141                 :            : 
     142                 :            : } // namespace prv
     143                 :            : 
     144                 :            : // ============================================================================
     145                 :            : 
     146                 :         40 : SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
     147                 :            :     maProgress( rxIndicator, rText ),
     148         [ +  - ]:         40 :     mfFreeStart( 0.0 )
     149                 :            : {
     150                 :         40 : }
     151                 :            : 
     152                 :          0 : double SegmentProgressBar::getPosition() const
     153                 :            : {
     154                 :          0 :     return maProgress.getPosition();
     155                 :            : }
     156                 :            : 
     157                 :          0 : void SegmentProgressBar::setPosition( double fPosition )
     158                 :            : {
     159                 :          0 :     maProgress.setPosition( fPosition );
     160                 :          0 : }
     161                 :            : 
     162                 :        320 : double SegmentProgressBar::getFreeLength() const
     163                 :            : {
     164                 :        320 :     return 1.0 - mfFreeStart;
     165                 :            : }
     166                 :            : 
     167                 :        180 : ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
     168                 :            : {
     169                 :            :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
     170                 :        180 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     171         [ +  - ]:        180 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
     172                 :        180 :     mfFreeStart += fLength;
     173                 :        180 :     return xSegment;
     174                 :            : }
     175                 :            : 
     176                 :            : // ============================================================================
     177                 :            : 
     178                 :            : } // namespace oox
     179                 :            : 
     180                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10