LCOV - code coverage report
Current view: top level - svtools/source/uno - toolboxcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 218 380 57.4 %
Date: 2014-04-11 Functions: 26 42 61.9 %
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 <svtools/toolboxcontroller.hxx>
      21             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      25             : #include <com/sun/star/lang/DisposedException.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/frame/XLayoutManager.hpp>
      28             : #include <com/sun/star/util/URLTransformer.hpp>
      29             : #include <osl/mutex.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <svtools/imgdef.hxx>
      32             : #include <svtools/miscopt.hxx>
      33             : #include <toolkit/helper/vclunohelper.hxx>
      34             : #include <vcl/toolbox.hxx>
      35             : #include <comphelper/processfactory.hxx>
      36             : 
      37             : const int TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE  = 1;
      38             : const char TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE[] = "SupportsVisible";
      39             : 
      40             : 
      41             : using namespace ::cppu;
      42             : using namespace ::com::sun::star::awt;
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::util;
      45             : using namespace ::com::sun::star::beans;
      46             : using namespace ::com::sun::star::lang;
      47             : using namespace ::com::sun::star::frame;
      48             : 
      49             : namespace svt
      50             : {
      51             : 
      52       47730 : ToolboxController::ToolboxController(
      53             :     const Reference< XComponentContext >& rxContext,
      54             :     const Reference< XFrame >& xFrame,
      55             :     const OUString& aCommandURL ) :
      56       47730 :     OPropertyContainer( GetBroadcastHelper() )
      57             :     ,   m_bSupportVisible( false )
      58             :     ,   m_bInitialized( false )
      59             :     ,   m_bDisposed( false )
      60             :     ,   m_nToolBoxId( SAL_MAX_UINT16 )
      61             :     ,   m_xFrame( xFrame )
      62             :     ,   m_xContext( rxContext )
      63             :     ,   m_aCommandURL( aCommandURL )
      64       95460 :     ,   m_aListenerContainer( m_aMutex )
      65             : {
      66             :     OSL_ASSERT( m_xContext.is() );
      67             :     registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE),
      68             :         TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE,
      69             :         css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY,
      70       47730 :         &m_bSupportVisible, getCppuType(&m_bSupportVisible));
      71             : 
      72             :     try
      73             :     {
      74       47730 :         m_xUrlTransformer = URLTransformer::create( rxContext );
      75             :     }
      76           0 :     catch(const Exception&)
      77             :     {
      78             :     }
      79       47730 : }
      80             : 
      81       11121 : ToolboxController::ToolboxController() :
      82       11121 :     OPropertyContainer(GetBroadcastHelper())
      83             :     ,   m_bSupportVisible(false)
      84             :     ,   m_bInitialized( false )
      85             :     ,   m_bDisposed( false )
      86             :     ,   m_nToolBoxId( SAL_MAX_UINT16 )
      87       22242 :     ,   m_aListenerContainer( m_aMutex )
      88             : {
      89             :     registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE),
      90             :         TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE,
      91             :         css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY,
      92       11121 :         &m_bSupportVisible, getCppuType(&m_bSupportVisible));
      93       11121 : }
      94             : 
      95       58841 : ToolboxController::~ToolboxController()
      96             : {
      97       58841 : }
      98             : 
      99       44284 : Reference< XFrame > ToolboxController::getFrameInterface() const
     100             : {
     101       44284 :     SolarMutexGuard aSolarMutexGuard;
     102       44284 :     return m_xFrame;
     103             : }
     104             : 
     105           0 : const Reference< XComponentContext > & ToolboxController::getContext() const
     106             : {
     107           0 :     SolarMutexGuard aSolarMutexGuard;
     108           0 :     return m_xContext;
     109             : }
     110             : 
     111         781 : Reference< XLayoutManager > ToolboxController::getLayoutManager() const
     112             : {
     113         781 :     Reference< XLayoutManager > xLayoutManager;
     114        1562 :     Reference< XPropertySet > xPropSet;
     115             :     {
     116         781 :         SolarMutexGuard aSolarMutexGuard;
     117         781 :         xPropSet = Reference< XPropertySet >( m_xFrame, UNO_QUERY );
     118             :     }
     119             : 
     120         781 :     if ( xPropSet.is() )
     121             :     {
     122             :         try
     123             :         {
     124         781 :             xLayoutManager.set(xPropSet->getPropertyValue("LayoutManager"),UNO_QUERY);
     125             :         }
     126           0 :         catch ( Exception& )
     127             :         {
     128             :         }
     129             :     }
     130             : 
     131        1562 :     return xLayoutManager;
     132             : }
     133             : 
     134             : // XInterface
     135      520233 : Any SAL_CALL ToolboxController::queryInterface( const Type& rType )
     136             : throw ( RuntimeException, std::exception )
     137             : {
     138      520233 :     css::uno::Any a(ToolboxController_Base::queryInterface(rType));
     139      520233 :     return a.hasValue() ? a : OPropertyContainer::queryInterface(rType);
     140             : }
     141             : 
     142     1077829 : void SAL_CALL ToolboxController::acquire() throw ()
     143             : {
     144     1077829 :     ToolboxController_Base::acquire();
     145     1077829 : }
     146             : 
     147     1077819 : void SAL_CALL ToolboxController::release() throw ()
     148             : {
     149     1077819 :     ToolboxController_Base::release();
     150     1077819 : }
     151             : 
     152           0 : css::uno::Sequence<css::uno::Type> ToolboxController::getTypes()
     153             :     throw (css::uno::RuntimeException, std::exception)
     154             : {
     155           0 :     css::uno::Sequence<css::uno::Type> s1(ToolboxController_Base::getTypes());
     156           0 :     css::uno::Sequence<css::uno::Type> s2(getBaseTypes());
     157           0 :     sal_Int32 n = s1.getLength();
     158           0 :     s1.realloc(n + s2.getLength());
     159           0 :     for (sal_Int32 i = 0; i != s2.getLength(); ++i) {
     160           0 :         s1[n + i] = s2[i];
     161             :     }
     162           0 :     return s1;
     163             : }
     164             : 
     165       58851 : void SAL_CALL ToolboxController::initialize( const Sequence< Any >& aArguments )
     166             : throw ( Exception, RuntimeException, std::exception )
     167             : {
     168       58851 :     bool bInitialized( true );
     169             : 
     170             :     {
     171       58851 :         SolarMutexGuard aSolarMutexGuard;
     172             : 
     173       58851 :         if ( m_bDisposed )
     174           0 :             throw DisposedException();
     175             : 
     176       58851 :         bInitialized = m_bInitialized;
     177             :     }
     178             : 
     179       58851 :     if ( !bInitialized )
     180             :     {
     181       58851 :         SolarMutexGuard aSolarMutexGuard;
     182       58851 :         m_bInitialized = true;
     183       58851 :         m_bSupportVisible = false;
     184      117702 :         PropertyValue aPropValue;
     185      360027 :         for ( int i = 0; i < aArguments.getLength(); i++ )
     186             :         {
     187      301176 :             if ( aArguments[i] >>= aPropValue )
     188             :             {
     189      301176 :                 if ( aPropValue.Name == "Frame" )
     190       58851 :                     m_xFrame.set(aPropValue.Value,UNO_QUERY);
     191      242325 :                 else if ( aPropValue.Name == "CommandURL" )
     192       58851 :                     aPropValue.Value >>= m_aCommandURL;
     193      183474 :                 else if ( aPropValue.Name == "ServiceManager" )
     194             :                 {
     195       58851 :                     Reference<XMultiServiceFactory> xMSF(aPropValue.Value, UNO_QUERY);
     196       58851 :                     if (xMSF.is())
     197       58851 :                         m_xContext = comphelper::getComponentContext(xMSF);
     198             :                 }
     199      124623 :                 else if ( aPropValue.Name == "ParentWindow" )
     200       41541 :                     m_xParentWindow.set(aPropValue.Value,UNO_QUERY);
     201       83082 :                 else if ( aPropValue.Name == "ModuleIdentifier" )
     202       41541 :                     aPropValue.Value >>= m_sModuleName;
     203       41541 :                 else if ( aPropValue.Name == "Identifier" )
     204       41541 :                     aPropValue.Value >>= m_nToolBoxId;
     205             :             }
     206             :         }
     207             : 
     208             :         try
     209             :         {
     210       58851 :             if ( !m_xUrlTransformer.is() && m_xContext.is() )
     211       11121 :                 m_xUrlTransformer = URLTransformer::create( m_xContext );
     212             :         }
     213           0 :         catch(const Exception&)
     214             :         {
     215             :         }
     216             : 
     217       58851 :         if ( !m_aCommandURL.isEmpty() )
     218      117702 :             m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() ));
     219             :     }
     220       58851 : }
     221             : 
     222       55484 : void SAL_CALL ToolboxController::update()
     223             : throw ( RuntimeException, std::exception )
     224             : {
     225             :     {
     226       55484 :         SolarMutexGuard aSolarMutexGuard;
     227       55484 :         if ( m_bDisposed )
     228           0 :             throw DisposedException();
     229             :     }
     230             : 
     231             :     // Bind all registered listeners to their dispatch objects
     232       55484 :     bindListener();
     233       55484 : }
     234             : 
     235             : // XComponent
     236       58739 : void SAL_CALL ToolboxController::dispose()
     237             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     238             : {
     239       58739 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
     240             : 
     241             :     {
     242       58739 :         SolarMutexGuard aSolarMutexGuard;
     243       58739 :         if ( m_bDisposed )
     244           0 :             throw DisposedException();
     245             :     }
     246             : 
     247      117478 :     com::sun::star::lang::EventObject aEvent( xThis );
     248       58739 :     m_aListenerContainer.disposeAndClear( aEvent );
     249             : 
     250      117478 :     SolarMutexGuard aSolarMutexGuard;
     251      117478 :     Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
     252       58739 :     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     253      181158 :     while ( pIter != m_aListenerMap.end() )
     254             :     {
     255             :         try
     256             :         {
     257       63680 :             Reference< XDispatch > xDispatch( pIter->second );
     258             : 
     259      127360 :             com::sun::star::util::URL aTargetURL;
     260       63680 :             aTargetURL.Complete = pIter->first;
     261       63680 :             if ( m_xUrlTransformer.is() )
     262       63680 :                 m_xUrlTransformer->parseStrict( aTargetURL );
     263             : 
     264       63680 :             if ( xDispatch.is() && xStatusListener.is() )
     265      109573 :                 xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     266             :         }
     267           0 :         catch ( Exception& )
     268             :         {
     269             :         }
     270             : 
     271       63680 :         ++pIter;
     272             :     }
     273             : 
     274      117478 :     m_bDisposed = true;
     275       58739 : }
     276             : 
     277           0 : void SAL_CALL ToolboxController::addEventListener( const Reference< XEventListener >& xListener )
     278             : throw ( RuntimeException, std::exception )
     279             : {
     280           0 :     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
     281           0 : }
     282             : 
     283           0 : void SAL_CALL ToolboxController::removeEventListener( const Reference< XEventListener >& aListener )
     284             : throw ( RuntimeException, std::exception )
     285             : {
     286           0 :     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener );
     287           0 : }
     288             : 
     289             : // XEventListener
     290           0 : void SAL_CALL ToolboxController::disposing( const EventObject& Source )
     291             : throw ( RuntimeException, std::exception )
     292             : {
     293           0 :     Reference< XInterface > xSource( Source.Source );
     294             : 
     295           0 :     SolarMutexGuard aSolarMutexGuard;
     296             : 
     297           0 :     if ( m_bDisposed )
     298           0 :         return;
     299             : 
     300           0 :     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     301           0 :     while ( pIter != m_aListenerMap.end() )
     302             :     {
     303             :         // Compare references and release dispatch references if they are equal.
     304           0 :         Reference< XInterface > xIfac( pIter->second, UNO_QUERY );
     305           0 :         if ( xSource == xIfac )
     306           0 :             pIter->second.clear();
     307           0 :         ++pIter;
     308           0 :     }
     309             : 
     310           0 :     Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
     311           0 :     if ( xIfac == xSource )
     312           0 :         m_xFrame.clear();
     313             : }
     314             : 
     315             : // XStatusListener
     316         173 : void SAL_CALL ToolboxController::statusChanged( const FeatureStateEvent& )
     317             : throw ( RuntimeException, std::exception )
     318             : {
     319             :     // must be implemented by sub class
     320         173 : }
     321             : 
     322             : // XToolbarController
     323           0 : void SAL_CALL ToolboxController::execute( sal_Int16 KeyModifier )
     324             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     325             : {
     326           0 :     Reference< XDispatch >       xDispatch;
     327           0 :     OUString                     aCommandURL;
     328             : 
     329             :     {
     330           0 :         SolarMutexGuard aSolarMutexGuard;
     331             : 
     332           0 :         if ( m_bDisposed )
     333           0 :             throw DisposedException();
     334             : 
     335           0 :         if ( m_bInitialized &&
     336           0 :              m_xFrame.is() &&
     337           0 :              m_xContext.is() &&
     338           0 :              !m_aCommandURL.isEmpty() )
     339             :         {
     340             : 
     341           0 :             aCommandURL = m_aCommandURL;
     342           0 :             URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
     343           0 :             if ( pIter != m_aListenerMap.end() )
     344           0 :                 xDispatch = pIter->second;
     345           0 :         }
     346             :     }
     347             : 
     348           0 :     if ( xDispatch.is() )
     349             :     {
     350             :         try
     351             :         {
     352           0 :             com::sun::star::util::URL aTargetURL;
     353           0 :             Sequence<PropertyValue>   aArgs( 1 );
     354             : 
     355             :             // Provide key modifier information to dispatch function
     356           0 :             aArgs[0].Name   = "KeyModifier";
     357           0 :             aArgs[0].Value  = makeAny( KeyModifier );
     358             : 
     359           0 :             aTargetURL.Complete = aCommandURL;
     360           0 :             if ( m_xUrlTransformer.is() )
     361           0 :                 m_xUrlTransformer->parseStrict( aTargetURL );
     362           0 :             xDispatch->dispatch( aTargetURL, aArgs );
     363             :         }
     364           0 :         catch ( DisposedException& )
     365             :         {
     366             :         }
     367           0 :     }
     368           0 : }
     369             : 
     370           2 : void SAL_CALL ToolboxController::click()
     371             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     372             : {
     373           2 : }
     374             : 
     375           0 : void SAL_CALL ToolboxController::doubleClick()
     376             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     377             : {
     378           0 : }
     379             : 
     380           0 : Reference< XWindow > SAL_CALL ToolboxController::createPopupWindow()
     381             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     382             : {
     383           0 :     return Reference< XWindow >();
     384             : }
     385             : 
     386       48025 : Reference< XWindow > SAL_CALL ToolboxController::createItemWindow( const Reference< XWindow >& )
     387             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     388             : {
     389       48025 :     return Reference< XWindow >();
     390             : }
     391             : 
     392        5402 : void ToolboxController::addStatusListener( const OUString& aCommandURL )
     393             : {
     394        5402 :     Reference< XDispatch >       xDispatch;
     395        5402 :     Reference< XStatusListener > xStatusListener;
     396        5402 :     com::sun::star::util::URL    aTargetURL;
     397             : 
     398             :     {
     399        5402 :         SolarMutexGuard aSolarMutexGuard;
     400        5402 :         URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
     401             : 
     402             :         // Already in the list of status listener. Do nothing.
     403        5402 :         if ( pIter != m_aListenerMap.end() )
     404         126 :             return;
     405             : 
     406             :         // Check if we are already initialized. Implementation starts adding itself as status listener when
     407             :         // intialize is called.
     408        5276 :         if ( !m_bInitialized )
     409             :         {
     410             :             // Put into the boost::unordered_map of status listener. Will be activated when initialized is called
     411        5276 :             m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, Reference< XDispatch >() ));
     412        5276 :             return;
     413             :         }
     414             :         else
     415             :         {
     416             :             // Add status listener directly as intialize has already been called.
     417           0 :             Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     418           0 :             if ( m_xContext.is() && xDispatchProvider.is() )
     419             :             {
     420           0 :                 aTargetURL.Complete = aCommandURL;
     421           0 :                 if ( m_xUrlTransformer.is() )
     422           0 :                     m_xUrlTransformer->parseStrict( aTargetURL );
     423           0 :                 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
     424             : 
     425           0 :                 xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
     426           0 :                 URLToDispatchMap::iterator aIter = m_aListenerMap.find( aCommandURL );
     427           0 :                 if ( aIter != m_aListenerMap.end() )
     428             :                 {
     429           0 :                     Reference< XDispatch > xOldDispatch( aIter->second );
     430           0 :                     aIter->second = xDispatch;
     431             : 
     432             :                     try
     433             :                     {
     434           0 :                         if ( xOldDispatch.is() )
     435           0 :                             xOldDispatch->removeStatusListener( xStatusListener, aTargetURL );
     436             :                     }
     437           0 :                     catch ( Exception& )
     438             :                     {
     439           0 :                     }
     440             :                 }
     441             :                 else
     442           0 :                     m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, xDispatch ));
     443           0 :             }
     444           0 :         }
     445             :     }
     446             : 
     447             :     // Call without locked mutex as we are called back from dispatch implementation
     448             :     try
     449             :     {
     450           0 :         if ( xDispatch.is() )
     451           0 :             xDispatch->addStatusListener( xStatusListener, aTargetURL );
     452             :     }
     453           0 :     catch ( Exception& )
     454             :     {
     455           0 :     }
     456             : }
     457             : 
     458          24 : void ToolboxController::removeStatusListener( const OUString& aCommandURL )
     459             : {
     460          24 :     SolarMutexGuard aSolarMutexGuard;
     461             : 
     462          24 :     URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
     463          24 :     if ( pIter != m_aListenerMap.end() )
     464             :     {
     465          24 :         Reference< XDispatch > xDispatch( pIter->second );
     466          48 :         Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
     467          24 :         m_aListenerMap.erase( pIter );
     468             : 
     469             :         try
     470             :         {
     471          24 :             com::sun::star::util::URL aTargetURL;
     472          24 :             aTargetURL.Complete = aCommandURL;
     473          24 :             if ( m_xUrlTransformer.is() )
     474          24 :                 m_xUrlTransformer->parseStrict( aTargetURL );
     475             : 
     476          24 :             if ( xDispatch.is() && xStatusListener.is() )
     477          20 :                 xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     478             :         }
     479           0 :         catch ( Exception& )
     480             :         {
     481          24 :         }
     482          24 :     }
     483          24 : }
     484             : 
     485       56258 : void ToolboxController::bindListener()
     486             : {
     487       56258 :     std::vector< Listener > aDispatchVector;
     488      112516 :     Reference< XStatusListener > xStatusListener;
     489             : 
     490             :     {
     491       56258 :         SolarMutexGuard aSolarMutexGuard;
     492             : 
     493       56258 :         if ( !m_bInitialized )
     494       56258 :             return;
     495             : 
     496             :         // Collect all registered command URL's and store them temporary
     497      112516 :         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     498       56258 :         if ( m_xContext.is() && xDispatchProvider.is() )
     499             :         {
     500       56258 :             xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
     501       56258 :             URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     502      174225 :             while ( pIter != m_aListenerMap.end() )
     503             :             {
     504       61709 :                 com::sun::star::util::URL aTargetURL;
     505       61709 :                 aTargetURL.Complete = pIter->first;
     506       61709 :                 if ( m_xUrlTransformer.is() )
     507       61709 :                     m_xUrlTransformer->parseStrict( aTargetURL );
     508             : 
     509      123418 :                 Reference< XDispatch > xDispatch( pIter->second );
     510       61709 :                 if ( xDispatch.is() )
     511             :                 {
     512             :                     // We already have a dispatch object => we have to requery.
     513             :                     // Release old dispatch object and remove it as listener
     514             :                     try
     515             :                     {
     516        2447 :                         xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     517             :                     }
     518           0 :                     catch ( Exception& )
     519             :                     {
     520             :                     }
     521             :                 }
     522             : 
     523       61709 :                 pIter->second.clear();
     524       61709 :                 xDispatch.clear();
     525             : 
     526             :                 // Query for dispatch object. Old dispatch will be released with this, too.
     527             :                 try
     528             :                 {
     529       61709 :                     xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
     530             :                 }
     531           0 :                 catch ( Exception& )
     532             :                 {
     533             :                 }
     534       61709 :                 pIter->second = xDispatch;
     535             : 
     536      123418 :                 Listener aListener( aTargetURL, xDispatch );
     537       61709 :                 aDispatchVector.push_back( aListener );
     538       61709 :                 ++pIter;
     539       61709 :             }
     540       56258 :         }
     541             :     }
     542             : 
     543             :     // Call without locked mutex as we are called back from dispatch implementation
     544       56258 :     if ( xStatusListener.is() )
     545             :     {
     546             :         try
     547             :         {
     548      117967 :             for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ )
     549             :             {
     550       61709 :                 Listener& rListener = aDispatchVector[i];
     551       61709 :                 if ( rListener.xDispatch.is() )
     552       48370 :                     rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL );
     553       13339 :                 else if ( rListener.aURL.Complete == m_aCommandURL )
     554             :                 {
     555             :                     try
     556             :                     {
     557             :                         // Send status changed for the main URL, if we cannot get a valid dispatch object.
     558             :                         // UI disables the button. Catch exception as we release our mutex, it is possible
     559             :                         // that someone else already disposed this instance!
     560       13186 :                         FeatureStateEvent aFeatureStateEvent;
     561       13186 :                         aFeatureStateEvent.IsEnabled = sal_False;
     562       13186 :                         aFeatureStateEvent.FeatureURL = rListener.aURL;
     563       13186 :                         aFeatureStateEvent.State = Any();
     564       13186 :                         xStatusListener->statusChanged( aFeatureStateEvent );
     565             :                     }
     566           0 :                     catch ( Exception& )
     567             :                     {
     568             :                     }
     569             :                 }
     570             :             }
     571             :         }
     572           0 :         catch ( Exception& )
     573             :         {
     574             :         }
     575       56258 :     }
     576             : }
     577             : 
     578           0 : void ToolboxController::unbindListener()
     579             : {
     580           0 :     SolarMutexGuard aSolarMutexGuard;
     581             : 
     582           0 :     if ( !m_bInitialized )
     583           0 :         return;
     584             : 
     585             :     // Collect all registered command URL's and store them temporary
     586           0 :     Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     587           0 :     if ( m_xContext.is() && xDispatchProvider.is() )
     588             :     {
     589           0 :         Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
     590           0 :         URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
     591           0 :         while ( pIter != m_aListenerMap.end() )
     592             :         {
     593           0 :             com::sun::star::util::URL aTargetURL;
     594           0 :             aTargetURL.Complete = pIter->first;
     595           0 :             if ( m_xUrlTransformer.is() )
     596           0 :                 m_xUrlTransformer->parseStrict( aTargetURL );
     597             : 
     598           0 :             Reference< XDispatch > xDispatch( pIter->second );
     599           0 :             if ( xDispatch.is() )
     600             :             {
     601             :                 // We already have a dispatch object => we have to requery.
     602             :                 // Release old dispatch object and remove it as listener
     603             :                 try
     604             :                 {
     605           0 :                     xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     606             :                 }
     607           0 :                 catch ( Exception& )
     608             :                 {
     609             :                 }
     610             :             }
     611           0 :             pIter->second.clear();
     612           0 :             ++pIter;
     613           0 :         }
     614           0 :     }
     615             : }
     616             : 
     617         814 : bool ToolboxController::isBound() const
     618             : {
     619         814 :     SolarMutexGuard aSolarMutexGuard;
     620             : 
     621         814 :     if ( !m_bInitialized )
     622           0 :         return false;
     623             : 
     624         814 :     URLToDispatchMap::const_iterator pIter = m_aListenerMap.find( m_aCommandURL );
     625         814 :     if ( pIter != m_aListenerMap.end() )
     626         814 :         return pIter->second.is();
     627             : 
     628           0 :     return false;
     629             : }
     630             : 
     631           0 : void ToolboxController::updateStatus()
     632             : {
     633           0 :     bindListener();
     634           0 : }
     635             : 
     636          61 : void ToolboxController::updateStatus( const OUString& aCommandURL )
     637             : {
     638          61 :     Reference< XDispatch > xDispatch;
     639         122 :     Reference< XStatusListener > xStatusListener;
     640         122 :     com::sun::star::util::URL aTargetURL;
     641             : 
     642             :     {
     643          61 :         SolarMutexGuard aSolarMutexGuard;
     644             : 
     645          61 :         if ( !m_bInitialized )
     646          61 :             return;
     647             : 
     648             :         // Try to find a dispatch object for the requested command URL
     649         122 :         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     650          61 :         xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
     651          61 :         if ( m_xContext.is() && xDispatchProvider.is() )
     652             :         {
     653          61 :             aTargetURL.Complete = aCommandURL;
     654          61 :             if ( m_xUrlTransformer.is() )
     655          61 :                 m_xUrlTransformer->parseStrict( aTargetURL );
     656          61 :             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
     657          61 :         }
     658             :     }
     659             : 
     660          61 :     if ( xDispatch.is() && xStatusListener.is() )
     661             :     {
     662             :         // Catch exception as we release our mutex, it is possible that someone else
     663             :         // has already disposed this instance!
     664             :         // Add/remove status listener to get a update status information from the
     665             :         // requested command.
     666             :         try
     667             :         {
     668          61 :             xDispatch->addStatusListener( xStatusListener, aTargetURL );
     669          61 :             xDispatch->removeStatusListener( xStatusListener, aTargetURL );
     670             :         }
     671           0 :         catch ( Exception& )
     672             :         {
     673             :         }
     674          61 :     }
     675             : }
     676             : 
     677           0 : Reference< XURLTransformer > ToolboxController::getURLTransformer() const
     678             : {
     679           0 :     return m_xUrlTransformer;
     680             : }
     681             : 
     682        3043 : Reference< ::com::sun::star::awt::XWindow > ToolboxController::getParent() const
     683             : {
     684        3043 :     return m_xParentWindow;
     685             : }
     686             : 
     687           0 : void ToolboxController::dispatchCommand( const OUString& sCommandURL, const Sequence< PropertyValue >& rArgs, const OUString &sTarget )
     688             : {
     689             :     try
     690             :     {
     691           0 :         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY_THROW );
     692           0 :         URL aURL;
     693           0 :         aURL.Complete = sCommandURL;
     694           0 :         getURLTransformer()->parseStrict( aURL );
     695             : 
     696           0 :         Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch( aURL, sTarget, 0 ), UNO_QUERY_THROW );
     697             : 
     698           0 :         DispatchInfo *pDispatchInfo = new DispatchInfo( xDispatch, aURL, rArgs );
     699           0 :         if ( !Application::PostUserEvent( STATIC_LINK(0, ToolboxController, ExecuteHdl_Impl),
     700           0 :                                           pDispatchInfo ) )
     701           0 :             delete pDispatchInfo;
     702             : 
     703             :     }
     704           0 :     catch( Exception& )
     705             :     {
     706             :     }
     707           0 : }
     708             : 
     709             : 
     710             : 
     711           0 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >  SAL_CALL ToolboxController::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException, std::exception)
     712             : {
     713           0 :     Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
     714           0 :     return xInfo;
     715             : }
     716             : 
     717       82878 : ::cppu::IPropertyArrayHelper& ToolboxController::getInfoHelper()
     718             : {
     719       82878 :         return *const_cast<ToolboxController*>(this)->getArrayHelper();
     720             : }
     721             : 
     722             : 
     723         578 : ::cppu::IPropertyArrayHelper* ToolboxController::createArrayHelper( ) const
     724             : {
     725         578 :         com::sun::star::uno::Sequence< Property > aProps;
     726         578 :         describeProperties(aProps);
     727         578 :         return new ::cppu::OPropertyArrayHelper(aProps);
     728             : }
     729             : 
     730        1126 : void ToolboxController::setSupportVisibleProperty(bool bValue)
     731             : {
     732        1126 :     m_bSupportVisible = bValue;
     733        1126 : }
     734             : 
     735           0 : sal_Bool SAL_CALL ToolboxController::convertFastPropertyValue( com::sun::star::uno::Any&    aConvertedValue ,
     736             :                                              com::sun::star::uno::Any&        aOldValue       ,
     737             :                                              sal_Int32                        nHandle         ,
     738             :                                              const com::sun::star::uno::Any&  aValue          ) throw( com::sun::star::lang::IllegalArgumentException )
     739             : {
     740           0 :     switch (nHandle)
     741             :     {
     742             :         case TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE:
     743             :         {
     744           0 :             sal_Bool aNewValue(sal_False);
     745           0 :             aValue >>= aNewValue;
     746           0 :             if (aNewValue != (m_bSupportVisible ? 1 : 0))
     747             :             {
     748           0 :                 aConvertedValue <<= aNewValue;
     749           0 :                 aOldValue <<= m_bSupportVisible;
     750           0 :                 return sal_True;
     751             :             }
     752           0 :             return sal_False;
     753             :         }
     754             :     }
     755           0 :     return OPropertyContainer::convertFastPropertyValue(aConvertedValue, aOldValue, nHandle, aValue);
     756             : }
     757             : 
     758        1126 : void SAL_CALL ToolboxController::setFastPropertyValue_NoBroadcast(
     759             :     sal_Int32                       nHandle,
     760             :     const com::sun::star::uno::Any& aValue )
     761             : throw( com::sun::star::uno::Exception, std::exception)
     762             : {
     763        1126 :     OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, aValue);
     764        1126 :     if (TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE == nHandle)
     765             :     {
     766        1126 :         sal_Bool rValue(sal_False);
     767        1126 :         if (( aValue >>= rValue ) && m_bInitialized)
     768        1126 :             this->setSupportVisibleProperty( rValue );
     769             :     }
     770        1126 : }
     771             : 
     772             : 
     773             : 
     774           0 : IMPL_STATIC_LINK_NOINSTANCE( ToolboxController, ExecuteHdl_Impl, DispatchInfo*, pDispatchInfo )
     775             : {
     776           0 :     pDispatchInfo->mxDispatch->dispatch( pDispatchInfo->maURL, pDispatchInfo->maArgs );
     777           0 :     delete pDispatchInfo;
     778           0 :     return 0;
     779             : }
     780             : 
     781        1167 : void ToolboxController::enable( bool bEnable )
     782             : {
     783        1167 :     ToolBox* pToolBox = 0;
     784        1167 :     sal_uInt16 nItemId = 0;
     785        1167 :     if( getToolboxId( nItemId, &pToolBox ) )
     786             :     {
     787        1167 :         pToolBox->EnableItem( nItemId, bEnable ? sal_True : sal_False );
     788             :     }
     789        1167 : }
     790             : 
     791        1167 : bool ToolboxController::getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox )
     792             : {
     793        1167 :     if( (m_nToolBoxId != SAL_MAX_UINT16) && (ppToolBox == 0) )
     794           0 :         return m_nToolBoxId;
     795             : 
     796        1167 :     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     797             : 
     798        1167 :     if( (m_nToolBoxId == SAL_MAX_UINT16) && pToolBox )
     799             :     {
     800           0 :         const sal_uInt16 nCount = pToolBox->GetItemCount();
     801           0 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     802             :         {
     803           0 :             const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
     804           0 :             if ( pToolBox->GetItemCommand( nItemId ) == m_aCommandURL )
     805             :             {
     806           0 :                 m_nToolBoxId = nItemId;
     807           0 :                 break;
     808             :             }
     809             :         }
     810             :     }
     811             : 
     812        1167 :     if( ppToolBox )
     813        1167 :         *ppToolBox = pToolBox;
     814             : 
     815        1167 :     rItemId = m_nToolBoxId;
     816             : 
     817        1167 :     return (rItemId != SAL_MAX_UINT16) && (( ppToolBox == 0) || (*ppToolBox != 0) );
     818             : }
     819             : //end
     820             : 
     821             : } // svt
     822             : 
     823             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10