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 namespace {
29 
30 struct SwProgress
31 {
32  long nStartValue,
33  nStartCount;
34  SwDocShell *pDocShell;
35  std::unique_ptr<SfxProgress> pProgress;
36 };
37 
38 }
39 
40 static std::vector<std::unique_ptr<SwProgress>> *pProgressContainer = nullptr;
41 
42 static 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 
52 void StartProgress( const char* pMessResId, long nStartValue, 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 
82 void SetProgressState( 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 
92 void EndProgress( SwDocShell const *pDocShell )
93 {
94  if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
95  {
96  SwProgress *pProgress = nullptr;
97  std::vector<SwProgress *>::size_type i;
98  for ( i = 0; i < pProgressContainer->size(); ++i )
99  {
100  SwProgress *pTmp = (*pProgressContainer)[i].get();
101  if ( pTmp->pDocShell == pDocShell )
102  {
103  pProgress = pTmp;
104  break;
105  }
106  }
107 
108  if ( pProgress && 0 == --pProgress->nStartCount )
109  {
110  pProgress->pProgress->Stop();
111  pProgressContainer->erase( pProgressContainer->begin() + i );
112  //#112337# it may happen that the container has been removed
113  //while rescheduling
114  if ( pProgressContainer && pProgressContainer->empty() )
115  {
116  delete pProgressContainer;
117  pProgressContainer = nullptr;
118  }
119  }
120  }
121 }
122 
123 void 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: */
void EndProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:92
void StartProgress(const char *pMessResId, long nStartValue, long nEndValue, SwDocShell *pDocShell)
Definition: mainwn.cxx:52
void SetProgressState(long nPosition, SwDocShell const *pDocShell)
Definition: mainwn.cxx:82
#define SW_MOD()
Definition: swmodule.hxx:256
int i
static std::vector< std::unique_ptr< SwProgress > > * pProgressContainer
Definition: mainwn.cxx:40
void RescheduleProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:123
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
static SwProgress * lcl_SwFindProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:42
static void Reschedule()