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