LCOV - code coverage report
Current view: top level - libreoffice/framework/source/helper - vclstatusindicator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 81 0.0 %
Date: 2012-12-27 Functions: 0 12 0.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 <helper/vclstatusindicator.hxx>
      21             : 
      22             : #include <threadhelp/readguard.hxx>
      23             : #include <threadhelp/writeguard.hxx>
      24             : 
      25             : #include <toolkit/unohlp.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : 
      28             : 
      29             : namespace framework {
      30             : 
      31             : 
      32             : //-----------------------------------------------
      33           0 : DEFINE_XINTERFACE_1(VCLStatusIndicator                           ,
      34             :                     OWeakObject                                  ,
      35             :                     DIRECT_INTERFACE(css::task::XStatusIndicator))
      36             : 
      37             : //-----------------------------------------------
      38           0 : VCLStatusIndicator::VCLStatusIndicator(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR        ,
      39             :                                        const css::uno::Reference< css::awt::XWindow >&               xParentWindow)
      40           0 :     : ThreadHelpBase     (&Application::GetSolarMutex())
      41             :     , ::cppu::OWeakObject(                             )
      42             :     , m_xSMGR            (xSMGR                        )
      43             :     , m_xParentWindow    (xParentWindow                )
      44             :     , m_pStatusBar       (0                            )
      45             :     , m_nRange           (0                            )
      46           0 :     , m_nValue           (0                            )
      47             : {
      48           0 :     if (!m_xParentWindow.is())
      49             :         throw css::uno::RuntimeException(
      50             :                 ::rtl::OUString("Cant work without a parent window!"),
      51           0 :                 static_cast< css::task::XStatusIndicator* >(this));
      52           0 : }
      53             : 
      54             : //-----------------------------------------------
      55           0 : VCLStatusIndicator::~VCLStatusIndicator()
      56             : {
      57           0 : }
      58             : 
      59             : //-----------------------------------------------
      60           0 : void SAL_CALL VCLStatusIndicator::start(const ::rtl::OUString& sText ,
      61             :                                               sal_Int32        nRange)
      62             :     throw(css::uno::RuntimeException)
      63             : {
      64             :     // SAFE -> ----------------------------------
      65           0 :     ReadGuard aReadLock(m_aLock);
      66           0 :     css::uno::Reference< css::awt::XWindow > xParentWindow = m_xParentWindow;
      67           0 :     aReadLock.unlock();
      68             :     // <- SAFE ----------------------------------
      69             : 
      70             :     // SOLAR SAFE -> ----------------------------
      71             :     {
      72           0 :         SolarMutexGuard aSolarGuard;
      73             : 
      74           0 :         Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
      75           0 :         if (!m_pStatusBar)
      76           0 :             m_pStatusBar = new StatusBar(pParentWindow, WB_3DLOOK|WB_BORDER);
      77             : 
      78           0 :         VCLStatusIndicator::impl_recalcLayout(m_pStatusBar, pParentWindow);
      79             : 
      80           0 :         m_pStatusBar->Show();
      81           0 :         m_pStatusBar->StartProgressMode(sText);
      82           0 :         m_pStatusBar->SetProgressValue(0);
      83             : 
      84             :         // force repaint!
      85           0 :         pParentWindow->Show();
      86           0 :         pParentWindow->Invalidate(INVALIDATE_CHILDREN);
      87           0 :         pParentWindow->Flush();
      88             :     }
      89             :     // <- SOLAR SAFE ----------------------------
      90             : 
      91             :     // SAFE -> ----------------------------------
      92           0 :     WriteGuard aWriteLock(m_aLock);
      93           0 :     m_sText  = sText;
      94           0 :     m_nRange = nRange;
      95           0 :     m_nValue = 0;
      96           0 :     aWriteLock.unlock();
      97             :     // <- SAFE ----------------------------------
      98           0 : }
      99             : 
     100             : //-----------------------------------------------
     101           0 : void SAL_CALL VCLStatusIndicator::reset()
     102             :     throw(css::uno::RuntimeException)
     103             : {
     104             :     // SOLAR SAFE -> ----------------------------
     105           0 :     SolarMutexGuard aSolarGuard;
     106           0 :     if (m_pStatusBar)
     107             :     {
     108           0 :         m_pStatusBar->SetProgressValue(0);
     109           0 :         m_pStatusBar->SetText(String());
     110           0 :     }
     111             :     // <- SOLAR SAFE ----------------------------
     112           0 : }
     113             : 
     114             : //-----------------------------------------------
     115           0 : void SAL_CALL VCLStatusIndicator::end()
     116             :     throw(css::uno::RuntimeException)
     117             : {
     118             :     // SAFE -> ----------------------------------
     119           0 :     WriteGuard aWriteLock(m_aLock);
     120           0 :     m_sText  = ::rtl::OUString();
     121           0 :     m_nRange = 0;
     122           0 :     m_nValue = 0;
     123           0 :     aWriteLock.unlock();
     124             :     // <- SAFE ----------------------------------
     125             : 
     126             :     // SOLAR SAFE -> ----------------------------
     127             :     {
     128           0 :         SolarMutexGuard aSolarGuard;
     129           0 :         if (m_pStatusBar)
     130             :         {
     131           0 :             m_pStatusBar->EndProgressMode();
     132           0 :             m_pStatusBar->Show(sal_False);
     133             : 
     134           0 :             delete m_pStatusBar;
     135           0 :             m_pStatusBar = 0;
     136           0 :         }
     137           0 :     }
     138             :     // <- SOLAR SAFE ----------------------------
     139           0 : }
     140             : 
     141             : //-----------------------------------------------
     142           0 : void SAL_CALL VCLStatusIndicator::setText(const ::rtl::OUString& sText)
     143             :     throw(css::uno::RuntimeException)
     144             : {
     145             :     // SAFE -> ----------------------------------
     146           0 :     WriteGuard aWriteLock(m_aLock);
     147           0 :     m_sText = sText;
     148           0 :     aWriteLock.unlock();
     149             :     // <- SAFE ----------------------------------
     150             : 
     151             :     // SOLAR SAFE -> ----------------------------
     152             :     {
     153           0 :         SolarMutexGuard aSolarGuard;
     154           0 :         if (m_pStatusBar)
     155           0 :             m_pStatusBar->SetText(sText);
     156           0 :     }
     157             :     // <- SOLAR SAFE ----------------------------
     158           0 : }
     159             : 
     160             : //-----------------------------------------------
     161           0 : void SAL_CALL VCLStatusIndicator::setValue(sal_Int32 nValue)
     162             :     throw(css::uno::RuntimeException)
     163             : {
     164             :     // SAFE -> ----------------------------------
     165           0 :     WriteGuard aWriteLock(m_aLock);
     166             : 
     167           0 :     if (nValue <= m_nRange)
     168           0 :         m_nValue = nValue;
     169             :     else
     170           0 :         m_nValue = m_nRange;
     171             : 
     172           0 :     sal_Int32 nRange = m_nRange;
     173           0 :               nValue = m_nValue;
     174             : 
     175           0 :     aWriteLock.unlock();
     176             :     // <- SAFE ----------------------------------
     177             : 
     178             :     // normalize value to fit the range of 0-100 %
     179             :     sal_uInt16 nPercent = sal::static_int_cast< sal_uInt16 >(
     180             :         ::std::min(
     181           0 :             ((nValue*100) / ::std::max(nRange,(sal_Int32)1)), (sal_Int32)100));
     182             : 
     183             :     // SOLAR SAFE -> ----------------------------
     184             :     {
     185           0 :         SolarMutexGuard aSolarGuard;
     186           0 :         if (m_pStatusBar)
     187           0 :             m_pStatusBar->SetProgressValue(nPercent);
     188           0 :     }
     189             :     // <- SOLAR SAFE ----------------------------
     190           0 : }
     191             : 
     192             : //-----------------------------------------------
     193           0 : void VCLStatusIndicator::impl_recalcLayout(Window* pStatusBar   ,
     194             :                                            Window* pParentWindow)
     195             : {
     196           0 :     if (
     197             :         (!pStatusBar   ) ||
     198             :         (!pParentWindow)
     199             :        )
     200           0 :        return;
     201             : 
     202           0 :     Size aParentSize = pParentWindow->GetSizePixel();
     203             :     pStatusBar->setPosSizePixel(0,
     204             :                                 0,
     205           0 :                                 aParentSize.Width(),
     206           0 :                                 aParentSize.Height());
     207             : }
     208             : 
     209             : } // namespace framework
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10