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

Generated by: LCOV version 1.10