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