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 SfxItemSet* pSet = pMed->GetItemSet();
56 const SfxBoolItem* pItem;
57 if ( pSet && (pItem = pSet->GetItemIfSet( SID_HIDDEN )) &&
58 pItem->GetValue() )
59 return true;
60 }
61 }
62 return false;
63}
64
65static bool lcl_HasControllersLocked( const SfxObjectShell& rObjSh )
66{
67 uno::Reference<frame::XModel> xModel( rObjSh.GetBaseModel() );
68 if (xModel.is())
69 return xModel->hasControllersLocked();
70 return false;
71}
72
73ScProgress::ScProgress(SfxObjectShell* pObjSh, const OUString& rText,
74 sal_uInt64 nRange, bool bWait)
75 : bEnabled(true)
76{
77
79 {
80 if ( lcl_IsHiddenDocument(pObjSh) )
81 {
82 // loading a hidden document while a progress is active is possible - no error
83 pProgress = nullptr;
84 }
85 else
86 {
87 OSL_FAIL( "ScProgress: there can be only one!" );
88 pProgress = nullptr;
89 }
90 }
91 else if ( SfxGetpApp()->IsDowning() )
92 {
93 // This happens. E.g. when saving the clipboard-content as OLE when closing the app.
94 // In this case a SfxProgress would produce dirt in memory.
95 //TODO: Should that be this way ???
96
97 pProgress = nullptr;
98 }
99 else if ( pObjSh && ( pObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED ||
100 pObjSh->GetProgress() ||
101 lcl_HasControllersLocked(*pObjSh) ) )
102 {
103 // no own progress for embedded objects,
104 // no second progress if the document already has one
105
106 pProgress = nullptr;
107 }
108 else
109 {
110 pProgress.reset(new SfxProgress( pObjSh, rText, nRange, bWait ));
112 nGlobalRange = nRange;
113 nGlobalPercent = 0;
114 }
115}
116
118 : bEnabled(true)
119{
120 // DummyInterpret
121}
122
124{
125 if ( pProgress )
126 {
127 pProgress.reset();
128 pGlobalProgress = nullptr;
129 nGlobalRange = 0;
130 nGlobalPercent = 0;
131 }
132}
133
135{
136 if ( nInterpretProgress )
138 else if ( pDoc->GetAutoCalc() )
139 {
142 pDoc->EnableIdle(false);
143 // Interpreter may be called in many circumstances, also if another
144 // progress bar is active, for example while adapting row heights.
145 // Keep the dummy interpret progress.
146 if ( !pGlobalProgress )
148 ScResId( STR_PROGRESS_CALCULATING ),
150 pInterpretDoc = pDoc;
151 }
152}
153
155{
156 if ( !nInterpretProgress )
157 return;
158
159 /* Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
160 is deleted. In rare cases, deletion of 'pInterpretProgress' causes
161 a refresh of the sheet window which may call CreateInterpretProgress
162 and DeleteInterpretProgress again (from Output::DrawStrings),
163 resulting in double deletion of 'pInterpretProgress'. */
164 if ( nInterpretProgress == 1 )
165 {
167 {
168 // move pointer to local temporary to avoid double deletion
169 ScProgress* pTmpProgress = pInterpretProgress;
171 delete pTmpProgress;
172 }
173 if ( pInterpretDoc )
175 }
177}
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
sal_uInt64 GetFormulaCodeInTree() const
Definition: document.hxx:2409
bool IsIdleEnabled() const
Definition: document.hxx:2206
SC_DLLPUBLIC bool GetAutoCalc() const
Definition: document.hxx:1412
void EnableIdle(bool bDo)
Definition: document.hxx:2207
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1082
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:154
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:134
static sal_uInt64 nInterpretProgress
Definition: progress.hxx:46
static ScProgress * pInterpretProgress
Definition: progress.hxx:45
bool GetValue() const
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:65
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