LCOV - code coverage report
Current view: top level - xmloff/source/core - ProgressBarHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 25 28 89.3 %
Date: 2014-11-03 Functions: 4 4 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             : 
      20             : #include <xmloff/ProgressBarHelper.hxx>
      21             : #include <xmloff/xmltoken.hxx>
      22             : 
      23             : using namespace ::com::sun::star;
      24             : 
      25             : static const sal_Int32 nDefaultProgressBarRange = 1000000;
      26             : 
      27        2428 : ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator,
      28             :                                     const bool bTempStrict)
      29             : : xStatusIndicator(xTempStatusIndicator)
      30             : , nRange(nDefaultProgressBarRange)
      31             : , nReference(100)
      32             : , nValue(0)
      33             : , bStrict(bTempStrict)
      34        2428 : , bRepeat(true)
      35             : #ifdef DBG_UTIL
      36             : , bFailure(false)
      37             : #endif
      38             : {
      39        2428 : }
      40             : 
      41        2428 : ProgressBarHelper::~ProgressBarHelper()
      42             : {
      43        2428 : }
      44             : 
      45         112 : sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
      46             : {
      47         112 :     if((nNewReference > 0) && (nNewReference != nReference))
      48             :     {
      49          66 :         if (nReference)
      50             :         {
      51          66 :             double fPercent((double)nNewReference / nReference);
      52          66 :             double fValue(nValue * fPercent);
      53          66 :             nValue = static_cast<sal_Int32>(fValue);
      54          66 :             nReference = nNewReference;
      55             :         }
      56             :         else
      57             :         {
      58           0 :             nReference = nNewReference;
      59           0 :             nValue = 0;
      60             :         }
      61             :     }
      62         112 :     return nValue;
      63             : }
      64             : 
      65       15854 : void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
      66             : {
      67       15854 :     if (xStatusIndicator.is() && (nReference > 0))
      68             :     {
      69        3586 :         if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference))))
      70             :         {
      71             :             // #91317# no progress bar with values > 100%
      72        3586 :             if (nTempValue > nReference)
      73             :             {
      74         206 :                 if (!bRepeat)
      75           0 :                     nValue = nReference;
      76             :                 else
      77             :                 {
      78         206 :                     xStatusIndicator->reset();
      79         206 :                     nValue = 0;
      80             :                 }
      81             :             }
      82             :             else
      83        3380 :                 nValue = nTempValue;
      84             : 
      85        3586 :             double fValue(nValue);
      86        3586 :             double fNewValue ((fValue * nRange) / nReference);
      87             : 
      88        3586 :             xStatusIndicator->setValue((sal_Int32)fNewValue);
      89             : 
      90             :             // #95181# disabled, because we want to call setValue very often to enable a good reschedule
      91             :         }
      92             : #ifdef DBG_UTIL
      93             :         else if (!bFailure)
      94             :         {
      95             :             OSL_FAIL("tried to set a wrong value on the progressbar");
      96             :             bFailure = true;
      97             :         }
      98             : #endif
      99             :     }
     100       15854 : }
     101             : 
     102             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10