LCOV - code coverage report
Current view: top level - framework/source/uielement - progressbarwrapper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 125 150 83.3 %
Date: 2014-04-11 Functions: 11 14 78.6 %
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 <uielement/progressbarwrapper.hxx>
      21             : 
      22             : #include <helper/statusindicator.hxx>
      23             : #include <uielement/statusindicatorinterfacewrapper.hxx>
      24             : 
      25             : #include <com/sun/star/ui/UIElementType.hpp>
      26             : #include <com/sun/star/lang/DisposedException.hpp>
      27             : 
      28             : #include <vcl/status.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : namespace framework{
      35             : 
      36        2077 : ProgressBarWrapper::ProgressBarWrapper() :
      37             : UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR )
      38             :     ,   m_bOwnsInstance( false )
      39             :     ,   m_nRange( 100 )
      40        2077 :     ,   m_nValue( 0 )
      41             : {
      42        2077 : }
      43             : 
      44        4128 : ProgressBarWrapper::~ProgressBarWrapper()
      45             : {
      46        4128 : }
      47             : 
      48             : // public interfaces
      49        9000 : void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, bool bOwnsInstance )
      50             : {
      51        9000 :     SolarMutexGuard g;
      52             : 
      53        9000 :     if ( m_bDisposed )
      54        9000 :         return;
      55             : 
      56        9000 :     if ( m_bOwnsInstance )
      57             :     {
      58             :         // dispose XWindow reference our our status bar
      59        2072 :         uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
      60             :         try
      61             :         {
      62        2072 :             if ( xComponent.is() )
      63        2072 :                 xComponent->dispose();
      64             :         }
      65           0 :         catch ( const uno::Exception& )
      66             :         {
      67             :         }
      68        2072 :         m_xStatusBar.clear();
      69             :     }
      70             : 
      71        9000 :     m_bOwnsInstance = bOwnsInstance;
      72        9000 :     m_xStatusBar    = rStatusBar;
      73             : }
      74             : 
      75       23552 : uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
      76             : {
      77       23552 :     SolarMutexGuard g;
      78             : 
      79       23552 :     if ( m_bDisposed )
      80           0 :         return uno::Reference< awt::XWindow >();
      81             : 
      82       23552 :     return m_xStatusBar;
      83             : }
      84             : 
      85             : // wrapped methods of ::com::sun::star::task::XStatusIndicator
      86        1533 : void ProgressBarWrapper::start( const OUString& Text, ::sal_Int32 Range )
      87             : throw (uno::RuntimeException)
      88             : {
      89        1533 :     uno::Reference< awt::XWindow > xWindow;
      90        1533 :     sal_Int32                      nValue( 0 );
      91             : 
      92             :     {
      93        1533 :         SolarMutexGuard g;
      94             : 
      95        1533 :         if ( m_bDisposed )
      96        1533 :             return;
      97             : 
      98        1533 :         xWindow  = m_xStatusBar;
      99        1533 :         m_nValue = 0;
     100        1533 :         m_nRange = Range;
     101        1533 :         nValue   = m_nValue;
     102             :     }
     103             : 
     104        1533 :     if ( xWindow.is() )
     105             :     {
     106        1533 :         SolarMutexGuard aSolarMutexGuard;
     107        1533 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     108        1533 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
     109             :         {
     110        1533 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     111        1533 :             if ( !pStatusBar->IsProgressMode() )
     112        1511 :                 pStatusBar->StartProgressMode( Text );
     113             :             else
     114             :             {
     115          22 :                 pStatusBar->SetUpdateMode( false );
     116          22 :                 pStatusBar->EndProgressMode();
     117          22 :                 pStatusBar->StartProgressMode( Text );
     118          22 :                 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     119          22 :                 pStatusBar->SetUpdateMode( true );
     120             :             }
     121        1533 :             pStatusBar->Show( true, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
     122        1533 :         }
     123        1533 :     }
     124             : }
     125             : 
     126         751 : void ProgressBarWrapper::end()
     127             : throw (uno::RuntimeException)
     128             : {
     129         751 :     uno::Reference< awt::XWindow > xWindow;
     130             : 
     131             :     {
     132         751 :         SolarMutexGuard g;
     133             : 
     134         751 :         if ( m_bDisposed )
     135         751 :             return;
     136             : 
     137         751 :         xWindow  = m_xStatusBar;
     138         751 :         m_nRange = 100;
     139         751 :         m_nValue = 0;
     140             :     }
     141             : 
     142         751 :     if ( xWindow.is() )
     143             :     {
     144         751 :         SolarMutexGuard aSolarMutexGuard;
     145         751 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     146         751 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
     147             :         {
     148         751 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     149         751 :             if ( pStatusBar->IsProgressMode() )
     150         717 :                 pStatusBar->EndProgressMode();
     151         751 :         }
     152         751 :     }
     153             : }
     154             : 
     155         373 : void ProgressBarWrapper::setText( const OUString& Text )
     156             : throw (uno::RuntimeException)
     157             : {
     158         373 :     uno::Reference< awt::XWindow > xWindow;
     159         373 :     sal_Int32 nValue( 0 );
     160             : 
     161             :     {
     162         373 :         SolarMutexGuard g;
     163             : 
     164         373 :         if ( m_bDisposed )
     165         373 :             return;
     166             : 
     167         373 :         xWindow  = m_xStatusBar;
     168         373 :         m_aText  = Text;
     169         373 :         nValue   = m_nValue;
     170             :     }
     171             : 
     172         373 :     if ( xWindow.is() )
     173             :     {
     174         373 :         SolarMutexGuard aSolarMutexGuard;
     175         373 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     176         373 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
     177             :         {
     178         373 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     179         373 :             if( pStatusBar->IsProgressMode() )
     180             :             {
     181         373 :                 pStatusBar->SetUpdateMode( false );
     182         373 :                 pStatusBar->EndProgressMode();
     183         373 :                 pStatusBar->StartProgressMode( Text );
     184         373 :                 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     185         373 :                 pStatusBar->SetUpdateMode( true );
     186             :             }
     187             :             else
     188           0 :                 pStatusBar->SetText( Text );
     189         373 :         }
     190         373 :     }
     191             : }
     192             : 
     193       21200 : void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
     194             : throw (uno::RuntimeException)
     195             : {
     196       21200 :     uno::Reference< awt::XWindow > xWindow;
     197       42400 :     OUString aText;
     198       21200 :     bool      bSetValue( false );
     199             : 
     200             :     {
     201       21200 :         SolarMutexGuard g;
     202             : 
     203       21200 :         if ( m_bDisposed )
     204       21200 :             return;
     205             : 
     206       21200 :         xWindow  = m_xStatusBar;
     207             : 
     208       21200 :         double fVal( 0 );
     209       21200 :         if ( m_nRange > 0 )
     210             :         {
     211       21192 :             fVal = ( double( nValue ) / double( m_nRange )) * 100;
     212       21192 :             fVal = std::max( double( 0 ), std::min( fVal, double( 100 )));
     213             :         }
     214             : 
     215       21200 :         if ( m_nValue != sal_Int32( fVal ))
     216             :         {
     217       19027 :             m_nValue = sal_Int32( fVal );
     218       19027 :             bSetValue = true;
     219             :         }
     220             : 
     221       21200 :         nValue   = m_nValue;
     222       21200 :         aText    = m_aText;
     223             :     }
     224             : 
     225       21200 :     if ( xWindow.is() && bSetValue )
     226             :     {
     227       19027 :         SolarMutexGuard aSolarMutexGuard;
     228       19027 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     229       19027 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
     230             :         {
     231       19027 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     232       19027 :             if ( !pStatusBar->IsProgressMode() )
     233           0 :                 pStatusBar->StartProgressMode( aText );
     234       19027 :             pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     235       19027 :         }
     236       21200 :     }
     237             : }
     238             : 
     239         373 : void ProgressBarWrapper::reset()
     240             : throw (uno::RuntimeException)
     241             : {
     242         373 :     setText( OUString() );
     243         373 :     setValue( 0 );
     244         373 : }
     245             : 
     246             : // XInitialization
     247           0 : void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
     248             : throw (uno::Exception, uno::RuntimeException, std::exception)
     249             : {
     250             :     // dummy - do nothing
     251           0 : }
     252             : 
     253             : // XUpdatable
     254           0 : void SAL_CALL ProgressBarWrapper::update()
     255             : throw (uno::RuntimeException, std::exception)
     256             : {
     257             :     // dummy - do nothing
     258           0 : }
     259             : 
     260             : // XComponent
     261           0 : void SAL_CALL ProgressBarWrapper::dispose()
     262             : throw (uno::RuntimeException, std::exception)
     263             : {
     264             :     uno::Reference< lang::XComponent > xThis(
     265             :         static_cast< cppu::OWeakObject* >(this),
     266           0 :         uno::UNO_QUERY );
     267             : 
     268             :     {
     269           0 :         SolarMutexGuard g;
     270             : 
     271           0 :         if ( m_bDisposed )
     272           0 :             return;
     273             :     }
     274             : 
     275             :     {
     276           0 :         lang::EventObject aEvent( xThis );
     277           0 :         m_aListenerContainer.disposeAndClear( aEvent );
     278             : 
     279           0 :         SolarMutexGuard g;
     280           0 :         if ( m_bOwnsInstance )
     281             :         {
     282             :             try
     283             :             {
     284           0 :                 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
     285           0 :                 if ( xComponent.is() )
     286           0 :                     xComponent->dispose();
     287             :             }
     288           0 :             catch ( const lang::DisposedException& )
     289             :             {
     290             :             }
     291             :         }
     292             : 
     293           0 :         m_xStatusBar.clear();
     294           0 :         m_bDisposed = true;
     295           0 :     }
     296             : }
     297             : 
     298             : // XUIElement
     299        3610 : uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
     300             : throw (uno::RuntimeException, std::exception)
     301             : {
     302        3610 :     SolarMutexGuard g;
     303             : 
     304        3610 :     if ( m_bDisposed )
     305           0 :         return uno::Reference< uno::XInterface >();
     306             :     else
     307             :     {
     308        3610 :         uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
     309        3610 :         if ( !xComp.is() )
     310             :         {
     311             :             StatusIndicatorInterfaceWrapper* pWrapper =
     312             :                 new StatusIndicatorInterfaceWrapper(
     313             :                     uno::Reference< lang::XComponent >(
     314             :                         static_cast< cppu::OWeakObject* >( this ),
     315        2077 :                         uno::UNO_QUERY ));
     316        4154 :                 xComp = uno::Reference< uno::XInterface >(
     317             :                     static_cast< cppu::OWeakObject* >( pWrapper ),
     318        2077 :                     uno::UNO_QUERY );
     319        2077 :              m_xProgressBarIfacWrapper = xComp;
     320             :         }
     321             : 
     322        3610 :         return xComp;
     323        3610 :     }
     324             : }
     325             : 
     326             : }       //  namespace framework
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10