Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <mdiexp.hxx>
21 : #include <tools/shl.hxx>
22 : #include <sfx2/progress.hxx>
23 : #include <tools/resid.hxx>
24 : #include <docsh.hxx>
25 : #include <swmodule.hxx>
26 : #include "swtypes.hxx"
27 :
28 : class SwDocShell;
29 :
30 : struct SwProgress
31 : {
32 : long nStartValue,
33 : nStartCount;
34 : SwDocShell *pDocShell;
35 : SfxProgress *pProgress;
36 : };
37 :
38 : static std::vector<SwProgress*> *pProgressContainer = 0;
39 :
40 180 : static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell )
41 : {
42 180 : for ( sal_uInt16 i = 0; i < pProgressContainer->size(); ++i )
43 : {
44 180 : SwProgress *pTmp = (*pProgressContainer)[i];
45 180 : if ( pTmp->pDocShell == pDocShell )
46 180 : return pTmp;
47 : }
48 0 : return 0;
49 : }
50 :
51 :
52 88 : void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue,
53 : SwDocShell *pDocShell )
54 : {
55 88 : if( !SW_MOD()->IsEmbeddedLoadSave() )
56 : {
57 61 : SwProgress *pProgress = 0;
58 :
59 61 : if ( !pProgressContainer )
60 61 : pProgressContainer = new std::vector<SwProgress*>;
61 : else
62 : {
63 0 : if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) )
64 0 : ++pProgress->nStartCount;
65 : }
66 61 : if ( !pProgress )
67 : {
68 61 : pProgress = new SwProgress;
69 : pProgress->pProgress = new SfxProgress( pDocShell,
70 : SW_RESSTR(nMessResId),
71 : nEndValue - nStartValue,
72 : sal_False,
73 61 : sal_True );
74 61 : pProgress->nStartCount = 1;
75 61 : pProgress->pDocShell = pDocShell;
76 61 : pProgressContainer->insert( pProgressContainer->begin(), pProgress );
77 : }
78 61 : pProgress->nStartValue = nStartValue;
79 : }
80 88 : }
81 :
82 :
83 2450 : void SetProgressState( long nPosition, SwDocShell *pDocShell )
84 : {
85 2450 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
86 : {
87 166 : SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
88 166 : if ( pProgress )
89 166 : pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
90 : }
91 2450 : }
92 :
93 :
94 88 : void EndProgress( SwDocShell *pDocShell )
95 : {
96 88 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
97 : {
98 61 : SwProgress *pProgress = 0;
99 : sal_uInt16 i;
100 61 : for ( i = 0; i < pProgressContainer->size(); ++i )
101 : {
102 61 : SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
103 61 : if ( pTmp->pDocShell == pDocShell )
104 : {
105 61 : pProgress = pTmp;
106 61 : break;
107 : }
108 : }
109 :
110 61 : if ( pProgress && 0 == --pProgress->nStartCount )
111 : {
112 61 : pProgress->pProgress->Stop();
113 61 : pProgressContainer->erase( pProgressContainer->begin() + i );
114 61 : delete pProgress->pProgress;
115 61 : delete pProgress;
116 : //#112337# it may happen that the container has been removed
117 : //while rescheduling
118 61 : if ( pProgressContainer && pProgressContainer->empty() )
119 61 : delete pProgressContainer, pProgressContainer = 0;
120 : }
121 : }
122 88 : }
123 :
124 :
125 0 : void SetProgressText( sal_uInt16 nId, SwDocShell *pDocShell )
126 : {
127 0 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
128 : {
129 0 : SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
130 0 : if ( pProgress )
131 0 : pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) );
132 : }
133 0 : }
134 :
135 :
136 14 : void RescheduleProgress( SwDocShell *pDocShell )
137 : {
138 14 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
139 : {
140 14 : SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
141 14 : if ( pProgress )
142 14 : pProgress->pProgress->Reschedule();
143 : }
144 14 : }
145 :
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|