LibreOffice Module sc (master)  1
fprogressbar.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <vector>
23 #include <memory>
24 #include <rtl/ustring.hxx>
25 #include <progress.hxx>
26 
27 class SfxObjectShell;
28 class SvStream;
29 
30 const sal_Int32 SCF_INV_SEGMENT = -1;
31 
101 class ScfProgressBar final
102 {
103 public:
104  ScfProgressBar(const ScfProgressBar&) = delete;
105  const ScfProgressBar operator=(const ScfProgressBar&) = delete;
106 
107  explicit ScfProgressBar(SfxObjectShell* pDocShell, const OUString& rText);
108  explicit ScfProgressBar(SfxObjectShell* pDocShell, const char* pResId);
109  ~ScfProgressBar();
110 
113  sal_Int32 AddSegment( std::size_t nSize );
118  ScfProgressBar& GetSegmentProgressBar( sal_Int32 nSegment );
119 
121  bool IsFull() const;
122 
124  void ActivateSegment( sal_Int32 nSegment );
126  void Activate() { ActivateSegment( 0 ); }
128  void ProgressAbs( std::size_t nPos );
130  void Progress( std::size_t nDelta = 1 );
131 
132 private:
133  struct ScfProgressSegment;
134 
136  explicit ScfProgressBar(
137  ScfProgressBar& rParProgress,
138  ScfProgressSegment* pParSegment );
139 
141  void Init( SfxObjectShell* pDocShell );
142 
144  ScfProgressSegment* GetSegment( sal_Int32 nSegment );
146  void SetCurrSegment( ScfProgressSegment* pSegment );
148  void IncreaseProgressBar( std::size_t nDelta );
149 
150 private:
153  {
154  typedef ::std::unique_ptr< ScfProgressBar > ScfProgressBarPtr;
155 
156  ScfProgressBarPtr mxProgress;
157  std::size_t mnSize;
158  std::size_t mnPos;
159 
160  explicit ScfProgressSegment( std::size_t nSize );
162  };
163 
164  typedef ::std::unique_ptr< ScProgress > ScProgressPtr;
165  typedef std::vector< std::unique_ptr<ScfProgressSegment> > ScfSegmentList;
166 
167  ScfSegmentList maSegments;
168  OUString maText;
169 
170  ScProgressPtr mxSysProgress;
175 
176  std::size_t mnTotalSize;
177  std::size_t mnTotalPos;
178  std::size_t mnUnitSize;
179  std::size_t mnNextUnitPos;
180  std::size_t mnSysProgressScale;
182 };
183 
186 {
187 public:
188  explicit ScfSimpleProgressBar(std::size_t nSize, SfxObjectShell* pDocShell, const OUString& rText);
189  explicit ScfSimpleProgressBar(std::size_t nSize, SfxObjectShell* pDocShell, const char* pResId);
190 
192  void ProgressAbs( std::size_t nPos ) { maProgress.ProgressAbs( nPos ); }
193 
194 private:
196  void Init( std::size_t nSize );
197 
198 private:
200 };
201 
204 {
205 public:
206  explicit ScfStreamProgressBar( SvStream& rStrm, SfxObjectShell* pDocShell );
207 
209  void Progress();
210 
211 private:
213  void Init( SfxObjectShell* pDocShell, const OUString& rText );
214 
215 private:
216  typedef ::std::unique_ptr< ScfSimpleProgressBar > ScfSimpleProgressBarPtr;
217 
218  ScfSimpleProgressBarPtr mxProgress;
220 };
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ActivateSegment(sal_Int32 nSegment)
Starts the progress bar or activates another segment.
ScfProgressSegment * mpCurrSegment
Parent segment, if this is a segment progress bar.
ScfSimpleProgressBarPtr mxProgress
ScProgressPtr mxSysProgress
UI string for system progress.
A simplified progress bar based on the stream position of an existing stream.
ScfProgressBar maProgress
std::size_t mnSysProgressScale
Limit for next system progress call.
std::size_t mnNextUnitPos
Size between two calls of system progress.
ScfStreamProgressBar(SvStream &rStrm, SfxObjectShell *pDocShell)
A simplified progress bar with only one segment.
SfxObjectShell * mpDocShell
System progress bar.
std::size_t mnTotalSize
Current segment for progress.
ScfProgressBar * mpParentProgress
The document shell for the progress bar.
void IncreaseProgressBar(std::size_t nDelta)
Increases mnTotalPos and calls the system progress bar.
ScfProgressSegment * mpParentSegment
Parent progress bar, if this is a segment progress bar.
ScfProgressBar(const ScfProgressBar &)=delete
const ScfProgressBar operator=(const ScfProgressBar &)=delete
std::size_t mnUnitSize
Sum of positions of all segments.
ScfProgressBar & GetSegmentProgressBar(sal_Int32 nSegment)
Returns a complete progress bar for the specified segment.
OUString maText
List of progress segments.
::std::unique_ptr< ScfSimpleProgressBar > ScfSimpleProgressBarPtr
bool IsFull() const
Returns true, if the current progress segment is already full.
ScfSegmentList maSegments
bool mbInProgress
Additionally scaling factor for system progress.
const sal_Int32 SCF_INV_SEGMENT
ScfProgressSegment * GetSegment(sal_Int32 nSegment)
Returns the segment specified by list index.
void Progress(std::size_t nDelta=1)
Increase current segment by the passed value.
void ProgressAbs(std::size_t nPos)
Set progress bar to the specified position.
void Activate()
Starts the progress bar (with first segment).
Contains all data of a segment of the progress bar.
::std::unique_ptr< ScfProgressBar > ScfProgressBarPtr
void Init(SfxObjectShell *pDocShell)
Initializes all members on construction.
std::size_t mnPos
Size of this segment.
void Init(SfxObjectShell *pDocShell, const OUString &rText)
Initializes and starts the progress bar.
std::size_t mnTotalPos
Total size of all segments.
std::size_t mnSize
Pointer to sub progress bar for this segment.
void Progress()
Sets the progress bar to the current stream position.
::std::unique_ptr< ScProgress > ScProgressPtr
Progress bar for complex progress representation.
void ProgressAbs(std::size_t nPos)
Set current segment to the specified absolute position.
ScfProgressSegment(std::size_t nSize)
Current position of this segment.
std::vector< std::unique_ptr< ScfProgressSegment > > ScfSegmentList
void SetCurrSegment(ScfProgressSegment *pSegment)
Activates progress bar and sets current segment.
ScfSimpleProgressBar(std::size_t nSize, SfxObjectShell *pDocShell, const OUString &rText)
void SvStream & rStrm
sal_Int32 AddSegment(std::size_t nSize)
Adds a new segment to the progress bar.
SvStream & mrStrm
The used progress bar.
void Init(std::size_t nSize)
Initializes and starts the progress bar.