LCOV - code coverage report
Current view: top level - framework/source/uielement - progressbarwrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 124 149 83.2 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 122 280 43.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <uielement/progressbarwrapper.hxx>
      30                 :            : 
      31                 :            : #include <helper/statusindicator.hxx>
      32                 :            : #include <threadhelp/resetableguard.hxx>
      33                 :            : #include <uielement/statusindicatorinterfacewrapper.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/ui/UIElementType.hpp>
      36                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      37                 :            : 
      38                 :            : #include <vcl/svapp.hxx>
      39                 :            : #include <toolkit/helper/vclunohelper.hxx>
      40                 :            : 
      41                 :            : using namespace ::com::sun::star;
      42                 :            : 
      43                 :            : namespace framework{
      44                 :            : 
      45                 :       1747 : ProgressBarWrapper::ProgressBarWrapper() :
      46                 :            : UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR )
      47                 :            :     ,   m_bOwnsInstance( sal_False )
      48                 :            :     ,   m_nRange( 100 )
      49         [ +  - ]:       1747 :     ,   m_nValue( 0 )
      50                 :            : {
      51                 :       1747 : }
      52                 :            : 
      53         [ +  - ]:       1656 : ProgressBarWrapper::~ProgressBarWrapper()
      54                 :            : {
      55         [ -  + ]:       3312 : }
      56                 :            : 
      57                 :            : // public interfaces
      58                 :       8129 : void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, sal_Bool bOwnsInstance )
      59                 :            : {
      60         [ +  - ]:       8129 :     ResetableGuard aGuard( m_aLock );
      61                 :            : 
      62         [ -  + ]:       8129 :     if ( m_bDisposed )
      63         [ #  # ]:       8129 :         return;
      64                 :            : 
      65         [ +  + ]:       8129 :     if ( m_bOwnsInstance )
      66                 :            :     {
      67                 :            :         // dispose XWindow reference our our status bar
      68         [ +  - ]:       1747 :         uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
      69                 :            :         try
      70                 :            :         {
      71         [ +  - ]:       1747 :             if ( xComponent.is() )
      72 [ +  - ][ +  - ]:       1747 :                 xComponent->dispose();
      73                 :            :         }
      74         [ #  # ]:          0 :         catch ( const uno::Exception& )
      75                 :            :         {
      76                 :            :         }
      77                 :       1747 :         m_xStatusBar.clear();
      78                 :            :     }
      79                 :            : 
      80                 :       8129 :     m_bOwnsInstance = bOwnsInstance;
      81 [ +  - ][ +  - ]:       8129 :     m_xStatusBar    = rStatusBar;
                 [ +  - ]
      82                 :            : }
      83                 :            : 
      84                 :       7065 : uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
      85                 :            : {
      86         [ +  - ]:       7065 :     ResetableGuard aGuard( m_aLock );
      87                 :            : 
      88         [ -  + ]:       7065 :     if ( m_bDisposed )
      89                 :          0 :         return uno::Reference< awt::XWindow >();
      90                 :            : 
      91         [ +  - ]:       7065 :     return m_xStatusBar;
      92                 :            : }
      93                 :            : 
      94                 :            : // wrapped methods of ::com::sun::star::task::XStatusIndicator
      95                 :        475 : void ProgressBarWrapper::start( const ::rtl::OUString& Text, ::sal_Int32 Range )
      96                 :            : throw (uno::RuntimeException)
      97                 :            : {
      98                 :        475 :     uno::Reference< awt::XWindow > xWindow;
      99                 :        475 :     sal_Int32                      nValue( 0 );
     100                 :            : 
     101                 :            :     {
     102         [ +  - ]:        475 :         ResetableGuard aGuard( m_aLock );
     103                 :            : 
     104         [ -  + ]:        475 :         if ( m_bDisposed )
     105                 :        475 :             return;
     106                 :            : 
     107         [ +  - ]:        475 :         xWindow  = m_xStatusBar;
     108                 :        475 :         m_nValue = 0;
     109                 :        475 :         m_nRange = Range;
     110 [ +  - ][ +  - ]:        475 :         nValue   = m_nValue;
     111                 :            :     }
     112                 :            : 
     113         [ +  - ]:        475 :     if ( xWindow.is() )
     114                 :            :     {
     115         [ +  - ]:        475 :         SolarMutexGuard aSolarMutexGuard;
     116         [ +  - ]:        475 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     117 [ +  - ][ +  - ]:        475 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
         [ +  - ][ +  - ]
     118                 :            :         {
     119                 :        475 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     120         [ +  + ]:        475 :             if ( !pStatusBar->IsProgressMode() )
     121 [ +  - ][ +  - ]:        454 :                 pStatusBar->StartProgressMode( Text );
                 [ +  - ]
     122                 :            :             else
     123                 :            :             {
     124         [ +  - ]:         21 :                 pStatusBar->SetUpdateMode( sal_False );
     125         [ +  - ]:         21 :                 pStatusBar->EndProgressMode();
     126 [ +  - ][ +  - ]:         21 :                 pStatusBar->StartProgressMode( Text );
                 [ +  - ]
     127         [ +  - ]:         21 :                 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     128         [ +  - ]:         21 :                 pStatusBar->SetUpdateMode( sal_True );
     129                 :            :             }
     130         [ +  - ]:        475 :             pStatusBar->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
     131         [ +  - ]:        475 :         }
     132         [ +  - ]:        475 :     }
     133                 :            : }
     134                 :            : 
     135                 :        482 : void ProgressBarWrapper::end()
     136                 :            : throw (uno::RuntimeException)
     137                 :            : {
     138                 :        482 :     uno::Reference< awt::XWindow > xWindow;
     139                 :            : 
     140                 :            :     {
     141         [ +  - ]:        482 :         ResetableGuard aGuard( m_aLock );
     142                 :            : 
     143         [ -  + ]:        482 :         if ( m_bDisposed )
     144                 :        482 :             return;
     145                 :            : 
     146         [ +  - ]:        482 :         xWindow  = m_xStatusBar;
     147                 :        482 :         m_nRange = 100;
     148 [ +  - ][ +  - ]:        482 :         m_nValue = 0;
     149                 :            :     }
     150                 :            : 
     151         [ +  - ]:        482 :     if ( xWindow.is() )
     152                 :            :     {
     153         [ +  - ]:        482 :         SolarMutexGuard aSolarMutexGuard;
     154         [ +  - ]:        482 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     155 [ +  - ][ +  - ]:        482 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
         [ +  - ][ +  - ]
     156                 :            :         {
     157                 :        482 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     158         [ +  + ]:        482 :             if ( pStatusBar->IsProgressMode() )
     159         [ +  - ]:        454 :                 pStatusBar->EndProgressMode();
     160         [ +  - ]:        482 :         }
     161         [ +  - ]:        482 :     }
     162                 :            : }
     163                 :            : 
     164                 :        119 : void ProgressBarWrapper::setText( const ::rtl::OUString& Text )
     165                 :            : throw (uno::RuntimeException)
     166                 :            : {
     167                 :        119 :     uno::Reference< awt::XWindow > xWindow;
     168                 :        119 :     sal_Int32 nValue( 0 );
     169                 :            : 
     170                 :            :     {
     171         [ +  - ]:        119 :         ResetableGuard aGuard( m_aLock );
     172                 :            : 
     173         [ -  + ]:        119 :         if ( m_bDisposed )
     174                 :        119 :             return;
     175                 :            : 
     176         [ +  - ]:        119 :         xWindow  = m_xStatusBar;
     177                 :        119 :         m_aText  = Text;
     178 [ +  - ][ +  - ]:        119 :         nValue   = m_nValue;
     179                 :            :     }
     180                 :            : 
     181         [ +  - ]:        119 :     if ( xWindow.is() )
     182                 :            :     {
     183         [ +  - ]:        119 :         SolarMutexGuard aSolarMutexGuard;
     184         [ +  - ]:        119 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     185 [ +  - ][ +  - ]:        119 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
         [ +  - ][ +  - ]
     186                 :            :         {
     187                 :        119 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     188         [ +  - ]:        119 :             if( pStatusBar->IsProgressMode() )
     189                 :            :             {
     190         [ +  - ]:        119 :                 pStatusBar->SetUpdateMode( sal_False );
     191         [ +  - ]:        119 :                 pStatusBar->EndProgressMode();
     192 [ +  - ][ +  - ]:        119 :                 pStatusBar->StartProgressMode( Text );
                 [ +  - ]
     193         [ +  - ]:        119 :                 pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     194         [ +  - ]:        119 :                 pStatusBar->SetUpdateMode( sal_True );
     195                 :            :             }
     196                 :            :             else
     197 [ #  # ][ #  # ]:          0 :                 pStatusBar->SetText( Text );
                 [ #  # ]
     198         [ +  - ]:        119 :         }
     199         [ +  - ]:        119 :     }
     200                 :            : }
     201                 :            : 
     202                 :      13866 : void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
     203                 :            : throw (uno::RuntimeException)
     204                 :            : {
     205                 :      13866 :     uno::Reference< awt::XWindow > xWindow;
     206                 :      13866 :     rtl::OUString aText;
     207                 :      13866 :     sal_Bool      bSetValue( sal_False );
     208                 :            : 
     209                 :            :     {
     210         [ +  - ]:      13866 :         ResetableGuard aGuard( m_aLock );
     211                 :            : 
     212         [ -  + ]:      13866 :         if ( m_bDisposed )
     213                 :      13866 :             return;
     214                 :            : 
     215         [ +  - ]:      13866 :         xWindow  = m_xStatusBar;
     216                 :            : 
     217                 :      13866 :         double fVal( 0 );
     218         [ +  + ]:      13866 :         if ( m_nRange > 0 )
     219                 :            :         {
     220                 :      13854 :             fVal = ( double( nValue ) / double( m_nRange )) * 100;
     221 [ +  - ][ +  - ]:      13854 :             fVal = std::max( double( 0 ), std::min( fVal, double( 100 )));
     222                 :            :         }
     223                 :            : 
     224         [ +  + ]:      13866 :         if ( m_nValue != sal_Int32( fVal ))
     225                 :            :         {
     226                 :      13596 :             m_nValue = sal_Int32( fVal );
     227                 :      13596 :             bSetValue = sal_True;
     228                 :            :         }
     229                 :            : 
     230                 :      13866 :         nValue   = m_nValue;
     231 [ +  - ][ +  - ]:      13866 :         aText    = m_aText;
     232                 :            :     }
     233                 :            : 
     234 [ +  - ][ +  + ]:      13866 :     if ( xWindow.is() && bSetValue )
                 [ +  + ]
     235                 :            :     {
     236         [ +  - ]:      13596 :         SolarMutexGuard aSolarMutexGuard;
     237         [ +  - ]:      13596 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     238 [ +  - ][ +  - ]:      13596 :         if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
         [ +  - ][ +  - ]
     239                 :            :         {
     240                 :      13596 :             StatusBar* pStatusBar = (StatusBar *)pWindow;
     241         [ -  + ]:      13596 :             if ( !pStatusBar->IsProgressMode() )
     242 [ #  # ][ #  # ]:          0 :                 pStatusBar->StartProgressMode( aText );
                 [ #  # ]
     243         [ +  - ]:      13596 :             pStatusBar->SetProgressValue( sal_uInt16( nValue ));
     244         [ +  - ]:      13866 :         }
     245 [ -  + ][ +  - ]:      13866 :     }
     246                 :            : }
     247                 :            : 
     248                 :        119 : void ProgressBarWrapper::reset()
     249                 :            : throw (uno::RuntimeException)
     250                 :            : {
     251         [ +  - ]:        119 :     setText( rtl::OUString() );
     252                 :        119 :     setValue( 0 );
     253                 :        119 : }
     254                 :            : 
     255                 :            : // XInitialization
     256                 :          0 : void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
     257                 :            : throw (uno::Exception, uno::RuntimeException)
     258                 :            : {
     259                 :            :     // dummy - do nothing
     260                 :          0 : }
     261                 :            : 
     262                 :            : // XUpdatable
     263                 :          0 : void SAL_CALL ProgressBarWrapper::update()
     264                 :            : throw (uno::RuntimeException)
     265                 :            : {
     266                 :            :     // dummy - do nothing
     267                 :          0 : }
     268                 :            : 
     269                 :            : // XComponent
     270                 :          0 : void SAL_CALL ProgressBarWrapper::dispose()
     271                 :            : throw (uno::RuntimeException)
     272                 :            : {
     273                 :            :     uno::Reference< lang::XComponent > xThis(
     274                 :            :         static_cast< cppu::OWeakObject* >(this),
     275         [ #  # ]:          0 :         uno::UNO_QUERY );
     276                 :            : 
     277                 :            :     {
     278         [ #  # ]:          0 :         ResetableGuard aLock( m_aLock );
     279                 :            : 
     280         [ #  # ]:          0 :         if ( m_bDisposed )
     281 [ #  # ][ #  # ]:          0 :             return;
     282                 :            :     }
     283                 :            : 
     284                 :            :     {
     285         [ #  # ]:          0 :         lang::EventObject aEvent( xThis );
     286         [ #  # ]:          0 :         m_aListenerContainer.disposeAndClear( aEvent );
     287                 :            : 
     288         [ #  # ]:          0 :         ResetableGuard aLock( m_aLock );
     289         [ #  # ]:          0 :         if ( m_bOwnsInstance )
     290                 :            :         {
     291                 :            :             try
     292                 :            :             {
     293         [ #  # ]:          0 :                 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
     294         [ #  # ]:          0 :                 if ( xComponent.is() )
     295 [ #  # ][ #  # ]:          0 :                     xComponent->dispose();
                 [ #  # ]
     296                 :            :             }
     297         [ #  # ]:          0 :             catch ( const lang::DisposedException& )
     298                 :            :             {
     299                 :            :             }
     300                 :            :         }
     301                 :            : 
     302                 :          0 :         m_xStatusBar.clear();
     303 [ #  # ][ #  # ]:          0 :         m_bDisposed = sal_True;
     304         [ #  # ]:          0 :     }
     305                 :            : }
     306                 :            : 
     307                 :            : // XUIElement
     308                 :       2222 : uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
     309                 :            : throw (uno::RuntimeException)
     310                 :            : {
     311                 :            :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     312                 :            :     // Ready for multithreading
     313         [ +  - ]:       2222 :     ResetableGuard aLock( m_aLock );
     314                 :            : 
     315         [ -  + ]:       2222 :     if ( m_bDisposed )
     316                 :          0 :         return uno::Reference< uno::XInterface >();
     317                 :            :     else
     318                 :            :     {
     319         [ +  - ]:       2222 :         uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
     320         [ +  + ]:       2222 :         if ( !xComp.is() )
     321                 :            :         {
     322                 :            :             StatusIndicatorInterfaceWrapper* pWrapper =
     323                 :            :                 new StatusIndicatorInterfaceWrapper(
     324                 :            :                     uno::Reference< lang::XComponent >(
     325                 :            :                         static_cast< cppu::OWeakObject* >( this ),
     326 [ +  - ][ +  - ]:       1747 :                         uno::UNO_QUERY ));
     327                 :            :                 xComp = uno::Reference< uno::XInterface >(
     328                 :            :                     static_cast< cppu::OWeakObject* >( pWrapper ),
     329 [ +  - ][ +  - ]:       1747 :                     uno::UNO_QUERY );
     330         [ +  - ]:       1747 :              m_xProgressBarIfacWrapper = xComp;
     331                 :            :         }
     332                 :            : 
     333                 :       2222 :         return xComp;
     334         [ +  - ]:       2222 :     }
     335                 :            : }
     336                 :            : 
     337                 :            : }       //  namespace framework
     338                 :            : 
     339                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10