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