LibreOffice Module sfx2 (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
21#include <sfx2/progress.hxx>
22#include <com/sun/star/uno/Reference.hxx>
23#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
24
25#include <svl/eitem.hxx>
26#include <tools/debug.hxx>
27#include <sal/log.hxx>
28
29#include <appdata.hxx>
30#include <sfx2/bindings.hxx>
31#include <sfx2/frame.hxx>
32#include <sfx2/viewfrm.hxx>
33#include <sfx2/objsh.hxx>
34#include <sfx2/app.hxx>
35#include <sfxtypes.hxx>
36#include <sfx2/docfile.hxx>
37#include <sfx2/sfxsids.hrc>
38#include <workwin.hxx>
40#include <time.h>
41
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::task;
44
46{
47 Reference < XStatusIndicator > xStatusInd;
48 OUString aText;
49 sal_uInt32 nMax;
50 clock_t nCreate;
53
58
59 explicit SfxProgress_Impl();
60};
61
63 : nMax(0)
64 , nCreate(0)
65 , bWaitMode(false)
66 , bRunning(false)
67 , pActiveProgress(nullptr)
68 , pWorkWin(nullptr)
69 , pView(nullptr)
70{
71}
72
73
75(
76 SfxObjectShell* pObjSh, /* The action is performed on the
77 SfxObjectShell which can be NULL.
78 When it is then the application will be
79 used */
80
81 const OUString& rText, /* Text, which appears before the Statusmonitor
82 in the status line */
83
84 sal_uInt32 nRange, /* Max value for range */
85
86 bool bWait /* Activate the wait-Pointer initially (TRUE) */
87)
88
89/* [Description]
90
91 The constructor of the class SfxProgress switches the SfxObjectShell
92 passed as parameter and SfxViewFrames which display this document in
93 a progress mode. Ie as long as one of those SfxViewFrame instances is
94 active the associated SfxDispatcher and associated Window is disabled.
95 A progress-bar will be displayed in the status bar,
96*/
97
98: pImpl( new SfxProgress_Impl ),
99 nVal(0),
100 bSuspended(true)
101{
102 pImpl->bRunning = true;
103
104 pImpl->xObjSh = pObjSh;
105 pImpl->aText = rText;
106 pImpl->nMax = nRange;
107 pImpl->bWaitMode = bWait;
108 pImpl->nCreate = Get10ThSec();
109 SAL_INFO(
110 "sfx.bastyp",
111 "SfxProgress: created for '" << rText << "' at " << pImpl->nCreate
112 << "ds");
113 pImpl->pWorkWin = nullptr;
114 pImpl->pView = nullptr;
115
116 pImpl->pActiveProgress = GetActiveProgress( pObjSh );
117 if ( pObjSh )
118 pObjSh->SetProgress_Impl(this);
119 else if( !pImpl->pActiveProgress )
121 Resume();
122}
123
124
126
127/* [Description]
128
129 The destructor of the class SfxProgress restores the old status,
130 the documents are released again and the status bar shows the items again.
131*/
132
133{
134 Stop();
135 if ( pImpl->xStatusInd.is() )
136 pImpl->xStatusInd->end();
137}
138
139
141
142/* [Description]
143
144 Early Exit of <SfxProgress>.
145*/
146
147{
148 if( pImpl->pActiveProgress )
149 {
150 if ( pImpl->xObjSh.is() && pImpl->xObjSh->GetProgress() == this )
151 pImpl->xObjSh->SetProgress_Impl(nullptr);
152 return;
153 }
154
155 if ( !pImpl->bRunning )
156 return;
157 pImpl->bRunning = false;
158 SAL_INFO(
159 "sfx.bastyp", "SfxProgress: destroyed at " << Get10ThSec() << "ds");
160
161 Suspend();
162 if ( pImpl->xObjSh.is() )
163 pImpl->xObjSh->SetProgress_Impl(nullptr);
164 else
165 SfxGetpApp()->SetProgress_Impl(nullptr);
166}
167
169(
170 sal_uInt32 nNewVal, /* new value for the progress bar */
171
172 sal_uInt32 nNewRange /* new maximum value, 0 for retaining the old */
173)
174/* [Description]
175
176 Setting the current status, after a time delay Reschedule is called.
177*/
178
179{
180 if( pImpl->pActiveProgress ) return;
181
182 nVal = nNewVal;
183
184 // new Range?
185 if ( nNewRange && nNewRange != pImpl->nMax )
186 {
187 SAL_INFO(
188 "sfx.bastyp",
189 "SfxProgress: range changed from " << pImpl->nMax << " to "
190 << nNewRange);
191 pImpl->nMax = nNewRange;
192 }
193
194 if ( !pImpl->xStatusInd.is() )
195 {
196 // get the active ViewFrame of the document this progress is working on
197 // if it doesn't work on a document, take the current ViewFrame
198 SfxObjectShell* pObjSh = pImpl->xObjSh.get();
199 pImpl->pView = SfxViewFrame::Current();
200 DBG_ASSERT( pImpl->pView || pObjSh, "Can't make progress bar!");
201 if ( pObjSh && ( !pImpl->pView || pObjSh != pImpl->pView->GetObjectShell() ) )
202 {
203 // current document does not belong to current ViewFrame; take it's first visible ViewFrame
204 SfxViewFrame* pDocView = SfxViewFrame::GetFirst( pObjSh );
205 if ( pDocView )
206 pImpl->pView = pDocView;
207 else
208 {
209 // don't show status indicator for hidden documents (only valid while loading)
210 SfxMedium* pMedium = pObjSh->GetMedium();
211 const SfxBoolItem* pHiddenItem = pMedium->GetItemSet().GetItem(SID_HIDDEN, false);
212 if ( !pHiddenItem || !pHiddenItem->GetValue() )
213 {
214 const SfxUnoAnyItem* pIndicatorItem = pMedium->GetItemSet().GetItem(SID_PROGRESS_STATUSBAR_CONTROL, false);
215 Reference< XStatusIndicator > xInd;
216 if ( pIndicatorItem && (pIndicatorItem->GetValue()>>=xInd) )
217 pImpl->xStatusInd = xInd;
218 }
219 }
220 }
221 else if ( pImpl->pView )
222 {
223 pImpl->pWorkWin = SfxGetpApp()->GetWorkWindow_Impl( pImpl->pView );
224 if ( pImpl->pWorkWin )
225 pImpl->xStatusInd = pImpl->pWorkWin->GetStatusIndicator();
226 }
227
228 if ( pImpl->xStatusInd.is() )
229 {
230 pImpl->xStatusInd->start( pImpl->aText, pImpl->nMax );
231 pImpl->pView = nullptr;
232 }
233 }
234
235 if ( pImpl->xStatusInd.is() )
236 {
237 pImpl->xStatusInd->setValue( nNewVal );
238 }
239}
240
241
243
244/* [Description]
245
246 Resumed the status of the display after an interrupt.
247
248 [Cross-reference]
249
250 <SfxProgress::Suspend()>
251*/
252
253{
254 if( pImpl->pActiveProgress ) return;
255 if ( !bSuspended )
256 return;
257
258 SAL_INFO("sfx.bastyp", "SfxProgress: resumed");
259 if ( pImpl->xStatusInd.is() )
260 {
261 pImpl->xStatusInd->start( pImpl->aText, pImpl->nMax );
262 pImpl->xStatusInd->setValue( nVal );
263 }
264
265 if ( pImpl->bWaitMode )
266 {
267 if ( pImpl->xObjSh.is() )
268 {
269 for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImpl->xObjSh.get() );
270 pFrame;
271 pFrame = SfxViewFrame::GetNext( *pFrame, pImpl->xObjSh.get() ) )
272 pFrame->GetWindow().EnterWait();
273 }
274 }
275
276 if ( pImpl->xObjSh.is() )
277 {
278 SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImpl->xObjSh.get());
279 if ( pFrame )
280 pFrame->GetBindings().ENTERREGISTRATIONS();
281 }
282
283 bSuspended = false;
284}
285
286
288
289/* [Description]
290
291 Interrupts the status of the display
292
293 [Cross-reference]
294
295 <SfxProgress::Resume()>
296*/
297
298{
299 if( pImpl->pActiveProgress ) return;
300 if ( bSuspended )
301 return;
302
303 SAL_INFO("sfx.bastyp", "SfxProgress: suspended");
304 bSuspended = true;
305
306 if ( pImpl->xStatusInd.is() )
307 {
308 pImpl->xStatusInd->reset();
309 }
310
311 if ( pImpl->xObjSh.is() )
312 {
313 for ( SfxViewFrame *pFrame =
314 SfxViewFrame::GetFirst(pImpl->xObjSh.get());
315 pFrame;
316 pFrame = SfxViewFrame::GetNext( *pFrame, pImpl->xObjSh.get() ) )
317 pFrame->GetWindow().LeaveWait();
318 }
319 if ( pImpl->xObjSh.is() )
320 {
321 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pImpl->xObjSh.get() );
322 if ( pFrame )
323 pFrame->GetBindings().LEAVEREGISTRATIONS();
324 }
325}
326
327
329
330/* [Description]
331
332 Reschedule, callable from the outside
333*/
334
335{
337}
338
339
341(
342 SfxObjectShell const * pDocSh /* the <SfxObjectShell>, which should be
343 queried after a current <SfxProgress>,
344 or 0 if a current SfxProgress for the
345 entire application should be obtained.
346 The pointer only needs at the time of
347 the call to be valid.
348 */
349)
350
351/* [Description]
352
353 This method is used to check whether and which <SfxProgress> is currently
354 active for a specific instance of SfxObjectShell or even an entire
355 application. This can for example be used to check for Time-Out-Events, etc.
356
357 Instead of a pointer to the SfxProgress the SfxObjectShell may be
358 pointed at the SfxProgress of the application, with the query
359 'SfxProgress:: GetActiveProgress (pMyDocSh)' thus the current
360 SfxProgress of 'pMyDocSh' is delivered, otherwise the SfxProgress of
361 the application or a 0-pointer.
362
363 [Note]
364
365 If no SfxProgress is running in the application and also not at the
366 specified SfxObjectShell, then this method will always return 0,
367 even if one SfxProgress runs on another SfxObjectShell.
368
369 [Cross-reference]
370
371 <SfxApplication::GetProgress()const>
372 <SfxObjectShell::GetProgress()const>
373*/
374
375{
376 if ( !SfxApplication::Get() )
377 return nullptr;
378
379 SfxProgress *pProgress = nullptr;
380 if ( pDocSh )
381 pProgress = pDocSh->GetProgress();
382 if ( !pProgress )
383 pProgress = SfxGetpApp()->GetProgress();
384 return pProgress;
385}
386
387
389{
391}
392
393
395{
397 DBG_ASSERT( 0 != pImp->nRescheduleLocks, "SFxProgress::LeaveLock but no locks" );
398 pImp->nRescheduleLocks--;
399}
400
401/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
sal_uInt16 nRescheduleLocks
Definition: appdata.hxx:94
SAL_DLLPRIVATE void SetProgress_Impl(SfxProgress *)
Definition: app.cxx:294
SAL_DLLPRIVATE SfxAppData_Impl * Get_Impl() const
Definition: app.hxx:169
static SfxApplication * Get()
Definition: app.cxx:70
SfxProgress * GetProgress() const
Returns the running SfxProgress for the entire application or 0 if none is running for the entire app...
Definition: appmisc.cxx:83
SAL_DLLPRIVATE SfxWorkWindow * GetWorkWindow_Impl(const SfxViewFrame *pFrame) const
Definition: appchild.cxx:56
bool GetValue() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
SfxItemSet & GetItemSet() const
Definition: docfile.cxx:3647
SfxProgress * GetProgress() const
Definition: objmisc.cxx:877
SfxMedium * GetMedium() const
Definition: objsh.hxx:261
SAL_DLLPRIVATE void SetProgress_Impl(SfxProgress *pProgress)
Definition: objmisc.cxx:884
static void Reschedule()
Definition: progress.cxx:328
std::unique_ptr< SfxProgress_Impl > pImpl
Definition: progress.hxx:34
static SfxProgress * GetActiveProgress(SfxObjectShell const *pDocSh=nullptr)
Definition: progress.cxx:341
sal_uInt32 nVal
Definition: progress.hxx:35
void Resume()
Definition: progress.cxx:242
bool bSuspended
Definition: progress.hxx:36
static void LeaveLock()
Definition: progress.cxx:394
void Stop()
Definition: progress.cxx:140
SfxProgress(SfxObjectShell *pObjSh, const OUString &rText, sal_uInt32 nRange, bool bWait=true)
Definition: progress.cxx:75
void Suspend()
Definition: progress.cxx:287
static void EnterLock()
Definition: progress.cxx:388
void SetState(sal_uInt32 nVal, sal_uInt32 nNewRange=0)
Definition: progress.cxx:169
virtual ~SfxProgress()
Definition: progress.cxx:125
const css::uno::Any & GetValue() const
Definition: frame.hxx:175
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
Definition: viewfrm.cxx:1975
SfxBindings & GetBindings()
Definition: viewfrm.hxx:110
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:2006
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:1983
#define DBG_ASSERT(sCon, aError)
#define SAL_INFO(area, stream)
sal_uInt32 Get10ThSec()
#define SFX_STACK(s)
Definition: sfxtypes.hxx:44
SfxViewFrame * pView
Definition: progress.cxx:57
Reference< XStatusIndicator > xStatusInd
Definition: progress.cxx:47
SfxObjectShellRef xObjSh
Definition: progress.cxx:55
clock_t nCreate
Definition: progress.cxx:50
OUString aText
Definition: progress.cxx:48
SfxProgress * pActiveProgress
Definition: progress.cxx:54
sal_uInt32 nMax
Definition: progress.cxx:49
SfxWorkWindow * pWorkWin
Definition: progress.cxx:56