Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/progress.hxx
Line
Count
Source
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 <rtl/ustring.hxx>
23
#include <sfx2/progress.hxx>
24
#include "scdllapi.h"
25
26
class ScDocument;
27
28
/*
29
 * #i102566
30
 * Drawing a progress bar update is not cheap, so if we draw it on every
31
 * percentage change of 200 calculations we get one progress draw per 2
32
 * calculations which is slower than doing the calculations themselves. So as a
33
 * rough guide only do an update per MIN_NO_CODES_PER_PROGRESS_UPDATE
34
 * calculations
35
 */
36
516k
#define MIN_NO_CODES_PER_PROGRESS_UPDATE 100
37
38
class SC_DLLPUBLIC ScProgress
39
{
40
private:
41
    static  SfxProgress*    pGlobalProgress;
42
    static  sal_uInt64      nGlobalRange;
43
    static  sal_uInt64      nGlobalPercent;
44
    static  ScProgress*     pInterpretProgress;
45
    static  sal_uInt64      nInterpretProgress;
46
    static  ScDocument*     pInterpretDoc;
47
    static  bool            bIdleWasEnabled;
48
            bool            bEnabled;
49
50
            std::unique_ptr<SfxProgress> pProgress;
51
52
                            ScProgress( const ScProgress& ) = delete;
53
            ScProgress&     operator=( const ScProgress& ) = delete;
54
55
    static  void            CalcGlobalPercent( sal_uInt64 nVal )
56
1.17M
                                {
57
1.17M
                                    nGlobalPercent = nGlobalRange ?
58
1.17M
                                        nVal * 100 / nGlobalRange : 0;
59
1.17M
                                }
60
61
public:
62
    static  void            CreateInterpretProgress( ScDocument* pDoc,
63
                                                    bool bWait = true );
64
516k
    static  ScProgress*     GetInterpretProgress() { return pInterpretProgress; }
65
    static  void            DeleteInterpretProgress();
66
67
                            ScProgress( SfxObjectShell* pObjSh,
68
                                         const OUString& rText,
69
                                         sal_uInt64 nRange,
70
                                         bool bWait );
71
                            ~ScProgress();
72
73
#ifdef SC_PROGRESS_CXX
74
                            /// for DummyInterpret only, never use otherwise!!!
75
                            ScProgress();
76
#endif
77
            void            SetState( sal_uInt64 nVal, sal_uInt64 nNewRange = 0 )
78
1.86M
                                {
79
1.86M
                                    if ( pProgress )
80
1.17M
                                    {
81
1.17M
                                        if ( nNewRange )
82
0
                                            nGlobalRange = nNewRange;
83
1.17M
                                        CalcGlobalPercent( nVal );
84
1.17M
                                        pProgress->SetState( nVal, nNewRange );
85
1.17M
                                    }
86
1.86M
                                }
87
            void            SetStateCountDown( sal_uInt64 nVal )
88
0
                                {
89
0
                                    if ( pProgress )
90
0
                                    {
91
0
                                        CalcGlobalPercent( nGlobalRange - nVal );
92
0
                                        pProgress->SetState( nGlobalRange - nVal );
93
0
                                    }
94
0
                                }
95
            void            SetStateOnPercent( sal_uInt64 nVal )
96
900k
                                {   /// only if percentage increased
97
900k
                                    if ( nGlobalRange && (nVal * 100 /
98
900k
                                            nGlobalRange) > nGlobalPercent )
99
548k
                                        SetState( nVal );
100
900k
                                }
101
            void            SetStateCountDownOnPercent( sal_uInt64 nVal )
102
690k
                                {   /// only if percentage increased
103
690k
                                    if ( nGlobalRange &&
104
0
                                            ((nGlobalRange - nVal) * 100 /
105
0
                                            nGlobalRange) > nGlobalPercent )
106
0
                                        SetStateCountDown( nVal );
107
690k
                                }
108
            sal_uInt64          GetState() const
109
0
                                {
110
0
                                    if ( pProgress )
111
0
                                        return pProgress->GetState();
112
0
                                    return 0;
113
0
                                }
114
516k
            bool                Enabled() const { return bEnabled; }
115
0
            void                Disable() { bEnabled = false; }
116
0
            void                Enable() { bEnabled = true; }
117
};
118
119
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */