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

Generated by: LCOV version 1.11