1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sfx2/progress.hxx>
23 #include <swmodule.hxx>
24 #include <swtypes.hxx>
32 tools::Long nStartValue
,
34 SwDocShell
*pDocShell
;
35 std::unique_ptr
<SfxProgress
> pProgress
;
40 static std::vector
<std::unique_ptr
<SwProgress
>> *pProgressContainer
= nullptr;
42 static SwProgress
*lcl_SwFindProgress( SwDocShell
const *pDocShell
)
44 for (const auto& pTmp
: *pProgressContainer
)
46 if ( pTmp
->pDocShell
== pDocShell
)
52 void StartProgress( TranslateId pMessResId
, tools::Long nStartValue
, tools::Long nEndValue
,
53 SwDocShell
*pDocShell
)
55 if( SW_MOD()->IsEmbeddedLoadSave() )
58 SwProgress
*pProgress
= nullptr;
60 if ( !pProgressContainer
)
61 pProgressContainer
= new std::vector
<std::unique_ptr
<SwProgress
>>;
64 pProgress
= lcl_SwFindProgress( pDocShell
);
66 ++pProgress
->nStartCount
;
71 pProgress
= new SwProgress
;
72 pProgress
->pProgress
.reset( new SfxProgress( pDocShell
,
74 nEndValue
- nStartValue
) );
75 pProgress
->nStartCount
= 1;
76 pProgress
->pDocShell
= pDocShell
;
77 pProgressContainer
->insert( pProgressContainer
->begin(), std::unique_ptr
<SwProgress
>(pProgress
) );
79 pProgress
->nStartValue
= nStartValue
;
82 void SetProgressState( tools::Long nPosition
, SwDocShell
const *pDocShell
)
84 if( pProgressContainer
&& !SW_MOD()->IsEmbeddedLoadSave() )
86 SwProgress
*pProgress
= lcl_SwFindProgress( pDocShell
);
88 pProgress
->pProgress
->SetState(nPosition
- pProgress
->nStartValue
);
92 void EndProgress( SwDocShell
const *pDocShell
)
94 if( !pProgressContainer
|| SW_MOD()->IsEmbeddedLoadSave() )
97 SwProgress
*pProgress
= nullptr;
98 std::vector
<SwProgress
*>::size_type i
;
99 for ( i
= 0; i
< pProgressContainer
->size(); ++i
)
101 SwProgress
*pTmp
= (*pProgressContainer
)[i
].get();
102 if ( pTmp
->pDocShell
== pDocShell
)
109 if ( pProgress
&& 0 == --pProgress
->nStartCount
)
111 pProgress
->pProgress
->Stop();
112 pProgressContainer
->erase( pProgressContainer
->begin() + i
);
113 //#112337# it may happen that the container has been removed
115 if ( pProgressContainer
&& pProgressContainer
->empty() )
117 delete pProgressContainer
;
118 pProgressContainer
= nullptr;
123 void RescheduleProgress( SwDocShell
const *pDocShell
)
125 if( pProgressContainer
&& !SW_MOD()->IsEmbeddedLoadSave() )
127 SwProgress
*pProgress
= lcl_SwFindProgress( pDocShell
);
129 SfxProgress::Reschedule();
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */