LibreOffice Module sw (master)  1
DocumentTimerManager.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 #include <DocumentTimerManager.hxx>
20 
21 #include <doc.hxx>
25 #include <rootfrm.hxx>
26 #include <viewsh.hxx>
27 #include <unotools/lingucfg.hxx>
28 #include <unotools/linguprops.hxx>
29 #include <fldupde.hxx>
30 #include <sfx2/progress.hxx>
31 #include <viewopt.hxx>
32 #include <docsh.hxx>
33 #include <docfld.hxx>
34 #include <fldbas.hxx>
35 #include <vcl/scheduler.hxx>
36 #include <comphelper/lok.hxx>
37 #include <editsh.hxx>
38 
39 namespace sw
40 {
42  : m_rDoc(i_rSwdoc)
43  , m_nIdleBlockCount(0)
44  , m_bStartOnUnblock(false)
45  , m_aDocIdle(i_rSwdoc, "sw::DocumentTimerManager m_aDocIdle")
46  , m_aFireIdleJobsTimer("sw::DocumentTimerManager m_aFireIdleJobsTimer")
47  , m_bWaitForLokInit(true)
48 {
49  m_aDocIdle.SetPriority(TaskPriority::LOWEST);
51 
53  m_aFireIdleJobsTimer.SetTimeout(1000); // Enough time for LOK to render the first tiles.
54 }
55 
57 {
59  {
60  // Start the idle jobs only after a certain delay.
61  m_bWaitForLokInit = false;
62  StopIdling();
64  return;
65  }
66 
67  m_bWaitForLokInit = false;
68  m_bStartOnUnblock = true;
69  if (0 == m_nIdleBlockCount)
70  {
71  if (!m_aDocIdle.IsActive())
72  m_aDocIdle.Start();
73  else
75  }
76 }
77 
79 {
80  m_bStartOnUnblock = false;
81  m_aDocIdle.Stop();
82 }
83 
85 {
88 }
89 
91 {
92  assert(0 != m_nIdleBlockCount);
94 
96  {
97  if (!m_aDocIdle.IsActive())
98  m_aDocIdle.Start();
99  else
101  }
102 }
103 
104 IMPL_LINK(DocumentTimerManager, FireIdleJobsTimeout, Timer*, , void)
105 {
106  // Now we can run the idle jobs, assuming we finished LOK initialization.
107  StartIdling();
108 }
109 
111 {
113  if( pTmpRoot &&
115  {
117  for(const SwViewShell& rSh : pShell->GetRingContainer())
118  if( rSh.ActionPend() )
119  return IdleJob::Busy;
120 
121  if( pTmpRoot->IsNeedGrammarCheck() )
122  {
123  bool bIsOnlineSpell = pShell->GetViewOptions()->IsOnlineSpell();
124  bool bIsAutoGrammar = false;
125  SvtLinguConfig().GetProperty( UPN_IS_GRAMMAR_AUTO ) >>= bIsAutoGrammar;
126 
127  if( bIsOnlineSpell && bIsAutoGrammar && m_rDoc.StartGrammarChecking( true ) )
128  return IdleJob::Grammar;
129  }
130 
131  // If we're dragging re-layout doesn't occur so avoid a busy loop.
132  if (!pShell->HasDrawViewDrag())
133  {
134  for ( auto pLayout : m_rDoc.GetAllLayouts() )
135  {
136  if( pLayout->IsIdleFormat() )
137  return IdleJob::Layout;
138  }
139  }
140 
142  if( ( AUTOUPD_FIELD_ONLY == nFieldUpdFlag
143  || AUTOUPD_FIELD_AND_CHARTS == nFieldUpdFlag )
145  {
148  return IdleJob::Busy;
149  return IdleJob::Fields;
150  }
151  }
152 
153  return IdleJob::None;
154 }
155 
157 {
158 #ifdef TIMELOG
159  static ::rtl::Logfile* pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
160 #endif
161  BlockIdling();
162  StopIdling();
163 
164  IdleJob eJob = GetNextIdleJob();
165 
166  switch ( eJob )
167  {
168  case IdleJob::Grammar:
170  break;
171 
172  case IdleJob::Layout:
173  for ( auto pLayout : m_rDoc.GetAllLayouts() )
174  if( pLayout->IsIdleFormat() )
175  {
176  pLayout->GetCurrShell()->LayoutIdle();
177  break;
178  }
179  break;
180 
181  case IdleJob::Fields:
182  {
185 
186  // Action brackets!
188 
189  pTmpRoot->StartAllAction();
190 
191  // no jump on update of fields #i85168#
192  const bool bOldLockView = pShell->IsViewLocked();
193  pShell->LockView( true );
194 
196  pChapterFieldType->CallSwClientNotify(sw::LegacyModifyHint( nullptr, nullptr )); // ChapterField
197  m_rDoc.getIDocumentFieldsAccess().UpdateExpFields( nullptr, false ); // Updates ExpressionFields
200 
201  // Validate and update the paragraph signatures.
202  if (m_rDoc.GetEditShell())
204 
205  pTmpRoot->EndAllAction();
206 
207  pShell->LockView( bOldLockView );
208 
211  break;
212  }
213 
214  case IdleJob::Busy:
215  break;
216  case IdleJob::None:
217  break;
218  }
219 
220  if ( IdleJob::None != eJob )
221  StartIdling();
222  UnblockIdling();
223 
224 #ifdef TIMELOG
225  if( pModLogFile && 1 != (long)pModLogFile )
226  delete pModLogFile, static_cast<long&>(pModLogFile) = 1;
227 #endif
228 }
229 
231 
232 }
233 
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void Wakeup()
SwFieldUpdateFlags
Definition: fldupde.hxx:22
virtual const SwRootFrame * GetCurrentLayout() const =0
SwDocShell * GetDocShell()
Definition: doc.hxx:1351
bool IsInUpdateFields() const
Definition: docfld.hxx:173
bool IsFieldsDirty() const
Definition: docfld.hxx:176
Definition: doc.hxx:187
bool IsNeedGrammarCheck() const
Definition: rootfrm.hxx:261
Dialog to specify the properties of date form field.
document has no idle jobs to do
bool m_bStartOnUnblock
true, if the last unblock should start the timer
The root element of a Writer document layout.
Definition: rootfrm.hxx:81
bool IsActive() const
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
#define SAL_MAX_UINT32
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
SwDoc & m_rDoc
Definition: docbm.cxx:1201
bool m_bWaitForLokInit
true if we waited for LOK to initialize already.
IMPL_LINK(DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, pIdle, void)
virtual void UpdateTableFields(SfxPoolItem *pHt)=0
virtual bool IsExpFieldsLocked() const =0
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1668
constexpr OUStringLiteral UPN_IS_GRAMMAR_AUTO
virtual ~DocumentTimerManager() override
sal_uInt32 m_nIdleBlockCount
Don't run the Idle, if > 0.
virtual void UpdateRefFields()=0
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
void UnblockIdling() override
Decrement block count.
css::uno::Any GetProperty(std::u16string_view rPropertyName) const
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
void SetInUpdateFields(bool b)
Definition: docfld.hxx:174
virtual void Start(bool bStartTimer=true) override
ring_container GetRingContainer()
Definition: ring.hxx:240
void SetTimeout(sal_uInt64 nTimeoutMs)
void StopIdling() override
Stop idle processing.
void BlockIdling() override
Increment block count.
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
void SetFieldsDirty(bool b)
Definition: docfld.hxx:177
void Stop()
virtual SwFieldUpdateFlags getFieldUpdateFlags(bool bGlobalSettings) const override
Get the current field update mode.
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
void ValidateAllParagraphSignatures(bool updateDontRemove)
Validate all paragraph signatures.
Definition: edfcol.cxx:1853
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:186
virtual SwDocUpdateField & GetUpdateFields() const =0
void SetInvokeHandler(const Link< Timer *, void > &rLink)
document is busy and idle jobs are postponed
static SfxProgress * GetActiveProgress(SfxObjectShell const *pDocSh=nullptr)
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:325
DocumentTimerManager(SwDoc &i_rSwdoc)
virtual void Start(bool bStartTimer=true) override
void SetPriority(TaskPriority ePriority)
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
bool StartGrammarChecking(bool bSkipStart=false)
Definition: docnew.cxx:138
void StartIdling() override
Start the idle task.
bool m_bDetectedRangeSegmentation false