LCOV - code coverage report
Current view: top level - sw/source/core/doc - DocumentTimerManager.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 73 76.7 %
Date: 2014-11-03 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          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             : #include <rtl/logfile.hxx>
      37             : 
      38             : namespace sw
      39             : {
      40             : 
      41        5052 : DocumentTimerManager::DocumentTimerManager( SwDoc& i_rSwdoc ) : m_rSwdoc( i_rSwdoc ),
      42             :                                                                 mbStartIdleTimer( false ),
      43        5052 :                                                                 mIdleBlockCount( 0 )
      44             : {
      45        5052 :     maIdleTimer.SetTimeout( 600 );
      46        5052 :     maIdleTimer.SetTimeoutHdl( LINK( this, DocumentTimerManager, DoIdleJobs) );
      47        5052 : }
      48             : 
      49        5266 : void DocumentTimerManager::StartIdling()
      50             : {
      51        5266 :     mbStartIdleTimer = true;
      52        5266 :     if( !mIdleBlockCount )
      53        5266 :         maIdleTimer.Start();
      54        5266 : }
      55             : 
      56       10311 : void DocumentTimerManager::StopIdling()
      57             : {
      58       10311 :     mbStartIdleTimer = false;
      59       10311 :     maIdleTimer.Stop();
      60       10311 : }
      61             : 
      62       35072 : void DocumentTimerManager::BlockIdling()
      63             : {
      64       35072 :     maIdleTimer.Stop();
      65       35072 :     ++mIdleBlockCount;
      66       35072 : }
      67             : 
      68       35072 : void DocumentTimerManager::UnblockIdling()
      69             : {
      70       35072 :     --mIdleBlockCount;
      71       35072 :     if( !mIdleBlockCount && mbStartIdleTimer && !maIdleTimer.IsActive() )
      72        6984 :         maIdleTimer.Start();
      73       35072 : }
      74             : 
      75      800382 : void DocumentTimerManager::StartBackgroundJobs() {
      76             :     // Trigger DoIdleJobs(), asynchronously.
      77      800382 :     maIdleTimer.Start();
      78      800382 : }
      79             : 
      80        1580 : IMPL_LINK( DocumentTimerManager, DoIdleJobs, Timer *, pTimer )
      81             : {
      82             : #ifdef TIMELOG
      83             :     static ::rtl::Logfile* pModLogFile = 0;
      84             :     if( !pModLogFile )
      85             :         pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
      86             : #endif
      87             : 
      88         790 :     SwRootFrm* pTmpRoot = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentLayout();
      89        1568 :     if( pTmpRoot &&
      90         778 :         !SfxProgress::GetActiveProgress( m_rSwdoc.GetDocShell() ) )
      91             :     {
      92             :         SwViewShell *pSh, *pStartSh;
      93         777 :         pSh = pStartSh = m_rSwdoc.getIDocumentLayoutAccess().GetCurrentViewShell();
      94         777 :         do {
      95         777 :             if( pSh->ActionPend() )
      96             :             {
      97           0 :                 pTimer->Start();
      98         637 :                 return 0;
      99             :             }
     100         777 :             pSh = (SwViewShell*)pSh->GetNext();
     101             :         } while( pSh != pStartSh );
     102             : 
     103         777 :         if( pTmpRoot->IsNeedGrammarCheck() )
     104             :         {
     105         777 :             bool bIsOnlineSpell = pSh->GetViewOptions()->IsOnlineSpell();
     106         777 :             bool bIsAutoGrammar = false;
     107             :             SvtLinguConfig().GetProperty( OUString(
     108         777 :                         UPN_IS_GRAMMAR_AUTO ) ) >>= bIsAutoGrammar;
     109             : 
     110         777 :             if (bIsOnlineSpell && bIsAutoGrammar)
     111         771 :                 StartGrammarChecking( m_rSwdoc );
     112             :         }
     113         777 :         std::set<SwRootFrm*> aAllLayouts = m_rSwdoc.GetAllLayouts();
     114         777 :         std::set<SwRootFrm*>::iterator pLayIter = aAllLayouts.begin();
     115         917 :         for ( ;pLayIter != aAllLayouts.end();++pLayIter )
     116             :         {
     117         777 :             if ((*pLayIter)->IsIdleFormat())
     118             :             {
     119         637 :                 (*pLayIter)->GetCurrShell()->LayoutIdle();
     120             : 
     121             :                 // Defer the remaining work.
     122         637 :                 pTimer->Start();
     123         637 :                 return 0;
     124             :             }
     125             :         }
     126             : 
     127         140 :         SwFldUpdateFlags nFldUpdFlag = m_rSwdoc.GetDocumentSettingManager().getFieldUpdateFlags(true);
     128         140 :         if( ( AUTOUPD_FIELD_ONLY == nFldUpdFlag
     129         280 :                     || AUTOUPD_FIELD_AND_CHARTS == nFldUpdFlag ) &&
     130         140 :                 m_rSwdoc.getIDocumentFieldsAccess().GetUpdtFlds().IsFieldsDirty()
     131             :                 // If we switch the field name the Fields are not updated.
     132             :                 // So the "backgorund update" should always be carried out
     133             :                 /* && !pStartSh->GetViewOptions()->IsFldName()*/ )
     134             :         {
     135           0 :             if ( m_rSwdoc.getIDocumentFieldsAccess().GetUpdtFlds().IsInUpdateFlds() ||
     136           0 :                  m_rSwdoc.getIDocumentFieldsAccess().IsExpFldsLocked() )
     137             :             {
     138           0 :                 pTimer->Start();
     139           0 :                 return 0;
     140             :             }
     141             : 
     142             :             //  Action brackets!
     143           0 :             m_rSwdoc.getIDocumentFieldsAccess().GetUpdtFlds().SetInUpdateFlds( true );
     144             : 
     145           0 :             pTmpRoot->StartAllAction();
     146             : 
     147             :             // no jump on update of fields #i85168#
     148           0 :             const bool bOldLockView = pStartSh->IsViewLocked();
     149           0 :             pStartSh->LockView( true );
     150             : 
     151           0 :             m_rSwdoc.getIDocumentFieldsAccess().GetSysFldType( RES_CHAPTERFLD )->ModifyNotification( 0, 0 );    // ChapterField
     152           0 :             m_rSwdoc.getIDocumentFieldsAccess().UpdateExpFlds( 0, false );      // Updates ExpressionFields
     153           0 :             m_rSwdoc.getIDocumentFieldsAccess().UpdateTblFlds(NULL);                // Tables
     154           0 :             m_rSwdoc.getIDocumentFieldsAccess().UpdateRefFlds(NULL);                // References
     155             : 
     156           0 :             pTmpRoot->EndAllAction();
     157             : 
     158           0 :             pStartSh->LockView( bOldLockView );
     159             : 
     160           0 :             m_rSwdoc.getIDocumentFieldsAccess().GetUpdtFlds().SetInUpdateFlds( false );
     161           0 :             m_rSwdoc.getIDocumentFieldsAccess().GetUpdtFlds().SetFieldsDirty( false );
     162         140 :         }
     163             :     }
     164             : #ifdef TIMELOG
     165             :     if( pModLogFile && 1 != (long)pModLogFile )
     166             :         delete pModLogFile, ((long&)pModLogFile) = 1;
     167             : #endif
     168         153 :     return 0;
     169             : }
     170             : 
     171       10090 : DocumentTimerManager::~DocumentTimerManager() {}
     172             : 
     173         270 : }
     174             : 
     175             : 
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10