Drop some needless mappings to identical strings
[LibreOffice.git] / sw / source / uibase / app / mainwn.cxx
blobfce2d12970a1eefd2bdc47630291387646e361c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <mdiexp.hxx>
21 #include <sfx2/progress.hxx>
22 #include <docsh.hxx>
23 #include <swmodule.hxx>
24 #include <swtypes.hxx>
26 class SwDocShell;
28 namespace {
30 struct SwProgress
32 tools::Long nStartValue,
33 nStartCount;
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 )
47 return pTmp.get();
49 return nullptr;
52 void StartProgress( TranslateId pMessResId, tools::Long nStartValue, tools::Long nEndValue,
53 SwDocShell *pDocShell )
55 if (SwModule::get()->IsEmbeddedLoadSave())
56 return;
58 SwProgress *pProgress = nullptr;
60 if ( !pProgressContainer )
61 pProgressContainer = new std::vector<std::unique_ptr<SwProgress>>;
62 else
64 pProgress = lcl_SwFindProgress( pDocShell );
65 if ( pProgress )
66 ++pProgress->nStartCount;
69 if ( !pProgress )
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) );
79 pProgress->nStartValue = nStartValue;
82 void SetProgressState( tools::Long nPosition, SwDocShell const *pDocShell )
84 if (pProgressContainer && !SwModule::get()->IsEmbeddedLoadSave())
86 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
87 if ( pProgress )
88 pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
92 void EndProgress( SwDocShell const *pDocShell )
94 if (!pProgressContainer || SwModule::get()->IsEmbeddedLoadSave())
95 return;
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 )
104 pProgress = pTmp;
105 break;
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
114 //while rescheduling
115 if ( pProgressContainer && pProgressContainer->empty() )
117 delete pProgressContainer;
118 pProgressContainer = nullptr;
123 void RescheduleProgress( SwDocShell const *pDocShell )
125 if (pProgressContainer && !SwModule::get()->IsEmbeddedLoadSave())
127 SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
128 if ( pProgress )
129 SfxProgress::Reschedule();
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */