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

Generated by: LCOV version 1.10