LCOV - code coverage report
Current view: top level - framework/source/uielement - newmenucontroller.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 92 265 34.7 %
Date: 2014-11-03 Functions: 15 26 57.7 %
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        1762 : DEFINE_XSERVICEINFO_MULTISERVICE_2      (   NewMenuController                           ,
      63             :                                             OWeakObject                                 ,
      64             :                                             SERVICENAME_POPUPMENUCONTROLLER             ,
      65             :                                             IMPLEMENTATIONNAME_NEWMENUCONTROLLER
      66             :                                         )
      67             : 
      68        1494 : DEFINE_INIT_SERVICE                     (   NewMenuController, {} )
      69             : 
      70        1494 : void NewMenuController::setMenuImages( PopupMenu* pPopupMenu, bool bSetImages )
      71             : {
      72        1494 :     sal_uInt16 nItemCount = pPopupMenu->GetItemCount();
      73        1494 :     Image               aImage;
      74        2988 :     Reference< XFrame > xFrame( m_xFrame );
      75             : 
      76       23904 :     for ( sal_uInt16 i = 0; i < nItemCount; i++ )
      77             :     {
      78       22410 :         sal_uInt16 nItemId = pPopupMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ));
      79       22410 :         if ( nItemId != 0 )
      80             :         {
      81       17928 :             if ( bSetImages )
      82             :             {
      83       17928 :                 bool        bImageSet( false );
      84       17928 :                 OUString aImageId;
      85             : 
      86       17928 :                 AddInfoForId::const_iterator pInfo = m_aAddInfoForItem.find( nItemId );
      87       17928 :                 if ( pInfo != m_aAddInfoForItem.end() )
      88       17928 :                     aImageId = pInfo->second.aImageId; // Retrieve image id for menu item
      89             : 
      90       17928 :                 if ( !aImageId.isEmpty() )
      91             :                 {
      92        5976 :                     aImage = GetImageFromURL( xFrame, aImageId, false );
      93        5976 :                     if ( !!aImage )
      94             :                     {
      95        4482 :                         bImageSet = true;
      96        4482 :                         pPopupMenu->SetItemImage( nItemId, aImage );
      97             :                     }
      98             :                 }
      99             : 
     100       17928 :                 if ( !bImageSet )
     101             :                 {
     102       13446 :                     OUString aCmd( pPopupMenu->GetItemCommand( nItemId ) );
     103       13446 :                     if ( !aCmd.isEmpty() )
     104       13446 :                         aImage = GetImageFromURL( xFrame, aCmd, false );
     105             : 
     106       13446 :                     if ( !!aImage )
     107       13410 :                         pPopupMenu->SetItemImage( nItemId, aImage );
     108       17928 :                 }
     109             :             }
     110             :             else
     111           0 :                 pPopupMenu->SetItemImage( nItemId, aImage );
     112             :         }
     113        1494 :     }
     114        1494 : }
     115             : 
     116           0 : void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const vcl::KeyCode& rKeyCode )
     117             : {
     118           0 :     sal_uInt16        nCount( pPopupMenu->GetItemCount() );
     119           0 :     sal_uInt16        nId( 0 );
     120           0 :     bool      bFound( false );
     121           0 :     OUString aCommand;
     122             : 
     123           0 :     if ( !m_aEmptyDocURL.isEmpty() )
     124             :     {
     125             :         // Search for the empty document URL
     126             : 
     127           0 :         for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
     128             :         {
     129           0 :             nId = pPopupMenu->GetItemId( sal_uInt16( i ));
     130           0 :             if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MenuItemType::SEPARATOR )
     131             :             {
     132           0 :                 aCommand = pPopupMenu->GetItemCommand( nId );
     133           0 :                 if ( aCommand.startsWith( m_aEmptyDocURL ) )
     134             :                 {
     135           0 :                     pPopupMenu->SetAccelKey( nId, rKeyCode );
     136           0 :                     bFound = true;
     137           0 :                     break;
     138             :                 }
     139             :             }
     140             :         }
     141             :     }
     142             : 
     143           0 :     if ( !bFound )
     144             :     {
     145             :         // Search for the default module name
     146           0 :         OUString aDefaultModuleName( SvtModuleOptions().GetDefaultModuleName() );
     147           0 :         if ( !aDefaultModuleName.isEmpty() )
     148             :         {
     149           0 :             for ( sal_uInt32 i = 0; i < sal_uInt32( nCount ); i++ )
     150             :             {
     151           0 :                 nId = pPopupMenu->GetItemId( sal_uInt16( i ));
     152           0 :                 if ( nId != 0 && pPopupMenu->GetItemType( nId ) != MenuItemType::SEPARATOR )
     153             :                 {
     154           0 :                     aCommand = pPopupMenu->GetItemCommand( nId );
     155           0 :                     if ( aCommand.indexOf( aDefaultModuleName ) >= 0 )
     156             :                     {
     157           0 :                         pPopupMenu->SetAccelKey( nId, rKeyCode );
     158           0 :                         break;
     159             :                     }
     160             :                 }
     161             :             }
     162           0 :         }
     163           0 :     }
     164           0 : }
     165             : 
     166           0 : void NewMenuController::setAccelerators( PopupMenu* pPopupMenu )
     167             : {
     168           0 :     if ( m_bModuleIdentified )
     169             :     {
     170           0 :         Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
     171           0 :         Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
     172           0 :         Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
     173             : 
     174           0 :         if ( !m_bAcceleratorCfg )
     175             :         {
     176             :             // Retrieve references on demand
     177           0 :             m_bAcceleratorCfg = true;
     178           0 :             if ( !xDocAccelCfg.is() )
     179             :             {
     180           0 :                 Reference< XController > xController = m_xFrame->getController();
     181           0 :                 Reference< XModel > xModel;
     182           0 :                 if ( xController.is() )
     183             :                 {
     184           0 :                     xModel = xController->getModel();
     185           0 :                     if ( xModel.is() )
     186             :                     {
     187           0 :                         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     188           0 :                         if ( xSupplier.is() )
     189             :                         {
     190           0 :                             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
     191           0 :                             if ( xDocUICfgMgr.is() )
     192             :                             {
     193           0 :                                 xDocAccelCfg = xDocUICfgMgr->getShortCutManager();
     194           0 :                                 m_xDocAcceleratorManager = xDocAccelCfg;
     195           0 :                             }
     196           0 :                         }
     197             :                     }
     198           0 :                 }
     199             :             }
     200             : 
     201           0 :             if ( !xModuleAccelCfg.is() )
     202             :             {
     203             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
     204           0 :                     theModuleUIConfigurationManagerSupplier::get( m_xContext );
     205           0 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
     206           0 :                 if ( xUICfgMgr.is() )
     207             :                 {
     208           0 :                     xModuleAccelCfg = xUICfgMgr->getShortCutManager();
     209           0 :                     m_xModuleAcceleratorManager = xModuleAccelCfg;
     210           0 :                 }
     211             :             }
     212             : 
     213           0 :             if ( !xGlobalAccelCfg.is() )
     214             :             {
     215           0 :                 xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( m_xContext );
     216           0 :                 m_xGlobalAcceleratorManager = xGlobalAccelCfg;
     217             :             }
     218             :         }
     219             : 
     220           0 :         vcl::KeyCode                    aEmptyKeyCode;
     221           0 :         sal_uInt32                      nItemCount( pPopupMenu->GetItemCount() );
     222           0 :         std::vector< vcl::KeyCode >     aMenuShortCuts;
     223           0 :         std::vector< OUString >    aCmds;
     224           0 :         std::vector< sal_uInt32 >       aIds;
     225           0 :         for ( sal_uInt32 i = 0; i < nItemCount; i++ )
     226             :         {
     227           0 :             sal_uInt16 nId( pPopupMenu->GetItemId( sal_uInt16( i )));
     228           0 :             if ( nId && ( pPopupMenu->GetItemType( nId ) != MenuItemType::SEPARATOR ))
     229             :             {
     230           0 :                 aIds.push_back( nId );
     231           0 :                 aMenuShortCuts.push_back( aEmptyKeyCode );
     232           0 :                 aCmds.push_back( pPopupMenu->GetItemCommand( nId ));
     233             :             }
     234             :         }
     235             : 
     236           0 :         sal_uInt32 nSeqCount( aIds.size() );
     237             : 
     238           0 :         if ( m_bNewMenu )
     239           0 :             nSeqCount+=1;
     240             : 
     241           0 :         Sequence< OUString > aSeq( nSeqCount );
     242             : 
     243             :         // Add a special command for our "New" menu.
     244           0 :         if ( m_bNewMenu )
     245             :         {
     246           0 :             aSeq[nSeqCount-1] = m_aCommandURL;
     247           0 :             aMenuShortCuts.push_back( aEmptyKeyCode );
     248             :         }
     249             : 
     250           0 :         const sal_uInt32 nCount = aCmds.size();
     251           0 :         for ( sal_uInt32 i = 0; i < nCount; i++ )
     252           0 :             aSeq[i] = aCmds[i];
     253             : 
     254           0 :         if ( m_xGlobalAcceleratorManager.is() )
     255           0 :             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
     256           0 :         if ( m_xModuleAcceleratorManager.is() )
     257           0 :             retrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts );
     258           0 :         if ( m_xDocAcceleratorManager.is() )
     259           0 :             retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
     260             : 
     261           0 :         const sal_uInt32 nCount2 = aIds.size();
     262           0 :         for ( sal_uInt32 i = 0; i < nCount2; i++ )
     263           0 :             pPopupMenu->SetAccelKey( sal_uInt16( aIds[i] ), aMenuShortCuts[i] );
     264             : 
     265             :         // Special handling for "New" menu short-cut should be set at the
     266             :         // document which will be opened using it.
     267           0 :         if ( m_bNewMenu )
     268             :         {
     269           0 :             if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode )
     270           0 :                 determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] );
     271           0 :         }
     272             :     }
     273           0 : }
     274             : 
     275           0 : void NewMenuController::retrieveShortcutsFromConfiguration(
     276             :     const Reference< XAcceleratorConfiguration >& rAccelCfg,
     277             :     const Sequence< OUString >& rCommands,
     278             :     std::vector< vcl::KeyCode >& aMenuShortCuts )
     279             : {
     280           0 :     if ( rAccelCfg.is() )
     281             :     {
     282             :         try
     283             :         {
     284           0 :             com::sun::star::awt::KeyEvent aKeyEvent;
     285           0 :             Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands );
     286           0 :             for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ )
     287             :             {
     288           0 :                 if ( aSeqKeyCode[i] >>= aKeyEvent )
     289           0 :                     aMenuShortCuts[i] = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent );
     290           0 :             }
     291             :         }
     292           0 :         catch ( const IllegalArgumentException& )
     293             :         {
     294             :         }
     295             :     }
     296           0 : }
     297             : 
     298        1494 : NewMenuController::NewMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) :
     299             :     svt::PopupMenuControllerBase( xContext ),
     300             :     m_bShowImages( true ),
     301             :     m_bNewMenu( false ),
     302             :     m_bModuleIdentified( false ),
     303             :     m_bAcceleratorCfg( false ),
     304             :     m_aTargetFrame( "_default" ),
     305        1494 :     m_xContext( xContext )
     306             : {
     307        1494 : }
     308             : 
     309        2988 : NewMenuController::~NewMenuController()
     310             : {
     311        2988 : }
     312             : 
     313             : // private function
     314        1494 : void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
     315             : {
     316        1494 :     VCLXPopupMenu* pPopupMenu    = static_cast<VCLXPopupMenu *>(VCLXMenu::GetImplementation( rPopupMenu ));
     317        1494 :     PopupMenu*     pVCLPopupMenu = 0;
     318             : 
     319        1494 :     SolarMutexGuard aSolarMutexGuard;
     320             : 
     321        1494 :     resetPopupMenu( rPopupMenu );
     322        1494 :     if ( pPopupMenu )
     323        1494 :         pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu());
     324             : 
     325        1494 :     if ( pVCLPopupMenu )
     326             :     {
     327        1494 :         MenuConfiguration aMenuCfg( m_xContext );
     328        2988 :         boost::scoped_ptr<BmkMenu> pSubMenu;
     329             : 
     330        1494 :         if ( m_bNewMenu )
     331        1494 :             pSubMenu.reset(static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU )));
     332             :         else
     333           0 :             pSubMenu.reset(static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU )));
     334             : 
     335             :         // copy entries as we have to use the provided popup menu
     336        1494 :         *pVCLPopupMenu = *pSubMenu;
     337             : 
     338        2988 :         Image           aImage;
     339        2988 :         AddInfo         aAddInfo;
     340             : 
     341             :         // retrieve additional parameters from bookmark menu and
     342             :         // store it in a boost::unordered_map.
     343       23904 :         for ( sal_uInt16 i = 0; i < pSubMenu->GetItemCount(); i++ )
     344             :         {
     345       22410 :             sal_uInt16 nItemId = pSubMenu->GetItemId( sal::static_int_cast<sal_uInt16>( i ) );
     346       40338 :             if (( nItemId != 0 ) &&
     347       17928 :                 ( pSubMenu->GetItemType( nItemId ) != MenuItemType::SEPARATOR ))
     348             :             {
     349       17928 :                 MenuConfiguration::Attributes* pBmkAttributes = reinterpret_cast<MenuConfiguration::Attributes *>(pSubMenu->GetUserValue( nItemId ));
     350       17928 :                 if ( pBmkAttributes != 0 )
     351             :                 {
     352       17928 :                     aAddInfo.aTargetFrame = pBmkAttributes->aTargetFrame;
     353       17928 :                     aAddInfo.aImageId     = pBmkAttributes->aImageId;
     354             : 
     355       17928 :                     m_aAddInfoForItem.insert( AddInfoForId::value_type( nItemId, aAddInfo ));
     356             :                 }
     357             :             }
     358             :         }
     359             : 
     360        1494 :         if ( m_bShowImages )
     361        2988 :             setMenuImages( pVCLPopupMenu, m_bShowImages );
     362        1494 :     }
     363        1494 : }
     364             : 
     365             : // XEventListener
     366           0 : void SAL_CALL NewMenuController::disposing( const EventObject& ) throw ( RuntimeException, std::exception )
     367             : {
     368           0 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     369             : 
     370           0 :     osl::MutexGuard aLock( m_aMutex );
     371           0 :     m_xFrame.clear();
     372           0 :     m_xDispatch.clear();
     373           0 :     m_xContext.clear();
     374             : 
     375           0 :     if ( m_xPopupMenu.is() )
     376           0 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
     377           0 :     m_xPopupMenu.clear();
     378           0 : }
     379             : 
     380             : // XStatusListener
     381        1494 : void SAL_CALL NewMenuController::statusChanged( const FeatureStateEvent& ) throw ( RuntimeException, std::exception )
     382             : {
     383        1494 : }
     384             : 
     385             : // XMenuListener
     386           0 : void SAL_CALL NewMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException, std::exception)
     387             : {
     388           0 :     Reference< css::awt::XPopupMenu > xPopupMenu;
     389           0 :     Reference< XDispatch >            xDispatch;
     390           0 :     Reference< XDispatchProvider >    xDispatchProvider;
     391           0 :     Reference< XComponentContext >    xContext;
     392           0 :     Reference< XURLTransformer >      xURLTransformer;
     393             : 
     394           0 :     osl::ClearableMutexGuard aLock( m_aMutex );
     395           0 :     xPopupMenu          = m_xPopupMenu;
     396           0 :     xDispatchProvider   = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
     397           0 :     xContext     = m_xContext;
     398           0 :     xURLTransformer     = m_xURLTransformer;
     399           0 :     aLock.clear();
     400             : 
     401           0 :     css::util::URL aTargetURL;
     402           0 :     Sequence< PropertyValue > aArgsList( 1 );
     403             : 
     404           0 :     if ( xPopupMenu.is() && xDispatchProvider.is() )
     405             :     {
     406           0 :         VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(VCLXPopupMenu::GetImplementation( xPopupMenu ));
     407           0 :         if ( pPopupMenu )
     408             :         {
     409             :             {
     410           0 :                 SolarMutexGuard aSolarMutexGuard;
     411           0 :                 PopupMenu* pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu());
     412           0 :                 aTargetURL.Complete = pVCLPopupMenu->GetItemCommand( rEvent.MenuId );
     413             :             }
     414             : 
     415           0 :             xURLTransformer->parseStrict( aTargetURL );
     416             : 
     417           0 :             aArgsList[0].Name = "Referer";
     418           0 :             aArgsList[0].Value = makeAny( OUString( "private:user" ));
     419             : 
     420           0 :             OUString aTargetFrame( m_aTargetFrame );
     421           0 :             AddInfoForId::const_iterator pItem = m_aAddInfoForItem.find( rEvent.MenuId );
     422           0 :             if ( pItem != m_aAddInfoForItem.end() )
     423           0 :                 aTargetFrame = pItem->second.aTargetFrame;
     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( STATIC_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        1494 : void NewMenuController::impl_setPopupMenu()
     468             : {
     469             : 
     470        1494 :     if ( m_xPopupMenu.is() )
     471        1494 :         fillPopupMenu( m_xPopupMenu );
     472             : 
     473             :     // Identify module that we are attach to. It's our context that we need to know.
     474        1494 :     Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
     475             :     try
     476             :     {
     477        1494 :         m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
     478        1494 :         m_bModuleIdentified = true;
     479             : 
     480        1494 :         if ( !m_aModuleIdentifier.isEmpty() )
     481             :         {
     482        1494 :             Sequence< PropertyValue > aSeq;
     483             : 
     484        1494 :             if ( xModuleManager->getByName( m_aModuleIdentifier ) >>= aSeq )
     485             :             {
     486        7470 :                 for ( sal_Int32 y = 0; y < aSeq.getLength(); y++ )
     487             :                 {
     488        7470 :                     if ( aSeq[y].Name == "ooSetupFactoryEmptyDocumentURL" )
     489             :                     {
     490        1494 :                         aSeq[y].Value >>= m_aEmptyDocURL;
     491        1494 :                         break;
     492             :                     }
     493             :                 }
     494        1494 :             }
     495             :         }
     496             :     }
     497           0 :     catch ( const RuntimeException& )
     498             :     {
     499           0 :         throw;
     500             :     }
     501           0 :     catch ( const Exception& )
     502             :     {
     503        1494 :     }
     504        1494 : }
     505             : 
     506             : // XInitialization
     507        1494 : void SAL_CALL NewMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException, std::exception )
     508             : {
     509        1494 :     osl::MutexGuard aLock( m_aMutex );
     510             : 
     511        1494 :     bool bInitalized( m_bInitialized );
     512        1494 :     if ( !bInitalized )
     513             :     {
     514        1494 :         svt::PopupMenuControllerBase::initialize( aArguments );
     515             : 
     516        1494 :         if ( m_bInitialized )
     517             :         {
     518        1494 :             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     519             : 
     520        1494 :             m_bShowImages   = rSettings.GetUseImagesInMenus();
     521        1494 :             m_bNewMenu      = m_aCommandURL == ".uno:AddDirect";
     522             :         }
     523        1494 :     }
     524        1494 : }
     525             : 
     526           0 : IMPL_STATIC_LINK_NOINSTANCE( 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         198 : }
     542             : 
     543             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10