LibreOffice Module sw (master)  1
swwait.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 <swwait.hxx>
21 #include <docsh.hxx>
22 
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/dispatch.hxx>
25 
26 #include <vcl/window.hxx>
27 
29  SwDocShell &rDocShell,
30  const bool bLockUnlockDispatcher )
31  : mrDoc ( rDocShell )
32  , mbLockUnlockDispatcher( bLockUnlockDispatcher )
33  , mpLockedDispatchers()
34 {
36 }
37 
39 {
41 }
42 
44 {
45  SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &mrDoc, false );
46  while ( pFrame )
47  {
48  pFrame->GetWindow().EnterWait();
50  {
51  // do not look already locked dispatchers
52  SfxDispatcher* pDispatcher = pFrame->GetDispatcher();
53  if ( !pDispatcher->IsLocked() )
54  {
55  pDispatcher->Lock( true );
56  mpLockedDispatchers.insert( pDispatcher );
57  }
58  }
59 
60  pFrame = SfxViewFrame::GetNext( *pFrame, &mrDoc, false );
61  }
62 }
63 
65 {
66  SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &mrDoc, false );
67  while ( pFrame )
68  {
69  pFrame->GetWindow().LeaveWait();
71  {
72  // only unlock dispatchers which had been locked
73  SfxDispatcher* pDispatcher = pFrame->GetDispatcher();
74  if ( mpLockedDispatchers.erase( pDispatcher ) )
75  {
76  pDispatcher->Lock( false );
77  }
78  }
79 
80  pFrame = SfxViewFrame::GetNext( *pFrame, &mrDoc, false );
81  }
82 }
83 
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void EnterWaitAndLockDispatcher()
Definition: swwait.cxx:43
SfxDispatcher * GetDispatcher()
void EnterWait()
SwDocShell & mrDoc
Definition: swwait.hxx:43
void LeaveWaitAndUnlockDispatcher()
Definition: swwait.cxx:64
vcl::Window & GetWindow() const
const bool mbLockUnlockDispatcher
Definition: swwait.hxx:44
static SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
std::unordered_set< SfxDispatcher * > mpLockedDispatchers
Definition: swwait.hxx:45
void Lock(bool bLock)
SwWait(SwDocShell &rDocShell, const bool bLockUnlockDispatcher)
Definition: swwait.cxx:28
bool IsLocked() const
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
void LeaveWait()
~SwWait()
Definition: swwait.cxx:38