1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 33 #include <mdiexp.hxx> 34 #include <tools/shl.hxx> 35 #include <tools/string.hxx> 36 #ifndef _SVARRAY_HXX 37 #include <svl/svstdarr.hxx> 38 #endif 39 #include <sfx2/progress.hxx> 40 #ifndef _RESID_HXX //autogen 41 #include <tools/resid.hxx> 42 #endif 43 #include <docsh.hxx> 44 #include <swmodule.hxx> 45 #include "swtypes.hxx" 46 47 class SwDocShell; 48 49 struct SwProgress 50 { 51 long nStartValue, 52 nStartCount; 53 SwDocShell *pDocShell; 54 SfxProgress *pProgress; 55 }; 56 57 static SvPtrarr *pProgressContainer = 0; 58 59 static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell ) 60 { 61 for ( sal_uInt16 i = 0; i < pProgressContainer->Count(); ++i ) 62 { 63 SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i]; 64 if ( pTmp->pDocShell == pDocShell ) 65 return pTmp; 66 } 67 return 0; 68 } 69 70 71 void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue, 72 SwDocShell *pDocShell ) 73 { 74 if( !SW_MOD()->IsEmbeddedLoadSave() ) 75 { 76 SwProgress *pProgress = 0; 77 78 if ( !pProgressContainer ) 79 pProgressContainer = new SvPtrarr( 2, 2 ); 80 else 81 { 82 if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) ) 83 ++pProgress->nStartCount; 84 } 85 if ( !pProgress ) 86 { 87 pProgress = new SwProgress; 88 pProgress->pProgress = new SfxProgress( pDocShell, 89 SW_RESSTR(nMessResId), 90 nEndValue - nStartValue, 91 sal_False, 92 sal_True ); 93 pProgress->nStartCount = 1; 94 pProgress->pDocShell = pDocShell; 95 pProgressContainer->Insert( (void*)pProgress, 0 ); 96 } 97 pProgress->nStartValue = nStartValue; 98 } 99 } 100 101 102 void SetProgressState( long nPosition, SwDocShell *pDocShell ) 103 { 104 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) 105 { 106 SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); 107 if ( pProgress ) 108 pProgress->pProgress->SetState(nPosition - pProgress->nStartValue); 109 } 110 } 111 112 113 void EndProgress( SwDocShell *pDocShell ) 114 { 115 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) 116 { 117 SwProgress *pProgress = 0; 118 sal_uInt16 i; 119 for ( i = 0; i < pProgressContainer->Count(); ++i ) 120 { 121 SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i]; 122 if ( pTmp->pDocShell == pDocShell ) 123 { 124 pProgress = pTmp; 125 break; 126 } 127 } 128 129 if ( pProgress && 0 == --pProgress->nStartCount ) 130 { 131 pProgress->pProgress->Stop(); 132 pProgressContainer->Remove( i ); 133 delete pProgress->pProgress; 134 delete pProgress; 135 //#112337# it may happen that the container has been removed 136 //while rescheduling 137 if ( pProgressContainer && !pProgressContainer->Count() ) 138 delete pProgressContainer, pProgressContainer = 0; 139 } 140 } 141 } 142 143 144 void SetProgressText( sal_uInt16 nId, SwDocShell *pDocShell ) 145 { 146 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) 147 { 148 SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); 149 if ( pProgress ) 150 pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) ); 151 } 152 } 153 154 155 void RescheduleProgress( SwDocShell *pDocShell ) 156 { 157 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() ) 158 { 159 SwProgress *pProgress = lcl_SwFindProgress( pDocShell ); 160 if ( pProgress ) 161 pProgress->pProgress->Reschedule(); 162 } 163 } 164 165 166