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