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 <osl/diagnose.h>
23 : #include <com/sun/star/task/XStatusIndicator.hpp>
24 : #include "oox/helper/helper.hxx"
25 :
26 : namespace oox {
27 :
28 : using namespace ::com::sun::star::task;
29 : using namespace ::com::sun::star::uno;
30 :
31 : namespace {
32 :
33 : const sal_Int32 PROGRESS_RANGE = 1000000;
34 :
35 : } // namespace
36 :
37 1656 : IProgressBar::~IProgressBar()
38 : {
39 1656 : }
40 :
41 1511 : ISegmentProgressBar::~ISegmentProgressBar()
42 : {
43 1511 : }
44 :
45 145 : ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
46 : mxIndicator( rxIndicator ),
47 145 : mfPosition( 0 )
48 : {
49 145 : if( mxIndicator.is() )
50 68 : mxIndicator->start( rText, PROGRESS_RANGE );
51 145 : }
52 :
53 290 : ProgressBar::~ProgressBar()
54 : {
55 145 : if( mxIndicator.is() )
56 68 : mxIndicator->end();
57 145 : }
58 :
59 0 : double ProgressBar::getPosition() const
60 : {
61 0 : return mfPosition;
62 : }
63 :
64 1532 : void ProgressBar::setPosition( double fPosition )
65 : {
66 : OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" );
67 1532 : mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
68 1532 : if( mxIndicator.is() )
69 661 : mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
70 1532 : }
71 :
72 : namespace prv {
73 :
74 2194 : class SubSegment : public ISegmentProgressBar
75 : {
76 : public:
77 : explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
78 :
79 : virtual double getPosition() const SAL_OVERRIDE;
80 : virtual void setPosition( double fPosition ) SAL_OVERRIDE;
81 :
82 : virtual double getFreeLength() const SAL_OVERRIDE;
83 : virtual ISegmentProgressBarRef createSegment( double fLength ) SAL_OVERRIDE;
84 :
85 : private:
86 : IProgressBar& mrParentProgress;
87 : double mfStartPos;
88 : double mfLength;
89 : double mfPosition;
90 : double mfFreeStart;
91 : };
92 :
93 1097 : SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
94 : mrParentProgress( rParentProgress ),
95 : mfStartPos( fStartPos ),
96 : mfLength( fLength ),
97 : mfPosition( 0.0 ),
98 1097 : mfFreeStart( 0.0 )
99 : {
100 1097 : }
101 :
102 0 : double SubSegment::getPosition() const
103 : {
104 0 : return mfPosition;
105 : }
106 :
107 2339 : void SubSegment::setPosition( double fPosition )
108 : {
109 : OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" );
110 2339 : mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
111 2339 : mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
112 2339 : }
113 :
114 538 : double SubSegment::getFreeLength() const
115 : {
116 538 : return 1.0 - mfFreeStart;
117 : }
118 :
119 538 : ISegmentProgressBarRef SubSegment::createSegment( double fLength )
120 : {
121 : OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" );
122 538 : fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
123 538 : ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
124 538 : mfFreeStart += fLength;
125 538 : return xSegment;
126 : }
127 :
128 : } // namespace prv
129 :
130 145 : SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
131 : maProgress( rxIndicator, rText ),
132 145 : mfFreeStart( 0.0 )
133 : {
134 145 : }
135 :
136 0 : double SegmentProgressBar::getPosition() const
137 : {
138 0 : return maProgress.getPosition();
139 : }
140 :
141 0 : void SegmentProgressBar::setPosition( double fPosition )
142 : {
143 0 : maProgress.setPosition( fPosition );
144 0 : }
145 :
146 973 : double SegmentProgressBar::getFreeLength() const
147 : {
148 973 : return 1.0 - mfFreeStart;
149 : }
150 :
151 559 : ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
152 : {
153 : OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
154 559 : fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
155 559 : ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
156 559 : mfFreeStart += fLength;
157 559 : return xSegment;
158 : }
159 :
160 : } // namespace oox
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|