LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/uno - contextmenuhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 248 0.0 %
Date: 2012-12-27 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <svtools/contextmenuhelper.hxx>
      22             : #include <svtools/menuoptions.hxx>
      23             : #include <svtools/miscopt.hxx>
      24             : 
      25             : #include <com/sun/star/frame/XDispatch.hpp>
      26             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      27             : #include <com/sun/star/frame/ModuleManager.hpp>
      28             : #include <com/sun/star/frame/XStatusListener.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      31             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      32             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
      33             : #include <com/sun/star/ui/ImageType.hpp>
      34             : #include <com/sun/star/frame/UICommandDescription.hpp>
      35             : #include <com/sun/star/util/URLTransformer.hpp>
      36             : #include <com/sun/star/beans/PropertyValue.hpp>
      37             : 
      38             : #include <osl/conditn.hxx>
      39             : #include <cppuhelper/weak.hxx>
      40             : #include <comphelper/processfactory.hxx>
      41             : #include <osl/mutex.hxx>
      42             : #include <vcl/svapp.hxx>
      43             : #include <vcl/image.hxx>
      44             : #include <toolkit/unohlp.hxx>
      45             : #include <toolkit/awt/vclxwindow.hxx>
      46             : #include <toolkit/awt/vclxmenu.hxx>
      47             : 
      48             : using namespace ::com::sun::star;
      49             : 
      50             : namespace svt
      51             : {
      52             : 
      53             : // internal helper class to retrieve status updates
      54             : class StateEventHelper : public ::com::sun::star::frame::XStatusListener,
      55             :                          public ::cppu::OWeakObject
      56             : {
      57             :     public:
      58             :         StateEventHelper( const uno::Reference< frame::XDispatchProvider >& xDispatchProvider,
      59             :                           const uno::Reference< util::XURLTransformer >& xURLTransformer,
      60             :                           const rtl::OUString& aCommandURL );
      61             :         virtual ~StateEventHelper();
      62             : 
      63             :         bool isCommandEnabled();
      64             : 
      65             :         // XInterface
      66             :         virtual uno::Any SAL_CALL queryInterface( const uno::Type& aType ) throw ( uno::RuntimeException);
      67             :         virtual void SAL_CALL acquire() throw ();
      68             :         virtual void SAL_CALL release() throw ();
      69             : 
      70             :         // XEventListener
      71             :         virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( uno::RuntimeException );
      72             : 
      73             :         // XStatusListener
      74             :         virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& Event) throw( uno::RuntimeException );
      75             : 
      76             :     private:
      77             :         StateEventHelper();
      78             :         StateEventHelper( const StateEventHelper& );
      79             :         StateEventHelper& operator=( const StateEventHelper& );
      80             : 
      81             :         bool                                       m_bCurrentCommandEnabled;
      82             :         ::rtl::OUString                            m_aCommandURL;
      83             :         uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
      84             :         uno::Reference< util::XURLTransformer >    m_xURLTransformer;
      85             :         osl::Condition                             m_aCondition;
      86             : };
      87             : 
      88           0 : StateEventHelper::StateEventHelper(
      89             :     const uno::Reference< frame::XDispatchProvider >& xDispatchProvider,
      90             :     const uno::Reference< util::XURLTransformer >& xURLTransformer,
      91             :     const rtl::OUString& rCommandURL ) :
      92             :     m_bCurrentCommandEnabled( true ),
      93             :     m_aCommandURL( rCommandURL ),
      94             :     m_xDispatchProvider( xDispatchProvider ),
      95           0 :     m_xURLTransformer( xURLTransformer )
      96             : {
      97           0 :     m_aCondition.reset();
      98           0 : }
      99             : 
     100           0 : StateEventHelper::~StateEventHelper()
     101           0 : {}
     102             : 
     103           0 : uno::Any SAL_CALL StateEventHelper::queryInterface(
     104             :     const uno::Type& aType )
     105             : throw ( uno::RuntimeException )
     106             : {
     107             :     uno::Any a = ::cppu::queryInterface(
     108             :                 aType,
     109           0 :                 (static_cast< XStatusListener* >(this)));
     110             : 
     111           0 :     if( a.hasValue() )
     112           0 :         return a;
     113             : 
     114           0 :     return ::cppu::OWeakObject::queryInterface( aType );
     115             : }
     116             : 
     117           0 : void SAL_CALL StateEventHelper::acquire()
     118             : throw ()
     119             : {
     120           0 :     ::cppu::OWeakObject::acquire();
     121           0 : }
     122             : 
     123           0 : void SAL_CALL StateEventHelper::release()
     124             : throw ()
     125             : {
     126           0 :     ::cppu::OWeakObject::release();
     127           0 : }
     128             : 
     129           0 : void SAL_CALL StateEventHelper::disposing(
     130             :     const lang::EventObject& )
     131             : throw ( uno::RuntimeException )
     132             : {
     133           0 :     SolarMutexGuard aSolarGuard;
     134           0 :     m_xDispatchProvider.clear();
     135           0 :     m_xURLTransformer.clear();
     136           0 :     m_aCondition.set();
     137           0 : }
     138             : 
     139           0 : void SAL_CALL StateEventHelper::statusChanged(
     140             :     const frame::FeatureStateEvent& Event )
     141             : throw ( uno::RuntimeException )
     142             : {
     143           0 :     SolarMutexGuard aSolarGuard;
     144           0 :     m_bCurrentCommandEnabled = Event.IsEnabled;
     145           0 :     m_aCondition.set();
     146           0 : }
     147             : 
     148           0 : bool StateEventHelper::isCommandEnabled()
     149             : {
     150             :     // Be sure that we cannot die during condition wait
     151             :     uno::Reference< frame::XStatusListener > xSelf(
     152           0 :         (static_cast< frame::XStatusListener* >(this)));
     153             : 
     154           0 :     uno::Reference< frame::XDispatch > xDispatch;
     155           0 :     util::URL                          aTargetURL;
     156             :     {
     157           0 :         SolarMutexGuard aSolarGuard;
     158           0 :         if ( m_xDispatchProvider.is() && m_xURLTransformer.is() )
     159             :         {
     160           0 :             ::rtl::OUString aSelf( RTL_CONSTASCII_USTRINGPARAM( "_self" ));
     161             : 
     162           0 :             aTargetURL.Complete = m_aCommandURL;
     163           0 :             m_xURLTransformer->parseStrict( aTargetURL );
     164             : 
     165             :             try
     166             :             {
     167           0 :                 xDispatch = m_xDispatchProvider->queryDispatch( aTargetURL, aSelf, 0 );
     168             :             }
     169           0 :             catch ( uno::RuntimeException& )
     170             :             {
     171           0 :                 throw;
     172             :             }
     173           0 :             catch ( uno::Exception& )
     174             :             {
     175           0 :             }
     176           0 :         }
     177             :     }
     178             : 
     179           0 :     bool bResult( false );
     180           0 :     if ( xDispatch.is() )
     181             :     {
     182             :         try
     183             :         {
     184             :             // add/remove ourself to retrieve status by callback
     185           0 :             xDispatch->addStatusListener( xSelf, aTargetURL );
     186           0 :             xDispatch->removeStatusListener( xSelf, aTargetURL );
     187             : 
     188             :             // wait for anwser
     189           0 :             m_aCondition.wait();
     190             :         }
     191           0 :         catch ( uno::RuntimeException& )
     192             :         {
     193           0 :             throw;
     194             :         }
     195           0 :         catch ( uno::Exception& )
     196             :         {
     197             :         }
     198             : 
     199           0 :         SolarMutexGuard aSolarGuard;
     200           0 :         bResult = m_bCurrentCommandEnabled;
     201             :     }
     202             : 
     203           0 :     return bResult;
     204             : }
     205             : 
     206             : /*************************************************************************/
     207             : 
     208           0 : struct ExecuteInfo
     209             : {
     210             :     uno::Reference< frame::XDispatch >    xDispatch;
     211             :     util::URL                             aTargetURL;
     212             :     uno::Sequence< beans::PropertyValue > aArgs;
     213             : };
     214             : 
     215           0 : static const PopupMenu* lcl_FindPopupFromItemId( const PopupMenu* pPopupMenu, sal_uInt16 nItemId )
     216             : {
     217           0 :     if ( pPopupMenu )
     218             :     {
     219           0 :         sal_uInt16 nCount = pPopupMenu->GetItemCount();
     220           0 :         for ( sal_uInt16 i = 0; i < nCount; i++ )
     221             :         {
     222           0 :             sal_uInt16 nId = pPopupMenu->GetItemId( i );
     223           0 :             if ( nId == nItemId )
     224           0 :                 return pPopupMenu;
     225             :             else
     226             :             {
     227           0 :                 const PopupMenu* pResult( 0 );
     228             : 
     229           0 :                 const PopupMenu* pSubPopup = pPopupMenu->GetPopupMenu( i );
     230           0 :                 if ( pPopupMenu )
     231           0 :                     pResult = lcl_FindPopupFromItemId( pSubPopup, nItemId );
     232           0 :                 if ( pResult != 0 )
     233           0 :                     return pResult;
     234             :             }
     235             :         }
     236             :     }
     237             : 
     238           0 :     return NULL;
     239             : }
     240             : 
     241           0 : static ::rtl::OUString lcl_GetItemCommandRecursive( const PopupMenu* pPopupMenu, sal_uInt16 nItemId )
     242             : {
     243           0 :     const PopupMenu* pPopup = lcl_FindPopupFromItemId( pPopupMenu, nItemId );
     244           0 :     if ( pPopup )
     245           0 :         return pPopup->GetItemCommand( nItemId );
     246             :     else
     247           0 :         return ::rtl::OUString();
     248             : }
     249             : 
     250             : /*************************************************************************/
     251             : 
     252           0 : ContextMenuHelper::ContextMenuHelper(
     253             :     const uno::Reference< frame::XFrame >& xFrame,
     254             :     bool bAutoRefresh ) :
     255             :     m_xWeakFrame( xFrame ),
     256             :     m_aSelf( RTL_CONSTASCII_USTRINGPARAM( "_self" )),
     257             :     m_bAutoRefresh( bAutoRefresh ),
     258           0 :     m_bUICfgMgrAssociated( false )
     259             : {
     260           0 : }
     261             : 
     262           0 : ContextMenuHelper::~ContextMenuHelper()
     263             : {
     264           0 : }
     265             : 
     266             : void
     267           0 : ContextMenuHelper::completeAndExecute(
     268             :     const Point& aPos,
     269             :     PopupMenu& rPopupMenu )
     270             : {
     271           0 :     SolarMutexGuard aSolarGuard;
     272             : 
     273           0 :     associateUIConfigurationManagers();
     274           0 :     completeMenuProperties( &rPopupMenu );
     275           0 :     executePopupMenu( aPos, &rPopupMenu );
     276           0 :     resetAssociations();
     277           0 : }
     278             : 
     279             : void
     280           0 : ContextMenuHelper::completeAndExecute(
     281             :     const Point& aPos,
     282             :     const uno::Reference< awt::XPopupMenu >& xPopupMenu )
     283             : {
     284           0 :     SolarMutexGuard aSolarGuard;
     285             : 
     286           0 :     VCLXMenu* pXMenu = VCLXMenu::GetImplementation( xPopupMenu );
     287           0 :     if ( pXMenu )
     288             :     {
     289           0 :         PopupMenu* pPopupMenu = dynamic_cast< PopupMenu* >( pXMenu->GetMenu() );
     290             :         // as dynamic_cast can return zero check pointer
     291           0 :         if ( pPopupMenu )
     292             :         {
     293           0 :             associateUIConfigurationManagers();
     294           0 :             completeMenuProperties( pPopupMenu );
     295           0 :             executePopupMenu( aPos, pPopupMenu );
     296           0 :             resetAssociations();
     297             :         }
     298           0 :     }
     299           0 : }
     300             : 
     301             : // private member
     302             : 
     303             : void
     304           0 : ContextMenuHelper::executePopupMenu(
     305             :     const Point& rPos,
     306             :     PopupMenu* pMenu )
     307             : {
     308           0 :     if ( pMenu )
     309             :     {
     310           0 :         uno::Reference< frame::XFrame > xFrame( m_xWeakFrame );
     311           0 :         if ( xFrame.is() )
     312             :         {
     313           0 :             uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow() );
     314           0 :             if ( xWindow.is() )
     315             :             {
     316           0 :                 Window* pParent = VCLUnoHelper::GetWindow( xWindow );
     317           0 :                 sal_uInt16 nResult = pMenu->Execute( pParent, rPos );
     318             : 
     319           0 :                 if ( nResult > 0 )
     320             :                 {
     321           0 :                     ::rtl::OUString aCommand = lcl_GetItemCommandRecursive( pMenu, nResult );
     322           0 :                     if ( !aCommand.isEmpty() )
     323           0 :                         dispatchCommand( xFrame, aCommand );
     324             :                 }
     325           0 :             }
     326           0 :         }
     327             :     }
     328           0 : }
     329             : 
     330             : bool
     331           0 : ContextMenuHelper::dispatchCommand(
     332             :     const uno::Reference< ::frame::XFrame >& rFrame,
     333             :     const ::rtl::OUString& aCommandURL )
     334             : {
     335           0 :     if ( !m_xURLTransformer.is() )
     336             :     {
     337           0 :         m_xURLTransformer = util::URLTransformer::create( ::comphelper::getProcessComponentContext() );
     338             :     }
     339             : 
     340           0 :     util::URL aTargetURL;
     341           0 :     aTargetURL.Complete = aCommandURL;
     342           0 :     m_xURLTransformer->parseStrict( aTargetURL );
     343             : 
     344           0 :     uno::Reference< frame::XDispatch > xDispatch;
     345             :     uno::Reference< frame::XDispatchProvider > xDispatchProvider(
     346           0 :         rFrame, uno::UNO_QUERY );
     347           0 :     if ( xDispatchProvider.is() )
     348             :     {
     349             :         try
     350             :         {
     351           0 :             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, m_aSelf, 0 );
     352             :         }
     353           0 :         catch ( uno::RuntimeException& )
     354             :         {
     355           0 :             throw;
     356             :         }
     357           0 :         catch ( uno::Exception& )
     358             :         {
     359             :         }
     360             :     }
     361             : 
     362           0 :     if ( xDispatch.is() )
     363             :     {
     364           0 :         ExecuteInfo* pExecuteInfo = new ExecuteInfo;
     365           0 :         pExecuteInfo->xDispatch    = xDispatch;
     366           0 :         pExecuteInfo->aTargetURL   = aTargetURL;
     367           0 :         pExecuteInfo->aArgs        = m_aDefaultArgs;
     368             : 
     369           0 :         Application::PostUserEvent( STATIC_LINK(0, ContextMenuHelper , ExecuteHdl_Impl), pExecuteInfo );
     370           0 :         return true;
     371             :     }
     372             : 
     373           0 :     return false;
     374             : }
     375             : 
     376             : // retrieves and stores references to our user-interface
     377             : // configuration managers, like image manager, ui command
     378             : // description manager.
     379             : bool
     380           0 : ContextMenuHelper::associateUIConfigurationManagers()
     381             : {
     382           0 :     uno::Reference< frame::XFrame > xFrame( m_xWeakFrame );
     383           0 :     if ( !m_bUICfgMgrAssociated && xFrame.is() )
     384             :     {
     385             :         // clear current state
     386           0 :         m_xDocImageMgr.clear();
     387           0 :         m_xModuleImageMgr.clear();
     388           0 :         m_xUICommandLabels.clear();
     389             : 
     390             :         try
     391             :         {
     392           0 :             uno::Reference < frame::XController > xController;
     393           0 :             uno::Reference < frame::XModel > xModel;
     394           0 :             xController = xFrame->getController();
     395           0 :             if ( xController.is() )
     396           0 :                 xModel = xController->getModel();
     397             : 
     398           0 :             if ( xModel.is() )
     399             :             {
     400             :                 // retrieve document image manager form model
     401           0 :                 uno::Reference< ui::XUIConfigurationManagerSupplier > xSupplier( xModel, uno::UNO_QUERY );
     402           0 :                 if ( xSupplier.is() )
     403             :                 {
     404             :                     uno::Reference< ui::XUIConfigurationManager > xDocUICfgMgr(
     405           0 :                         xSupplier->getUIConfigurationManager(), uno::UNO_QUERY );
     406             :                     m_xDocImageMgr = uno::Reference< ui::XImageManager >(
     407           0 :                         xDocUICfgMgr->getImageManager(), uno::UNO_QUERY );
     408           0 :                 }
     409             :             }
     410             : 
     411             :             uno::Reference< frame::XModuleManager2 > xModuleManager(
     412           0 :                 frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ) );
     413             : 
     414           0 :             uno::Reference< ui::XImageManager > xModuleImageManager;
     415           0 :             rtl::OUString                       aModuleId;
     416             :             // retrieve module image manager
     417           0 :             aModuleId = xModuleManager->identify( xFrame );
     418             : 
     419             :             uno::Reference< ui::XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier(
     420             :                 ui::ModuleUIConfigurationManagerSupplier::create(
     421           0 :                     ::comphelper::getProcessComponentContext() ) );
     422             :             uno::Reference< ui::XUIConfigurationManager > xUICfgMgr(
     423           0 :                 xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId ));
     424           0 :             if ( xUICfgMgr.is() )
     425             :             {
     426             :                 m_xModuleImageMgr = uno::Reference< ui::XImageManager >(
     427           0 :                     xUICfgMgr->getImageManager(), uno::UNO_QUERY );
     428             :             }
     429             : 
     430             :             uno::Reference< container::XNameAccess > xNameAccess(
     431             :                 frame::UICommandDescription::create(
     432             :                         ::comphelper::getProcessComponentContext()),
     433           0 :                     uno::UNO_QUERY_THROW );
     434             :             try
     435             :             {
     436           0 :                 uno::Any a = xNameAccess->getByName( aModuleId );
     437           0 :                 a >>= m_xUICommandLabels;
     438             :             }
     439           0 :             catch ( container::NoSuchElementException& )
     440             :             {
     441           0 :             }
     442             :         }
     443           0 :         catch ( uno::RuntimeException& )
     444             :         {
     445           0 :             throw;
     446             :         }
     447           0 :         catch ( uno::Exception& )
     448             :         {
     449           0 :             m_bUICfgMgrAssociated = true;
     450           0 :             return false;
     451             :         }
     452           0 :         m_bUICfgMgrAssociated = true;
     453             :     }
     454             : 
     455           0 :     return true;
     456             : }
     457             : 
     458             : Image
     459           0 : ContextMenuHelper::getImageFromCommandURL( const ::rtl::OUString& aCmdURL ) const
     460             : {
     461           0 :     Image     aImage;
     462             :     sal_Int16 nImageType( ui::ImageType::COLOR_NORMAL|
     463           0 :                           ui::ImageType::SIZE_DEFAULT );
     464             : 
     465           0 :     uno::Sequence< uno::Reference< graphic::XGraphic > > aGraphicSeq;
     466           0 :     uno::Sequence< ::rtl::OUString > aImageCmdSeq( 1 );
     467           0 :     aImageCmdSeq[0] = aCmdURL;
     468             : 
     469           0 :     if ( m_xDocImageMgr.is() )
     470             :     {
     471             :         try
     472             :         {
     473           0 :             aGraphicSeq = m_xDocImageMgr->getImages( nImageType, aImageCmdSeq );
     474           0 :             uno::Reference< graphic::XGraphic > xGraphic = aGraphicSeq[0];
     475           0 :             aImage = Image( xGraphic );
     476             : 
     477           0 :             if ( !!aImage )
     478           0 :                 return aImage;
     479             :         }
     480           0 :         catch ( uno::RuntimeException& )
     481             :         {
     482           0 :             throw;
     483             :         }
     484           0 :         catch ( uno::Exception& )
     485             :         {
     486             :         }
     487             :     }
     488             : 
     489           0 :     if ( m_xModuleImageMgr.is() )
     490             :     {
     491             :         try
     492             :         {
     493           0 :             aGraphicSeq = m_xModuleImageMgr->getImages( nImageType, aImageCmdSeq );
     494           0 :             uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     495           0 :             aImage = Image( xGraphic );
     496             : 
     497           0 :             if ( !!aImage )
     498           0 :                 return aImage;
     499             :         }
     500           0 :         catch ( uno::RuntimeException& )
     501             :         {
     502           0 :             throw;
     503             :         }
     504           0 :         catch ( uno::Exception& )
     505             :         {
     506             :         }
     507             :     }
     508             : 
     509           0 :     return aImage;
     510             : }
     511             : 
     512             : rtl::OUString
     513           0 : ContextMenuHelper::getLabelFromCommandURL(
     514             :     const ::rtl::OUString& aCmdURL ) const
     515             : {
     516           0 :     ::rtl::OUString aLabel;
     517             : 
     518           0 :     if ( m_xUICommandLabels.is() )
     519             :     {
     520             :         try
     521             :         {
     522           0 :             if ( !aCmdURL.isEmpty() )
     523             :             {
     524           0 :                 rtl::OUString aStr;
     525           0 :                 uno::Sequence< beans::PropertyValue > aPropSeq;
     526           0 :                 uno::Any a( m_xUICommandLabels->getByName( aCmdURL ));
     527           0 :                 if ( a >>= aPropSeq )
     528             :                 {
     529           0 :                     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
     530             :                     {
     531           0 :                         if ( aPropSeq[i].Name == "Label" )
     532             :                         {
     533           0 :                             aPropSeq[i].Value >>= aStr;
     534           0 :                             break;
     535             :                         }
     536             :                     }
     537             :                 }
     538           0 :                 aLabel = aStr;
     539             :             }
     540             :         }
     541           0 :         catch ( uno::RuntimeException& )
     542             :         {
     543             :         }
     544           0 :         catch ( uno::Exception& )
     545             :         {
     546             :         }
     547             :     }
     548             : 
     549           0 :     return aLabel;
     550             : }
     551             : 
     552             : void
     553           0 : ContextMenuHelper::completeMenuProperties(
     554             :     Menu* pMenu )
     555             : {
     556             :     // Retrieve some settings necessary to display complete context
     557             :     // menu correctly.
     558           0 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     559           0 :     bool  bShowMenuImages( rSettings.GetUseImagesInMenus() );
     560             : 
     561           0 :     if ( pMenu )
     562             :     {
     563           0 :         uno::Reference< frame::XFrame > xFrame( m_xWeakFrame );
     564           0 :         uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY );
     565             : 
     566           0 :         if ( !m_xURLTransformer.is() )
     567             :         {
     568           0 :             m_xURLTransformer = util::URLTransformer::create( ::comphelper::getProcessComponentContext() );
     569             :         }
     570             : 
     571           0 :         for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
     572             :         {
     573           0 :             sal_uInt16 nId        = pMenu->GetItemId( nPos );
     574           0 :             PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nId );
     575           0 :             if ( pPopupMenu )
     576           0 :                 completeMenuProperties( pPopupMenu );
     577           0 :             if ( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR )
     578             :             {
     579           0 :                 ::rtl::OUString aCmdURL( pMenu->GetItemCommand( nId ));
     580             : 
     581           0 :                 if ( bShowMenuImages )
     582             :                 {
     583           0 :                     Image aImage;
     584           0 :                     if ( !aCmdURL.isEmpty() )
     585           0 :                         aImage = getImageFromCommandURL( aCmdURL );
     586           0 :                     pMenu->SetItemImage( nId, aImage );
     587             :                 }
     588             :                 else
     589           0 :                     pMenu->SetItemImage( nId, Image() );
     590             : 
     591           0 :                 if ( pMenu->GetItemText( nId ).Len() == 0 )
     592             :                 {
     593           0 :                     ::rtl::OUString aLabel( getLabelFromCommandURL( aCmdURL ));
     594           0 :                     pMenu->SetItemText( nId, aLabel );
     595             :                 }
     596             : 
     597             :                 // Use helper to retrieve state of the command URL
     598             :                 StateEventHelper* pHelper = new StateEventHelper(
     599             :                                                     xDispatchProvider,
     600             :                                                     m_xURLTransformer,
     601           0 :                                                     aCmdURL );
     602             : 
     603           0 :                 uno::Reference< frame::XStatusListener > xHelper( pHelper );
     604           0 :                 pMenu->EnableItem( nId, pHelper->isCommandEnabled() );
     605             :             }
     606           0 :         }
     607             :     }
     608           0 : }
     609             : 
     610             : 
     611           0 : IMPL_STATIC_LINK_NOINSTANCE( ContextMenuHelper, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     612             : {
     613             :     // Release solar mutex to prevent deadlocks with clipboard thread
     614           0 :     const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     615             :     try
     616             :     {
     617             :         // Asynchronous execution as this can lead to our own destruction while we are
     618             :         // on the stack. Stack unwinding would access the destroyed context menu.
     619           0 :         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
     620             :     }
     621           0 :     catch ( uno::Exception& )
     622             :     {
     623             :     }
     624             : 
     625             :     // Acquire solar mutex again
     626           0 :     Application::AcquireSolarMutex( nRef );
     627           0 :     delete pExecuteInfo;
     628           0 :     return 0;
     629             : }
     630             : 
     631             : } // namespace svt
     632             : 
     633             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10