LibreOffice Module sw (master) 1
mainwn.cxx
Go to the documentation of this file.
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 <docsh.hxx>
23#include <swmodule.hxx>
24#include <swtypes.hxx>
25
26class SwDocShell;
27
28namespace {
29
30struct SwProgress
31{
32 tools::Long nStartValue,
33 nStartCount;
34 SwDocShell *pDocShell;
35 std::unique_ptr<SfxProgress> pProgress;
36};
37
38}
39
40static std::vector<std::unique_ptr<SwProgress>> *pProgressContainer = nullptr;
41
42static SwProgress *lcl_SwFindProgress( SwDocShell const *pDocShell )
43{
44 for (const auto& pTmp : *pProgressContainer)
45 {
46 if ( pTmp->pDocShell == pDocShell )
47 return pTmp.get();
48 }
49 return nullptr;
50}
51
52void StartProgress( TranslateId pMessResId, tools::Long nStartValue, tools::Long nEndValue,
53 SwDocShell *pDocShell )
54{
55 if( SW_MOD()->IsEmbeddedLoadSave() )
56 return;
57
58 SwProgress *pProgress = nullptr;
59
60 if ( !pProgressContainer )
61 pProgressContainer = new std::vector<std::unique_ptr<SwProgress>>;
62 else
63 {
64 pProgress = lcl_SwFindProgress( pDocShell );
65 if ( pProgress )
66 ++pProgress->nStartCount;
67 }
68
69 if ( !pProgress )
70 {
71 pProgress = new SwProgress;
72 pProgress->pProgress.reset( new SfxProgress( pDocShell,
73 SwResId(pMessResId),
74 nEndValue - nStartValue ) );
75 pProgress->nStartCount = 1;
76 pProgress->pDocShell = pDocShell;
77 pProgressContainer->insert( pProgressContainer->begin(), std::unique_ptr<SwProgress>(pProgress) );
78 }
79 pProgress->nStartValue = nStartValue;
80}
81
82void SetProgressState( tools::Long nPosition, SwDocShell const *pDocShell )
83{
84 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
85 {
86 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
87 if ( pProgress )
88 pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
89 }
90}
91
92void EndProgress( SwDocShell const *pDocShell )
93{
94 if( !pProgressContainer || SW_MOD()->IsEmbeddedLoadSave() )
95 return;
96
97 SwProgress *pProgress = nullptr;
98 std::vector<SwProgress *>::size_type i;
99 for ( i = 0; i < pProgressContainer->size(); ++i )
100 {
101 SwProgress *pTmp = (*pProgressContainer)[i].get();
102 if ( pTmp->pDocShell == pDocShell )
103 {
104 pProgress = pTmp;
105 break;
106 }
107 }
108
109 if ( pProgress && 0 == --pProgress->nStartCount )
110 {
111 pProgress->pProgress->Stop();
112 pProgressContainer->erase( pProgressContainer->begin() + i );
113 //#112337# it may happen that the container has been removed
114 //while rescheduling
115 if ( pProgressContainer && pProgressContainer->empty() )
116 {
117 delete pProgressContainer;
118 pProgressContainer = nullptr;
119 }
120 }
121}
122
123void RescheduleProgress( SwDocShell const *pDocShell )
124{
125 if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
126 {
127 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
128 if ( pProgress )
130 }
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void Reschedule()
void RescheduleProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:123
void StartProgress(TranslateId pMessResId, tools::Long nStartValue, tools::Long nEndValue, SwDocShell *pDocShell)
Definition: mainwn.cxx:52
static std::vector< std::unique_ptr< SwProgress > > * pProgressContainer
Definition: mainwn.cxx:40
void EndProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:92
static SwProgress * lcl_SwFindProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:42
void SetProgressState(tools::Long nPosition, SwDocShell const *pDocShell)
Definition: mainwn.cxx:82
int i
long Long
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
#define SW_MOD()
Definition: swmodule.hxx:256