sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / oox / source / helper / progressbar.cxx
blob86170b47e66a1d285bb57f186efd0bcdca32ca34
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <oox/helper/progressbar.hxx>
22 #include <com/sun/star/task/XStatusIndicator.hpp>
23 #include <oox/helper/helper.hxx>
25 #include <sal/log.hxx>
27 namespace oox {
29 using namespace ::com::sun::star::task;
30 using namespace ::com::sun::star::uno;
32 namespace {
34 const sal_Int32 PROGRESS_RANGE = 1000000;
36 } // namespace
38 IProgressBar::~IProgressBar()
42 ISegmentProgressBar::~ISegmentProgressBar()
46 ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
47 mxIndicator( rxIndicator ),
48 mfPosition( 0 )
50 if( mxIndicator.is() )
51 mxIndicator->start( rText, PROGRESS_RANGE );
54 ProgressBar::~ProgressBar()
56 if( mxIndicator.is() )
57 mxIndicator->end();
60 double ProgressBar::getPosition() const
62 return mfPosition;
65 void ProgressBar::setPosition( double fPosition )
67 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "ProgressBar::setPosition - invalid position" );
68 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
69 if( mxIndicator.is() )
70 mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
73 namespace prv {
75 namespace {
77 class SubSegment : public ISegmentProgressBar
79 public:
80 explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
82 virtual double getPosition() const override;
83 virtual void setPosition( double fPosition ) override;
85 virtual double getFreeLength() const override;
86 virtual ISegmentProgressBarRef createSegment( double fLength ) override;
88 private:
89 IProgressBar& mrParentProgress;
90 double mfStartPos;
91 double mfLength;
92 double mfPosition;
93 double mfFreeStart;
98 SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
99 mrParentProgress( rParentProgress ),
100 mfStartPos( fStartPos ),
101 mfLength( fLength ),
102 mfPosition( 0.0 ),
103 mfFreeStart( 0.0 )
107 double SubSegment::getPosition() const
109 return mfPosition;
112 void SubSegment::setPosition( double fPosition )
114 SAL_WARN_IF( (mfPosition > fPosition) || (fPosition > 1.0), "oox", "SubSegment::setPosition - invalid position" );
115 mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
116 mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
119 double SubSegment::getFreeLength() const
121 return 1.0 - mfFreeStart;
124 ISegmentProgressBarRef SubSegment::createSegment( double fLength )
126 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SubSegment::createSegment - invalid length" );
127 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
128 ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( *this, mfFreeStart, fLength );
129 mfFreeStart += fLength;
130 return xSegment;
133 } // namespace oox::prv
135 SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
136 maProgress( rxIndicator, rText ),
137 mfFreeStart( 0.0 )
141 double SegmentProgressBar::getPosition() const
143 return maProgress.getPosition();
146 void SegmentProgressBar::setPosition( double fPosition )
148 maProgress.setPosition( fPosition );
151 double SegmentProgressBar::getFreeLength() const
153 return 1.0 - mfFreeStart;
156 ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
158 SAL_WARN_IF( (0.0 >= fLength) || (fLength > getFreeLength()), "oox", "SegmentProgressBar::createSegment - invalid length" );
159 fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
160 ISegmentProgressBarRef xSegment = std::make_shared<prv::SubSegment>( maProgress, mfFreeStart, fLength );
161 mfFreeStart += fLength;
162 return xSegment;
165 } // namespace oox
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */