xref: /aoo42x/main/sw/source/ui/app/mainwn.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 
29 #include <mdiexp.hxx>
30 #include <tools/shl.hxx>
31 #include <tools/string.hxx>
32 #ifndef _SVARRAY_HXX
33 #include <svl/svstdarr.hxx>
34 #endif
35 #include <sfx2/progress.hxx>
36 #ifndef _RESID_HXX //autogen
37 #include <tools/resid.hxx>
38 #endif
39 #include <docsh.hxx>
40 #include <swmodule.hxx>
41 #include "swtypes.hxx"
42 
43 class SwDocShell;
44 
45 struct SwProgress
46 {
47 	long nStartValue,
48 		 nStartCount;
49 	SwDocShell  *pDocShell;
50 	SfxProgress *pProgress;
51 };
52 
53 static SvPtrarr *pProgressContainer = 0;
54 
lcl_SwFindProgress(SwDocShell * pDocShell)55 static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell )
56 {
57 	for ( sal_uInt16 i = 0; i < pProgressContainer->Count(); ++i )
58 	{
59 		SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
60 		if ( pTmp->pDocShell == pDocShell )
61 			return pTmp;
62 	}
63 	return 0;
64 }
65 
66 
StartProgress(sal_uInt16 nMessResId,long nStartValue,long nEndValue,SwDocShell * pDocShell)67 void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue,
68 					SwDocShell *pDocShell )
69 {
70 	if( !SW_MOD()->IsEmbeddedLoadSave() )
71 	{
72 		SwProgress *pProgress = 0;
73 
74 		if ( !pProgressContainer )
75 			pProgressContainer = new SvPtrarr( 2, 2 );
76 		else
77 		{
78 			if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) )
79 				++pProgress->nStartCount;
80 		}
81 		if ( !pProgress )
82 		{
83 			pProgress = new SwProgress;
84 			pProgress->pProgress = new SfxProgress( pDocShell,
85 													SW_RESSTR(nMessResId),
86 													nEndValue - nStartValue,
87 													sal_False,
88 													sal_True );
89 			pProgress->nStartCount = 1;
90 			pProgress->pDocShell = pDocShell;
91 			pProgressContainer->Insert( (void*)pProgress, 0 );
92 		}
93 		pProgress->nStartValue = nStartValue;
94 	}
95 }
96 
97 
SetProgressState(long nPosition,SwDocShell * pDocShell)98 void SetProgressState( long nPosition, SwDocShell *pDocShell )
99 {
100 	if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
101 	{
102 		SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
103 		if ( pProgress )
104 			pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
105 	}
106 }
107 
108 
EndProgress(SwDocShell * pDocShell)109 void EndProgress( SwDocShell *pDocShell )
110 {
111 	if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
112 	{
113 		SwProgress *pProgress = 0;
114 		sal_uInt16 i;
115 		for ( i = 0; i < pProgressContainer->Count(); ++i )
116 		{
117 			SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
118 			if ( pTmp->pDocShell == pDocShell )
119 			{
120 				pProgress = pTmp;
121 				break;
122 			}
123 		}
124 
125 		if ( pProgress && 0 == --pProgress->nStartCount )
126 		{
127 			pProgress->pProgress->Stop();
128 			pProgressContainer->Remove( i );
129 			delete pProgress->pProgress;
130 			delete pProgress;
131             //#112337# it may happen that the container has been removed
132             //while rescheduling
133             if ( pProgressContainer && !pProgressContainer->Count() )
134 				delete pProgressContainer, pProgressContainer = 0;
135 		}
136 	}
137 }
138 
139 
SetProgressText(sal_uInt16 nId,SwDocShell * pDocShell)140 void SetProgressText( sal_uInt16 nId, SwDocShell *pDocShell )
141 {
142 	if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
143 	{
144 		SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
145 		if ( pProgress )
146 			pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) );
147 	}
148 }
149 
150 
RescheduleProgress(SwDocShell * pDocShell)151 void RescheduleProgress( SwDocShell *pDocShell )
152 {
153 	if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
154 	{
155 		SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
156 		if ( pProgress )
157 			pProgress->pProgress->Reschedule();
158 	}
159 }
160 
161 
162