LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - newmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 265 0.0 %
Date: 2012-12-27 Functions: 0 23 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             : #include <uielement/newmenucontroller.hxx>
      21             : 
      22             : #include <threadhelp/resetableguard.hxx>
      23             : #include "services.h"
      24             : #include <classes/resource.hrc>
      25             : #include <classes/fwkresid.hxx>
      26             : #include <framework/bmkmenu.hxx>
      27             : #include <framework/imageproducer.hxx>
      28             : #include <framework/menuconfiguration.hxx>
      29             : 
      30             : #include <com/sun/star/awt/XDevice.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/awt/MenuItemStyle.hpp>
      33             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
      34             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      35             : #include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
      36             : #include <com/sun/star/frame/ModuleManager.hpp>
      37             : 
      38             : #include <vcl/svapp.hxx>
      39             : #include <vcl/i18nhelp.hxx>
      40             : #include <rtl/ustrbuf.hxx>
      41             : #include <cppuhelper/implbase1.hxx>
      42             : #include <osl/file.hxx>
      43             : #include <svtools/menuoptions.hxx>
      44             : #include <svtools/acceleratorexecute.hxx>
      45             : #include <unotools/moduleoptions.hxx>
      46             : #include <osl/mutex.hxx>
      47             : 
      48             : //_________________________________________________________________________________________________________________
      49             : //  Defines
      50             : //_________________________________________________________________________________________________________________
      51             : 
      52             : using namespace com::sun::star::uno;
      53             : using namespace com::sun::star::lang;
      54             : using namespace com::sun::star::frame;
      55             : using namespace com::sun::star::beans;
      56             : using namespace com::sun::star::util;
      57             : using namespace com::sun::star::container;
      58             : using namespace com::sun::star::ui;
      59             : 
      60             : static const char SFX_REFERER_USER[] = "private:user";
      61             : 
      62             : namespace framework
      63             : {
      64             : 
      65           0 : DEFINE_XSERVICEINFO_MULTISERVICE        (   NewMenuController                           ,
      66             :                                             OWeakObject                                 ,
      67             :                                             SERVICENAME_POPUPMENUCONTROLLER             ,
      68             :                                             IMPLEMENTATIONNAME_NEWMENUCONTROLLER
      69             :                                         )
      70             : 
      71           0 : DEFINE_INIT_SERVICE                     (   NewMenuController, {} )
      72             : 
      73           0 : void NewMenuController::setMenuImages( PopupMenu* pPopupMenu, sal_Bool bSetImages )
      74             : {
      75           0 :     sal_uInt16 nItemCount = pPopupMenu->GetItemCount();
      76           0 :     Image               aImage;
      77           0 :     Reference< XFrame > xFrame( m_xFrame );
      78             : 
      79           0 :     for ( sal_uInt16 i = 0; i < nItemCount; i++ )
      80             :     {
      81           0 :         sal_uInt16 nItemId = pPopupMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ));
      82           0 :         if ( nItemId != 0 )
      83             :         {
      84           0 :             if ( bSetImages )
      85             :             {
      86           0 :                 sal_Bool        bImageSet( sal_False );
      87           0 :                 ::rtl::OUString aImageId;
      88             : 
      89           0 :                 AddInfoForId::const_iterator pInfo = m_aAddInfoForItem.find( nItemId );
      90           0 :                 if ( pInfo != m_aAddInfoForItem.end() )
      91           0 :                     aImageId = pInfo->second.aImageId; // Retrieve image id for menu item
      92             : 
      93           0 :                 if ( !aImageId.isEmpty() )
      94             :                 {
      95           0 :                     aImage = GetImageFromURL( xFrame, aImageId, false );
      96           0 :                     if ( !!aImage )
      97             :                     {
      98           0 :                         bImageSet = sal_True;
      99           0 :                         pPopupMenu->SetItemImage( nItemId, aImage );
     100             :                     }
     101             :                 }
     102             : 
     103           0 :                 if ( !bImageSet )
     104             :                 {
     105           0 :                     String aCmd( pPopupMenu->GetItemCommand( nItemId ) );
     106           0 :                     if ( aCmd.Len() )
     107           0 :                         aImage = GetImageFromURL( xFrame, aCmd, false );
     108             : 
     109           0 :                     if ( !!aImage )
     110           0 :                         pPopupMenu->SetItemImage( nItemId, aImage );
     111           0 :                 }
     112             :             }
     113             :             else
     114           0 :                 pPopupMenu->SetItemImage( nItemId, aImage );
     115             :         }
     116           0 :     }
     117           0 : }
     118             : 
     119           0 : void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const KeyCode& rKeyCode )
     120             : {
     121           0 :     sal_uInt16        nCount( pPopupMenu->GetItemCount() );
     122           0 :     sal_uInt16        nId( 0 );
     123           0 :     sal_Bool      bFound( sal_False );
     124           0 :     rtl::OUString aCommand;
     125             : 
     126           0 :     if ( !m_aEmptyDocURL.isEmpty() )
     127             :     {
     128             :         // Search for the empty document URL
     129             : 
     130           0 :         for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
     131             :         {
     132           0 :             nId = pPopupMenu->GetItemId( sal_uInt16( i ));
     133           0 :             if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR )
     134             :             {
     135           0 :                 aCommand = pPopupMenu->GetItemCommand( nId );
     136           0 :                 if ( aCommand.indexOf( m_aEmptyDocURL ) == 0 )
     137             :                 {
     138           0 :                     pPopupMenu->SetAccelKey( nId, rKeyCode );
     139           0 :                     bFound = sal_True;
     140           0 :                     break;
     141             :                 }
     142             :             }
     143             :         }
     144             :     }
     145             : 
     146           0 :     if ( !bFound )
     147             :     {
     148             :         // Search for the default module name
     149           0 :         rtl::OUString aDefaultModuleName( SvtModuleOptions().GetDefaultModuleName() );
     150           0 :         if ( !aDefaultModuleName.isEmpty() )
     151             :         {
     152           0 :             for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
     153             :             {
     154           0 :                 nId = pPopupMenu->GetItemId( sal_uInt16( i ));
     155           0 :                 if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR )
     156             :                 {
     157           0 :                     aCommand = pPopupMenu->GetItemCommand( nId );
     158           0 :                     if ( aCommand.indexOf( aDefaultModuleName ) >= 0 )
     159             :                     {
     160           0 :                         pPopupMenu->SetAccelKey( nId, rKeyCode );
     161           0 :                         break;
     162             :                     }
     163             :                 }
     164             :             }
     165           0 :         }
     166           0 :     }
     167           0 : }
     168             : 
     169           0 : void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
     170             : {
     171           0 :     if ( m_bModuleIdentified )
     172             :     {
     173           0 :         Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
     174           0 :         Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
     175           0 :         Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
     176             : 
     177           0 :         if ( !m_bAcceleratorCfg )
     178             :         {
     179             :             // Retrieve references on demand
     180           0 :             m_bAcceleratorCfg = sal_True;
     181           0 :             if ( !xDocAccelCfg.is() )
     182             :             {
     183           0 :                 Reference< XController > xController = m_xFrame->getController();
     184           0 :                 Reference< XModel > xModel;
     185           0 :                 if ( xController.is() )
     186             :                 {
     187           0 :                     xModel = xController->getModel();
     188           0 :                     if ( xModel.is() )
     189             :                     {
     190           0 :                         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     191           0 :                         if ( xSupplier.is() )
     192             :                         {
     193           0 :                             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
     194           0 :                             if ( xDocUICfgMgr.is() )
     195             :                             {
     196           0 :                                 xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY );
     197           0 :                                 m_xDocAcceleratorManager = xDocAccelCfg;
     198           0 :                             }
     199           0 :                         }
     200             :                     }
     201           0 :                 }
     202             :             }
     203             : 
     204           0 :             if ( !xModuleAccelCfg.is() )
     205             :             {
     206             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
     207           0 :                     ModuleUIConfigurationManagerSupplier::create( comphelper::getComponentContext(m_xServiceManager) );
     208           0 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
     209           0 :                 if ( xUICfgMgr.is() )
     210             :                 {
     211           0 :                     xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY );
     212           0 :                     m_xModuleAcceleratorManager = xModuleAccelCfg;
     213           0 :                 }
     214             :             }
     215             : 
     216           0 :             if ( !xGlobalAccelCfg.is() )
     217             :             {
     218           0 :                 xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( comphelper::getComponentContext(m_xServiceManager) );
     219           0 :                 m_xGlobalAcceleratorManager = xGlobalAccelCfg;
     220             :             }
     221             :         }
     222             : 
     223           0 :         KeyCode                         aEmptyKeyCode;
     224           0 :         sal_uInt32                      nItemCount( pPopupMenu->GetItemCount() );
     225           0 :         std::vector< KeyCode >          aMenuShortCuts;
     226           0 :         std::vector< rtl::OUString >    aCmds;
     227           0 :         std::vector< sal_uInt32 >       aIds;
     228           0 :         for ( sal_uInt32 i = 0; i < nItemCount; i++ )
     229             :         {
     230           0 :             sal_uInt16 nId( pPopupMenu->GetItemId( sal_uInt16( i )));
     231           0 :             if ( nId & ( pPopupMenu->GetItemType( nId ) != MENUITEM_SEPARATOR ))
     232             :             {
     233           0 :                 aIds.push_back( nId );
     234           0 :                 aMenuShortCuts.push_back( aEmptyKeyCode );
     235           0 :                 aCmds.push_back( pPopupMenu->GetItemCommand( nId ));
     236             :             }
     237             :         }
     238             : 
     239           0 :         sal_uInt32 nSeqCount( aIds.size() );
     240             : 
     241           0 :         if ( m_bNewMenu )
     242           0 :             nSeqCount+=1;
     243             : 
     244           0 :         Sequence< rtl::OUString > aSeq( nSeqCount );
     245             : 
     246             :         // Add a special command for our "New" menu.
     247           0 :         if ( m_bNewMenu )
     248             :         {
     249           0 :             aSeq[nSeqCount-1] = m_aCommandURL;
     250           0 :             aMenuShortCuts.push_back( aEmptyKeyCode );
     251             :         }
     252             : 
     253           0 :         const sal_uInt32 nCount = aCmds.size();
     254           0 :         for ( sal_uInt32 i = 0; i < nCount; i++ )
     255           0 :             aSeq[i] = aCmds[i];
     256             : 
     257           0 :         if ( m_xGlobalAcceleratorManager.is() )
     258           0 :             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
     259           0 :         if ( m_xModuleAcceleratorManager.is() )
     260           0 :             retrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts );
     261           0 :         if ( m_xDocAcceleratorManager.is() )
     262           0 :             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
     263             : 
     264           0 :         const sal_uInt32 nCount2 = aIds.size();
     265           0 :         for ( sal_uInt32 i = 0; i < nCount2; i++ )
     266           0 :             pPopupMenu->SetAccelKey( sal_uInt16( aIds[i] ), aMenuShortCuts[i] );
     267             : 
     268             :         // Special handling for "New" menu short-cut should be set at the
     269             :         // document which will be opened using it.
     270           0 :         if ( m_bNewMenu )
     271             :         {
     272           0 :             if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode )
     273           0 :                 determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] );
     274           0 :         }
     275             :     }
     276           0 : }
     277             : 
     278           0 : void NewMenuController::retrieveShortcutsFromConfiguration(
     279             :     const Reference< XAcceleratorConfiguration >& rAccelCfg,
     280             :     const Sequence< rtl::OUString >& rCommands,
     281             :     std::vector< KeyCode >& aMenuShortCuts )
     282             : {
     283           0 :     if ( rAccelCfg.is() )
     284             :     {
     285             :         try
     286             :         {
     287           0 :             com::sun::star::awt::KeyEvent aKeyEvent;
     288           0 :             Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands );
     289           0 :             for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ )
     290             :             {
     291           0 :                 if ( aSeqKeyCode[i] >>= aKeyEvent )
     292           0 :                     aMenuShortCuts[i] = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent );
     293           0 :             }
     294             :         }
     295           0 :         catch ( const IllegalArgumentException& )
     296             :         {
     297             :         }
     298             :     }
     299           0 : }
     300             : 
     301           0 : NewMenuController::NewMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
     302             :     svt::PopupMenuControllerBase( xServiceManager ),
     303             :     m_bShowImages( sal_True ),
     304             :     m_bNewMenu( sal_False ),
     305             :     m_bModuleIdentified( sal_False ),
     306             :     m_bAcceleratorCfg( sal_False ),
     307           0 :     m_aTargetFrame( "_default" )
     308             : {
     309           0 : }
     310             : 
     311           0 : NewMenuController::~NewMenuController()
     312             : {
     313           0 : }
     314             : 
     315             : // private function
     316           0 : void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
     317             : {
     318           0 :     VCLXPopupMenu* pPopupMenu    = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
     319           0 :     PopupMenu*     pVCLPopupMenu = 0;
     320             : 
     321           0 :     SolarMutexGuard aSolarMutexGuard;
     322             : 
     323           0 :     resetPopupMenu( rPopupMenu );
     324           0 :     if ( pPopupMenu )
     325           0 :         pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
     326             : 
     327           0 :     if ( pVCLPopupMenu )
     328             :     {
     329           0 :         MenuConfiguration aMenuCfg( m_xServiceManager );
     330           0 :         BmkMenu* pSubMenu( 0 );
     331             : 
     332           0 :         if ( m_bNewMenu )
     333           0 :             pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
     334             :         else
     335           0 :             pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
     336             : 
     337             :         // copy entries as we have to use the provided popup menu
     338           0 :         *pVCLPopupMenu = *pSubMenu;
     339             : 
     340           0 :         Image           aImage;
     341           0 :         AddInfo         aAddInfo;
     342             : 
     343             :         // retrieve additional parameters from bookmark menu and
     344             :         // store it in a boost::unordered_map.
     345           0 :         for ( sal_uInt16 i = 0; i < pSubMenu->GetItemCount(); i++ )
     346             :         {
     347           0 :             sal_uInt16 nItemId = pSubMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ) );
     348           0 :             if (( nItemId != 0 ) &&
     349           0 :                 ( pSubMenu->GetItemType( nItemId ) != MENUITEM_SEPARATOR ))
     350             :             {
     351           0 :                 MenuConfiguration::Attributes* pBmkAttributes = (MenuConfiguration::Attributes *)(pSubMenu->GetUserValue( nItemId ));
     352           0 :                 if ( pBmkAttributes != 0 )
     353             :                 {
     354           0 :                     aAddInfo.aTargetFrame = pBmkAttributes->aTargetFrame;
     355           0 :                     aAddInfo.aImageId     = pBmkAttributes->aImageId;
     356             : 
     357           0 :                     m_aAddInfoForItem.insert( AddInfoForId::value_type( nItemId, aAddInfo ));
     358             :                 }
     359             :             }
     360             :         }
     361             : 
     362           0 :         if ( m_bShowImages )
     363           0 :             setMenuImages( pVCLPopupMenu, m_bShowImages );
     364             : 
     365           0 :         delete pSubMenu;
     366           0 :     }
     367           0 : }
     368             : 
     369             : // XEventListener
     370           0 : void SAL_CALL NewMenuController::disposing( const EventObject& ) throw ( RuntimeException )
     371             : {
     372           0 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     373             : 
     374           0 :     osl::MutexGuard aLock( m_aMutex );
     375           0 :     m_xFrame.clear();
     376           0 :     m_xDispatch.clear();
     377           0 :     m_xServiceManager.clear();
     378             : 
     379           0 :     if ( m_xPopupMenu.is() )
     380           0 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
     381           0 :     m_xPopupMenu.clear();
     382           0 : }
     383             : 
     384             : // XStatusListener
     385           0 : void SAL_CALL NewMenuController::statusChanged( const FeatureStateEvent& ) throw ( RuntimeException )
     386             : {
     387           0 : }
     388             : 
     389             : // XMenuListener
     390           0 : void SAL_CALL NewMenuController::select( const css::awt::MenuEvent& rEvent ) throw (RuntimeException)
     391             : {
     392           0 :     Reference< css::awt::XPopupMenu > xPopupMenu;
     393           0 :     Reference< XDispatch >            xDispatch;
     394           0 :     Reference< XDispatchProvider >    xDispatchProvider;
     395           0 :     Reference< XMultiServiceFactory > xServiceManager;
     396           0 :     Reference< XURLTransformer >      xURLTransformer;
     397             : 
     398           0 :     osl::ClearableMutexGuard aLock( m_aMutex );
     399           0 :     xPopupMenu          = m_xPopupMenu;
     400           0 :     xDispatchProvider   = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
     401           0 :     xServiceManager     = m_xServiceManager;
     402           0 :     xURLTransformer     = m_xURLTransformer;
     403           0 :     aLock.clear();
     404             : 
     405           0 :     css::util::URL aTargetURL;
     406           0 :     Sequence< PropertyValue > aArgsList( 1 );
     407             : 
     408           0 :     if ( xPopupMenu.is() && xDispatchProvider.is() )
     409             :     {
     410           0 :         VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( xPopupMenu );
     411           0 :         if ( pPopupMenu )
     412             :         {
     413             :             {
     414           0 :                 SolarMutexGuard aSolarMutexGuard;
     415           0 :                 PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
     416           0 :                 aTargetURL.Complete = pVCLPopupMenu->GetItemCommand( rEvent.MenuId );
     417             :             }
     418             : 
     419           0 :             xURLTransformer->parseStrict( aTargetURL );
     420             : 
     421           0 :             aArgsList[0].Name = ::rtl::OUString( "Referer" );
     422           0 :             aArgsList[0].Value = makeAny( ::rtl::OUString(SFX_REFERER_USER ));
     423             : 
     424           0 :             rtl::OUString aTargetFrame( m_aTargetFrame );
     425           0 :             AddInfoForId::const_iterator pItem = m_aAddInfoForItem.find( rEvent.MenuId );
     426           0 :             if ( pItem != m_aAddInfoForItem.end() )
     427           0 :                 aTargetFrame = pItem->second.aTargetFrame;
     428             : 
     429           0 :             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTargetFrame, 0 );
     430             :         }
     431             :     }
     432             : 
     433           0 :     if ( xDispatch.is() )
     434             :     {
     435             :         // Call dispatch asychronously as we can be destroyed while dispatch is
     436             :         // executed. VCL is not able to survive this as it wants to call listeners
     437             :         // after select!!!
     438           0 :         NewDocument* pNewDocument = new NewDocument;
     439           0 :         pNewDocument->xDispatch  = xDispatch;
     440           0 :         pNewDocument->aTargetURL = aTargetURL;
     441           0 :         pNewDocument->aArgSeq    = aArgsList;
     442           0 :         Application::PostUserEvent( STATIC_LINK(0, NewMenuController, ExecuteHdl_Impl), pNewDocument );
     443           0 :     }
     444           0 : }
     445             : 
     446           0 : void SAL_CALL NewMenuController::activate( const css::awt::MenuEvent& ) throw (RuntimeException)
     447             : {
     448           0 :     SolarMutexGuard aSolarMutexGuard;
     449           0 :     if ( m_xFrame.is() && m_xPopupMenu.is() )
     450             :     {
     451           0 :         VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( m_xPopupMenu );
     452           0 :         if ( pPopupMenu )
     453             :         {
     454           0 :             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     455           0 :             sal_Bool bShowImages( rSettings.GetUseImagesInMenus() );
     456             : 
     457           0 :             PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
     458             : 
     459           0 :             if ( m_bShowImages != bShowImages )
     460             :             {
     461           0 :                 m_bShowImages = bShowImages;
     462           0 :                 setMenuImages( pVCLPopupMenu, m_bShowImages );
     463             :             }
     464             : 
     465           0 :             setAccelerators( pVCLPopupMenu );
     466             :         }
     467           0 :     }
     468           0 : }
     469             : 
     470             : // XPopupMenuController
     471           0 : void NewMenuController::impl_setPopupMenu()
     472             : {
     473             : 
     474           0 :     if ( m_xPopupMenu.is() )
     475           0 :         fillPopupMenu( m_xPopupMenu );
     476             : 
     477             :     // Identify module that we are attach to. It's our context that we need to know.
     478           0 :     Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext(m_xServiceManager) );
     479             :     try
     480             :     {
     481           0 :         m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
     482           0 :         m_bModuleIdentified = sal_True;
     483             : 
     484           0 :         if ( !m_aModuleIdentifier.isEmpty() )
     485             :         {
     486           0 :             Sequence< PropertyValue > aSeq;
     487             : 
     488           0 :             if ( xModuleManager->getByName( m_aModuleIdentifier ) >>= aSeq )
     489             :             {
     490           0 :                 for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
     491             :                 {
     492           0 :                     if ( aSeq[y].Name == "ooSetupFactoryEmptyDocumentURL" )
     493             :                     {
     494           0 :                         aSeq[y].Value >>= m_aEmptyDocURL;
     495           0 :                         break;
     496             :                     }
     497             :                 }
     498           0 :             }
     499             :         }
     500             :     }
     501           0 :     catch ( const RuntimeException& )
     502             :     {
     503           0 :         throw;
     504             :     }
     505           0 :     catch ( const Exception& )
     506             :     {
     507           0 :     }
     508           0 : }
     509             : 
     510             : // XInitialization
     511           0 : void SAL_CALL NewMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
     512             : {
     513           0 :     osl::MutexGuard aLock( m_aMutex );
     514             : 
     515           0 :     sal_Bool bInitalized( m_bInitialized );
     516           0 :     if ( !bInitalized )
     517             :     {
     518           0 :         svt::PopupMenuControllerBase::initialize( aArguments );
     519             : 
     520           0 :         if ( m_bInitialized )
     521             :         {
     522           0 :             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     523             : 
     524           0 :             m_bShowImages   = rSettings.GetUseImagesInMenus();
     525           0 :             m_bNewMenu      = m_aCommandURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:AddDirect" ) );
     526             :         }
     527           0 :     }
     528           0 : }
     529             : 
     530           0 : IMPL_STATIC_LINK_NOINSTANCE( NewMenuController, ExecuteHdl_Impl, NewDocument*, pNewDocument )
     531             : {
     532             : /*  i62706: Don't catch all exceptions. We hide all problems here and are not able
     533             :             to handle them on higher levels.
     534             :     try
     535             :     {
     536             : */
     537             :         // Asynchronous execution as this can lead to our own destruction!
     538             :         // Framework can recycle our current frame and the layout manager disposes all user interface
     539             :         // elements if a component gets detached from its frame!
     540           0 :         pNewDocument->xDispatch->dispatch( pNewDocument->aTargetURL, pNewDocument->aArgSeq );
     541           0 :     delete pNewDocument;
     542           0 :     return 0;
     543             : }
     544             : 
     545             : }
     546             : 
     547             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10