LCOV - code coverage report
Current view: top level - oox/source/helper - progressbar.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 52 82.7 %
Date: 2014-11-03 Functions: 14 21 66.7 %
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             : #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             : using namespace ::com::sun::star::task;
      28             : using namespace ::com::sun::star::uno;
      29             : 
      30             : namespace {
      31             : 
      32             : const sal_Int32 PROGRESS_RANGE      = 1000000;
      33             : 
      34             : } // namespace
      35             : 
      36        1552 : IProgressBar::~IProgressBar()
      37             : {
      38        1552 : }
      39             : 
      40        1424 : ISegmentProgressBar::~ISegmentProgressBar()
      41             : {
      42        1424 : }
      43             : 
      44         128 : ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
      45             :     mxIndicator( rxIndicator ),
      46         128 :     mfPosition( 0 )
      47             : {
      48         128 :     if( mxIndicator.is() )
      49          30 :         mxIndicator->start( rText, PROGRESS_RANGE );
      50         128 : }
      51             : 
      52         256 : ProgressBar::~ProgressBar()
      53             : {
      54         128 :     if( mxIndicator.is() )
      55          30 :         mxIndicator->end();
      56         128 : }
      57             : 
      58           0 : double ProgressBar::getPosition() const
      59             : {
      60           0 :     return mfPosition;
      61             : }
      62             : 
      63        1420 : void ProgressBar::setPosition( double fPosition )
      64             : {
      65             :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" );
      66        1420 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
      67        1420 :     if( mxIndicator.is() )
      68         294 :         mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
      69        1420 : }
      70             : 
      71             : namespace prv {
      72             : 
      73        2072 : class SubSegment : public ISegmentProgressBar
      74             : {
      75             : public:
      76             :     explicit            SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
      77             : 
      78             :     virtual double      getPosition() const SAL_OVERRIDE;
      79             :     virtual void        setPosition( double fPosition ) SAL_OVERRIDE;
      80             : 
      81             :     virtual double      getFreeLength() const SAL_OVERRIDE;
      82             :     virtual ISegmentProgressBarRef createSegment( double fLength ) SAL_OVERRIDE;
      83             : 
      84             : private:
      85             :     IProgressBar&       mrParentProgress;
      86             :     double              mfStartPos;
      87             :     double              mfLength;
      88             :     double              mfPosition;
      89             :     double              mfFreeStart;
      90             : };
      91             : 
      92        1036 : SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
      93             :     mrParentProgress( rParentProgress ),
      94             :     mfStartPos( fStartPos ),
      95             :     mfLength( fLength ),
      96             :     mfPosition( 0.0 ),
      97        1036 :     mfFreeStart( 0.0 )
      98             : {
      99        1036 : }
     100             : 
     101           0 : double SubSegment::getPosition() const
     102             : {
     103           0 :     return mfPosition;
     104             : }
     105             : 
     106        2200 : void SubSegment::setPosition( double fPosition )
     107             : {
     108             :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" );
     109        2200 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
     110        2200 :     mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
     111        2200 : }
     112             : 
     113         520 : double SubSegment::getFreeLength() const
     114             : {
     115         520 :     return 1.0 - mfFreeStart;
     116             : }
     117             : 
     118         520 : ISegmentProgressBarRef SubSegment::createSegment( double fLength )
     119             : {
     120             :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" );
     121         520 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     122         520 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
     123         520 :     mfFreeStart += fLength;
     124         520 :     return xSegment;
     125             : }
     126             : 
     127             : } // namespace prv
     128             : 
     129         128 : SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
     130             :     maProgress( rxIndicator, rText ),
     131         128 :     mfFreeStart( 0.0 )
     132             : {
     133         128 : }
     134             : 
     135           0 : double SegmentProgressBar::getPosition() const
     136             : {
     137           0 :     return maProgress.getPosition();
     138             : }
     139             : 
     140           0 : void SegmentProgressBar::setPosition( double fPosition )
     141             : {
     142           0 :     maProgress.setPosition( fPosition );
     143           0 : }
     144             : 
     145         904 : double SegmentProgressBar::getFreeLength() const
     146             : {
     147         904 :     return 1.0 - mfFreeStart;
     148             : }
     149             : 
     150         516 : ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
     151             : {
     152             :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
     153         516 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     154         516 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
     155         516 :     mfFreeStart += fLength;
     156         516 :     return xSegment;
     157             : }
     158             : 
     159             : } // namespace oox
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10