1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_FPROGRESSBAR_HXX 25cdf0e10cSrcweir #define SC_FPROGRESSBAR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "globstr.hrc" 28cdf0e10cSrcweir #include "ftools.hxx" 29cdf0e10cSrcweir #include "scdllapi.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir class SfxObjectShell; 32cdf0e10cSrcweir class ScProgress; 33cdf0e10cSrcweir 34cdf0e10cSrcweir // ============================================================================ 35cdf0e10cSrcweir 36cdf0e10cSrcweir const sal_Int32 SCF_INV_SEGMENT = -1; 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ============================================================================ 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** Progress bar for complex progress representation. 41cdf0e10cSrcweir 42cdf0e10cSrcweir The progress bar contains one or more segments, each with customable 43cdf0e10cSrcweir size. Each segment is represented by a unique identifier. While showing the 44cdf0e10cSrcweir progress bar, several segments can be started simultaneously. The progress 45cdf0e10cSrcweir bar displays the sum of all started segments on screen. 46cdf0e10cSrcweir 47cdf0e10cSrcweir It is possible to create a full featured ScfProgressBar object from 48cdf0e10cSrcweir any segment. This sub progress bar works only on that parent segment, with 49cdf0e10cSrcweir the effect, that if the sub progress bar reaches 100%, the parent segment is 50cdf0e10cSrcweir filled completely. 51cdf0e10cSrcweir 52cdf0e10cSrcweir After adding segments, the progress bar has to be activated. In this step the 53cdf0e10cSrcweir total size of all segments is calculated. Therefore it is not possible to add 54cdf0e10cSrcweir more segments from here. 55cdf0e10cSrcweir 56cdf0e10cSrcweir If a sub progress bar is created from a segment, and the main progress bar 57cdf0e10cSrcweir has been started (but not the sub progress bar), it is still possible to add 58cdf0e10cSrcweir segments to the sub progress bar. It is not allowed to get the sub progress bar 59cdf0e10cSrcweir of a started segment. And it is not allowed to modify the segment containing 60cdf0e10cSrcweir a sub progress bar directly. 61cdf0e10cSrcweir 62cdf0e10cSrcweir Following a few code examples, how to use the progress bar. 63cdf0e10cSrcweir 64cdf0e10cSrcweir Example 1: Simple progress bar (see also ScfSimpleProgressBar below). 65cdf0e10cSrcweir 66cdf0e10cSrcweir ScfProgressBar aProgress( ... ); 67cdf0e10cSrcweir sal_Int32 nSeg = aProgress.AddSegment( 50 ); // segment with 50 steps (1 step = 2%) 68cdf0e10cSrcweir 69cdf0e10cSrcweir aProgress.ActivateSegment( nSeg ); // start segment nSeg 70cdf0e10cSrcweir aProgress.Progress(); // 0->1; display: 2% 71cdf0e10cSrcweir aProgress.ProgressAbs( 9 ); // 1->9; display: 18% 72cdf0e10cSrcweir 73cdf0e10cSrcweir Example 2: Progress bar with 2 segments. 74cdf0e10cSrcweir 75cdf0e10cSrcweir ScfProgressBar aProgress( ... ); 76cdf0e10cSrcweir sal_Int32 nSeg1 = aProgress.AddSegment( 70 ); // segment with 70 steps 77cdf0e10cSrcweir sal_Int32 nSeg2 = aProgress.AddSegment( 30 ); // segment with 30 steps 78cdf0e10cSrcweir // both segments: 100 steps (1 step = 1%) 79cdf0e10cSrcweir 80cdf0e10cSrcweir aProgress.ActivateSegment( nSeg1 ); // start first segment 81cdf0e10cSrcweir aProgress.Progress(); // 0->1, display: 1% 82cdf0e10cSrcweir aProgress.Progress( 2 ); // 1->3, display: 3% 83cdf0e10cSrcweir aProgress.ActivateSegment( nSeg2 ); // start second segment 84cdf0e10cSrcweir aProgress.Progress( 5 ); // 0->5, display: 8% (5+3 steps) 85cdf0e10cSrcweir aProgress.ActivateSegment( nSeg1 ); // continue with first segment 86cdf0e10cSrcweir aProgress.Progress(); // 3->4, display: 9% (5+4 steps) 87cdf0e10cSrcweir 88cdf0e10cSrcweir Example 3: Progress bar with 2 segments, one contains a sub progress bar. 89cdf0e10cSrcweir 90cdf0e10cSrcweir ScfProgressBar aProgress( ... ); 91cdf0e10cSrcweir sal_Int32 nSeg1 = aProgress.AddSegment( 75 ); // segment with 75 steps 92cdf0e10cSrcweir sal_Int32 nSeg2 = aProgress.AddSegment( 25 ); // segment with 25 steps 93cdf0e10cSrcweir // both segments: 100 steps (1 step = 1%) 94cdf0e10cSrcweir 95cdf0e10cSrcweir aProgress.ActivateSegment( nSeg1 ); // start first segment 96cdf0e10cSrcweir aProgress.Progress(); // 0->1, display: 1% 97cdf0e10cSrcweir 98cdf0e10cSrcweir ScfProgressBar& rSubProgress = aProgress.GetSegmentProgressBar( nSeg2 ); 99cdf0e10cSrcweir // sub progress bar from second segment 100cdf0e10cSrcweir sal_Int32 nSubSeg = rSubProgress.AddSegment( 5 ); // 5 steps, mapped to second segment 101cdf0e10cSrcweir // => 1 step = 5 steps in parent = 5% 102cdf0e10cSrcweir 103cdf0e10cSrcweir rSubProgress.ActivateSegment( nSubSeg ); // start the segment (auto activate parent segment) 104cdf0e10cSrcweir rSubProgress.Progress(); // 0->1 (0->5 in parent); display: 6% (1+5) 105cdf0e10cSrcweir 106cdf0e10cSrcweir // not allowed (second segment active): aProgress.Progress(); 107cdf0e10cSrcweir // not allowed (first segment not empty): aProgress.GetSegmentProgressBar( nSeg1 ); 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir class ScfProgressBar : ScfNoCopy 110cdf0e10cSrcweir { 111cdf0e10cSrcweir public: 112cdf0e10cSrcweir explicit ScfProgressBar( SfxObjectShell* pDocShell, const String& rText ); 113cdf0e10cSrcweir explicit ScfProgressBar( SfxObjectShell* pDocShell, sal_uInt16 nResId ); 114cdf0e10cSrcweir virtual ~ScfProgressBar(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir /** Adds a new segment to the progress bar. 117cdf0e10cSrcweir @return the identifier of the segment. */ 118cdf0e10cSrcweir sal_Int32 AddSegment( sal_Size nSize ); 119cdf0e10cSrcweir /** Returns a complete progress bar for the specified segment. 120cdf0e10cSrcweir @descr The progress bar can be used to create sub segments inside of the 121cdf0e10cSrcweir segment. Do not delete it (done by root progress bar)! 122cdf0e10cSrcweir @return A reference to an ScfProgressBar connected to the segment. */ 123cdf0e10cSrcweir ScfProgressBar& GetSegmentProgressBar( sal_Int32 nSegment ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir /** Returns true, if any progress segment has been started. */ IsStarted() const126cdf0e10cSrcweir inline bool IsStarted() const { return mbInProgress; } 127cdf0e10cSrcweir /** Returns true, if the current progress segment is already full. */ 128cdf0e10cSrcweir bool IsFull() const; 129cdf0e10cSrcweir 130cdf0e10cSrcweir /** Starts the progress bar or activates another segment. */ 131cdf0e10cSrcweir void ActivateSegment( sal_Int32 nSegment ); 132cdf0e10cSrcweir /** Starts the progress bar (with first segment). */ Activate()133cdf0e10cSrcweir inline void Activate() { ActivateSegment( 0 ); } 134cdf0e10cSrcweir /** Set current segment to the specified absolute position. */ 135cdf0e10cSrcweir void ProgressAbs( sal_Size nPos ); 136cdf0e10cSrcweir /** Increase current segment by the passed value. */ 137cdf0e10cSrcweir void Progress( sal_Size nDelta = 1 ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir private: 140cdf0e10cSrcweir struct ScfProgressSegment; 141cdf0e10cSrcweir 142cdf0e10cSrcweir /** Used to create sub progress bars. */ 143cdf0e10cSrcweir explicit ScfProgressBar( 144cdf0e10cSrcweir ScfProgressBar& rParProgress, 145cdf0e10cSrcweir ScfProgressSegment* pParSegment ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir /** Initializes all members on construction. */ 148cdf0e10cSrcweir void Init( SfxObjectShell* pDocShell ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir /** Returns the segment specified by list index. */ 151cdf0e10cSrcweir ScfProgressSegment* GetSegment( sal_Int32 nSegment ) const; 152cdf0e10cSrcweir /** Activates progress bar and sets current segment. */ 153cdf0e10cSrcweir void SetCurrSegment( ScfProgressSegment* pSegment ); 154cdf0e10cSrcweir /** Increases mnTotalPos and calls the system progress bar. */ 155cdf0e10cSrcweir void IncreaseProgressBar( sal_Size nDelta ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir private: 158cdf0e10cSrcweir /** Contains all data of a segment of the progress bar. */ 159cdf0e10cSrcweir struct ScfProgressSegment 160cdf0e10cSrcweir { 161cdf0e10cSrcweir typedef ::std::auto_ptr< ScfProgressBar > ScfProgressBarPtr; 162cdf0e10cSrcweir 163cdf0e10cSrcweir ScfProgressBarPtr mxProgress; /// Pointer to sub progress bar for this segment. 164cdf0e10cSrcweir sal_Size mnSize; /// Size of this segment. 165cdf0e10cSrcweir sal_Size mnPos; /// Current position of this segment. 166cdf0e10cSrcweir 167cdf0e10cSrcweir explicit ScfProgressSegment( sal_Size nSize ); 168cdf0e10cSrcweir ~ScfProgressSegment(); 169cdf0e10cSrcweir }; 170cdf0e10cSrcweir 171cdf0e10cSrcweir typedef ::std::auto_ptr< ScProgress > ScProgressPtr; 172cdf0e10cSrcweir typedef ScfDelList< ScfProgressSegment > ScfSegmentList; 173cdf0e10cSrcweir 174cdf0e10cSrcweir ScfSegmentList maSegments; /// List of progress segments. 175cdf0e10cSrcweir String maText; /// UI string for system progress. 176cdf0e10cSrcweir 177cdf0e10cSrcweir ScProgressPtr mxSysProgress; /// System progress bar. 178cdf0e10cSrcweir SfxObjectShell* mpDocShell; /// The document shell for the progress bar. 179cdf0e10cSrcweir ScfProgressBar* mpParentProgress; /// Parent progress bar, if this is a segment progress bar. 180cdf0e10cSrcweir ScfProgressSegment* mpParentSegment; /// Parent segment, if this is a segment progress bar. 181cdf0e10cSrcweir ScfProgressSegment* mpCurrSegment; /// Current segment for progress. 182cdf0e10cSrcweir 183cdf0e10cSrcweir sal_Size mnTotalSize; /// Total size of all segments. 184cdf0e10cSrcweir sal_Size mnTotalPos; /// Sum of positions of all segments. 185cdf0e10cSrcweir sal_Size mnUnitSize; /// Size between two calls of system progress. 186cdf0e10cSrcweir sal_Size mnNextUnitPos; /// Limit for next system progress call. 187cdf0e10cSrcweir sal_Size mnSysProgressScale; /// Additionally scaling factor for system progress. 188cdf0e10cSrcweir bool mbInProgress; /// true = progress bar started. 189cdf0e10cSrcweir }; 190cdf0e10cSrcweir 191cdf0e10cSrcweir // ============================================================================ 192cdf0e10cSrcweir 193cdf0e10cSrcweir /** A simplified progress bar with only one segment. */ 194cdf0e10cSrcweir class ScfSimpleProgressBar 195cdf0e10cSrcweir { 196cdf0e10cSrcweir public: 197cdf0e10cSrcweir explicit ScfSimpleProgressBar( sal_Size nSize, SfxObjectShell* pDocShell, const String& rText ); 198cdf0e10cSrcweir explicit ScfSimpleProgressBar( sal_Size nSize, SfxObjectShell* pDocShell, sal_uInt16 nResId ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir /** Set progress bar to the specified position. */ ProgressAbs(sal_Size nPos)201cdf0e10cSrcweir inline void ProgressAbs( sal_Size nPos ) { maProgress.ProgressAbs( nPos ); } 202cdf0e10cSrcweir /** Increase progress bar by 1. */ Progress(sal_Size nDelta=1)203cdf0e10cSrcweir inline void Progress( sal_Size nDelta = 1 ) { maProgress.Progress( nDelta ); } 204cdf0e10cSrcweir 205cdf0e10cSrcweir private: 206cdf0e10cSrcweir /** Initializes and starts the progress bar. */ 207cdf0e10cSrcweir void Init( sal_Size nSize ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir private: 210cdf0e10cSrcweir ScfProgressBar maProgress; /// The used progress bar. 211cdf0e10cSrcweir }; 212cdf0e10cSrcweir 213cdf0e10cSrcweir // ============================================================================ 214cdf0e10cSrcweir 215cdf0e10cSrcweir /** A simplified progress bar based on the stream position of an existing stream. */ 216cdf0e10cSrcweir class ScfStreamProgressBar 217cdf0e10cSrcweir { 218cdf0e10cSrcweir public: 219cdf0e10cSrcweir //UNUSED2008-05 explicit ScfStreamProgressBar( SvStream& rStrm, SfxObjectShell* pDocShell, const String& rText ); 220cdf0e10cSrcweir explicit ScfStreamProgressBar( SvStream& rStrm, SfxObjectShell* pDocShell, sal_uInt16 nResId = STR_LOAD_DOC ); 221cdf0e10cSrcweir 222cdf0e10cSrcweir /** Sets the progress bar to the current stream position. */ 223cdf0e10cSrcweir void Progress(); 224cdf0e10cSrcweir 225cdf0e10cSrcweir private: 226cdf0e10cSrcweir /** Initializes and starts the progress bar. */ 227cdf0e10cSrcweir void Init( SfxObjectShell* pDocShell, const String& rText ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir private: 230cdf0e10cSrcweir typedef ::std::auto_ptr< ScfSimpleProgressBar > ScfSimpleProgressBarPtr; 231cdf0e10cSrcweir 232cdf0e10cSrcweir ScfSimpleProgressBarPtr mxProgress; /// The used progress bar. 233cdf0e10cSrcweir SvStream& mrStrm; /// The used stream. 234cdf0e10cSrcweir }; 235cdf0e10cSrcweir 236cdf0e10cSrcweir // ============================================================================ 237cdf0e10cSrcweir 238cdf0e10cSrcweir #endif 239cdf0e10cSrcweir 240