LCOV - code coverage report
Current view: top level - sw/source/core/uibase/app - mainwn.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 47 56 83.9 %
Date: 2014-04-11 Functions: 5 6 83.3 %
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             : 
      20             : #include <mdiexp.hxx>
      21             : #include <tools/shl.hxx>
      22             : #include <sfx2/progress.hxx>
      23             : #include <tools/resid.hxx>
      24             : #include <docsh.hxx>
      25             : #include <swmodule.hxx>
      26             : #include "swtypes.hxx"
      27             : 
      28             : class SwDocShell;
      29             : 
      30             : struct SwProgress
      31             : {
      32             :     long nStartValue,
      33             :          nStartCount;
      34             :     SwDocShell  *pDocShell;
      35             :     SfxProgress *pProgress;
      36             : };
      37             : 
      38             : static std::vector<SwProgress*> *pProgressContainer = 0;
      39             : 
      40       46357 : static SwProgress *lcl_SwFindProgress( SwDocShell *pDocShell )
      41             : {
      42       46357 :     for ( sal_uInt16 i = 0; i < pProgressContainer->size(); ++i )
      43             :     {
      44       46357 :         SwProgress *pTmp = (*pProgressContainer)[i];
      45       46357 :         if ( pTmp->pDocShell == pDocShell )
      46       46357 :             return pTmp;
      47             :     }
      48           0 :     return 0;
      49             : }
      50             : 
      51        1713 : void StartProgress( sal_uInt16 nMessResId, long nStartValue, long nEndValue,
      52             :                     SwDocShell *pDocShell )
      53             : {
      54        1713 :     if( !SW_MOD()->IsEmbeddedLoadSave() )
      55             :     {
      56        1683 :         SwProgress *pProgress = 0;
      57             : 
      58        1683 :         if ( !pProgressContainer )
      59        1683 :             pProgressContainer = new std::vector<SwProgress*>;
      60             :         else
      61             :         {
      62           0 :             if ( 0 != (pProgress = lcl_SwFindProgress( pDocShell )) )
      63           0 :                 ++pProgress->nStartCount;
      64             :         }
      65        1683 :         if ( !pProgress )
      66             :         {
      67        1683 :             pProgress = new SwProgress;
      68             :             pProgress->pProgress = new SfxProgress( pDocShell,
      69             :                                                     SW_RESSTR(nMessResId),
      70        1683 :                                                     nEndValue - nStartValue,
      71             :                                                     false,
      72        3366 :                                                     true );
      73        1683 :             pProgress->nStartCount = 1;
      74        1683 :             pProgress->pDocShell = pDocShell;
      75        1683 :             pProgressContainer->insert( pProgressContainer->begin(), pProgress );
      76             :         }
      77        1683 :         pProgress->nStartValue = nStartValue;
      78             :     }
      79        1713 : }
      80             : 
      81       14719 : void SetProgressState( long nPosition, SwDocShell *pDocShell )
      82             : {
      83       14719 :     if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
      84             :     {
      85        2961 :         SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
      86        2961 :         if ( pProgress )
      87        2961 :             pProgress->pProgress->SetState(nPosition - pProgress->nStartValue);
      88             :     }
      89       14719 : }
      90             : 
      91        1719 : void EndProgress( SwDocShell *pDocShell )
      92             : {
      93        1719 :     if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
      94             :     {
      95        1683 :         SwProgress *pProgress = 0;
      96             :         sal_uInt16 i;
      97        1683 :         for ( i = 0; i < pProgressContainer->size(); ++i )
      98             :         {
      99        1683 :             SwProgress *pTmp = (SwProgress*)(*pProgressContainer)[i];
     100        1683 :             if ( pTmp->pDocShell == pDocShell )
     101             :             {
     102        1683 :                 pProgress = pTmp;
     103        1683 :                 break;
     104             :             }
     105             :         }
     106             : 
     107        1683 :         if ( pProgress && 0 == --pProgress->nStartCount )
     108             :         {
     109        1683 :             pProgress->pProgress->Stop();
     110        1683 :             pProgressContainer->erase( pProgressContainer->begin() + i );
     111        1683 :             delete pProgress->pProgress;
     112        1683 :             delete pProgress;
     113             :             //#112337# it may happen that the container has been removed
     114             :             //while rescheduling
     115        1683 :             if ( pProgressContainer && pProgressContainer->empty() )
     116        1683 :                 delete pProgressContainer, pProgressContainer = 0;
     117             :         }
     118             :     }
     119        1719 : }
     120             : 
     121           0 : void SetProgressText( sal_uInt16 nId, SwDocShell *pDocShell )
     122             : {
     123           0 :     if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
     124             :     {
     125           0 :         SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
     126           0 :         if ( pProgress )
     127           0 :             pProgress->pProgress->SetStateText( 0, SW_RESSTR(nId) );
     128             :     }
     129           0 : }
     130             : 
     131       43396 : void RescheduleProgress( SwDocShell *pDocShell )
     132             : {
     133       43396 :     if( pProgressContainer && !SW_MOD()->IsEmbeddedLoadSave() )
     134             :     {
     135       43396 :         SwProgress *pProgress = lcl_SwFindProgress( pDocShell );
     136       43396 :         if ( pProgress )
     137       43396 :             pProgress->pProgress->Reschedule();
     138             :     }
     139       43396 : }
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10