Update ooo320-m1
[ooovba.git] / sw / source / ui / app / mainwn.cxx
blobc86509835bd481275b9a373d3c0b06fa58b71eed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mainwn.cxx,v $
10 * $Revision: 1.11 $
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_sw.hxx"
36 #include <mdiexp.hxx>
37 #include <tools/shl.hxx>
38 #include <tools/string.hxx>
39 #ifndef _SVARRAY_HXX
40 #include <svtools/svstdarr.hxx>
41 #endif
42 #include <sfx2/progress.hxx>
43 #ifndef _RESID_HXX //autogen
44 #include <tools/resid.hxx>
45 #endif
46 #include <docsh.hxx>
47 #include <swmodule.hxx>
48 #include "swtypes.hxx"
50 class SwDocShell;
52 struct SwProgress
54 long nStartValue,
55 nStartCount;
56 SwDocShell *pDocShell;
57 SfxProgress *pProgress;
60 static SvPtrarr *pProgressContainer = 0;
62 static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell )
64 for ( USHORT i = 0; i < pProgressContainer->Count(); ++i )
66 SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
67 if ( pTmp->pDocShell == pDocShell )
68 return pTmp;
70 return 0;
74 void StartProgress( USHORT nMessResId, long nStartValue, long nEndValue,
75 SwDocShell *pDocShell )
77 if( !SW_MOD()->IsEmbeddedLoadSave() )
79 SwProgress *pProgress = 0;
81 if ( !pProgressContainer )
82 pProgressContainer = new SvPtrarr( 2, 2 );
83 else
85 if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) )
86 ++pProgress->nStartCount;
88 if ( !pProgress )
90 pProgress = new SwProgress;
91 pProgress->pProgress = new SfxProgress( pDocShell,
92 SW_RESSTR(nMessResId),
93 nEndValue - nStartValue,
94 FALSE,
95 TRUE );
96 pProgress->nStartCount = 1;
97 pProgress->pDocShell = pDocShell;
98 pProgressContainer->Insert( (void*)pProgress, 0 );
100 pProgress->nStartValue = nStartValue;
105 void SetProgressState( long nPosition, SwDocShell *pDocShell )
107 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
109 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
110 if ( pProgress )
111 pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
116 void EndProgress( SwDocShell *pDocShell )
118 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
120 SwProgress *pProgress = 0;
121 USHORT i;
122 for ( i = 0; i < pProgressContainer->Count(); ++i )
124 SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
125 if ( pTmp->pDocShell == pDocShell )
127 pProgress = pTmp;
128 break;
132 if ( pProgress && 0 == --pProgress->nStartCount )
134 pProgress->pProgress->Stop();
135 pProgressContainer->Remove( i );
136 delete pProgress->pProgress;
137 delete pProgress;
138 //#112337# it may happen that the container has been removed
139 //while rescheduling
140 if ( pProgressContainer && !pProgressContainer->Count() )
141 delete pProgressContainer, pProgressContainer = 0;
147 void SetProgressText( USHORT nId, SwDocShell *pDocShell )
149 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
151 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
152 if ( pProgress )
153 pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) );
158 void RescheduleProgress( SwDocShell *pDocShell )
160 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
162 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
163 if ( pProgress )
164 pProgress->pProgress->Reschedule();