LibreOffice Module sc (master) 1
progress.cxx
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#include <sfx2/app.hxx>
21#include <sfx2/objsh.hxx>
22#include <sfx2/progress.hxx>
23#include <sfx2/docfile.hxx>
24#include <sfx2/sfxsids.hrc>
25#include <svl/eitem.hxx>
26#include <svl/itemset.hxx>
27#include <osl/diagnose.h>
28
29#include <com/sun/star/frame/XModel.hpp>
30
31#define SC_PROGRESS_CXX
32#include <progress.hxx>
33#include <document.hxx>
34#include <globstr.hrc>
35#include <scresid.hxx>
36
37using namespace com::sun::star;
38
41sal_uInt64 ScProgress::nGlobalRange = 0;
42sal_uInt64 ScProgress::nGlobalPercent = 0;
47
48static bool lcl_IsHiddenDocument( const SfxObjectShell* pObjSh )
49{
50 if (pObjSh)
51 {
52 SfxMedium* pMed = pObjSh->GetMedium();
53 if (pMed)
54 {
55 if (const SfxBoolItem* pItem = pMed->GetItemSet().GetItemIfSet(SID_HIDDEN);
56 pItem && pItem->GetValue())
57 return true;
58 }
59 }
60 return false;
61}
62
63static bool lcl_HasControllersLocked( const SfxObjectShell& rObjSh )
64{
65 uno::Reference<frame::XModel> xModel( rObjSh.GetBaseModel() );
66 if (xModel.is())
67 return xModel->hasControllersLocked();
68 return false;
69}
70
71ScProgress::ScProgress(SfxObjectShell* pObjSh, const OUString& rText,
72 sal_uInt64 nRange, bool bWait)
73 : bEnabled(true)
74{
75
77 {
78 if ( lcl_IsHiddenDocument(pObjSh) )
79 {
80 // loading a hidden document while a progress is active is possible - no error
81 pProgress = nullptr;
82 }
83 else
84 {
85 OSL_FAIL( "ScProgress: there can be only one!" );
86 pProgress = nullptr;
87 }
88 }
89 else if ( SfxGetpApp()->IsDowning() )
90 {
91 // This happens. E.g. when saving the clipboard-content as OLE when closing the app.
92 // In this case a SfxProgress would produce dirt in memory.
93 //TODO: Should that be this way ???
94
95 pProgress = nullptr;
96 }
97 else if ( pObjSh && ( pObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED ||
98 pObjSh->GetProgress() ||
99 lcl_HasControllersLocked(*pObjSh) ) )
100 {
101 // no own progress for embedded objects,
102 // no second progress if the document already has one
103
104 pProgress = nullptr;
105 }
106 else
107 {
108 pProgress.reset(new SfxProgress( pObjSh, rText, nRange, bWait ));
110 nGlobalRange = nRange;
111 nGlobalPercent = 0;
112 }
113}
114
116 : bEnabled(true)
117{
118 // DummyInterpret
119}
120
122{
123 if ( pProgress )
124 {
125 pProgress.reset();
126 pGlobalProgress = nullptr;
127 nGlobalRange = 0;
128 nGlobalPercent = 0;
129 }
130}
131
133{
134 if ( nInterpretProgress )
136 else if ( pDoc->GetAutoCalc() )
137 {
140 pDoc->EnableIdle(false);
141 // Interpreter may be called in many circumstances, also if another
142 // progress bar is active, for example while adapting row heights.
143 // Keep the dummy interpret progress.
144 if ( !pGlobalProgress )
146 ScResId( STR_PROGRESS_CALCULATING ),
148 pInterpretDoc = pDoc;
149 }
150}
151
153{
154 if ( !nInterpretProgress )
155 return;
156
157 /* Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
158 is deleted. In rare cases, deletion of 'pInterpretProgress' causes
159 a refresh of the sheet window which may call CreateInterpretProgress
160 and DeleteInterpretProgress again (from Output::DrawStrings),
161 resulting in double deletion of 'pInterpretProgress'. */
162 if ( nInterpretProgress == 1 )
163 {
165 {
166 // move pointer to local temporary to avoid double deletion
167 ScProgress* pTmpProgress = pInterpretProgress;
169 delete pTmpProgress;
170 }
171 if ( pInterpretDoc )
173 }
175}
176
177/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
sal_uInt64 GetFormulaCodeInTree() const
Definition: document.hxx:2410
bool IsIdleEnabled() const
Definition: document.hxx:2207
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1413
void EnableIdle(bool bDo)
Definition: document.hxx:2208
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
static sal_uInt64 nGlobalRange
Definition: progress.hxx:43
static sal_uInt64 nGlobalPercent
Definition: progress.hxx:44
ScProgress(const ScProgress &)=delete
static ScDocument * pInterpretDoc
Definition: progress.hxx:47
static SfxProgress * pGlobalProgress
Definition: progress.hxx:42
static void DeleteInterpretProgress()
Definition: progress.cxx:152
std::unique_ptr< SfxProgress > pProgress
Definition: progress.hxx:51
static bool bIdleWasEnabled
Definition: progress.hxx:48
static void CreateInterpretProgress(ScDocument *pDoc, bool bWait=true)
Definition: progress.cxx:132
static sal_uInt64 nInterpretProgress
Definition: progress.hxx:46
static ScProgress * pInterpretProgress
Definition: progress.hxx:45
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemSet & GetItemSet() const
SfxProgress * GetProgress() const
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
SfxObjectCreateMode GetCreateMode() const
static SfxProgress * GetActiveProgress(SfxObjectShell const *pDocSh=nullptr)
static bool lcl_HasControllersLocked(const SfxObjectShell &rObjSh)
Definition: progress.cxx:63
static bool lcl_IsHiddenDocument(const SfxObjectShell *pObjSh)
Definition: progress.cxx:48
static ScProgress theDummyInterpretProgress
Definition: progress.cxx:39
#define MIN_NO_CODES_PER_PROGRESS_UPDATE
Definition: progress.hxx:37
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
Reference< XModel > xModel