Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sfx2/app.hxx>
30 : : #include <sfx2/objsh.hxx>
31 : : #include <sfx2/progress.hxx>
32 : : #include <sfx2/docfile.hxx>
33 : : #include <sfx2/sfxsids.hrc>
34 : : #include <svl/eitem.hxx>
35 : : #include <svl/itemset.hxx>
36 : :
37 : : #define SC_PROGRESS_CXX
38 : : #include "progress.hxx"
39 : : #include "document.hxx"
40 : : #include "global.hxx"
41 : : #include "globstr.hrc"
42 : :
43 : : using namespace com::sun::star;
44 : :
45 : :
46 : 51 : static ScProgress theDummyInterpretProgress;
47 : : SfxProgress* ScProgress::pGlobalProgress = NULL;
48 : : sal_uLong ScProgress::nGlobalRange = 0;
49 : : sal_uLong ScProgress::nGlobalPercent = 0;
50 : : sal_Bool ScProgress::bGlobalNoUserBreak = sal_True;
51 : : ScProgress* ScProgress::pInterpretProgress = &theDummyInterpretProgress;
52 : : ScProgress* ScProgress::pOldInterpretProgress = NULL;
53 : : sal_uLong ScProgress::nInterpretProgress = 0;
54 : : sal_Bool ScProgress::bAllowInterpretProgress = sal_True;
55 : : ScDocument* ScProgress::pInterpretDoc;
56 : : sal_Bool ScProgress::bIdleWasDisabled = false;
57 : :
58 : :
59 : 0 : sal_Bool lcl_IsHiddenDocument( SfxObjectShell* pObjSh )
60 : : {
61 [ # # ]: 0 : if (pObjSh)
62 : : {
63 : 0 : SfxMedium* pMed = pObjSh->GetMedium();
64 [ # # ]: 0 : if (pMed)
65 : : {
66 [ # # ]: 0 : SfxItemSet* pSet = pMed->GetItemSet();
67 : : const SfxPoolItem* pItem;
68 [ # # ][ # # ]: 0 : if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_HIDDEN, sal_True, &pItem ) &&
[ # # # # ]
[ # # ]
69 : 0 : ((const SfxBoolItem*)pItem)->GetValue() )
70 : 0 : return sal_True;
71 : : }
72 : : }
73 : 0 : return false;
74 : : }
75 : :
76 : 139 : bool lcl_HasControllersLocked( SfxObjectShell& rObjSh )
77 : : {
78 [ + - ]: 139 : uno::Reference<frame::XModel> xModel( rObjSh.GetBaseModel() );
79 [ + - ]: 139 : if (xModel.is())
80 [ + - ][ + - ]: 139 : return xModel->hasControllersLocked();
81 : 139 : return false;
82 : : }
83 : :
84 : 315 : ScProgress::ScProgress( SfxObjectShell* pObjSh, const String& rText,
85 : : sal_uLong nRange, sal_Bool bAllDocs, sal_Bool bWait )
86 : : {
87 : :
88 [ + - ][ - + ]: 315 : if ( pGlobalProgress || SfxProgress::GetActiveProgress( NULL ) )
[ - + ]
89 : : {
90 [ # # ]: 0 : if ( lcl_IsHiddenDocument(pObjSh) )
91 : : {
92 : : // loading a hidden document while a progress is active is possible - no error
93 : 0 : pProgress = NULL;
94 : : }
95 : : else
96 : : {
97 : : OSL_FAIL( "ScProgress: there can be only one!" );
98 : 0 : pProgress = NULL;
99 : : }
100 : : }
101 [ - + ]: 315 : else if ( SFX_APP()->IsDowning() )
102 : : {
103 : : // kommt vor z.B. beim Speichern des Clipboard-Inhalts als OLE beim Beenden
104 : : // Dann wuerde ein SfxProgress wild im Speicher rummuellen
105 : : //! Soll das so sein ???
106 : :
107 : 0 : pProgress = NULL;
108 : : }
109 [ + - ][ + + : 593 : else if ( pObjSh && ( pObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
+ - - + ]
[ + + ]
110 : 139 : pObjSh->GetProgress() ||
111 : 139 : lcl_HasControllersLocked(*pObjSh) ) )
112 : : {
113 : : // no own progress for embedded objects,
114 : : // no second progress if the document already has one
115 : :
116 : 176 : pProgress = NULL;
117 : : }
118 : : else
119 : : {
120 [ + - ]: 139 : pProgress = new SfxProgress( pObjSh, rText, nRange, bAllDocs, bWait );
121 : 139 : pGlobalProgress = pProgress;
122 : 139 : nGlobalRange = nRange;
123 : 139 : nGlobalPercent = 0;
124 : 139 : bGlobalNoUserBreak = sal_True;
125 : : }
126 : 315 : }
127 : :
128 : :
129 : 51 : ScProgress::ScProgress() :
130 : 51 : pProgress( NULL )
131 : : { // DummyInterpret
132 : 51 : }
133 : :
134 : :
135 : 366 : ScProgress::~ScProgress()
136 : : {
137 [ + + ]: 366 : if ( pProgress )
138 : : {
139 [ + - ]: 139 : delete pProgress;
140 : 139 : pGlobalProgress = NULL;
141 : 139 : nGlobalRange = 0;
142 : 139 : nGlobalPercent = 0;
143 : 139 : bGlobalNoUserBreak = sal_True;
144 : : }
145 : 366 : }
146 : :
147 : :
148 : 86 : void ScProgress::CreateInterpretProgress( ScDocument* pDoc, sal_Bool bWait )
149 : : {
150 [ + - ]: 86 : if ( bAllowInterpretProgress )
151 : : {
152 [ - + ]: 86 : if ( nInterpretProgress )
153 : 0 : nInterpretProgress++;
154 [ + + ]: 86 : else if ( pDoc->GetAutoCalc() )
155 : : {
156 : 84 : nInterpretProgress = 1;
157 : 84 : bIdleWasDisabled = pDoc->IsIdleDisabled();
158 : 84 : pDoc->DisableIdle( sal_True );
159 : : // Interpreter may be called in many circumstances, also if another
160 : : // progress bar is active, for example while adapting row heights.
161 : : // Keep the dummy interpret progress.
162 [ + + ]: 84 : if ( !pGlobalProgress )
163 : : pInterpretProgress = new ScProgress( pDoc->GetDocumentShell(),
164 : : ScGlobal::GetRscString( STR_PROGRESS_CALCULATING ),
165 [ + - ]: 82 : pDoc->GetFormulaCodeInTree()/MIN_NO_CODES_PER_PROGRESS_UPDATE, false, bWait );
166 : 84 : pInterpretDoc = pDoc;
167 : : }
168 : : }
169 : 86 : }
170 : :
171 : :
172 : :
173 : 86 : void ScProgress::DeleteInterpretProgress()
174 : : {
175 [ + - ][ + + ]: 86 : if ( bAllowInterpretProgress && nInterpretProgress )
176 : : {
177 : : /* Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
178 : : is deleted. In rare cases, deletion of 'pInterpretProgress' causes
179 : : a refresh of the sheet window which may call CreateInterpretProgress
180 : : and DeleteInterpretProgress again (from Output::DrawStrings),
181 : : resulting in double deletion of 'pInterpretProgress'. */
182 [ + - ]: 84 : if ( nInterpretProgress == 1 )
183 : : {
184 [ + + ]: 84 : if ( pInterpretProgress != &theDummyInterpretProgress )
185 : : {
186 : : // move pointer to local temporary to avoid double deletion
187 : 82 : ScProgress* pTmpProgress = pInterpretProgress;
188 : 82 : pInterpretProgress = &theDummyInterpretProgress;
189 [ + - ]: 82 : delete pTmpProgress;
190 : : }
191 [ + - ]: 84 : if ( pInterpretDoc )
192 : 84 : pInterpretDoc->DisableIdle( bIdleWasDisabled );
193 : : }
194 : 84 : --nInterpretProgress;
195 : : }
196 [ + - ][ + - ]: 239 : }
197 : :
198 : :
199 : :
200 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|