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