1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mainwn.cxx,v $
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"
37 #include <tools/shl.hxx>
38 #include <tools/string.hxx>
40 #include <svtools/svstdarr.hxx>
42 #include <sfx2/progress.hxx>
43 #ifndef _RESID_HXX //autogen
44 #include <tools/resid.hxx>
47 #include <swmodule.hxx>
48 #include "swtypes.hxx"
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
)
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 );
85 if ( 0 != (pProgress
= lcl_SwFindProgress( pDocShell
)) )
86 ++pProgress
->nStartCount
;
90 pProgress
= new SwProgress
;
91 pProgress
->pProgress
= new SfxProgress( pDocShell
,
92 SW_RESSTR(nMessResId
),
93 nEndValue
- nStartValue
,
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
);
111 pProgress
->pProgress
->SetState(nPosition
- pProgress
->nStartValue
);
116 void EndProgress( SwDocShell
*pDocShell
)
118 if( pProgressContainer
&& !SW_MOD()->IsEmbeddedLoadSave() )
120 SwProgress
*pProgress
= 0;
122 for ( i
= 0; i
< pProgressContainer
->Count(); ++i
)
124 SwProgress
*pTmp
= (SwProgress
*)(*pProgressContainer
)[i
];
125 if ( pTmp
->pDocShell
== pDocShell
)
132 if ( pProgress
&& 0 == --pProgress
->nStartCount
)
134 pProgress
->pProgress
->Stop();
135 pProgressContainer
->Remove( i
);
136 delete pProgress
->pProgress
;
138 //#112337# it may happen that the container has been removed
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
);
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
);
164 pProgress
->pProgress
->Reschedule();