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 */
20
21#include <doc.hxx>
25#include <rootfrm.hxx>
26#include <viewsh.hxx>
27#include <unotools/lingucfg.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
39namespace 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())
73 else
75 }
76}
77
79{
80 m_bStartOnUnblock = false;
82}
83
85{
88}
89
91{
92 assert(0 != m_nIdleBlockCount);
94
96 {
97 if (!m_aDocIdle.IsActive())
99 else
101 }
102}
103
104IMPL_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 (SwEditShell* pSh = m_rDoc.GetEditShell())
203 pSh->ValidateAllParagraphSignatures(true);
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: */
virtual void UpdateTableFields(const SwTable *pTable)=0
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
virtual void UpdateRefFields()=0
virtual SwDocUpdateField & GetUpdateFields() const =0
virtual bool IsExpFieldsLocked() const =0
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
virtual const SwRootFrame * GetCurrentLayout() const =0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual void Start(bool bStartTimer=true) override
static void Wakeup()
static SfxProgress * GetActiveProgress(SfxObjectShell const *pDocSh=nullptr)
css::uno::Any GetProperty(std::u16string_view rPropertyName) const
bool IsInUpdateFields() const
Definition: docfld.hxx:174
void SetFieldsDirty(bool b)
Definition: docfld.hxx:178
void SetInUpdateFields(bool b)
Definition: docfld.hxx:175
bool IsFieldsDirty() const
Definition: docfld.hxx:177
Definition: doc.hxx:197
bool StartGrammarChecking(bool bSkipStart=false)
Definition: docnew.cxx:141
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1699
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:330
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:200
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
void StartAllAction()
Set up Start-/EndAction for all Shells on an as high as possible (Shell section) level.
Definition: pagechg.cxx:1920
void EndAllAction()
Definition: pagechg.cxx:1932
bool IsNeedGrammarCheck() const
Definition: rootfrm.hxx:270
bool IsOnlineSpell() const
Definition: viewopt.hxx:537
bool IsViewLocked() const
Definition: viewsh.hxx:490
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:452
bool HasDrawViewDrag() const
Definition: vnew.cxx:381
void LockView(bool b)
Definition: viewsh.hxx:491
bool IsActive() const
void SetPriority(TaskPriority ePriority)
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
virtual SwFieldUpdateFlags getFieldUpdateFlags(bool bGlobalSettings) const override
Get the current field update mode.
DocumentTimerManager(SwDoc &i_rSwdoc)
@ None
document has no idle jobs to do
@ Busy
document is busy and idle jobs are postponed
virtual ~DocumentTimerManager() override
sal_uInt32 m_nIdleBlockCount
Don't run the Idle, if > 0.
bool m_bStartOnUnblock
true, if the last unblock should start the timer
void StopIdling() override
Stop idle processing.
void UnblockIdling() override
Decrement block count.
void StartIdling() override
Start the idle task.
bool m_bWaitForLokInit
true if we waited for LOK to initialize already.
void BlockIdling() override
Increment block count.
ring_container GetRingContainer()
Definition: ring.hxx:240
SwDoc & m_rDoc
Definition: docbm.cxx:1228
SwFieldUpdateFlags
Definition: fldupde.hxx:23
@ AUTOUPD_FIELD_ONLY
Definition: fldupde.hxx:25
@ AUTOUPD_FIELD_AND_CHARTS
Definition: fldupde.hxx:26
constexpr OUStringLiteral UPN_IS_GRAMMAR_AUTO
Dialog to specify the properties of date form field.
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
IMPL_LINK(DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, pIdle, void)
#define SAL_MAX_UINT32