xref: /AOO41X/main/sfx2/source/bastyp/progress.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sfx2/progress.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
29cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _SBX_HXX //autogen
32cdf0e10cSrcweir #include <basic/sbx.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <svl/eitem.hxx>
36cdf0e10cSrcweir #include <tools/time.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // wg. nRescheduleLocks
39cdf0e10cSrcweir #include "appdata.hxx"
40cdf0e10cSrcweir #include <sfx2/request.hxx>
41cdf0e10cSrcweir #include <sfx2/frame.hxx>
42cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
43cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
44cdf0e10cSrcweir #include <sfx2/objsh.hxx>
45cdf0e10cSrcweir #include <sfx2/app.hxx>
46cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
47cdf0e10cSrcweir #include "sfxtypes.hxx"
48cdf0e10cSrcweir #include <sfx2/docfile.hxx>
49cdf0e10cSrcweir #include "workwin.hxx"
50cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
51cdf0e10cSrcweir #include "bastyp.hrc"
52cdf0e10cSrcweir #include <sfx2/msg.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <time.h>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir using namespace ::com::sun::star::frame;
58cdf0e10cSrcweir using namespace ::com::sun::star::task;
59cdf0e10cSrcweir 
AddNumber_Impl(String & aNumber,sal_uInt32 nArg)60cdf0e10cSrcweir void AddNumber_Impl( String& aNumber, sal_uInt32 nArg )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	if ( nArg >= 10240 )
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		aNumber += String::CreateFromInt32( (sal_uInt16)( ( nArg + 512 ) / 1024 ) );
65cdf0e10cSrcweir 		aNumber += ' ';
66cdf0e10cSrcweir 		aNumber += SfxResId( STR_KB );
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir 	else
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		aNumber += String::CreateFromInt32( nArg );
71cdf0e10cSrcweir 		aNumber += ' ';
72cdf0e10cSrcweir 		aNumber += SfxResId( STR_BYTES );
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir struct SfxProgress_Impl
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     Reference < XStatusIndicator > xStatusInd;
79cdf0e10cSrcweir     String                  aText, aStateText;
80cdf0e10cSrcweir 	sal_uIntPtr					nMax;
81cdf0e10cSrcweir 	clock_t 				nCreate;
82cdf0e10cSrcweir 	clock_t					nNextReschedule;
83cdf0e10cSrcweir 	sal_Bool					bLocked, bAllDocs;
84cdf0e10cSrcweir 	sal_Bool					bWaitMode;
85cdf0e10cSrcweir 	sal_Bool					bAllowRescheduling;
86cdf0e10cSrcweir 	sal_Bool					bRunning;
87cdf0e10cSrcweir 	sal_Bool                    bIsStatusText;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	SfxProgress*            pActiveProgress;
90cdf0e10cSrcweir 	SfxObjectShellRef		xObjSh;
91cdf0e10cSrcweir 	SfxWorkWindow*			pWorkWin;
92cdf0e10cSrcweir     SfxViewFrame*           pView;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 							SfxProgress_Impl( const String& );
95cdf0e10cSrcweir     void                    Enable_Impl( sal_Bool );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir };
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //========================================================================
100cdf0e10cSrcweir 
101cdf0e10cSrcweir #define TIMEOUT_PROGRESS	 	 5L	/* 10th s */
102cdf0e10cSrcweir #define MAXPERCENT_PROGRESS		33
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #define TIMEOUT_RESCHEDULE 		10L	/* 10th s */
105cdf0e10cSrcweir #define MAXPERCENT_RESCHEDULE 	50
106cdf0e10cSrcweir 
107cdf0e10cSrcweir #define Progress
108cdf0e10cSrcweir #include "sfxslots.hxx"
109cdf0e10cSrcweir 
110cdf0e10cSrcweir #define aTypeLibInfo aProgressTypeLibImpl
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //========================================================================
113cdf0e10cSrcweir extern sal_uIntPtr Get10ThSec();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // -----------------------------------------------------------------------
116cdf0e10cSrcweir 
Enable_Impl(sal_Bool bEnable)117cdf0e10cSrcweir void SfxProgress_Impl::Enable_Impl( sal_Bool bEnable )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     SfxObjectShell* pDoc = bAllDocs ? NULL : (SfxObjectShell*) xObjSh;
120cdf0e10cSrcweir 	SfxViewFrame *pFrame= SfxViewFrame::GetFirst(pDoc);
121cdf0e10cSrcweir 	while ( pFrame )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		pFrame->Enable(bEnable);
124cdf0e10cSrcweir         pFrame->GetDispatcher()->Lock( !bEnable );
125cdf0e10cSrcweir 		pFrame = SfxViewFrame::GetNext(*pFrame, pDoc);
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     if ( pView )
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         pView->Enable( bEnable );
131cdf0e10cSrcweir         pView->GetDispatcher()->Lock( !bEnable );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	if ( !pDoc )
135cdf0e10cSrcweir         SFX_APP()->GetAppDispatcher_Impl()->Lock( !bEnable );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir // -----------------------------------------------------------------------
139cdf0e10cSrcweir 
SfxProgress_Impl(const String &)140cdf0e10cSrcweir SfxProgress_Impl::SfxProgress_Impl( const String &/*rTitle*/ )
141cdf0e10cSrcweir     :   pActiveProgress( 0 )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir // -----------------------------------------------------------------------
146cdf0e10cSrcweir 
SfxProgress(SfxObjectShell * pObjSh,const String & rText,sal_uIntPtr nRange,sal_Bool bAll,sal_Bool bWait)147cdf0e10cSrcweir SfxProgress::SfxProgress
148cdf0e10cSrcweir (
149cdf0e10cSrcweir 	SfxObjectShell*	pObjSh, /* SfxObjectShell, an der die Aktion ausgef"uhrt
150cdf0e10cSrcweir 							   wird. Kann NULL sein, dann wird die Applikation
151cdf0e10cSrcweir 							   verwendet */
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	const String&	rText,	/* Text, der in der Statuszeile vor den Statusmonitor
154cdf0e10cSrcweir 							   erscheint */
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	sal_uIntPtr			nRange, /* Maximalwert des Bereiches */
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	sal_Bool			bAll    /* alle Dokumente oder nur das Dokument des ViewFrames
159cdf0e10cSrcweir 							   disablen (sal_False) */
160cdf0e10cSrcweir 	,sal_Bool			bWait   /* initial den Wait-Pointer aktivieren (sal_True) */
161cdf0e10cSrcweir )
162cdf0e10cSrcweir 
163cdf0e10cSrcweir /*	[Beschreibung]
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	Der Konstruktor der Klasse SfxProgress schaltet den als Parameter
166cdf0e10cSrcweir 	"ubergebenen SfxObjectShell und SfxViewFrames, welche dieses Dokument
167cdf0e10cSrcweir 	anzeigen in einen Progress-Mode. D.h. solange eine dieser SfxViewFrame
168cdf0e10cSrcweir 	Instanzen aktiv ist, ist der dazugeh"orige SfxDispatcher und das
169cdf0e10cSrcweir 	dazugeh"orige Window disabled. In der Statuszeile wird ein Balken zur
170cdf0e10cSrcweir 	Fortschritts-Anzeige angezeigt.
171cdf0e10cSrcweir */
172cdf0e10cSrcweir 
173cdf0e10cSrcweir :	pImp( new SfxProgress_Impl( rText ) ),
174cdf0e10cSrcweir 	nVal(0),
175cdf0e10cSrcweir 	bSuspended(sal_True)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	pImp->bRunning = sal_True;
178cdf0e10cSrcweir 	pImp->bAllowRescheduling = Application::IsInExecute();;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	pImp->xObjSh = pObjSh;
181cdf0e10cSrcweir 	pImp->aText = rText;
182cdf0e10cSrcweir 	pImp->nMax = nRange;
183cdf0e10cSrcweir 	pImp->bLocked = sal_False;
184cdf0e10cSrcweir 	pImp->bWaitMode = bWait;
185cdf0e10cSrcweir 	pImp->bIsStatusText = sal_False;
186cdf0e10cSrcweir 	pImp->nCreate = Get10ThSec();
187cdf0e10cSrcweir 	pImp->nNextReschedule = pImp->nCreate;
188cdf0e10cSrcweir 	DBG( DbgOutf( "SfxProgress: created for '%s' at %luds",
189cdf0e10cSrcweir 				  rText.GetBuffer(), pImp->nCreate ) );
190cdf0e10cSrcweir 	pImp->bAllDocs = bAll;
191cdf0e10cSrcweir 	pImp->pWorkWin = 0;
192cdf0e10cSrcweir     pImp->pView = 0;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	pImp->pActiveProgress = GetActiveProgress( pObjSh );
195cdf0e10cSrcweir 	if ( pObjSh )
196cdf0e10cSrcweir 		pObjSh->SetProgress_Impl(this);
197cdf0e10cSrcweir 	else if( !pImp->pActiveProgress )
198cdf0e10cSrcweir         SFX_APP()->SetProgress_Impl(this);
199cdf0e10cSrcweir 	Resume();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // -----------------------------------------------------------------------
203cdf0e10cSrcweir 
~SfxProgress()204cdf0e10cSrcweir SfxProgress::~SfxProgress()
205cdf0e10cSrcweir 
206cdf0e10cSrcweir /*	[Beschreibung]
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	Der Destruktor der Klasse SfxProgress restauriert den alten Zustand;
209cdf0e10cSrcweir 	die Dokumente werden wieder freigeschaltet und die Statuszeile zeigt
210cdf0e10cSrcweir 	wieder Items an.
211cdf0e10cSrcweir */
212cdf0e10cSrcweir 
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	Stop();
215cdf0e10cSrcweir     if ( pImp->xStatusInd.is() )
216cdf0e10cSrcweir         pImp->xStatusInd->end();
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	if( pImp->bIsStatusText == sal_True )
219cdf0e10cSrcweir 		GetpApp()->HideStatusText( );
220cdf0e10cSrcweir 	delete pImp;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // -----------------------------------------------------------------------
224cdf0e10cSrcweir 
Stop()225cdf0e10cSrcweir void SfxProgress::Stop()
226cdf0e10cSrcweir 
227cdf0e10cSrcweir /*	[Beschreibung]
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	Vorzeitiges Beenden des <SfxProgress>.
230cdf0e10cSrcweir */
231cdf0e10cSrcweir 
232cdf0e10cSrcweir {
233cdf0e10cSrcweir     if( pImp->pActiveProgress )
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         if ( pImp->xObjSh.Is() && pImp->xObjSh->GetProgress() == this )
236cdf0e10cSrcweir             pImp->xObjSh->SetProgress_Impl(0);
237cdf0e10cSrcweir         return;
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	if ( !pImp->bRunning )
241cdf0e10cSrcweir 		return;
242cdf0e10cSrcweir 	pImp->bRunning = sal_False;
243cdf0e10cSrcweir 	DBG( DbgOutf( "SfxProgress: destroyed at %luds", Get10ThSec() ) );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	Suspend();
246cdf0e10cSrcweir 	if ( pImp->xObjSh.Is() )
247cdf0e10cSrcweir 		pImp->xObjSh->SetProgress_Impl(0);
248cdf0e10cSrcweir 	else
249cdf0e10cSrcweir         SFX_APP()->SetProgress_Impl(0);
250cdf0e10cSrcweir 	if ( pImp->bLocked )
251cdf0e10cSrcweir         pImp->Enable_Impl(sal_True);
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir // -----------------------------------------------------------------------
255cdf0e10cSrcweir 
SetText(const String &)256cdf0e10cSrcweir void SfxProgress::SetText
257cdf0e10cSrcweir (
258cdf0e10cSrcweir 	const String&	/*	neuer Text */
259cdf0e10cSrcweir )
260cdf0e10cSrcweir 
261cdf0e10cSrcweir /*	[Beschreibung]
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	"Andert den Text, der links neben dem Fortschritts-Balken
264cdf0e10cSrcweir 	angezeigt wird.
265cdf0e10cSrcweir */
266cdf0e10cSrcweir 
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
269cdf0e10cSrcweir     if ( pImp->xStatusInd.is() )
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         pImp->xStatusInd->reset();
272cdf0e10cSrcweir         pImp->xStatusInd->start( pImp->aText, pImp->nMax );
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir // -----------------------------------------------------------------------
277cdf0e10cSrcweir 
GetStateText_Impl() const278cdf0e10cSrcweir const String& SfxProgress::GetStateText_Impl() const
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	return pImp->aStateText;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir // -----------------------------------------------------------------------
284cdf0e10cSrcweir /*
285cdf0e10cSrcweir IMPL_STATIC_LINK( SfxProgress, SetStateHdl, PlugInLoadStatus*, pStatus )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	INetRequest* pReq = 0;
288cdf0e10cSrcweir 	const INetHint *pHint = PTR_CAST( INetHint, pStatus->pHint );
289cdf0e10cSrcweir 	pReq = PTR_CAST( INetRequest, pStatus->pBC );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	String aString;
292cdf0e10cSrcweir 	if( pReq )
293cdf0e10cSrcweir 		aString = SfxMedium::GetStatusString( pHint->GetId(), pReq, pHint );
294cdf0e10cSrcweir 	if( aString.Len() )
295cdf0e10cSrcweir 	{
296cdf0e10cSrcweir 		GetpApp()->ShowStatusText( aString );
297cdf0e10cSrcweir 		if( pThis )
298cdf0e10cSrcweir 			pThis->pImp->bIsStatusText = sal_True;
299cdf0e10cSrcweir 	}
300cdf0e10cSrcweir 	return 0;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir */
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // -----------------------------------------------------------------------
305cdf0e10cSrcweir 
306cdf0e10cSrcweir // muss in AppDaten
307cdf0e10cSrcweir static sal_uIntPtr nLastTime = 0;
308cdf0e10cSrcweir 
TimeOut_Impl(void *,void * pArgV)309cdf0e10cSrcweir long TimeOut_Impl( void*, void* pArgV )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     Timer *pArg = (Timer*)pArgV;
312cdf0e10cSrcweir 	if( Time::GetSystemTicks() - nLastTime > 3000 )
313cdf0e10cSrcweir 	{
314cdf0e10cSrcweir 		GetpApp()->HideStatusText();
315cdf0e10cSrcweir 		nLastTime = 0;
316cdf0e10cSrcweir 		delete pArg;
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 	else pArg->Start();
319cdf0e10cSrcweir 	return 0;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir // -----------------------------------------------------------------------
323cdf0e10cSrcweir 
SetStateText(sal_uLong nNewVal,const String & rNewVal,sal_uLong nNewRange)324cdf0e10cSrcweir sal_Bool SfxProgress::SetStateText
325cdf0e10cSrcweir (
326cdf0e10cSrcweir 	sal_uLong			nNewVal,	/* neuer Wert f"ur die Fortschritts-Anzeige */
327cdf0e10cSrcweir 	const String&	rNewVal,	/* Status als Text */
328cdf0e10cSrcweir 	sal_uLong			nNewRange	/* neuer Maximalwert, 0 f"ur Beibehaltung des alten */
329cdf0e10cSrcweir )
330cdf0e10cSrcweir 
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	pImp->aStateText = rNewVal;
333cdf0e10cSrcweir 	return SetState( nNewVal, nNewRange );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir // -----------------------------------------------------------------------
337cdf0e10cSrcweir 
SetState(sal_uLong nNewVal,sal_uLong nNewRange)338cdf0e10cSrcweir sal_Bool SfxProgress::SetState
339cdf0e10cSrcweir (
340cdf0e10cSrcweir 	sal_uLong	nNewVal,	/* neuer Wert f"ur die Fortschritts-Anzeige */
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	sal_uLong	nNewRange	/* neuer Maximalwert, 0 f"ur Beibehaltung des alten */
343cdf0e10cSrcweir )
344cdf0e10cSrcweir /*	[Beschreibung]
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	Setzen des aktuellen Status; nach einem zeitlichen Versatz
347cdf0e10cSrcweir 	wird Reschedule aufgerufen.
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	[R"uckgabewert]
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	sal_Bool				TRUE
353cdf0e10cSrcweir 						Fortfahren mit der Aktion
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 						FALSE
356cdf0e10cSrcweir 						Abbrechen der Aktion
357cdf0e10cSrcweir */
358cdf0e10cSrcweir 
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	// wurde via Stop-Button angehalten?
361cdf0e10cSrcweir //	if ( pImp->IsCancelled() )
362cdf0e10cSrcweir //		return sal_False;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return sal_True;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 	// neuen Wert "ubernehmen
367cdf0e10cSrcweir 	sal_Bool bOver=sal_False;
368cdf0e10cSrcweir 	nVal = nNewVal;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	// neuer Range?
371cdf0e10cSrcweir 	if ( nNewRange && nNewRange != pImp->nMax )
372cdf0e10cSrcweir 	{
373cdf0e10cSrcweir 		DBG( DbgOutf( "SfxProgress: range changed from %lu to %lu",
374cdf0e10cSrcweir 					  pImp->nMax, nNewRange ) );
375cdf0e10cSrcweir 		pImp->nMax = nNewRange;
376cdf0e10cSrcweir 		bOver = sal_True;
377cdf0e10cSrcweir 	}
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     if ( !pImp->xStatusInd.is() )
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir         // get the active ViewFrame of the document this progress is working on
382cdf0e10cSrcweir         // if it doesn't work on a document, take the current ViewFrame
383cdf0e10cSrcweir         SfxObjectShell* pObjSh = pImp->xObjSh;
384cdf0e10cSrcweir         pImp->pView = SfxViewFrame::Current();
385cdf0e10cSrcweir         DBG_ASSERT( pImp->pView || pObjSh, "Can't make progress bar!");
386cdf0e10cSrcweir         if ( pObjSh && ( !pImp->pView || pObjSh != pImp->pView->GetObjectShell() ) )
387cdf0e10cSrcweir         {
388cdf0e10cSrcweir             // current document does not belong to current ViewFrame; take it's first visible ViewFrame
389cdf0e10cSrcweir             SfxViewFrame* pDocView = SfxViewFrame::GetFirst( pObjSh );
390cdf0e10cSrcweir             if ( pDocView )
391cdf0e10cSrcweir                 pImp->pView = pDocView;
392cdf0e10cSrcweir             else
393cdf0e10cSrcweir             {
394cdf0e10cSrcweir                 // don't show status indicator for hidden documents (only valid while loading)
395cdf0e10cSrcweir                 SfxMedium* pMedium = pObjSh->GetMedium();
396cdf0e10cSrcweir                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
397cdf0e10cSrcweir                 if ( !pHiddenItem || !pHiddenItem->GetValue() )
398cdf0e10cSrcweir                 {
399cdf0e10cSrcweir                     // not in a view, perhaps it's just loading
400cdf0e10cSrcweir                     //SfxFrame* pFrame = pMedium->GetLoadTargetFrame();
401cdf0e10cSrcweir                     //if ( pFrame && pFrame->GetCurrentViewFrame() )
402cdf0e10cSrcweir                     //{
403cdf0e10cSrcweir                         // recycling frame
404cdf0e10cSrcweir                         //pImp->pView = pFrame->GetCurrentViewFrame();
405cdf0e10cSrcweir                     //}
406cdf0e10cSrcweir                     //else
407cdf0e10cSrcweir                     {
408cdf0e10cSrcweir                         SFX_ITEMSET_ARG( pMedium->GetItemSet(), pIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False );
409cdf0e10cSrcweir                         Reference< XStatusIndicator > xInd;
410cdf0e10cSrcweir                         if ( pIndicatorItem && (pIndicatorItem->GetValue()>>=xInd) )
411cdf0e10cSrcweir                             pImp->xStatusInd = xInd;
412cdf0e10cSrcweir                     }
413cdf0e10cSrcweir                 }
414cdf0e10cSrcweir             }
415cdf0e10cSrcweir         }
416cdf0e10cSrcweir         else if ( pImp->pView )
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             pImp->pWorkWin = SFX_APP()->GetWorkWindow_Impl( pImp->pView );
419cdf0e10cSrcweir             if ( pImp->pWorkWin )
420cdf0e10cSrcweir                 pImp->xStatusInd = pImp->pWorkWin->GetStatusIndicator();
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         if ( pImp->xStatusInd.is() )
424cdf0e10cSrcweir         {
425cdf0e10cSrcweir             pImp->xStatusInd->start( pImp->aText, pImp->nMax );
426cdf0e10cSrcweir             pImp->pView = NULL;
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir 	}
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     if ( pImp->xStatusInd.is() )
431cdf0e10cSrcweir     {
432cdf0e10cSrcweir         pImp->xStatusInd->setValue( nNewVal );
433cdf0e10cSrcweir     }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	return sal_True;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir // -----------------------------------------------------------------------
439cdf0e10cSrcweir 
Resume()440cdf0e10cSrcweir void SfxProgress::Resume()
441cdf0e10cSrcweir 
442cdf0e10cSrcweir /*	[Beschreibung]
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 	Nimmt die Anzeige des Status nach einer Unterbrechung wieder auf.
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	[Querverweise]
447cdf0e10cSrcweir 	<SfxProgress::Suspend()>
448cdf0e10cSrcweir */
449cdf0e10cSrcweir 
450cdf0e10cSrcweir {
451cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
452cdf0e10cSrcweir 	if ( bSuspended )
453cdf0e10cSrcweir 	{
454cdf0e10cSrcweir 		DBG( DbgOutf( "SfxProgress: resumed" ) );
455cdf0e10cSrcweir         if ( pImp->xStatusInd.is() )
456cdf0e10cSrcweir         {
457cdf0e10cSrcweir             pImp->xStatusInd->start( pImp->aText, pImp->nMax );
458cdf0e10cSrcweir             pImp->xStatusInd->setValue( nVal );
459cdf0e10cSrcweir         }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 		if ( pImp->bWaitMode )
462cdf0e10cSrcweir 		{
463cdf0e10cSrcweir 			if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
464cdf0e10cSrcweir 			{
465cdf0e10cSrcweir 				for ( SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
466cdf0e10cSrcweir 						pFrame;
467cdf0e10cSrcweir 						pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
468cdf0e10cSrcweir 					pFrame->GetWindow().EnterWait();
469cdf0e10cSrcweir 			}
470cdf0e10cSrcweir 		}
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 		if ( pImp->xObjSh )
473cdf0e10cSrcweir 		{
474cdf0e10cSrcweir             SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
475cdf0e10cSrcweir             if ( pFrame )
476cdf0e10cSrcweir                 pFrame->GetBindings().ENTERREGISTRATIONS();
477cdf0e10cSrcweir 		}
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 		bSuspended = sal_False;
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir // -----------------------------------------------------------------------
484cdf0e10cSrcweir 
Suspend()485cdf0e10cSrcweir void SfxProgress::Suspend()
486cdf0e10cSrcweir 
487cdf0e10cSrcweir /*	[Beschreibung]
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	Unterbricht die Anzeige des Status
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	[Querverweise]
492cdf0e10cSrcweir 	<SfxProgress::Resume()>
493cdf0e10cSrcweir */
494cdf0e10cSrcweir 
495cdf0e10cSrcweir {
496cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
497cdf0e10cSrcweir 	if ( !bSuspended )
498cdf0e10cSrcweir 	{
499cdf0e10cSrcweir 		DBG( DbgOutf( "SfxProgress: suspended" ) );
500cdf0e10cSrcweir 		bSuspended = sal_True;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir         if ( pImp->xStatusInd.is() )
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir             pImp->xStatusInd->reset();
505cdf0e10cSrcweir         }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 		if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
508cdf0e10cSrcweir 		{
509cdf0e10cSrcweir 			for ( SfxViewFrame *pFrame =
510cdf0e10cSrcweir 					SfxViewFrame::GetFirst(pImp->xObjSh);
511cdf0e10cSrcweir 					pFrame;
512cdf0e10cSrcweir 					pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
513cdf0e10cSrcweir 				pFrame->GetWindow().LeaveWait();
514cdf0e10cSrcweir 		}
515cdf0e10cSrcweir 		if ( pImp->xObjSh.Is() )
516cdf0e10cSrcweir 		{
517cdf0e10cSrcweir 			SfxViewFrame *pFrame = SfxViewFrame::GetFirst(pImp->xObjSh);
518cdf0e10cSrcweir             if ( pFrame )
519cdf0e10cSrcweir                 pFrame->GetBindings().LEAVEREGISTRATIONS();
520cdf0e10cSrcweir 		}
521cdf0e10cSrcweir 	}
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // -----------------------------------------------------------------------
525cdf0e10cSrcweir 
Lock()526cdf0e10cSrcweir void SfxProgress::Lock()
527cdf0e10cSrcweir {
528cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
529cdf0e10cSrcweir 	// kein Reschedule bei Embedded-Objekten,
530cdf0e10cSrcweir 	// da wir gegen das OLE Protokoll wehrlos sind
531cdf0e10cSrcweir 	if ( !pImp->xObjSh.Is() )
532cdf0e10cSrcweir 	{
533cdf0e10cSrcweir 		for ( SfxObjectShell *pDocSh = SfxObjectShell::GetFirst();
534cdf0e10cSrcweir 			  pDocSh;
535cdf0e10cSrcweir 			  pDocSh = SfxObjectShell::GetNext(*pDocSh) )
536cdf0e10cSrcweir 		{
537cdf0e10cSrcweir 			SfxObjectCreateMode eMode = pDocSh->GetCreateMode();
538cdf0e10cSrcweir 			if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) ||
539cdf0e10cSrcweir 				 ( eMode == SFX_CREATE_MODE_PREVIEW ) )
540cdf0e10cSrcweir 			{
541cdf0e10cSrcweir 				DBG( DbgOutf( "SfxProgress: not locked because EMBEDDED/PREVIEW found" ) );
542cdf0e10cSrcweir 				pImp->bAllowRescheduling = sal_False;
543cdf0e10cSrcweir 			}
544cdf0e10cSrcweir 		}
545cdf0e10cSrcweir 	}
546cdf0e10cSrcweir 	else
547cdf0e10cSrcweir 	{
548cdf0e10cSrcweir 		SfxObjectCreateMode eMode = pImp->xObjSh->GetCreateMode();
549cdf0e10cSrcweir 		if ( ( eMode == SFX_CREATE_MODE_EMBEDDED ) ||
550cdf0e10cSrcweir 			 ( eMode == SFX_CREATE_MODE_PREVIEW ) )
551cdf0e10cSrcweir 		{
552cdf0e10cSrcweir 			DBG( DbgOutf( "SfxProgress: not locked because ObjectShell is EMBEDDED/PREVIEW" ) );
553cdf0e10cSrcweir 			pImp->bAllowRescheduling = sal_False;
554cdf0e10cSrcweir 		}
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir     pImp->Enable_Impl( sal_False );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 	DBG( DbgOutf( "SfxProgress: locked" ) );
560cdf0e10cSrcweir 	pImp->bLocked = sal_True;
561cdf0e10cSrcweir }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir // -----------------------------------------------------------------------
564cdf0e10cSrcweir 
UnLock()565cdf0e10cSrcweir void SfxProgress::UnLock()
566cdf0e10cSrcweir {
567cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
568cdf0e10cSrcweir 	if ( !pImp->bLocked )
569cdf0e10cSrcweir 		return;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	DBG( DbgOutf( "SfxProgress: unlocked" ) );
572cdf0e10cSrcweir 	pImp->bLocked = sal_False;
573cdf0e10cSrcweir     pImp->Enable_Impl(sal_True);
574cdf0e10cSrcweir }
575cdf0e10cSrcweir 
576cdf0e10cSrcweir // -----------------------------------------------------------------------
577cdf0e10cSrcweir 
Reschedule()578cdf0e10cSrcweir void SfxProgress::Reschedule()
579cdf0e10cSrcweir 
580cdf0e10cSrcweir /*	[Beschreibung]
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 	Reschedule von au"sen rufbar
583cdf0e10cSrcweir 
584cdf0e10cSrcweir */
585cdf0e10cSrcweir 
586cdf0e10cSrcweir {
587cdf0e10cSrcweir 	SFX_STACK(SfxProgress::Reschedule);
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
590cdf0e10cSrcweir     SfxApplication* pApp = SFX_APP();
591cdf0e10cSrcweir     if ( pImp->bLocked && 0 == pApp->Get_Impl()->nRescheduleLocks )
592cdf0e10cSrcweir 	{
593cdf0e10cSrcweir         DBG_ASSERTWARNING( pApp->IsInAsynchronCall_Impl(),
594cdf0e10cSrcweir 							"Reschedule in synchron-call-stack" );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir         SfxAppData_Impl *pAppData = pApp->Get_Impl();
597cdf0e10cSrcweir 		++pAppData->nInReschedule;
598cdf0e10cSrcweir 		Application::Reschedule();
599cdf0e10cSrcweir 		--pAppData->nInReschedule;
600cdf0e10cSrcweir 	}
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir // -----------------------------------------------------------------------
604cdf0e10cSrcweir 
SetWaitMode(sal_Bool bWait)605cdf0e10cSrcweir void SfxProgress::SetWaitMode
606cdf0e10cSrcweir (
607cdf0e10cSrcweir 	sal_Bool	bWait		/*	TRUE
608cdf0e10cSrcweir 							Wartecursor wird verwendet
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 							FALSE
611cdf0e10cSrcweir 							Es wird kein Wartecursor verwendet */
612cdf0e10cSrcweir )
613cdf0e10cSrcweir 
614cdf0e10cSrcweir /*	[Beschreibung]
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 	Wartecursor-Modus umschalten.
617cdf0e10cSrcweir 
618cdf0e10cSrcweir */
619cdf0e10cSrcweir 
620cdf0e10cSrcweir {
621cdf0e10cSrcweir 	if( pImp->pActiveProgress ) return;
622cdf0e10cSrcweir 	if ( !bSuspended && pImp->bWaitMode != bWait )
623cdf0e10cSrcweir 	{
624cdf0e10cSrcweir 		if ( bWait )
625cdf0e10cSrcweir 		{
626cdf0e10cSrcweir 			if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
627cdf0e10cSrcweir 			{
628cdf0e10cSrcweir 				for ( SfxViewFrame *pFrame =
629cdf0e10cSrcweir 						SfxViewFrame::GetFirst(pImp->xObjSh);
630cdf0e10cSrcweir 						pFrame;
631cdf0e10cSrcweir 						pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
632cdf0e10cSrcweir 					pFrame->GetWindow().EnterWait();
633cdf0e10cSrcweir 			}
634cdf0e10cSrcweir 		}
635cdf0e10cSrcweir 		else
636cdf0e10cSrcweir 		{
637cdf0e10cSrcweir 			if ( pImp->xObjSh.Is() && !pImp->bAllDocs )
638cdf0e10cSrcweir 			{
639cdf0e10cSrcweir 				for ( SfxViewFrame *pFrame =
640cdf0e10cSrcweir 						SfxViewFrame::GetFirst(pImp->xObjSh);
641cdf0e10cSrcweir 						pFrame;
642cdf0e10cSrcweir 						pFrame = SfxViewFrame::GetNext( *pFrame, pImp->xObjSh ) )
643cdf0e10cSrcweir 					pFrame->GetWindow().LeaveWait();
644cdf0e10cSrcweir 			}
645cdf0e10cSrcweir 		}
646cdf0e10cSrcweir 	}
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	pImp->bWaitMode = bWait;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // -----------------------------------------------------------------------
652cdf0e10cSrcweir 
GetWaitMode() const653cdf0e10cSrcweir sal_Bool SfxProgress::GetWaitMode() const
654cdf0e10cSrcweir 
655cdf0e10cSrcweir /*	[Beschreibung]
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 	Wartecursor-Modus abfragen.
658cdf0e10cSrcweir 
659cdf0e10cSrcweir */
660cdf0e10cSrcweir 
661cdf0e10cSrcweir {
662cdf0e10cSrcweir 	return pImp->bWaitMode;
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir // -----------------------------------------------------------------------
666cdf0e10cSrcweir 
GetActiveProgress(SfxObjectShell * pDocSh)667cdf0e10cSrcweir SfxProgress* SfxProgress::GetActiveProgress
668cdf0e10cSrcweir (
669cdf0e10cSrcweir 	SfxObjectShell* pDocSh	  /*  <SfxObjectShell>, die nach einem laufenden
670cdf0e10cSrcweir 									<SfxProgress> gefragt werden soll, oder
671cdf0e10cSrcweir 									0, wenn ein f"ur die gesamte Applikation
672cdf0e10cSrcweir 									laufender SfxProgress erfragt werden soll.
673cdf0e10cSrcweir 									Der Pointer braucht nur zum Zeitpunkt des
674cdf0e10cSrcweir 									Aufrufs g"ultig zu sein. */
675cdf0e10cSrcweir )
676cdf0e10cSrcweir 
677cdf0e10cSrcweir /*	[Beschreibung]
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 	Mit dieser Methode kann erfragt werden, ob und welcher <SfxProgress>-
680cdf0e10cSrcweir 	f"ur eine bestimmte Instanz von SfxObjectShell oder gar die gesamte
681cdf0e10cSrcweir 	Applikation zur Zeit aktiv ist. Dies kann z.B. zum Abfangen von
682cdf0e10cSrcweir 	Time-Out-Events etc. verwendet werden.
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 	Anstelle eines Pointer auf den SfxProgress der SfxObjectShell wird
685cdf0e10cSrcweir 	ggf. der auf den SfxProgress der Applikation geliefert, mit der
686cdf0e10cSrcweir 	Abfrage 'SfxProgress::GetActiveProgress(pMyDocSh)' wird also
687cdf0e10cSrcweir 	insofern vorhanden der SfxProgress von 'pMyDocSh' geliefert,
688cdf0e10cSrcweir 	sonst der SfxProgress der Applikation bzw. ein 0-Pointer.
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 	[Anmerkung]
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 	"auft kein SfxProgress an der Applikation und ebenfalls keiner an
694cdf0e10cSrcweir 	der angegebenen SfxObjectShell, dann wird immer 0 zur"uckgeliefert,
695cdf0e10cSrcweir 	auch wenn an einer anderen SfxObjectShell ein SfxProgress l"uft.
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 	[Querverweise]
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	<SfxApplication::GetProgress()const>
701cdf0e10cSrcweir 	<SfxObjectShell::GetProgress()const>
702cdf0e10cSrcweir */
703cdf0e10cSrcweir 
704cdf0e10cSrcweir {
705cdf0e10cSrcweir     if ( !SfxApplication::Get() )
706cdf0e10cSrcweir         return 0;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 	SfxProgress *pProgress = 0;
709cdf0e10cSrcweir 	if ( pDocSh )
710cdf0e10cSrcweir 		pProgress = pDocSh->GetProgress();
711cdf0e10cSrcweir 	if ( !pProgress )
712cdf0e10cSrcweir 		pProgress = SFX_APP()->GetProgress();
713cdf0e10cSrcweir 	return pProgress;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir // -----------------------------------------------------------------------
717cdf0e10cSrcweir 
EnterLock()718cdf0e10cSrcweir void SfxProgress::EnterLock()
719cdf0e10cSrcweir {
720cdf0e10cSrcweir 	SFX_APP()->Get_Impl()->nRescheduleLocks++;
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir // -----------------------------------------------------------------------
724cdf0e10cSrcweir 
LeaveLock()725cdf0e10cSrcweir void SfxProgress::LeaveLock()
726cdf0e10cSrcweir {
727cdf0e10cSrcweir 	SfxAppData_Impl *pImp = SFX_APP()->Get_Impl();
728cdf0e10cSrcweir 	DBG_ASSERT( 0 != pImp->nRescheduleLocks, "SFxProgress::LeaveLock but no locks" );
729cdf0e10cSrcweir 	pImp->nRescheduleLocks--;
730cdf0e10cSrcweir }
731cdf0e10cSrcweir 
732cdf0e10cSrcweir // -----------------------------------------------------------------------
733cdf0e10cSrcweir 
StatusBarManagerGone_Impl(SfxStatusBarManager *)734cdf0e10cSrcweir FASTBOOL SfxProgress::StatusBarManagerGone_Impl
735cdf0e10cSrcweir (
736cdf0e10cSrcweir 	SfxStatusBarManager	*	// dieser <SfxStatusBarManager> wird zerst"ort
737cdf0e10cSrcweir )
738cdf0e10cSrcweir 
739cdf0e10cSrcweir /*	[Beschreibung]
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 	Interne Methode zum Benachrichtigen des SfxProgress, da\s der angegebene
742cdf0e10cSrcweir 	SfxStatusBarManger zerst"ort wird. Damit der Progress ihn loslassen
743cdf0e10cSrcweir 	kann.
744cdf0e10cSrcweir */
745cdf0e10cSrcweir 
746cdf0e10cSrcweir {
747cdf0e10cSrcweir 	return sal_True;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750