LCOV - code coverage report
Current view: top level - libreoffice/oox/source/helper - progressbar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 52 80.8 %
Date: 2012-12-17 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             : using ::rtl::OUString;
      33             : 
      34             : namespace {
      35             : 
      36             : const sal_Int32 PROGRESS_RANGE      = 1000000;
      37             : 
      38             : } // namespace
      39             : 
      40             : // ============================================================================
      41             : 
      42         238 : IProgressBar::~IProgressBar()
      43             : {
      44         238 : }
      45             : 
      46             : // ----------------------------------------------------------------------------
      47             : 
      48         216 : ISegmentProgressBar::~ISegmentProgressBar()
      49             : {
      50         216 : }
      51             : 
      52             : // ============================================================================
      53             : // ============================================================================
      54             : 
      55          22 : ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
      56             :     mxIndicator( rxIndicator ),
      57          22 :     mfPosition( 0 )
      58             : {
      59          22 :     if( mxIndicator.is() )
      60           0 :         mxIndicator->start( rText, PROGRESS_RANGE );
      61          22 : }
      62             : 
      63          44 : ProgressBar::~ProgressBar()
      64             : {
      65          22 :     if( mxIndicator.is() )
      66           0 :         mxIndicator->end();
      67          22 : }
      68             : 
      69           0 : double ProgressBar::getPosition() const
      70             : {
      71           0 :     return mfPosition;
      72             : }
      73             : 
      74         716 : void ProgressBar::setPosition( double fPosition )
      75             : {
      76             :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" );
      77         716 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
      78         716 :     if( mxIndicator.is() )
      79           0 :         mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
      80         716 : }
      81             : 
      82             : // ============================================================================
      83             : 
      84             : namespace prv {
      85             : 
      86         388 : 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         194 : SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
     108             :     mrParentProgress( rParentProgress ),
     109             :     mfStartPos( fStartPos ),
     110             :     mfLength( fLength ),
     111             :     mfPosition( 0.0 ),
     112         194 :     mfFreeStart( 0.0 )
     113             : {
     114         194 : }
     115             : 
     116         306 : double SubSegment::getPosition() const
     117             : {
     118         306 :     return mfPosition;
     119             : }
     120             : 
     121        1272 : void SubSegment::setPosition( double fPosition )
     122             : {
     123             :     OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" );
     124        1272 :     mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
     125        1272 :     mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
     126        1272 : }
     127             : 
     128         100 : double SubSegment::getFreeLength() const
     129             : {
     130         100 :     return 1.0 - mfFreeStart;
     131             : }
     132             : 
     133         100 : ISegmentProgressBarRef SubSegment::createSegment( double fLength )
     134             : {
     135             :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" );
     136         100 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     137         100 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
     138         100 :     mfFreeStart += fLength;
     139         100 :     return xSegment;
     140             : }
     141             : 
     142             : } // namespace prv
     143             : 
     144             : // ============================================================================
     145             : 
     146          22 : SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
     147             :     maProgress( rxIndicator, rText ),
     148          22 :     mfFreeStart( 0.0 )
     149             : {
     150          22 : }
     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         166 : double SegmentProgressBar::getFreeLength() const
     163             : {
     164         166 :     return 1.0 - mfFreeStart;
     165             : }
     166             : 
     167          94 : ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
     168             : {
     169             :     OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
     170          94 :     fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
     171          94 :     ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
     172          94 :     mfFreeStart += fLength;
     173          94 :     return xSegment;
     174             : }
     175             : 
     176             : // ============================================================================
     177             : 
     178             : } // namespace oox
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10