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 638 : static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell )
41 : {
42 638 : for ( sal_uInt16 i = 0; i < pProgressContainer->size(); ++i )
43 : {
44 638 : SwProgress *pTmp = (*pProgressContainer)[i];
45 638 : if ( pTmp->pDocShell == pDocShell )
46 638 : return pTmp;
47 : }
48 0 : return 0;
49 : }
50 :
51 :
52 202 : void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue,
53 : SwDocShell *pDocShell )
54 : {
55 202 : if( !SW_MOD()->IsEmbeddedLoadSave() )
56 : {
57 148 : SwProgress *pProgress = 0;
58 :
59 148 : if ( !pProgressContainer )
60 148 : pProgressContainer = new std::vector<SwProgress*>;
61 : else
62 : {
63 0 : if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) )
64 0 : ++pProgress->nStartCount;
65 : }
66 148 : if ( !pProgress )
67 : {
68 148 : pProgress = new SwProgress;
69 : pProgress->pProgress = new SfxProgress( pDocShell,
70 : SW_RESSTR(nMessResId),
71 : nEndValue - nStartValue,
72 : sal_False,
73 148 : sal_True );
74 148 : pProgress->nStartCount = 1;
75 148 : pProgress->pDocShell = pDocShell;
76 148 : pProgressContainer->insert( pProgressContainer->begin(), pProgress );
77 : }
78 148 : pProgress->nStartValue = nStartValue;
79 : }
80 202 : }
81 :
82 :
83 5132 : void SetProgressState( long nPosition, SwDocShell *pDocShell )
84 : {
85 5132 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
86 : {
87 570 : SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
88 570 : if ( pProgress )
89 570 : pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
90 : }
91 5132 : }
92 :
93 :
94 202 : void EndProgress( SwDocShell *pDocShell )
95 : {
96 202 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
97 : {
98 148 : SwProgress *pProgress = 0;
99 : sal_uInt16 i;
100 148 : for ( i = 0; i < pProgressContainer->size(); ++i )
101 : {
102 148 : SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
103 148 : if ( pTmp->pDocShell == pDocShell )
104 : {
105 148 : pProgress = pTmp;
106 148 : break;
107 : }
108 : }
109 :
110 148 : if ( pProgress && 0 == --pProgress->nStartCount )
111 : {
112 148 : pProgress->pProgress->Stop();
113 148 : pProgressContainer->erase( pProgressContainer->begin() + i );
114 148 : delete pProgress->pProgress;
115 148 : delete pProgress;
116 : //#112337# it may happen that the container has been removed
117 : //while rescheduling
118 148 : if ( pProgressContainer && pProgressContainer->empty() )
119 148 : delete pProgressContainer, pProgressContainer = 0;
120 : }
121 : }
122 202 : }
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 68 : void RescheduleProgress( SwDocShell *pDocShell )
137 : {
138 68 : if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
139 : {
140 68 : SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
141 68 : if ( pProgress )
142 68 : pProgress->pProgress->Reschedule();
143 : }
144 68 : }
145 :
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|