LCOV - code coverage report
Current view: top level - svtools/source/uno - statusbarcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 153 273 56.0 %
Date: 2012-08-25 Functions: 17 28 60.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 170 564 30.1 %

           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 <svtools/statusbarcontroller.hxx>
      30                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      31                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      32                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      33                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      34                 :            : #include <com/sun/star/frame/XLayoutManager.hpp>
      35                 :            : #include <com/sun/star/util/URLTransformer.hpp>
      36                 :            : #include <osl/mutex.hxx>
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : #include <vcl/window.hxx>
      39                 :            : #include <vcl/status.hxx>
      40                 :            : #include <svtools/imgdef.hxx>
      41                 :            : #include <svtools/miscopt.hxx>
      42                 :            : #include <toolkit/unohlp.hxx>
      43                 :            : #include <comphelper/componentcontext.hxx>
      44                 :            : 
      45                 :            : using namespace ::cppu;
      46                 :            : using namespace ::com::sun::star::awt;
      47                 :            : using namespace ::com::sun::star::uno;
      48                 :            : using namespace ::com::sun::star::util;
      49                 :            : using namespace ::com::sun::star::beans;
      50                 :            : using namespace ::com::sun::star::lang;
      51                 :            : using namespace ::com::sun::star::frame;
      52                 :            : using namespace ::com::sun::star::frame;
      53                 :            : 
      54                 :            : namespace svt
      55                 :            : {
      56                 :            : 
      57                 :       2316 : StatusbarController::StatusbarController(
      58                 :            :     const Reference< XMultiServiceFactory >& rServiceManager,
      59                 :            :     const Reference< XFrame >& xFrame,
      60                 :            :     const ::rtl::OUString& aCommandURL,
      61                 :            :     unsigned short nID ) :
      62                 :            :     OWeakObject()
      63                 :            :     ,   m_bInitialized( sal_False )
      64                 :            :     ,   m_bDisposed( sal_False )
      65                 :            :     ,   m_nID( nID )
      66                 :            :     ,   m_xFrame( xFrame )
      67                 :            :     ,   m_xServiceManager( rServiceManager )
      68                 :            :     ,   m_aCommandURL( aCommandURL )
      69 [ +  - ][ +  - ]:       2316 :     ,   m_aListenerContainer( m_aMutex )
                 [ +  - ]
      70                 :            : {
      71                 :       2316 : }
      72                 :            : 
      73                 :      10023 : StatusbarController::StatusbarController() :
      74                 :            :     OWeakObject()
      75                 :            :     ,   m_bInitialized( sal_False )
      76                 :            :     ,   m_bDisposed( sal_False )
      77                 :            :     ,   m_nID( 0 )
      78 [ +  - ][ +  - ]:      10023 :     ,   m_aListenerContainer( m_aMutex )
                 [ +  - ]
      79                 :            : {
      80                 :      10023 : }
      81                 :            : 
      82 [ +  - ][ +  - ]:      12339 : StatusbarController::~StatusbarController()
         [ +  - ][ +  - ]
      83                 :            : {
      84         [ -  + ]:      13891 : }
      85                 :            : 
      86                 :       1040 : Reference< XFrame > StatusbarController::getFrameInterface() const
      87                 :            : {
      88         [ +  - ]:       1040 :     SolarMutexGuard aSolarMutexGuard;
      89         [ +  - ]:       1040 :     return m_xFrame;
      90                 :            : }
      91                 :            : 
      92                 :      28005 : Reference< XURLTransformer > StatusbarController::getURLTransformer() const
      93                 :            : {
      94         [ +  - ]:      28005 :     SolarMutexGuard aSolarMutexGuard;
      95 [ +  + ][ +  - ]:      28005 :     if ( !m_xURLTransformer.is() && m_xServiceManager.is() )
                 [ +  + ]
      96                 :            :     {
      97 [ +  - ][ +  - ]:      12339 :         m_xURLTransformer = com::sun::star::util::URLTransformer::create( ::comphelper::ComponentContext(m_xServiceManager).getUNOContext() );
         [ +  - ][ +  - ]
                 [ +  - ]
      98                 :            :     }
      99                 :            : 
     100         [ +  - ]:      28005 :     return m_xURLTransformer;
     101                 :            : }
     102                 :            : 
     103                 :            : // XInterface
     104                 :     108656 : Any SAL_CALL StatusbarController::queryInterface( const Type& rType )
     105                 :            : throw ( RuntimeException )
     106                 :            : {
     107                 :            :     Any a = ::cppu::queryInterface(
     108                 :            :                 rType ,
     109                 :            :                 static_cast< XStatusbarController* >( this ),
     110                 :            :                 static_cast< XStatusListener* >( this ),
     111                 :            :                 static_cast< XEventListener* >( this ),
     112                 :            :                 static_cast< XInitialization* >( this ),
     113                 :            :                 static_cast< XComponent* >( this ),
     114         [ +  - ]:     108656 :                 static_cast< XUpdatable* >( this ));
     115                 :            : 
     116         [ +  + ]:     108656 :     if ( a.hasValue() )
     117                 :     107892 :         return a;
     118                 :            : 
     119         [ +  - ]:     108656 :     return OWeakObject::queryInterface( rType );
     120                 :            : }
     121                 :            : 
     122                 :      69787 : void SAL_CALL StatusbarController::acquire() throw ()
     123                 :            : {
     124                 :      69787 :     OWeakObject::acquire();
     125                 :      69787 : }
     126                 :            : 
     127                 :      69787 : void SAL_CALL StatusbarController::release() throw ()
     128                 :            : {
     129                 :      69787 :     OWeakObject::release();
     130                 :      69787 : }
     131                 :            : 
     132                 :      12339 : void SAL_CALL StatusbarController::initialize( const Sequence< Any >& aArguments )
     133                 :            : throw ( Exception, RuntimeException )
     134                 :            : {
     135                 :      12339 :     bool bInitialized( true );
     136                 :            : 
     137                 :            :     {
     138         [ +  - ]:      12339 :         SolarMutexGuard aSolarMutexGuard;
     139                 :            : 
     140         [ -  + ]:      12339 :         if ( m_bDisposed )
     141         [ #  # ]:          0 :             throw DisposedException();
     142                 :            : 
     143         [ +  - ]:      12339 :         bInitialized = m_bInitialized;
     144                 :            :     }
     145                 :            : 
     146         [ +  - ]:      12339 :     if ( !bInitialized )
     147                 :            :     {
     148         [ +  - ]:      12339 :         SolarMutexGuard aSolarMutexGuard;
     149                 :      12339 :         m_bInitialized = sal_True;
     150                 :            : 
     151                 :      12339 :         PropertyValue aPropValue;
     152         [ +  + ]:      75562 :         for ( int i = 0; i < aArguments.getLength(); i++ )
     153                 :            :         {
     154 [ +  - ][ +  - ]:      63223 :             if ( aArguments[i] >>= aPropValue )
     155                 :            :             {
     156         [ +  + ]:      63223 :                 if ( aPropValue.Name == "Frame" )
     157         [ +  - ]:      12339 :                     aPropValue.Value >>= m_xFrame;
     158         [ +  + ]:      50884 :                 else if ( aPropValue.Name == "CommandURL" )
     159                 :      12339 :                     aPropValue.Value >>= m_aCommandURL;
     160         [ +  + ]:      38545 :                 else if ( aPropValue.Name == "ServiceManager" )
     161         [ +  - ]:      12339 :                     aPropValue.Value >>= m_xServiceManager;
     162         [ +  + ]:      26206 :                 else if ( aPropValue.Name == "ParentWindow" )
     163         [ +  - ]:      12339 :                     aPropValue.Value >>= m_xParentWindow;
     164         [ +  + ]:      13867 :                 else if ( aPropValue.Name == "Identifier" )
     165                 :      12339 :                     aPropValue.Value >>= m_nID;
     166                 :            :             }
     167                 :            :         }
     168                 :            : 
     169         [ +  - ]:      12339 :         if ( !m_aCommandURL.isEmpty() )
     170 [ +  - ][ +  - ]:      12339 :             m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() ));
         [ +  - ][ +  - ]
     171                 :            :     }
     172                 :      12339 : }
     173                 :            : 
     174                 :      12339 : void SAL_CALL StatusbarController::update()
     175                 :            : throw ( RuntimeException )
     176                 :            : {
     177                 :            :     {
     178         [ +  - ]:      12339 :         SolarMutexGuard aSolarMutexGuard;
     179         [ -  + ]:      12339 :         if ( m_bDisposed )
     180 [ #  # ][ +  - ]:      12339 :             throw DisposedException();
     181                 :            :     }
     182                 :            : 
     183                 :            :     // Bind all registered listeners to their dispatch objects
     184                 :      12339 :     bindListener();
     185                 :      12339 : }
     186                 :            : 
     187                 :            : // XComponent
     188                 :      12339 : void SAL_CALL StatusbarController::dispose()
     189                 :            : throw (::com::sun::star::uno::RuntimeException)
     190                 :            : {
     191         [ +  - ]:      12339 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
     192                 :            : 
     193                 :            :     {
     194         [ +  - ]:      12339 :         SolarMutexGuard aSolarMutexGuard;
     195         [ -  + ]:      12339 :         if ( m_bDisposed )
     196 [ #  # ][ +  - ]:      12339 :             throw DisposedException();
     197                 :            :     }
     198                 :            : 
     199         [ +  - ]:      12339 :     com::sun::star::lang::EventObject aEvent( xThis );
     200         [ +  - ]:      12339 :     m_aListenerContainer.disposeAndClear( aEvent );
     201                 :            : 
     202         [ +  - ]:      12339 :     SolarMutexGuard aSolarMutexGuard;
     203         [ +  - ]:      12339 :     Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
     204         [ +  - ]:      12339 :     Reference< XURLTransformer > xURLTransformer = getURLTransformer();
     205         [ +  - ]:      12339 :     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     206                 :      12339 :     com::sun::star::util::URL aTargetURL;
     207 [ +  - ][ +  + ]:      28005 :     while ( pIter != m_aListenerMap.end() )
     208                 :            :     {
     209                 :            :         try
     210                 :            :         {
     211         [ +  - ]:      15666 :             Reference< XDispatch > xDispatch( pIter->second );
     212         [ +  - ]:      15666 :             aTargetURL.Complete = pIter->first;
     213 [ +  - ][ +  - ]:      15666 :             xURLTransformer->parseStrict( aTargetURL );
     214                 :            : 
     215 [ +  + ][ +  - ]:      15666 :             if ( xDispatch.is() && xStatusListener.is() )
                 [ +  + ]
     216 [ +  - ][ +  - ]:      15666 :                 xDispatch->removeStatusListener( xStatusListener, aTargetURL );
                 [ #  # ]
     217                 :            :         }
     218         [ #  # ]:          0 :         catch ( Exception& )
     219                 :            :         {
     220                 :            :         }
     221                 :            : 
     222                 :      15666 :         ++pIter;
     223                 :            :     }
     224                 :            : 
     225                 :            :     // clear hash map
     226         [ +  - ]:      12339 :     m_aListenerMap.clear();
     227                 :            : 
     228                 :            :     // release references
     229                 :      12339 :     m_xURLTransformer.clear();
     230                 :      12339 :     m_xServiceManager.clear();
     231                 :      12339 :     m_xFrame.clear();
     232                 :      12339 :     m_xParentWindow.clear();
     233                 :            : 
     234 [ +  - ][ +  - ]:      12339 :     m_bDisposed = sal_True;
     235                 :      12339 : }
     236                 :            : 
     237                 :          0 : void SAL_CALL StatusbarController::addEventListener( const Reference< XEventListener >& xListener )
     238                 :            : throw ( RuntimeException )
     239                 :            : {
     240                 :          0 :     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
     241                 :          0 : }
     242                 :            : 
     243                 :          0 : void SAL_CALL StatusbarController::removeEventListener( const Reference< XEventListener >& aListener )
     244                 :            : throw ( RuntimeException )
     245                 :            : {
     246                 :          0 :     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener );
     247                 :          0 : }
     248                 :            : 
     249                 :            : // XEventListener
     250                 :          0 : void SAL_CALL StatusbarController::disposing( const EventObject& Source )
     251                 :            : throw ( RuntimeException )
     252                 :            : {
     253                 :          0 :     Reference< XInterface > xSource( Source.Source );
     254                 :            : 
     255         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
     256                 :            : 
     257         [ #  # ]:          0 :     if ( m_bDisposed )
     258                 :          0 :         return;
     259                 :            : 
     260         [ #  # ]:          0 :     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     261 [ #  # ][ #  # ]:          0 :     while ( pIter != m_aListenerMap.end() )
     262                 :            :     {
     263                 :            :         // Compare references and release dispatch references if they are equal.
     264 [ #  # ][ #  # ]:          0 :         Reference< XInterface > xIfac( pIter->second, UNO_QUERY );
     265 [ #  # ][ #  # ]:          0 :         if ( xSource == xIfac )
     266         [ #  # ]:          0 :             pIter->second.clear();
     267                 :          0 :         ++pIter;
     268                 :          0 :     }
     269                 :            : 
     270         [ #  # ]:          0 :     Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
     271 [ #  # ][ #  # ]:          0 :     if ( xIfac == xSource )
     272 [ #  # ][ #  # ]:          0 :         m_xFrame.clear();
                 [ #  # ]
     273                 :            : }
     274                 :            : 
     275                 :            : // XStatusListener
     276                 :       6991 : void SAL_CALL StatusbarController::statusChanged( const FeatureStateEvent& Event )
     277                 :            : throw ( RuntimeException )
     278                 :            : {
     279         [ +  - ]:       6991 :     SolarMutexGuard aSolarMutexGuard;
     280                 :            : 
     281         [ -  + ]:       6991 :     if ( m_bDisposed )
     282                 :       6991 :         return;
     283                 :            : 
     284         [ +  - ]:       6991 :     Window* pWindow = VCLUnoHelper::GetWindow( m_xParentWindow );
     285 [ +  - ][ +  - ]:       6991 :     if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR && m_nID != 0 )
         [ +  - ][ +  - ]
                 [ +  - ]
     286                 :            :     {
     287                 :       6991 :         rtl::OUString aStrValue;
     288                 :       6991 :         StatusBar*    pStatusBar = (StatusBar *)pWindow;
     289                 :            : 
     290         [ +  + ]:       6991 :         if ( Event.State >>= aStrValue )
     291 [ +  - ][ +  - ]:       6884 :             pStatusBar->SetItemText( m_nID, aStrValue );
                 [ +  - ]
     292         [ +  - ]:        107 :         else if ( !Event.State.hasValue() )
     293 [ +  - ][ +  - ]:       6991 :             pStatusBar->SetItemText( m_nID, String() );
                 [ +  - ]
     294 [ +  - ][ +  - ]:       6991 :     }
     295                 :            : }
     296                 :            : 
     297                 :            : // XStatusbarController
     298                 :          0 : ::sal_Bool SAL_CALL StatusbarController::mouseButtonDown(
     299                 :            :     const ::com::sun::star::awt::MouseEvent& )
     300                 :            : throw (::com::sun::star::uno::RuntimeException)
     301                 :            : {
     302                 :          0 :     return sal_False;
     303                 :            : }
     304                 :            : 
     305                 :          0 : ::sal_Bool SAL_CALL StatusbarController::mouseMove(
     306                 :            :     const ::com::sun::star::awt::MouseEvent& )
     307                 :            : throw (::com::sun::star::uno::RuntimeException)
     308                 :            : {
     309                 :          0 :     return sal_False;
     310                 :            : }
     311                 :            : 
     312                 :          0 : ::sal_Bool SAL_CALL StatusbarController::mouseButtonUp(
     313                 :            :     const ::com::sun::star::awt::MouseEvent& )
     314                 :            : throw (::com::sun::star::uno::RuntimeException)
     315                 :            : {
     316                 :          0 :     return sal_False;
     317                 :            : }
     318                 :            : 
     319                 :          0 : void SAL_CALL StatusbarController::command(
     320                 :            :     const ::com::sun::star::awt::Point&,
     321                 :            :     ::sal_Int32,
     322                 :            :     ::sal_Bool,
     323                 :            :     const ::com::sun::star::uno::Any& )
     324                 :            : throw (::com::sun::star::uno::RuntimeException)
     325                 :            : {
     326                 :          0 : }
     327                 :            : 
     328                 :         80 : void SAL_CALL StatusbarController::paint(
     329                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >&,
     330                 :            :     const ::com::sun::star::awt::Rectangle&,
     331                 :            :     ::sal_Int32,
     332                 :            :     ::sal_Int32 )
     333                 :            : throw (::com::sun::star::uno::RuntimeException)
     334                 :            : {
     335                 :         80 : }
     336                 :            : 
     337                 :          0 : void SAL_CALL StatusbarController::click()
     338                 :            : throw (::com::sun::star::uno::RuntimeException)
     339                 :            : {
     340                 :          0 : }
     341                 :            : 
     342                 :          0 : void SAL_CALL StatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException)
     343                 :            : {
     344         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
     345                 :            : 
     346         [ #  # ]:          0 :     if ( m_bDisposed )
     347                 :          0 :         return;
     348                 :            : 
     349         [ #  # ]:          0 :     Sequence< PropertyValue > aArgs;
     350 [ #  # ][ #  # ]:          0 :     execute( aArgs );
         [ #  # ][ #  # ]
     351                 :            : }
     352                 :            : 
     353                 :       3327 : void StatusbarController::addStatusListener( const rtl::OUString& aCommandURL )
     354                 :            : {
     355                 :       3327 :     Reference< XDispatch >       xDispatch;
     356                 :       3327 :     Reference< XStatusListener > xStatusListener;
     357                 :       3327 :     com::sun::star::util::URL    aTargetURL;
     358                 :            : 
     359                 :            :     {
     360         [ +  - ]:       3327 :         SolarMutexGuard aSolarMutexGuard;
     361         [ +  - ]:       3327 :         URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
     362                 :            : 
     363                 :            :         // Already in the list of status listener. Do nothing.
     364 [ +  - ][ -  + ]:       3327 :         if ( pIter != m_aListenerMap.end() )
     365                 :            :             return;
     366                 :            : 
     367                 :            :         // Check if we are already initialized. Implementation starts adding itself as status listener when
     368                 :            :         // intialize is called.
     369         [ +  - ]:       3327 :         if ( !m_bInitialized )
     370                 :            :         {
     371                 :            :             // Put into the boost::unordered_map of status listener. Will be activated when initialized is called
     372 [ +  - ][ +  - ]:       3327 :             m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, Reference< XDispatch >() ));
                 [ +  - ]
     373                 :            :             return;
     374                 :            :         }
     375                 :            :         else
     376                 :            :         {
     377                 :            :             // Add status listener directly as intialize has already been called.
     378         [ #  # ]:          0 :             Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     379 [ #  # ][ #  # ]:          0 :             if ( m_xServiceManager.is() && xDispatchProvider.is() )
                 [ #  # ]
     380                 :            :             {
     381         [ #  # ]:          0 :                 Reference< XURLTransformer > xURLTransformer = getURLTransformer();
     382                 :          0 :                 aTargetURL.Complete = aCommandURL;
     383 [ #  # ][ #  # ]:          0 :                 xURLTransformer->parseStrict( aTargetURL );
     384 [ #  # ][ #  # ]:          0 :                 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
                 [ #  # ]
     385                 :            : 
     386 [ #  # ][ #  # ]:          0 :                 xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
                 [ #  # ]
     387         [ #  # ]:          0 :                 URLToDispatchMap::iterator aIter = m_aListenerMap.find( aCommandURL );
     388 [ #  # ][ #  # ]:          0 :                 if ( aIter != m_aListenerMap.end() )
     389                 :            :                 {
     390         [ #  # ]:          0 :                     Reference< XDispatch > xOldDispatch( aIter->second );
     391 [ #  # ][ #  # ]:          0 :                     aIter->second = xDispatch;
     392                 :            : 
     393                 :            :                     try
     394                 :            :                     {
     395         [ #  # ]:          0 :                         if ( xOldDispatch.is() )
     396 [ #  # ][ #  # ]:          0 :                             xOldDispatch->removeStatusListener( xStatusListener, aTargetURL );
     397                 :            :                     }
     398         [ #  # ]:          0 :                     catch ( Exception& )
     399                 :            :                     {
     400                 :          0 :                     }
     401                 :            :                 }
     402                 :            :                 else
     403 [ #  # ][ #  # ]:          0 :                     m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, xDispatch ));
                 [ #  # ]
     404                 :          0 :             }
     405         [ +  - ]:       3327 :         }
           [ -  +  #  # ]
     406                 :            :     }
     407                 :            : 
     408                 :            :     // Call without locked mutex as we are called back from dispatch implementation
     409                 :            :     try
     410                 :            :     {
     411         [ #  # ]:       3327 :         if ( xDispatch.is() )
     412 [ #  # ][ #  # ]:          0 :             xDispatch->addStatusListener( xStatusListener, aTargetURL );
     413                 :            :     }
     414         [ #  # ]:          0 :     catch ( Exception& )
     415                 :            :     {
     416 [ +  - ][ +  - ]:       3327 :     }
                 [ -  + ]
     417                 :            : }
     418                 :            : 
     419                 :      12339 : void StatusbarController::bindListener()
     420                 :            : {
     421         [ +  - ]:      12339 :     std::vector< Listener > aDispatchVector;
     422                 :      12339 :     Reference< XStatusListener > xStatusListener;
     423                 :            : 
     424                 :            :     {
     425         [ +  - ]:      12339 :         SolarMutexGuard aSolarMutexGuard;
     426                 :            : 
     427         [ -  + ]:      12339 :         if ( !m_bInitialized )
     428                 :      12339 :             return;
     429                 :            : 
     430                 :            :         // Collect all registered command URL's and store them temporary
     431         [ +  - ]:      12339 :         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     432 [ +  - ][ +  - ]:      12339 :         if ( m_xServiceManager.is() && xDispatchProvider.is() )
                 [ +  - ]
     433                 :            :         {
     434 [ +  - ][ +  - ]:      12339 :             xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
                 [ #  # ]
     435         [ +  - ]:      12339 :             URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     436 [ +  - ][ +  + ]:      28005 :             while ( pIter != m_aListenerMap.end() )
     437                 :            :             {
     438         [ +  - ]:      15666 :                 Reference< XURLTransformer > xURLTransformer = getURLTransformer();
     439                 :      15666 :                 com::sun::star::util::URL aTargetURL;
     440         [ +  - ]:      15666 :                 aTargetURL.Complete = pIter->first;
     441 [ +  - ][ +  - ]:      15666 :                 xURLTransformer->parseStrict( aTargetURL );
     442                 :            : 
     443         [ +  - ]:      15666 :                 Reference< XDispatch > xDispatch( pIter->second );
     444         [ -  + ]:      15666 :                 if ( xDispatch.is() )
     445                 :            :                 {
     446                 :            :                     // We already have a dispatch object => we have to requery.
     447                 :            :                     // Release old dispatch object and remove it as listener
     448                 :            :                     try
     449                 :            :                     {
     450 [ #  # ][ #  # ]:          0 :                         xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     451                 :            :                     }
     452         [ #  # ]:          0 :                     catch ( Exception& )
     453                 :            :                     {
     454                 :            :                     }
     455                 :            :                 }
     456                 :            : 
     457         [ +  - ]:      15666 :                 pIter->second.clear();
     458                 :      15666 :                 xDispatch.clear();
     459                 :            : 
     460                 :            :                 // Query for dispatch object. Old dispatch will be released with this, too.
     461                 :            :                 try
     462                 :            :                 {
     463 [ +  - ][ +  - ]:      15666 :                     xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
         [ #  # ][ +  - ]
     464                 :            :                 }
     465         [ #  # ]:          0 :                 catch ( Exception& )
     466                 :            :                 {
     467                 :            :                 }
     468 [ +  - ][ +  - ]:      15666 :                 pIter->second = xDispatch;
     469                 :            : 
     470         [ +  - ]:      15666 :                 Listener aListener( aTargetURL, xDispatch );
     471         [ +  - ]:      15666 :                 aDispatchVector.push_back( aListener );
     472                 :      15666 :                 ++pIter;
     473         [ +  - ]:      15666 :             }
     474 [ +  - ][ +  - ]:      12339 :         }
     475                 :            :     }
     476                 :            : 
     477                 :            :     // Call without locked mutex as we are called back from dispatch implementation
     478         [ +  - ]:      12339 :     if ( xStatusListener.is() )
     479                 :            :     {
     480                 :            :         try
     481                 :            :         {
     482         [ +  + ]:      28005 :             for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ )
     483                 :            :             {
     484         [ +  - ]:      15666 :                 Listener& rListener = aDispatchVector[i];
     485         [ +  + ]:      15666 :                 if ( rListener.xDispatch.is() )
     486 [ +  - ][ +  - ]:      14642 :                     rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL );
     487         [ -  + ]:       1024 :                 else if ( rListener.aURL.Complete == m_aCommandURL )
     488                 :            :                 {
     489                 :            :                     try
     490                 :            :                     {
     491                 :            :                         // Send status changed for the main URL, if we cannot get a valid dispatch object.
     492                 :            :                         // UI disables the button. Catch exception as we release our mutex, it is possible
     493                 :            :                         // that someone else already disposed this instance!
     494         [ #  # ]:          0 :                         FeatureStateEvent aFeatureStateEvent;
     495                 :          0 :                         aFeatureStateEvent.IsEnabled = sal_False;
     496                 :          0 :                         aFeatureStateEvent.FeatureURL = rListener.aURL;
     497                 :          0 :                         aFeatureStateEvent.State = Any();
     498 [ #  # ][ #  # ]:          0 :                         xStatusListener->statusChanged( aFeatureStateEvent );
         [ #  # ][ #  # ]
     499                 :            :                     }
     500   [ #  #  #  # ]:          0 :                     catch ( Exception& )
     501                 :            :                     {
     502                 :            :                     }
     503                 :            :                 }
     504                 :            :             }
     505                 :            :         }
     506         [ #  # ]:          0 :         catch ( Exception& )
     507                 :            :         {
     508                 :            :         }
     509 [ -  + ][ +  - ]:      12339 :     }
     510                 :            : }
     511                 :            : 
     512                 :      12570 : ::Rectangle StatusbarController::getControlRect() const
     513                 :            : {
     514                 :      12570 :     ::Rectangle aRect;
     515                 :            : 
     516                 :            :     {
     517         [ +  - ]:      12570 :         SolarMutexGuard aSolarMutexGuard;
     518                 :            : 
     519         [ -  + ]:      12570 :         if ( m_bDisposed )
     520         [ #  # ]:          0 :             throw DisposedException();
     521                 :            : 
     522         [ +  - ]:      12570 :         if ( m_xParentWindow.is() )
     523                 :            :         {
     524 [ +  - ][ -  + ]:      12570 :             StatusBar* pStatusBar = dynamic_cast< StatusBar* >( VCLUnoHelper::GetWindow( m_xParentWindow ));
     525 [ +  - ][ +  - ]:      12570 :             if ( pStatusBar && pStatusBar->GetType() == WINDOW_STATUSBAR )
         [ +  - ][ +  - ]
     526         [ +  - ]:      12570 :                 aRect = pStatusBar->GetItemRect( m_nID );
     527         [ +  - ]:      12570 :         }
     528                 :            :     }
     529                 :            : 
     530                 :      12570 :     return aRect;
     531                 :            : }
     532                 :            : 
     533                 :          0 : void StatusbarController::execute( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
     534                 :            : {
     535                 :          0 :     Reference< XDispatch >       xDispatch;
     536                 :          0 :     Reference< XURLTransformer > xURLTransformer;
     537                 :          0 :     rtl::OUString                aCommandURL;
     538                 :            : 
     539                 :            :     {
     540         [ #  # ]:          0 :         SolarMutexGuard aSolarMutexGuard;
     541                 :            : 
     542         [ #  # ]:          0 :         if ( m_bDisposed )
     543         [ #  # ]:          0 :             throw DisposedException();
     544                 :            : 
     545   [ #  #  #  #  :          0 :         if ( m_bInitialized &&
             #  #  #  # ]
                 [ #  # ]
     546                 :          0 :              m_xFrame.is() &&
     547                 :          0 :              m_xServiceManager.is() &&
     548                 :          0 :              !m_aCommandURL.isEmpty() )
     549                 :            :         {
     550 [ #  # ][ #  # ]:          0 :             xURLTransformer = getURLTransformer();
     551                 :          0 :             aCommandURL = m_aCommandURL;
     552         [ #  # ]:          0 :             URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
     553 [ #  # ][ #  # ]:          0 :             if ( pIter != m_aListenerMap.end() )
     554 [ #  # ][ #  # ]:          0 :                 xDispatch = pIter->second;
     555         [ #  # ]:          0 :         }
     556                 :            :     }
     557                 :            : 
     558 [ #  # ][ #  # ]:          0 :     if ( xDispatch.is() && xURLTransformer.is() )
                 [ #  # ]
     559                 :            :     {
     560                 :            :         try
     561                 :            :         {
     562                 :          0 :             com::sun::star::util::URL aTargetURL;
     563                 :            : 
     564                 :          0 :             aTargetURL.Complete = aCommandURL;
     565 [ #  # ][ #  # ]:          0 :             xURLTransformer->parseStrict( aTargetURL );
     566 [ #  # ][ #  # ]:          0 :             xDispatch->dispatch( aTargetURL, aArgs );
                 [ #  # ]
     567                 :            :         }
     568         [ #  # ]:          0 :         catch ( DisposedException& )
     569                 :            :         {
     570                 :            :         }
     571                 :          0 :     }
     572                 :          0 : }
     573                 :            : 
     574                 :          0 : void StatusbarController::execute(
     575                 :            :     const rtl::OUString& aCommandURL,
     576                 :            :     const Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
     577                 :            : {
     578                 :          0 :     Reference< XDispatch >      xDispatch;
     579                 :          0 :     com::sun::star::util::URL   aTargetURL;
     580                 :            : 
     581                 :            :     {
     582         [ #  # ]:          0 :         SolarMutexGuard aSolarMutexGuard;
     583                 :            : 
     584         [ #  # ]:          0 :         if ( m_bDisposed )
     585         [ #  # ]:          0 :             throw DisposedException();
     586                 :            : 
     587   [ #  #  #  #  :          0 :         if ( m_bInitialized &&
             #  #  #  # ]
                 [ #  # ]
     588                 :          0 :              m_xFrame.is() &&
     589                 :          0 :              m_xServiceManager.is() &&
     590                 :          0 :              !m_aCommandURL.isEmpty() )
     591                 :            :         {
     592         [ #  # ]:          0 :             Reference< XURLTransformer > xURLTransformer( getURLTransformer() );
     593                 :          0 :             aTargetURL.Complete = aCommandURL;
     594 [ #  # ][ #  # ]:          0 :             xURLTransformer->parseStrict( aTargetURL );
     595                 :            : 
     596         [ #  # ]:          0 :             URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
     597 [ #  # ][ #  # ]:          0 :             if ( pIter != m_aListenerMap.end() )
     598 [ #  # ][ #  # ]:          0 :                 xDispatch = pIter->second;
     599                 :            :             else
     600                 :            :             {
     601                 :            :                 Reference< ::com::sun::star::frame::XDispatchProvider > xDispatchProvider(
     602 [ #  # ][ #  # ]:          0 :                     m_xFrame->getController(), UNO_QUERY );
                 [ #  # ]
     603         [ #  # ]:          0 :                 if ( xDispatchProvider.is() )
     604 [ #  # ][ #  # ]:          0 :                     xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
                 [ #  # ]
     605                 :          0 :             }
     606   [ #  #  #  # ]:          0 :         }
     607                 :            :     }
     608                 :            : 
     609         [ #  # ]:          0 :     if ( xDispatch.is() )
     610                 :            :     {
     611                 :            :         try
     612                 :            :         {
     613 [ #  # ][ #  # ]:          0 :             xDispatch->dispatch( aTargetURL, aArgs );
     614                 :            :         }
     615         [ #  # ]:          0 :         catch ( DisposedException& )
     616                 :            :         {
     617                 :            :         }
     618                 :          0 :     }
     619                 :          0 : }
     620                 :            : 
     621                 :            : } // svt
     622                 :            : 
     623                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10