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)
46  , m_aFireIdleJobsTimer("sw::DocumentTimerManager m_aFireIdleJobsTimer")
47  , m_bWaitForLokInit(true)
48 {
49  m_aDocIdle.SetPriority(TaskPriority::LOWEST);
51  m_aDocIdle.SetDebugName("sw::DocumentTimerManager m_aDocIdle");
52 
54  m_aFireIdleJobsTimer.SetTimeout(1000); // Enough time for LOK to render the first tiles.
55 }
56 
58 {
60  {
61  // Start the idle jobs only after a certain delay.
62  m_bWaitForLokInit = false;
63  StopIdling();
65  return;
66  }
67 
68  m_bWaitForLokInit = false;
69  m_bStartOnUnblock = true;
70  if (0 == m_nIdleBlockCount)
71  {
72  if (!m_aDocIdle.IsActive())
73  m_aDocIdle.Start();
74  else
76  }
77 }
78 
80 {
81  m_bStartOnUnblock = false;
82  m_aDocIdle.Stop();
83 }
84 
86 {
89 }
90 
92 {
95 
97  {
98  if (!m_aDocIdle.IsActive())
99  m_aDocIdle.Start();
100  else
102  }
103 }
104 
105 IMPL_LINK(DocumentTimerManager, FireIdleJobsTimeout, Timer*, , void)
106 {
107  // Now we can run the idle jobs, assuming we finished LOK initialization.
108  StartIdling();
109 }
110 
112 {
114  if( pTmpRoot &&
116  {
118  for(const SwViewShell& rSh : pShell->GetRingContainer())
119  if( rSh.ActionPend() )
120  return IdleJob::Busy;
121 
122  if( pTmpRoot->IsNeedGrammarCheck() )
123  {
124  bool bIsOnlineSpell = pShell->GetViewOptions()->IsOnlineSpell();
125  bool bIsAutoGrammar = false;
126  SvtLinguConfig().GetProperty( UPN_IS_GRAMMAR_AUTO ) >>= bIsAutoGrammar;
127 
128  if( bIsOnlineSpell && bIsAutoGrammar && m_rDoc.StartGrammarChecking( true ) )
129  return IdleJob::Grammar;
130  }
131 
132  // If we're dragging re-layout doesn't occur so avoid a busy loop.
133  if (!pShell->HasDrawViewDrag())
134  {
135  for ( auto pLayout : m_rDoc.GetAllLayouts() )
136  {
137  if( pLayout->IsIdleFormat() )
138  return IdleJob::Layout;
139  }
140  }
141 
143  if( ( AUTOUPD_FIELD_ONLY == nFieldUpdFlag
144  || AUTOUPD_FIELD_AND_CHARTS == nFieldUpdFlag )
146  {
149  return IdleJob::Busy;
150  return IdleJob::Fields;
151  }
152  }
153 
154  return IdleJob::None;
155 }
156 
158 {
159 #ifdef TIMELOG
160  static ::rtl::Logfile* pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
161 #endif
162  BlockIdling();
163  StopIdling();
164 
165  IdleJob eJob = GetNextIdleJob();
166 
167  switch ( eJob )
168  {
169  case IdleJob::Grammar:
171  break;
172 
173  case IdleJob::Layout:
174  for ( auto pLayout : m_rDoc.GetAllLayouts() )
175  if( pLayout->IsIdleFormat() )
176  {
177  pLayout->GetCurrShell()->LayoutIdle();
178  break;
179  }
180  break;
181 
182  case IdleJob::Fields:
183  {
186 
187  // Action brackets!
189 
190  pTmpRoot->StartAllAction();
191 
192  // no jump on update of fields #i85168#
193  const bool bOldLockView = pShell->IsViewLocked();
194  pShell->LockView( true );
195 
197  pChapterFieldType->CallSwClientNotify(sw::LegacyModifyHint( nullptr, nullptr )); // ChapterField
198  m_rDoc.getIDocumentFieldsAccess().UpdateExpFields( nullptr, false ); // Updates ExpressionFields
201 
202  // Validate and update the paragraph signatures.
203  if (m_rDoc.GetEditShell())
205 
206  pTmpRoot->EndAllAction();
207 
208  pShell->LockView( bOldLockView );
209 
212  break;
213  }
214 
215  case IdleJob::Busy:
216  break;
217  case IdleJob::None:
218  break;
219  }
220 
221  if ( IdleJob::None != eJob )
222  StartIdling();
223  UnblockIdling();
224 
225 #ifdef TIMELOG
226  if( pModLogFile && 1 != (long)pModLogFile )
227  delete pModLogFile, static_cast<long&>(pModLogFile) = 1;
228 #endif
229 }
230 
232 
233 }
234 
235 
236 /* 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:1350
bool IsInUpdateFields() const
Definition: docfld.hxx:160
bool IsFieldsDirty() const
Definition: docfld.hxx:163
Definition: doc.hxx:186
bool IsNeedGrammarCheck() const
Definition: rootfrm.hxx:263
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:82
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:1205
bool m_bWaitForLokInit
true if we waited for LOK to initialize already.
#define UPN_IS_GRAMMAR_AUTO
IMPL_LINK(DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, pIdle, void)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual void UpdateTableFields(SfxPoolItem *pHt)=0
virtual void Start() override
virtual bool IsExpFieldsLocked() const =0
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1669
virtual ~DocumentTimerManager() override
sal_uInt32 m_nIdleBlockCount
Don't run the Idle, if > 0.
void SetDebugName(const char *pDebugName)
virtual void UpdateRefFields()=0
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
void UnblockIdling() override
Decrement block count.
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
void SetInUpdateFields(bool b)
Definition: docfld.hxx:161
virtual void Start() 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:164
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:370
DocumentTimerManager(SwDoc &i_rSwdoc)
css::uno::Any GetProperty(const OUString &rPropertyName) const
void SetPriority(TaskPriority ePriority)
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
bool StartGrammarChecking(bool bSkipStart=false)
Definition: docnew.cxx:131
void StartIdling() override
Start the idle task.