1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: progress.cxx,v $
10 * $Revision: 1.7.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include <sfx2/app.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <sfx2/progress.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/sfxsids.hrc>
43 #include <svtools/eitem.hxx>
44 #include <svtools/itemset.hxx>
46 #define SC_PROGRESS_CXX
47 #include "progress.hxx"
48 #include "document.hxx"
50 #include "globstr.hrc"
54 static ScProgress theDummyInterpretProgress
;
55 SfxProgress
* ScProgress::pGlobalProgress
= NULL
;
56 ULONG
ScProgress::nGlobalRange
= 0;
57 ULONG
ScProgress::nGlobalPercent
= 0;
58 BOOL
ScProgress::bGlobalNoUserBreak
= TRUE
;
59 ScProgress
* ScProgress::pInterpretProgress
= &theDummyInterpretProgress
;
60 ScProgress
* ScProgress::pOldInterpretProgress
= NULL
;
61 ULONG
ScProgress::nInterpretProgress
= 0;
62 BOOL
ScProgress::bAllowInterpretProgress
= TRUE
;
63 ScDocument
* ScProgress::pInterpretDoc
;
64 BOOL
ScProgress::bIdleWasDisabled
= FALSE
;
67 BOOL
lcl_IsHiddenDocument( SfxObjectShell
* pObjSh
)
71 SfxMedium
* pMed
= pObjSh
->GetMedium();
74 SfxItemSet
* pSet
= pMed
->GetItemSet();
75 const SfxPoolItem
* pItem
;
76 if ( pSet
&& SFX_ITEM_SET
== pSet
->GetItemState( SID_HIDDEN
, TRUE
, &pItem
) &&
77 ((const SfxBoolItem
*)pItem
)->GetValue() )
84 ScProgress::ScProgress( SfxObjectShell
* pObjSh
, const String
& rText
,
85 ULONG nRange
, BOOL bAllDocs
, BOOL bWait
)
88 if ( pGlobalProgress
|| SfxProgress::GetActiveProgress( NULL
) )
90 if ( lcl_IsHiddenDocument(pObjSh
) )
92 // loading a hidden document while a progress is active is possible - no error
97 DBG_ERROR( "ScProgress: there can be only one!" );
101 else if ( SFX_APP()->IsDowning() )
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 ???
109 else if ( pObjSh
&& ( pObjSh
->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
||
110 pObjSh
->GetProgress() ) )
112 // #62808# no own progress for embedded objects,
113 // #73633# no second progress if the document already has one
119 pProgress
= new SfxProgress( pObjSh
, rText
, nRange
, bAllDocs
, bWait
);
120 pGlobalProgress
= pProgress
;
121 nGlobalRange
= nRange
;
123 bGlobalNoUserBreak
= TRUE
;
128 ScProgress::ScProgress() :
134 ScProgress::~ScProgress()
139 pGlobalProgress
= NULL
;
142 bGlobalNoUserBreak
= TRUE
;
148 void ScProgress::CreateInterpretProgress( ScDocument
* pDoc
, BOOL bWait
)
150 if ( bAllowInterpretProgress
)
152 if ( nInterpretProgress
)
153 nInterpretProgress
++;
154 else if ( pDoc
->GetAutoCalc() )
156 nInterpretProgress
= 1;
157 bIdleWasDisabled
= pDoc
->IsIdleDisabled();
158 pDoc
->DisableIdle( 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 if ( !pGlobalProgress
)
163 pInterpretProgress
= new ScProgress( pDoc
->GetDocumentShell(),
164 ScGlobal::GetRscString( STR_PROGRESS_CALCULATING
),
165 pDoc
->GetFormulaCodeInTree()/MIN_NO_CODES_PER_PROGRESS_UPDATE
, FALSE
, bWait
);
166 pInterpretDoc
= pDoc
;
174 void ScProgress::DeleteInterpretProgress()
176 if ( bAllowInterpretProgress
&& nInterpretProgress
)
178 /* Do not decrement 'nInterpretProgress', before 'pInterpretProgress'
179 is deleted. In rare cases, deletion of 'pInterpretProgress' causes
180 a refresh of the sheet window which may call CreateInterpretProgress
181 and DeleteInterpretProgress again (from Output::DrawStrings),
182 resulting in double deletion of 'pInterpretProgress'. */
183 // if ( --nInterpretProgress == 0 )
184 if ( nInterpretProgress
== 1 )
186 if ( pInterpretProgress
!= &theDummyInterpretProgress
)
188 // move pointer to local temporary to avoid double deletion
189 ScProgress
* pTmpProgress
= pInterpretProgress
;
190 pInterpretProgress
= &theDummyInterpretProgress
;
194 pInterpretDoc
->DisableIdle( bIdleWasDisabled
);
196 --nInterpretProgress
;