Line data Source code
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>
22 : #include <DocumentSettingManager.hxx>
23 : #include <IDocumentFieldsAccess.hxx>
24 : #include <IDocumentLayoutAccess.hxx>
25 : #include <rootfrm.hxx>
26 : #include <viewsh.hxx>
27 : #include <unotools/lingucfg.hxx>
28 : #include <unotools/linguprops.hxx>
29 : #include <set>
30 : #include <fldupde.hxx>
31 : #include <sfx2/progress.hxx>
32 : #include <viewopt.hxx>
33 : #include <docsh.hxx>
34 : #include <docfld.hxx>
35 : #include <fldbas.hxx>
36 :
37 : namespace sw
38 : {
39 :
40 2958 : DocumentTimerManager::DocumentTimerManager( SwDoc& i_rSwdoc ) : m_rDoc( i_rSwdoc ),
41 : mbStartIdleTimer( false ),
42 2958 : mIdleBlockCount( 0 )
43 : {
44 2958 : maIdle.SetPriority( SchedulerPriority::LOWEST );
45 2958 : maIdle.SetIdleHdl( LINK( this, DocumentTimerManager, DoIdleJobs) );
46 2958 : }
47 :
48 3042 : void DocumentTimerManager::StartIdling()
49 : {
50 3042 : mbStartIdleTimer = true;
51 3042 : if( !mIdleBlockCount )
52 3042 : maIdle.Start();
53 3042 : }
54 :
55 5991 : void DocumentTimerManager::StopIdling()
56 : {
57 5991 : mbStartIdleTimer = false;
58 5991 : maIdle.Stop();
59 5991 : }
60 :
61 19845 : void DocumentTimerManager::BlockIdling()
62 : {
63 19845 : maIdle.Stop();
64 19845 : ++mIdleBlockCount;
65 19845 : }
66 :
67 19845 : void DocumentTimerManager::UnblockIdling()
68 : {
69 19845 : --mIdleBlockCount;
70 19845 : if( !mIdleBlockCount && mbStartIdleTimer && !maIdle.IsActive() )
71 3991 : maIdle.Start();
72 19845 : }
73 :
74 435974 : void DocumentTimerManager::StartBackgroundJobs()
75 : {
76 : // Trigger DoIdleJobs(), asynchronously.
77 435974 : if (!maIdle.IsActive()) //fdo#73165 if the timer is already running don't restart from 0
78 11137 : maIdle.Start();
79 435974 : }
80 :
81 53561012 : IMPL_LINK_TYPED( DocumentTimerManager, DoIdleJobs, Idle*, pIdle, void )
82 : {
83 : #ifdef TIMELOG
84 : static ::rtl::Logfile* pModLogFile = 0;
85 : if( !pModLogFile )
86 : pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
87 : #endif
88 :
89 26780506 : SwRootFrm* pTmpRoot = m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout();
90 53560960 : if( pTmpRoot &&
91 26780454 : !SfxProgress::GetActiveProgress( m_rDoc.GetDocShell() ) )
92 : {
93 26780446 : SwViewShell* pShell(m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell());
94 53560915 : for(SwViewShell& rSh : pShell->GetRingContainer())
95 : {
96 26780469 : if( rSh.ActionPend() )
97 : {
98 0 : pIdle->Start();
99 0 : return;
100 : }
101 : }
102 :
103 26780446 : if( pTmpRoot->IsNeedGrammarCheck() )
104 : {
105 26780446 : bool bIsOnlineSpell = pShell->GetViewOptions()->IsOnlineSpell();
106 26780446 : bool bIsAutoGrammar = false;
107 : SvtLinguConfig().GetProperty( OUString(
108 26780446 : UPN_IS_GRAMMAR_AUTO ) ) >>= bIsAutoGrammar;
109 :
110 26780446 : if (bIsOnlineSpell && bIsAutoGrammar)
111 26780438 : StartGrammarChecking( m_rDoc );
112 : }
113 26780446 : std::set<SwRootFrm*> aAllLayouts = m_rDoc.GetAllLayouts();
114 26780446 : std::set<SwRootFrm*>::iterator pLayIter = aAllLayouts.begin();
115 26785815 : for ( ;pLayIter != aAllLayouts.end();++pLayIter )
116 : {
117 26780446 : if ((*pLayIter)->IsIdleFormat())
118 : {
119 26775077 : (*pLayIter)->GetCurrShell()->LayoutIdle();
120 :
121 : // Defer the remaining work.
122 26775077 : pIdle->Start();
123 26775077 : return;
124 : }
125 : }
126 :
127 5369 : SwFieldUpdateFlags nFieldUpdFlag = m_rDoc.GetDocumentSettingManager().getFieldUpdateFlags(true);
128 5369 : if( ( AUTOUPD_FIELD_ONLY == nFieldUpdFlag
129 10738 : || AUTOUPD_FIELD_AND_CHARTS == nFieldUpdFlag ) &&
130 5369 : m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().IsFieldsDirty()
131 : // If we switch the field name the Fields are not updated.
132 : // So the "background update" should always be carried out
133 : /* && !pStartSh->GetViewOptions()->IsFieldName()*/ )
134 : {
135 174 : if ( m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().IsInUpdateFields() ||
136 87 : m_rDoc.getIDocumentFieldsAccess().IsExpFieldsLocked() )
137 : {
138 0 : pIdle->Start();
139 0 : return;
140 : }
141 :
142 : // Action brackets!
143 87 : m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().SetInUpdateFields( true );
144 :
145 87 : pTmpRoot->StartAllAction();
146 :
147 : // no jump on update of fields #i85168#
148 87 : const bool bOldLockView = pShell->IsViewLocked();
149 87 : pShell->LockView( true );
150 :
151 87 : m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( RES_CHAPTERFLD )->ModifyNotification( 0, 0 ); // ChapterField
152 87 : m_rDoc.getIDocumentFieldsAccess().UpdateExpFields( 0, false ); // Updates ExpressionFields
153 87 : m_rDoc.getIDocumentFieldsAccess().UpdateTableFields(NULL); // Tables
154 87 : m_rDoc.getIDocumentFieldsAccess().UpdateRefFields(NULL); // References
155 :
156 87 : pTmpRoot->EndAllAction();
157 :
158 87 : pShell->LockView( bOldLockView );
159 :
160 87 : m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().SetInUpdateFields( false );
161 87 : m_rDoc.getIDocumentFieldsAccess().GetUpdateFields().SetFieldsDirty( false );
162 5369 : }
163 : }
164 : #ifdef TIMELOG
165 : if( pModLogFile && 1 != (long)pModLogFile )
166 : delete pModLogFile, static_cast<long&>(pModLogFile) = 1;
167 : #endif
168 : }
169 :
170 5898 : DocumentTimerManager::~DocumentTimerManager() {}
171 :
172 177 : }
173 :
174 :
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|