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

Generated by: LCOV version 1.10