LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - menubarmanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 143 984 14.5 %
Date: 2012-12-27 Functions: 14 59 23.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/menubarmanager.hxx>
      21             : #include <framework/menuconfiguration.hxx>
      22             : #include <framework/bmkmenu.hxx>
      23             : #include <framework/addonmenu.hxx>
      24             : #include <framework/imageproducer.hxx>
      25             : #include <threadhelp/resetableguard.hxx>
      26             : #include "framework/addonsoptions.hxx"
      27             : #include <classes/fwkresid.hxx>
      28             : #include <classes/menumanager.hxx>
      29             : #include <helper/mischelper.hxx>
      30             : #include <framework/menuextensionsupplier.hxx>
      31             : #include <classes/resource.hrc>
      32             : #include <services.h>
      33             : 
      34             : #include <com/sun/star/frame/XDispatch.hpp>
      35             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      36             : #include <com/sun/star/lang/DisposedException.hpp>
      37             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      38             : #include <com/sun/star/frame/Desktop.hpp>
      39             : #include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
      40             : #include <com/sun/star/container/XEnumeration.hpp>
      41             : #include <com/sun/star/util/XStringWidth.hpp>
      42             : #include <com/sun/star/uno/XComponentContext.hpp>
      43             : #include <com/sun/star/uno/XCurrentContext.hpp>
      44             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      45             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      46             : #include <com/sun/star/frame/XUIControllerRegistration.hpp>
      47             : #include <com/sun/star/lang/SystemDependent.hpp>
      48             : #include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp>
      49             : #include <com/sun/star/ui/ItemType.hpp>
      50             : #include <com/sun/star/ui/ImageType.hpp>
      51             : #include <com/sun/star/container/XNameAccess.hpp>
      52             : #include <com/sun/star/frame/ModuleManager.hpp>
      53             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
      54             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      55             : #include <com/sun/star/ui/ItemStyle.hpp>
      56             : #include <com/sun/star/frame/status/Visibility.hpp>
      57             : #include <com/sun/star/util/URLTransformer.hpp>
      58             : 
      59             : #include <comphelper/processfactory.hxx>
      60             : #include <comphelper/extract.hxx>
      61             : #include <svtools/menuoptions.hxx>
      62             : #include <svtools/javainteractionhandler.hxx>
      63             : #include <uno/current_context.hxx>
      64             : #include <unotools/historyoptions.hxx>
      65             : #include <unotools/pathoptions.hxx>
      66             : #include <unotools/cmdoptions.hxx>
      67             : #include <unotools/localfilehelper.hxx>
      68             : #include <toolkit/unohlp.hxx>
      69             : #include <vcl/svapp.hxx>
      70             : #include <vcl/window.hxx>
      71             : #include <osl/mutex.hxx>
      72             : #include <vcl/svapp.hxx>
      73             : #include <osl/file.hxx>
      74             : #include <cppuhelper/implbase1.hxx>
      75             : #include <svtools/acceleratorexecute.hxx>
      76             : #include <rtl/logfile.hxx>
      77             : #include "svtools/miscopt.hxx"
      78             : #include <framework/addonmenu.hxx>
      79             : #include <uielement/menubarmerger.hxx>
      80             : 
      81             : // Be careful removing this "bad" construct. There are serious problems
      82             : // with #define STRICT and including windows.h. Changing this needs some
      83             : // redesign on other projects, too. Especially sal/main.h which defines
      84             : // HINSTANCE depending on STRCIT!!!!!!!!!!!!!!!
      85             : struct SystemMenuData
      86             : {
      87             :     unsigned long nSize;
      88             :     long          hMenu;
      89             : };
      90             : 
      91             : using namespace ::cppu;
      92             : using namespace ::com::sun::star;
      93             : using namespace ::com::sun::star::uno;
      94             : using namespace ::com::sun::star::util;
      95             : using namespace ::com::sun::star::beans;
      96             : using namespace ::com::sun::star::frame;
      97             : using namespace ::com::sun::star::container;
      98             : using namespace ::com::sun::star::lang;
      99             : using namespace ::com::sun::star::frame;
     100             : using namespace ::com::sun::star::ui;
     101             : 
     102             : static const char ITEM_DESCRIPTOR_COMMANDURL[]        = "CommandURL";
     103             : static const char ITEM_DESCRIPTOR_HELPURL[]           = "HelpURL";
     104             : static const char ITEM_DESCRIPTOR_CONTAINER[]         = "ItemDescriptorContainer";
     105             : static const char ITEM_DESCRIPTOR_LABEL[]             = "Label";
     106             : static const char ITEM_DESCRIPTOR_TYPE[]              = "Type";
     107             : static const char ITEM_DESCRIPTOR_MODULEIDENTIFIER[]  = "ModuleIdentifier";
     108             : static const char ITEM_DESCRIPTOR_DISPATCHPROVIDER[]  = "DispatchProvider";
     109             : static const char ITEM_DESCRIPTOR_STYLE[]             = "Style";
     110             : static const char ITEM_DESCRIPTOR_ISVISIBLE[]         = "IsVisible";
     111             : static const char ITEM_DESCRIPTOR_ENABLED[]           = "Enabled";
     112             : 
     113             : static const sal_Int32 LEN_DESCRIPTOR_COMMANDURL       = 10;
     114             : static const sal_Int32 LEN_DESCRIPTOR_HELPURL          = 7;
     115             : static const sal_Int32 LEN_DESCRIPTOR_CONTAINER        = 23;
     116             : static const sal_Int32 LEN_DESCRIPTOR_LABEL            = 5;
     117             : static const sal_Int32 LEN_DESCRIPTOR_TYPE             = 4;
     118             : static const sal_Int32 LEN_DESCRIPTOR_MODULEIDENTIFIER = 16;
     119             : static const sal_Int32 LEN_DESCRIPTOR_DISPATCHPROVIDER = 16;
     120             : static const sal_Int32 LEN_DESCRIPTOR_STYLE            = 5;
     121             : static const sal_Int32 LEN_DESCRIPTOR_ISVISIBLE        = 9;
     122             : static const sal_Int32 LEN_DESCRIPTOR_ENABLED          = 7;
     123             : 
     124             : const sal_uInt16 ADDONMENU_MERGE_ITEMID_START = 1500;
     125             : 
     126             : class StringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
     127             : {
     128             :     public:
     129             :         StringLength() {}
     130           0 :         virtual ~StringLength() {}
     131             : 
     132             :         // XStringWidth
     133           0 :         sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
     134             :             throw (RuntimeException)
     135             :         {
     136           0 :             return aString.getLength();
     137             :         }
     138             : };
     139             : 
     140             : namespace framework
     141             : {
     142             : 
     143             : // special menu ids/command ids for dynamic popup menus
     144             : #define SID_SFX_START           5000
     145             : #define SID_NEWDOCDIRECT        (SID_SFX_START + 537)
     146             : #define SID_AUTOPILOTMENU       (SID_SFX_START + 1381)
     147             : #define SID_PICKLIST            (SID_SFX_START + 510)
     148             : #define SID_MDIWINDOWLIST       (SID_SFX_START + 610)
     149             : #define SID_ADDONLIST           (SID_SFX_START + 1677)
     150             : #define SID_HELPMENU            (SID_SFX_START + 410)
     151             : 
     152             : #define SFX_REFERER_USER        "private:user"
     153             : 
     154             : #define aCmdHelpIndex ".uno:HelpIndex"
     155             : #define aCmdToolsMenu ".uno:ToolsMenu"
     156             : #define aCmdHelpMenu ".uno:HelpMenu"
     157             : #define aSlotHelpMenu "slot:5410"
     158             : 
     159             : #define aSpecialWindowMenu "window"
     160             : #define aSlotSpecialWindowMenu "slot:5610"
     161             : #define aSlotSpecialToolsMenu "slot:6677"
     162             : 
     163             : // special uno commands for window list
     164             : #define aSpecialWindowCommand ".uno:WindowList"
     165             : 
     166           0 : static sal_Int16 getImageTypeFromBools( sal_Bool bBig )
     167             : {
     168           0 :     sal_Int16 n( 0 );
     169           0 :     if ( bBig )
     170           0 :         n |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
     171           0 :     return n;
     172             : }
     173             : 
     174         236 : MenuBarManager::MenuBarManager(
     175             :     const Reference< XMultiServiceFactory >& xServiceFactory,
     176             :     const Reference< XFrame >& rFrame,
     177             :     const Reference< XURLTransformer >& _xURLTransformer,
     178             :     const Reference< XDispatchProvider >& rDispatchProvider,
     179             :     const rtl::OUString& rModuleIdentifier,
     180             :     Menu* pMenu, sal_Bool bDelete, sal_Bool bDeleteChildren )
     181         236 : : ThreadHelpBase( &Application::GetSolarMutex() ), OWeakObject()
     182             :     , m_bDisposed( sal_False )
     183             :     , m_bRetrieveImages( sal_False )
     184             :     , m_bAcceleratorCfg( sal_False )
     185             :     , m_bModuleIdentified( sal_False )
     186         236 :     , m_aListenerContainer( m_aLock.getShareableOslMutex() )
     187             :     , mxServiceFactory(xServiceFactory)
     188             :     , m_xURLTransformer(_xURLTransformer)
     189         708 :     , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
     190             : {
     191             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
     192         236 :     m_xPopupMenuControllerRegistration = PopupMenuControllerFactory::create( comphelper::getComponentContext(getServiceFactory()) );
     193         236 :     FillMenuManager( pMenu, rFrame, rDispatchProvider, rModuleIdentifier, bDelete, bDeleteChildren );
     194         236 : }
     195             : 
     196           0 : MenuBarManager::MenuBarManager(
     197             :     const Reference< XMultiServiceFactory >& xServiceFactory,
     198             :     const Reference< XFrame >& rFrame,
     199             :     const Reference< XURLTransformer >& _xURLTransformer,
     200             :     AddonMenu* pAddonMenu,
     201             :     sal_Bool bDelete,
     202             :     sal_Bool bDeleteChildren )
     203           0 : :   ThreadHelpBase( &Application::GetSolarMutex() )
     204             :     , OWeakObject()
     205             :     , m_bDisposed( sal_False )
     206             :     , m_bRetrieveImages( sal_True )
     207             :     , m_bAcceleratorCfg( sal_False )
     208             :     , m_bModuleIdentified( sal_False )
     209           0 :     , m_aListenerContainer( m_aLock.getShareableOslMutex() )
     210             :     , mxServiceFactory(xServiceFactory)
     211             :     , m_xURLTransformer(_xURLTransformer)
     212           0 :     , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
     213             : {
     214             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
     215           0 :     Init(rFrame,pAddonMenu,bDelete,bDeleteChildren);
     216           0 : }
     217             : 
     218           0 : MenuBarManager::MenuBarManager(
     219             :     const Reference< XMultiServiceFactory >& xServiceFactory,
     220             :     const Reference< XFrame >& rFrame,
     221             :     const Reference< XURLTransformer >& _xURLTransformer,
     222             :     AddonPopupMenu* pAddonPopupMenu,
     223             :     sal_Bool bDelete,
     224             :     sal_Bool bDeleteChildren )
     225           0 : :     ThreadHelpBase( &Application::GetSolarMutex() )
     226             :     , OWeakObject()
     227             :     , m_bDisposed( sal_False )
     228             :     , m_bRetrieveImages( sal_True )
     229             :     , m_bAcceleratorCfg( sal_False )
     230             :     , m_bModuleIdentified( sal_False )
     231           0 :     , m_aListenerContainer( m_aLock.getShareableOslMutex() )
     232             :     , mxServiceFactory(xServiceFactory)
     233             :     , m_xURLTransformer(_xURLTransformer)
     234           0 :     , m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() )
     235             : {
     236             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MenuBarManager" );
     237           0 :     Init(rFrame,pAddonPopupMenu,bDelete,bDeleteChildren,true);
     238           0 : }
     239             : 
     240        1511 : Any SAL_CALL MenuBarManager::queryInterface( const Type & rType ) throw ( RuntimeException )
     241             : {
     242             :     Any a = ::cppu::queryInterface(
     243             :                 rType ,
     244             :                 (static_cast< ::com::sun::star::frame::XStatusListener* >(this)),
     245             :                 (static_cast< ::com::sun::star::frame::XFrameActionListener* >(this)),
     246             :                 (static_cast< ::com::sun::star::ui::XUIConfigurationListener* >(this)),
     247             :                 (static_cast< XEventListener* >((XStatusListener *)this)),
     248             :                 (static_cast< XComponent* >(this)),
     249        1511 :                 (static_cast< ::com::sun::star::awt::XSystemDependentMenuPeer* >(this)));
     250             : 
     251        1511 :     if ( a.hasValue() )
     252        1133 :         return a;
     253             : 
     254         378 :     return OWeakObject::queryInterface( rType );
     255             : }
     256             : 
     257             : 
     258        4353 : void SAL_CALL MenuBarManager::acquire() throw()
     259             : {
     260        4353 :     OWeakObject::acquire();
     261        4353 : }
     262             : 
     263             : 
     264        4007 : void SAL_CALL MenuBarManager::release() throw()
     265             : {
     266        4007 :     OWeakObject::release();
     267        4007 : }
     268             : 
     269             : 
     270           0 : Any SAL_CALL MenuBarManager::getMenuHandle( const Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw (RuntimeException)
     271             : {
     272             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::getMenuHandle" );
     273           0 :     ResetableGuard aGuard( m_aLock );
     274             : 
     275           0 :     if ( m_bDisposed )
     276           0 :         throw com::sun::star::lang::DisposedException();
     277             : 
     278           0 :     Any a;
     279             : 
     280           0 :     if ( m_pVCLMenu )
     281             :     {
     282           0 :         SolarMutexGuard aSolarGuard;
     283             : 
     284             :         SystemMenuData aSystemMenuData;
     285           0 :         aSystemMenuData.nSize = sizeof( SystemMenuData );
     286             : 
     287           0 :         m_pVCLMenu->GetSystemMenuData( &aSystemMenuData );
     288             : #ifdef QUARTZ
     289             :         if( SystemType == SystemDependent::SYSTEM_MAC )
     290             :         {
     291             :         }
     292             : #elif (defined WNT)
     293             :         if( SystemType == SystemDependent::SYSTEM_WIN32 )
     294             :         {
     295             :             a <<= (long) aSystemMenuData.hMenu;
     296             :         }
     297             : #elif (defined UNX)
     298             :         if( SystemType == SystemDependent::SYSTEM_XWINDOW )
     299             :         {
     300           0 :         }
     301             : #endif
     302             :     }
     303             : 
     304           0 :     return a;
     305             : }
     306             : 
     307         189 : MenuBarManager::~MenuBarManager()
     308             : {
     309             :     // stop asynchronous settings timer
     310          63 :     m_xDeferedItemContainer.clear();
     311          63 :     m_aAsyncSettingsTimer.Stop();
     312             : 
     313             :     DBG_ASSERT( OWeakObject::m_refCount == 0, "Who wants to delete an object with refcount > 0!" );
     314         126 : }
     315             : 
     316          63 : void MenuBarManager::Destroy()
     317             : {
     318             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Destroy" );
     319          63 :     SolarMutexGuard aGuard;
     320             : 
     321          63 :     if ( !m_bDisposed )
     322             :     {
     323             :         // stop asynchronous settings timer and
     324             :         // release defered item container reference
     325          63 :         m_aAsyncSettingsTimer.Stop();
     326          63 :         m_xDeferedItemContainer.clear();
     327          63 :         RemoveListener();
     328             : 
     329          63 :         std::vector< MenuItemHandler* >::iterator p;
     330          63 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     331             :         {
     332           0 :             MenuItemHandler* pItemHandler = *p;
     333           0 :             pItemHandler->xMenuItemDispatch.clear();
     334           0 :             pItemHandler->xSubMenuManager.clear();
     335           0 :             pItemHandler->xPopupMenu.clear();
     336           0 :             delete pItemHandler;
     337             :         }
     338          63 :         m_aMenuItemHandlerVector.clear();
     339             : 
     340          63 :         if ( m_bDeleteMenu )
     341             :         {
     342           0 :             delete m_pVCLMenu;
     343           0 :             m_pVCLMenu = 0;
     344             :         }
     345          63 :     }
     346          63 : }
     347             : 
     348             : // XComponent
     349          63 : void SAL_CALL MenuBarManager::dispose() throw( RuntimeException )
     350             : {
     351             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::dispose" );
     352          63 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
     353             : 
     354          63 :     EventObject aEvent( xThis );
     355          63 :     m_aListenerContainer.disposeAndClear( aEvent );
     356             : 
     357             :     {
     358          63 :         ResetableGuard aGuard( m_aLock );
     359          63 :         Destroy();
     360          63 :         m_bDisposed = sal_True;
     361             : 
     362          63 :         if ( m_xDocImageManager.is() )
     363             :         {
     364             :             try
     365             :             {
     366          63 :                 m_xDocImageManager->removeConfigurationListener(
     367             :                     Reference< XUIConfigurationListener >(
     368          63 :                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
     369             :             }
     370           0 :             catch ( const Exception& )
     371             :             {
     372             :             }
     373             :         }
     374          63 :         if ( m_xModuleImageManager.is() )
     375             :         {
     376             :             try
     377             :             {
     378          63 :                 m_xModuleImageManager->removeConfigurationListener(
     379             :                     Reference< XUIConfigurationListener >(
     380          63 :                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
     381             :             }
     382           0 :             catch ( const Exception& )
     383             :             {
     384             :             }
     385             :         }
     386          63 :         m_xDocImageManager.clear();
     387          63 :         m_xModuleImageManager.clear();
     388          63 :         m_xGlobalAcceleratorManager.clear();
     389          63 :         m_xModuleAcceleratorManager.clear();
     390          63 :         m_xDocAcceleratorManager.clear();
     391          63 :         m_xUICommandLabels.clear();
     392          63 :         m_xPopupMenuControllerRegistration.clear();
     393          63 :         mxServiceFactory.clear();
     394          63 :     }
     395          63 : }
     396             : 
     397           0 : void SAL_CALL MenuBarManager::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
     398             : {
     399             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::addEventListener" );
     400           0 :     ResetableGuard aGuard( m_aLock );
     401             : 
     402             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     403           0 :     if ( m_bDisposed )
     404           0 :         throw DisposedException();
     405             : 
     406           0 :     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
     407           0 : }
     408             : 
     409           0 : void SAL_CALL MenuBarManager::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
     410             : {
     411             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::removeEventListener" );
     412           0 :     ResetableGuard aGuard( m_aLock );
     413             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     414           0 :     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
     415           0 : }
     416             : 
     417           0 : void SAL_CALL MenuBarManager::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event )
     418             : throw (RuntimeException)
     419             : {
     420             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementInserted" );
     421           0 :     ResetableGuard aGuard( m_aLock );
     422             : 
     423             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     424           0 :     if ( m_bDisposed )
     425           0 :         return;
     426             : 
     427           0 :     sal_Int16 nImageType = sal_Int16();
     428           0 :     sal_Int16 nCurrentImageType = getImageTypeFromBools( sal_False );
     429           0 :     if (( Event.aInfo >>= nImageType ) &&
     430             :         ( nImageType == nCurrentImageType ))
     431           0 :         RequestImages();
     432             : }
     433             : 
     434           0 : void SAL_CALL MenuBarManager::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event )
     435             : throw (RuntimeException)
     436             : {
     437             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementRemoved" );
     438           0 :     elementInserted(Event);
     439           0 : }
     440             : 
     441           0 : void SAL_CALL MenuBarManager::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event )
     442             : throw (RuntimeException)
     443             : {
     444             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::elementReplaced" );
     445           0 :     elementInserted(Event);
     446           0 : }
     447             : 
     448             : // XFrameActionListener
     449           0 : void SAL_CALL MenuBarManager::frameAction( const FrameActionEvent& Action )
     450             : throw ( RuntimeException )
     451             : {
     452             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::frameAction" );
     453           0 :     ResetableGuard aGuard( m_aLock );
     454             : 
     455           0 :     if ( m_bDisposed )
     456           0 :         throw com::sun::star::lang::DisposedException();
     457             : 
     458           0 :     if ( Action.Action == FrameAction_CONTEXT_CHANGED )
     459             :     {
     460           0 :         std::vector< MenuItemHandler* >::iterator p;
     461           0 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     462             :         {
     463             :             // Clear dispatch reference as we will requery it later o
     464           0 :             MenuItemHandler* pItemHandler = *p;
     465           0 :             pItemHandler->xMenuItemDispatch.clear();
     466             :         }
     467           0 :     }
     468           0 : }
     469             : 
     470             : // XStatusListener
     471           0 : void SAL_CALL MenuBarManager::statusChanged( const FeatureStateEvent& Event )
     472             : throw ( RuntimeException )
     473             : {
     474             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::statusChanged" );
     475           0 :     ::rtl::OUString aFeatureURL = Event.FeatureURL.Complete;
     476             : 
     477           0 :     SolarMutexGuard aSolarGuard;
     478             :     {
     479           0 :         ResetableGuard aGuard( m_aLock );
     480             : 
     481           0 :         if ( m_bDisposed )
     482           0 :             return;
     483             : 
     484             :         // We have to check all menu entries as there can be identical entries in a popup menu.
     485           0 :         std::vector< MenuItemHandler* >::iterator p;
     486           0 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     487             :         {
     488           0 :             MenuItemHandler* pMenuItemHandler = *p;
     489           0 :             if ( pMenuItemHandler->aMenuItemURL == aFeatureURL )
     490             :             {
     491           0 :                 sal_Bool            bCheckmark( sal_False );
     492           0 :                 sal_Bool            bMenuItemEnabled( m_pVCLMenu->IsItemEnabled( pMenuItemHandler->nItemId ));
     493           0 :                 sal_Bool            bEnabledItem( Event.IsEnabled );
     494           0 :                 rtl::OUString       aItemText;
     495           0 :                 status::Visibility  aVisibilityStatus;
     496             : 
     497             :                 #ifdef UNIX
     498             :                 //enable some slots hardly, because UNIX clipboard does not notify all changes
     499             :                 // Can be removed if follow up task will be fixed directly within applications.
     500             :                 // Note: PasteSpecial is handled specifically by calc
     501           0 :                 if ( pMenuItemHandler->aMenuItemURL == ".uno:Paste"
     502           0 :                     || pMenuItemHandler->aMenuItemURL == ".uno:PasteClipboard" )      // special for draw/impress
     503           0 :                     bEnabledItem = sal_True;
     504             :                 #endif
     505             : 
     506             :                 // Enable/disable item
     507           0 :                 if ( bEnabledItem != bMenuItemEnabled )
     508           0 :                     m_pVCLMenu->EnableItem( pMenuItemHandler->nItemId, bEnabledItem );
     509             : 
     510           0 :                 if ( Event.State >>= bCheckmark )
     511             :                 {
     512             :                     // Checkmark or RadioButton
     513           0 :                     m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
     514           0 :                     m_pVCLMenu->CheckItem( pMenuItemHandler->nItemId, bCheckmark );
     515             : 
     516           0 :                     MenuItemBits nBits = m_pVCLMenu->GetItemBits( pMenuItemHandler->nItemId );
     517             :                     //If not already designated RadioButton set as CheckMark
     518           0 :                     if (!(nBits & MIB_RADIOCHECK))
     519           0 :                         m_pVCLMenu->SetItemBits( pMenuItemHandler->nItemId, nBits | MIB_CHECKABLE );
     520             :                 }
     521           0 :                 else if ( Event.State >>= aItemText )
     522             :                 {
     523             :                     // Replacement for place holders
     524           0 :                     if ( aItemText.matchAsciiL( "($1)", 4 ))
     525             :                     {
     526           0 :                         String aResStr = String( FwkResId( STR_UPDATEDOC ));
     527           0 :                         rtl::OUString aTmp( aResStr );
     528           0 :                         aTmp += rtl::OUString( " " );
     529           0 :                         aTmp += aItemText.copy( 4 );
     530           0 :                         aItemText = aTmp;
     531             :                     }
     532           0 :                     else if ( aItemText.matchAsciiL( "($2)", 4 ))
     533             :                     {
     534           0 :                         String aResStr = String( FwkResId( STR_CLOSEDOC_ANDRETURN ));
     535           0 :                         rtl::OUString aTmp( aResStr );
     536           0 :                         aTmp += aItemText.copy( 4 );
     537           0 :                         aItemText = aTmp;
     538             :                     }
     539           0 :                     else if ( aItemText.matchAsciiL( "($3)", 4 ))
     540             :                     {
     541           0 :                         String aResStr = String( FwkResId( STR_SAVECOPYDOC ));
     542           0 :                         rtl::OUString aTmp( aResStr );
     543           0 :                         aTmp += aItemText.copy( 4 );
     544           0 :                         aItemText = aTmp;
     545             :                     }
     546             : 
     547           0 :                     m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
     548           0 :                     m_pVCLMenu->SetItemText( pMenuItemHandler->nItemId, aItemText );
     549             :                 }
     550           0 :                 else if ( Event.State >>= aVisibilityStatus )
     551             :                 {
     552             :                     // Visibility
     553           0 :                     m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, aVisibilityStatus.bVisible );
     554             :                 }
     555             :                 else
     556           0 :                     m_pVCLMenu->ShowItem( pMenuItemHandler->nItemId, sal_True );
     557             :             }
     558             : 
     559           0 :             if ( Event.Requery )
     560             :             {
     561             :                 // Release dispatch object - will be requeried on the next activate!
     562           0 :                 pMenuItemHandler->xMenuItemDispatch.clear();
     563             :             }
     564           0 :         }
     565           0 :     }
     566             : }
     567             : 
     568             : // Helper to retrieve own structure from item ID
     569           0 : MenuBarManager::MenuItemHandler* MenuBarManager::GetMenuItemHandler( sal_uInt16 nItemId )
     570             : {
     571             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::GetMenuItemHandler" );
     572           0 :     ResetableGuard aGuard( m_aLock );
     573             : 
     574           0 :     std::vector< MenuItemHandler* >::iterator p;
     575           0 :     for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     576             :     {
     577           0 :         MenuItemHandler* pItemHandler = *p;
     578           0 :         if ( pItemHandler->nItemId == nItemId )
     579           0 :             return pItemHandler;
     580             :     }
     581             : 
     582           0 :     return 0;
     583             : }
     584             : 
     585             : // Helper to set request images flag
     586           0 : void MenuBarManager::RequestImages()
     587             : {
     588             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RequestImages" );
     589             : 
     590           0 :     m_bRetrieveImages = sal_True;
     591           0 :     const sal_uInt32 nCount = m_aMenuItemHandlerVector.size();
     592           0 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
     593             :     {
     594           0 :         MenuItemHandler* pItemHandler = m_aMenuItemHandlerVector[i];
     595           0 :         if ( pItemHandler->xSubMenuManager.is() )
     596             :         {
     597           0 :             MenuBarManager* pMenuBarManager = (MenuBarManager*)(pItemHandler->xSubMenuManager.get());
     598           0 :             pMenuBarManager->RequestImages();
     599             :         }
     600             :     }
     601           0 : }
     602             : 
     603             : // Helper to reset objects to prepare shutdown
     604          63 : void MenuBarManager::RemoveListener()
     605             : {
     606             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RemoveListener" );
     607          63 :     ResetableGuard aGuard( m_aLock );
     608             : 
     609             :     // Check service manager reference. Remove listener can be called due
     610             :     // to a disposing call from the frame and therefore we already removed
     611             :     // our listeners and release the service manager reference!
     612          63 :     Reference< XMultiServiceFactory > xServiceManager = getServiceFactory();
     613          63 :     if ( xServiceManager.is() )
     614             :     {
     615          63 :         std::vector< MenuItemHandler* >::iterator p;
     616          63 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     617             :         {
     618           0 :             MenuItemHandler* pItemHandler = *p;
     619           0 :             if ( pItemHandler->xMenuItemDispatch.is() )
     620             :             {
     621           0 :                 URL aTargetURL;
     622           0 :                 aTargetURL.Complete = pItemHandler->aMenuItemURL;
     623           0 :                 m_xURLTransformer->parseStrict( aTargetURL );
     624             : 
     625           0 :                 pItemHandler->xMenuItemDispatch->removeStatusListener(
     626           0 :                     static_cast< XStatusListener* >( this ), aTargetURL );
     627             :             }
     628             : 
     629           0 :             pItemHandler->xMenuItemDispatch.clear();
     630           0 :             if ( pItemHandler->xPopupMenu.is() )
     631             :             {
     632             :                 {
     633             :                     // Remove popup menu from menu structure
     634           0 :                     SolarMutexGuard aGuard2;
     635           0 :                     m_pVCLMenu->SetPopupMenu( pItemHandler->nItemId, 0 );
     636             :                 }
     637             : 
     638           0 :                 Reference< com::sun::star::lang::XEventListener > xEventListener( pItemHandler->xPopupMenuController, UNO_QUERY );
     639           0 :                 if ( xEventListener.is() )
     640             :                 {
     641           0 :                     EventObject aEventObject;
     642           0 :                     aEventObject.Source = (OWeakObject *)this;
     643           0 :                     xEventListener->disposing( aEventObject );
     644             :                 }
     645             : 
     646             :                 // We now provide a popup menu controller to external code.
     647             :                 // Therefore the life-time must be explicitly handled via
     648             :                 // dispose!!
     649             :                 try
     650             :                 {
     651           0 :                     Reference< XComponent > xComponent( pItemHandler->xPopupMenuController, UNO_QUERY );
     652           0 :                     if ( xComponent.is() )
     653           0 :                         xComponent->dispose();
     654             :                 }
     655           0 :                 catch ( const RuntimeException& )
     656             :                 {
     657           0 :                     throw;
     658             :                 }
     659           0 :                 catch ( const Exception& )
     660             :                 {
     661             :                 }
     662             : 
     663             :                 // Release references to controller and popup menu
     664           0 :                 pItemHandler->xPopupMenuController.clear();
     665           0 :                 pItemHandler->xPopupMenu.clear();
     666             :             }
     667             : 
     668           0 :             Reference< XComponent > xComponent( pItemHandler->xSubMenuManager, UNO_QUERY );
     669           0 :             if ( xComponent.is() )
     670           0 :                 xComponent->dispose();
     671           0 :         }
     672             :     }
     673             : 
     674             :     try
     675             :     {
     676          63 :         if ( m_xFrame.is() )
     677          63 :             m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(
     678          63 :                                                     static_cast< OWeakObject* >( this ), UNO_QUERY ));
     679             :     }
     680           0 :     catch ( const Exception& )
     681             :     {
     682             :     }
     683             : 
     684          63 :     m_xFrame = 0;
     685          63 : }
     686             : 
     687         173 : void SAL_CALL MenuBarManager::disposing( const EventObject& Source ) throw ( RuntimeException )
     688             : {
     689             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::disposing(evt)" );
     690         173 :     MenuItemHandler* pMenuItemDisposing = NULL;
     691             : 
     692         173 :     ResetableGuard aGuard( m_aLock );
     693             : 
     694         173 :     std::vector< MenuItemHandler* >::iterator p;
     695         173 :     for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     696             :     {
     697           0 :         MenuItemHandler* pMenuItemHandler = *p;
     698           0 :         if ( pMenuItemHandler->xMenuItemDispatch.is() &&
     699           0 :              pMenuItemHandler->xMenuItemDispatch == Source.Source )
     700             :         {
     701             :             // disposing called from menu item dispatcher, remove listener
     702           0 :             pMenuItemDisposing = pMenuItemHandler;
     703           0 :             break;
     704             :         }
     705             :     }
     706             : 
     707         173 :     if ( pMenuItemDisposing )
     708             :     {
     709             :         // Release references to the dispatch object
     710           0 :         URL aTargetURL;
     711           0 :         aTargetURL.Complete = pMenuItemDisposing->aMenuItemURL;
     712             : 
     713             :         // Check reference of service manager before we use it. Reference could
     714             :         // be cleared due to RemoveListener call!
     715           0 :         Reference< XMultiServiceFactory > xServiceManager( getServiceFactory() );
     716           0 :         if ( xServiceManager.is() )
     717             :         {
     718           0 :             m_xURLTransformer->parseStrict( aTargetURL );
     719             : 
     720           0 :             pMenuItemDisposing->xMenuItemDispatch->removeStatusListener(
     721           0 :                 static_cast< XStatusListener* >( this ), aTargetURL );
     722           0 :             pMenuItemDisposing->xMenuItemDispatch = Reference< XDispatch >();
     723           0 :             if ( pMenuItemDisposing->xPopupMenu.is() )
     724             :             {
     725           0 :                 Reference< com::sun::star::lang::XEventListener > xEventListener( pMenuItemDisposing->xPopupMenuController, UNO_QUERY );
     726           0 :                 if ( xEventListener.is() )
     727           0 :                     xEventListener->disposing( Source );
     728             : 
     729             :                 {
     730             :                     // Remove popup menu from menu structure as we release our reference to
     731             :                     // the controller.
     732           0 :                     SolarMutexGuard aGuard2;
     733           0 :                     m_pVCLMenu->SetPopupMenu( pMenuItemDisposing->nItemId, 0 );
     734             :                 }
     735             : 
     736           0 :                 pMenuItemDisposing->xPopupMenuController.clear();
     737           0 :                 pMenuItemDisposing->xPopupMenu.clear();
     738             :             }
     739             :         }
     740         173 :         return;
     741             :     }
     742         173 :     else if ( Source.Source == m_xFrame )
     743             :     {
     744             :         // Our frame gets disposed. We have to remove all our listeners
     745           0 :         RemoveListener();
     746             :     }
     747         173 :     else if ( Source.Source == Reference< XInterface >( m_xDocImageManager, UNO_QUERY ))
     748           0 :         m_xDocImageManager.clear();
     749         173 :     else if ( Source.Source == Reference< XInterface >( m_xModuleImageManager, UNO_QUERY ))
     750         173 :         m_xModuleImageManager.clear();
     751             : }
     752             : 
     753             : 
     754           0 : void MenuBarManager::CheckAndAddMenuExtension( Menu* pMenu )
     755             : {
     756             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::CheckAndAddMenuExtension" );
     757             : 
     758             :     // retrieve menu extension item
     759           0 :     MenuExtensionItem aMenuItem( GetMenuExtension() );
     760           0 :     if (( !aMenuItem.aURL.isEmpty() ) &&
     761           0 :         ( !aMenuItem.aLabel.isEmpty() ))
     762             :     {
     763             :         // remove all old window list entries from menu
     764           0 :         sal_uInt16 nNewItemId( 0 );
     765           0 :         sal_uInt16 nInsertPos( MENU_APPEND );
     766           0 :         sal_uInt16 nBeforePos( MENU_APPEND );
     767           0 :         String aCommandBefore( rtl::OUString(".uno:About"));
     768           0 :         for ( sal_uInt16 n = 0; n < pMenu->GetItemCount(); n++ )
     769             :         {
     770           0 :             sal_uInt16 nItemId = pMenu->GetItemId( n );
     771           0 :             nNewItemId = std::max( nItemId, nNewItemId );
     772           0 :             if ( pMenu->GetItemCommand( nItemId ) == aCommandBefore )
     773           0 :                 nBeforePos = n;
     774             :         }
     775           0 :         ++nNewItemId;
     776             : 
     777           0 :         if ( nBeforePos != MENU_APPEND )
     778           0 :             nInsertPos = nBeforePos;
     779             : 
     780           0 :         pMenu->InsertItem( nNewItemId, aMenuItem.aLabel, 0, nInsertPos );
     781           0 :         pMenu->SetItemCommand( nNewItemId, aMenuItem.aURL );
     782           0 :     }
     783           0 : }
     784             : 
     785           0 : static void lcl_CheckForChildren(Menu* pMenu, sal_uInt16 nItemId)
     786             : {
     787           0 :     if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( nItemId ))
     788           0 :         pMenu->EnableItem( nItemId, pThisPopup->GetItemCount() ? true : false );
     789           0 : }
     790             : 
     791             : //_________________________________________________________________________________________________________________
     792             : // vcl handler
     793             : //_________________________________________________________________________________________________________________
     794             : 
     795             : namespace {
     796             : 
     797             : class QuietInteractionContext:
     798             :     public cppu::WeakImplHelper1< com::sun::star::uno::XCurrentContext >,
     799             :     private boost::noncopyable
     800             : {
     801             : public:
     802           0 :     QuietInteractionContext(
     803             :         com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext >
     804             :             const & context):
     805           0 :         context_(context) {}
     806             : 
     807             : private:
     808           0 :     virtual ~QuietInteractionContext() {}
     809             : 
     810           0 :     virtual com::sun::star::uno::Any SAL_CALL getValueByName(
     811             :         rtl::OUString const & Name)
     812             :         throw (com::sun::star::uno::RuntimeException)
     813             :     {
     814           0 :         return Name != JAVA_INTERACTION_HANDLER_NAME && context_.is()
     815           0 :             ? context_->getValueByName(Name)
     816           0 :             : com::sun::star::uno::Any();
     817             :     }
     818             : 
     819             :     com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext >
     820             :         context_;
     821             : };
     822             : 
     823             : }
     824             : 
     825           0 : IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu )
     826             : {
     827             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Activate" );
     828           0 :     if ( pMenu == m_pVCLMenu )
     829             :     {
     830             :         com::sun::star::uno::ContextLayer layer(
     831             :             new QuietInteractionContext(
     832           0 :                 com::sun::star::uno::getCurrentContext()));
     833             : 
     834             :         // set/unset hiding disabled menu entries
     835           0 :         sal_Bool bDontHide           = SvtMenuOptions().IsEntryHidingEnabled();
     836           0 :         const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
     837           0 :         sal_Bool bShowMenuImages     = rSettings.GetUseImagesInMenus();
     838           0 :         sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
     839             : 
     840           0 :         ResetableGuard aGuard( m_aLock );
     841             : 
     842           0 :         sal_uInt16 nFlag = pMenu->GetMenuFlags();
     843           0 :         if ( bDontHide )
     844           0 :             nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
     845             :         else
     846           0 :             nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
     847           0 :         pMenu->SetMenuFlags( nFlag );
     848             : 
     849           0 :         if ( m_bActive )
     850           0 :             return 0;
     851             : 
     852           0 :         m_bActive = sal_True;
     853             : 
     854           0 :         ::rtl::OUString aMenuCommand( m_aMenuItemCommand );
     855           0 :         if ( m_aMenuItemCommand == aSpecialWindowMenu || m_aMenuItemCommand == aSlotSpecialWindowMenu || aMenuCommand == aSpecialWindowCommand )
     856           0 :              MenuManager::UpdateSpecialWindowMenu( pMenu, comphelper::getComponentContext(getServiceFactory()), m_aLock );
     857             : 
     858             :         // Check if some modes have changed so we have to update our menu images
     859           0 :         sal_Int16 nSymbolsStyle = SvtMiscOptions().GetCurrentSymbolsStyle();
     860             : 
     861           0 :         if ( m_bRetrieveImages ||
     862             :              bShowMenuImages != m_bShowMenuImages ||
     863             :              nSymbolsStyle != m_nSymbolsStyle )
     864             :         {
     865           0 :             m_bShowMenuImages   = bShowMenuImages;
     866           0 :             m_bRetrieveImages   = sal_False;
     867           0 :             m_nSymbolsStyle     = nSymbolsStyle;
     868           0 :             MenuManager::FillMenuImages( m_xFrame, pMenu, bShowMenuImages );
     869             :         }
     870             : 
     871             :         // Try to map commands to labels
     872           0 :         for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
     873             :         {
     874           0 :             sal_uInt16 nItemId = pMenu->GetItemId( nPos );
     875           0 :             if (( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR ) &&
     876           0 :                 ( pMenu->GetItemText( nItemId ).Len() == 0 ))
     877             :             {
     878           0 :                 String aCommand = pMenu->GetItemCommand( nItemId );
     879           0 :                 if ( aCommand.Len() > 0 ) {
     880           0 :                     pMenu->SetItemText( nItemId, RetrieveLabelFromCommand( aCommand ));
     881           0 :                 }
     882             :             }
     883             :         }
     884             : 
     885             :         // Try to set accelerator keys
     886             :         {
     887           0 :             RetrieveShortcuts( m_aMenuItemHandlerVector );
     888           0 :             std::vector< MenuItemHandler* >::iterator p;
     889           0 :             for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     890             :             {
     891           0 :                 MenuItemHandler* pMenuItemHandler = *p;
     892             : 
     893             :                 // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex
     894             :                 // Only non-popup menu items can have a short-cut
     895           0 :                 if ( pMenuItemHandler->aMenuItemURL == aCmdHelpIndex )
     896             :                 {
     897           0 :                     KeyCode aKeyCode( KEY_F1 );
     898           0 :                     pMenu->SetAccelKey( pMenuItemHandler->nItemId, aKeyCode );
     899             :                 }
     900           0 :                 else if ( pMenu->GetPopupMenu( pMenuItemHandler->nItemId ) == 0 )
     901           0 :                     pMenu->SetAccelKey( pMenuItemHandler->nItemId, pMenuItemHandler->aKeyCode );
     902             :             }
     903             :         }
     904             : 
     905           0 :         URL aTargetURL;
     906             : 
     907             :         // Use provided dispatch provider => fallback to frame as dispatch provider
     908           0 :         Reference< XDispatchProvider > xDispatchProvider;
     909           0 :         if ( m_xDispatchProvider.is() )
     910           0 :             xDispatchProvider = m_xDispatchProvider;
     911             :         else
     912           0 :             xDispatchProvider = Reference< XDispatchProvider >( m_xFrame, UNO_QUERY );
     913             : 
     914           0 :         if ( xDispatchProvider.is() )
     915             :         {
     916           0 :             KeyCode             aEmptyKeyCode;
     917           0 :             SvtCommandOptions   aCmdOptions;
     918           0 :             std::vector< MenuItemHandler* >::iterator p;
     919           0 :             for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
     920             :             {
     921           0 :                 MenuItemHandler* pMenuItemHandler = *p;
     922           0 :                 if ( pMenuItemHandler )
     923             :                 {
     924           0 :                     if ( !pMenuItemHandler->xMenuItemDispatch.is() &&
     925           0 :                          !pMenuItemHandler->xSubMenuManager.is()      )
     926             :                     {
     927             :                         // There is no dispatch mechanism for the special window list menu items,
     928             :                         // because they are handled directly through XFrame->activate!!!
     929             :                         // Don't update dispatches for special file menu items.
     930           0 :                         if ( !(( pMenuItemHandler->nItemId >= START_ITEMID_WINDOWLIST &&
     931           0 :                                  pMenuItemHandler->nItemId < END_ITEMID_WINDOWLIST )))
     932             :                         {
     933           0 :                             Reference< XDispatch > xMenuItemDispatch;
     934             : 
     935           0 :                             ::rtl::OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId );
     936           0 :                             if ( aItemCommand.isEmpty() )
     937             :                             {
     938           0 :                                 aItemCommand = ::rtl::OUString( "slot:" );
     939           0 :                                 aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)pMenuItemHandler->nItemId );
     940           0 :                                 pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand );
     941             :                             }
     942             : 
     943           0 :                             aTargetURL.Complete = aItemCommand;
     944             : 
     945           0 :                             m_xURLTransformer->parseStrict( aTargetURL );
     946             : 
     947           0 :                             if ( bHasDisabledEntries )
     948             :                             {
     949           0 :                                 if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path ))
     950           0 :                                     pMenu->HideItem( pMenuItemHandler->nItemId );
     951             :                             }
     952             : 
     953           0 :                             if ( m_bIsBookmarkMenu )
     954           0 :                                 xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, pMenuItemHandler->aTargetFrame, 0 );
     955             :                             else
     956           0 :                                 xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
     957             : 
     958           0 :                             sal_Bool bPopupMenu( sal_False );
     959           0 :                             if ( !pMenuItemHandler->xPopupMenuController.is() &&
     960           0 :                                  m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
     961             :                             {
     962           0 :                                 bPopupMenu = CreatePopupMenuController( pMenuItemHandler );
     963             :                             }
     964           0 :                             else if ( pMenuItemHandler->xPopupMenuController.is() )
     965             :                             {
     966             :                                 // Force update of popup menu
     967           0 :                                 pMenuItemHandler->xPopupMenuController->updatePopupMenu();
     968           0 :                                 bPopupMenu = sal_True;
     969           0 :                                 if (PopupMenu*  pThisPopup = pMenu->GetPopupMenu( pMenuItemHandler->nItemId ))
     970           0 :                                     pMenu->EnableItem( pMenuItemHandler->nItemId, pThisPopup->GetItemCount() ? true : false );
     971             :                             }
     972             : 
     973           0 :                             lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
     974             : 
     975           0 :                             if ( xMenuItemDispatch.is() )
     976             :                             {
     977           0 :                                 pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch;
     978           0 :                                 pMenuItemHandler->aMenuItemURL      = aTargetURL.Complete;
     979             : 
     980           0 :                                 if ( !bPopupMenu )
     981             :                                 {
     982             :                                     // We need only an update to reflect the current state
     983           0 :                                     xMenuItemDispatch->addStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
     984           0 :                                     xMenuItemDispatch->removeStatusListener( static_cast< XStatusListener* >( this ), aTargetURL );
     985             :                                 }
     986             :                             }
     987           0 :                             else if ( !bPopupMenu )
     988           0 :                                 pMenu->EnableItem( pMenuItemHandler->nItemId, sal_False );
     989             :                         }
     990             :                     }
     991           0 :                     else if ( pMenuItemHandler->xPopupMenuController.is() )
     992             :                     {
     993             :                         // Force update of popup menu
     994           0 :                         pMenuItemHandler->xPopupMenuController->updatePopupMenu();
     995           0 :                         lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
     996             :                     }
     997           0 :                     else if ( pMenuItemHandler->xMenuItemDispatch.is() )
     998             :                     {
     999             :                         // We need an update to reflect the current state
    1000             :                         try
    1001             :                         {
    1002           0 :                             aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
    1003           0 :                             m_xURLTransformer->parseStrict( aTargetURL );
    1004             : 
    1005           0 :                             pMenuItemHandler->xMenuItemDispatch->addStatusListener(
    1006           0 :                                                                     static_cast< XStatusListener* >( this ), aTargetURL );
    1007           0 :                             pMenuItemHandler->xMenuItemDispatch->removeStatusListener(
    1008           0 :                                                                     static_cast< XStatusListener* >( this ), aTargetURL );
    1009             :                         }
    1010           0 :                         catch ( const Exception& )
    1011             :                         {
    1012             :                         }
    1013             :                     }
    1014           0 :                     else if ( pMenuItemHandler->xSubMenuManager.is() )
    1015           0 :                         lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId);
    1016             :                 }
    1017           0 :             }
    1018           0 :         }
    1019             :     }
    1020             : 
    1021           0 :     return 1;
    1022             : }
    1023             : 
    1024             : 
    1025           0 : IMPL_LINK( MenuBarManager, Deactivate, Menu *, pMenu )
    1026             : {
    1027             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Deactivate" );
    1028           0 :     if ( pMenu == m_pVCLMenu )
    1029             :     {
    1030           0 :         m_bActive = sal_False;
    1031           0 :         if ( pMenu->IsMenuBar() && m_xDeferedItemContainer.is() )
    1032             :         {
    1033             :             // Start timer to handle settings asynchronous
    1034             :             // Changing the menu inside this handler leads to
    1035             :             // a crash under X!
    1036           0 :             m_aAsyncSettingsTimer.SetTimeoutHdl(LINK(this, MenuBarManager, AsyncSettingsHdl));
    1037           0 :             m_aAsyncSettingsTimer.SetTimeout(10);
    1038           0 :             m_aAsyncSettingsTimer.Start();
    1039             :         }
    1040             :     }
    1041             : 
    1042           0 :     return 1;
    1043             : }
    1044             : 
    1045           0 : IMPL_LINK( MenuBarManager, AsyncSettingsHdl, Timer*,)
    1046             : {
    1047           0 :     SolarMutexGuard aGuard;
    1048             :     Reference< XInterface > xSelfHold(
    1049           0 :         static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY_THROW );
    1050             : 
    1051           0 :     m_aAsyncSettingsTimer.Stop();
    1052           0 :     if ( !m_bActive && m_xDeferedItemContainer.is() )
    1053             :     {
    1054           0 :         SetItemContainer( m_xDeferedItemContainer );
    1055           0 :         m_xDeferedItemContainer.clear();
    1056             :     }
    1057             : 
    1058           0 :     return 0;
    1059             : }
    1060             : 
    1061           0 : IMPL_LINK( MenuBarManager, Select, Menu *, pMenu )
    1062             : {
    1063             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Select" );
    1064           0 :     URL                     aTargetURL;
    1065           0 :     Sequence<PropertyValue> aArgs;
    1066           0 :     Reference< XDispatch >  xDispatch;
    1067             : 
    1068             :     {
    1069           0 :         ResetableGuard aGuard( m_aLock );
    1070             : 
    1071           0 :         sal_uInt16 nCurItemId = pMenu->GetCurItemId();
    1072           0 :         sal_uInt16 nCurPos    = pMenu->GetItemPos( nCurItemId );
    1073           0 :         if ( pMenu == m_pVCLMenu &&
    1074           0 :              pMenu->GetItemType( nCurPos ) != MENUITEM_SEPARATOR )
    1075             :         {
    1076           0 :             if ( nCurItemId >= START_ITEMID_WINDOWLIST &&
    1077             :                  nCurItemId <= END_ITEMID_WINDOWLIST )
    1078             :             {
    1079             :                 // window list menu item selected
    1080             : 
    1081           0 :                 Reference< XDesktop2 > xDesktop = Desktop::create( comphelper::getComponentContext(getServiceFactory()) );
    1082             : 
    1083           0 :                 sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST;
    1084           0 :                 Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
    1085           0 :                 sal_Int32 nCount = xList->getCount();
    1086           0 :                 for ( sal_Int32 i=0; i<nCount; ++i )
    1087             :                 {
    1088           0 :                     Reference< XFrame > xFrame;
    1089           0 :                     xList->getByIndex(i) >>= xFrame;
    1090           0 :                     if ( xFrame.is() && nTaskId == nCurItemId )
    1091             :                     {
    1092           0 :                         Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
    1093           0 :                         pWin->GrabFocus();
    1094           0 :                         pWin->ToTop( TOTOP_RESTOREWHENMIN );
    1095             :                         break;
    1096             :                     }
    1097             : 
    1098           0 :                     nTaskId++;
    1099           0 :                 }
    1100             :             }
    1101             :             else
    1102             :             {
    1103           0 :                 MenuItemHandler* pMenuItemHandler = GetMenuItemHandler( nCurItemId );
    1104           0 :                 if ( pMenuItemHandler && pMenuItemHandler->xMenuItemDispatch.is() )
    1105             :                 {
    1106           0 :                     aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
    1107           0 :                     m_xURLTransformer->parseStrict( aTargetURL );
    1108             : 
    1109           0 :                     if ( m_bIsBookmarkMenu )
    1110             :                     {
    1111             :                         // bookmark menu item selected
    1112           0 :                         aArgs.realloc( 1 );
    1113           0 :                         aArgs[0].Name = ::rtl::OUString( "Referer" );
    1114           0 :                         aArgs[0].Value <<= ::rtl::OUString( SFX_REFERER_USER );
    1115             :                     }
    1116             : 
    1117           0 :                     xDispatch = pMenuItemHandler->xMenuItemDispatch;
    1118             :                 }
    1119             :             }
    1120           0 :         }
    1121             :     }
    1122             : 
    1123           0 :     if ( xDispatch.is() )
    1124             :     {
    1125           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
    1126           0 :         xDispatch->dispatch( aTargetURL, aArgs );
    1127           0 :         Application::AcquireSolarMutex( nRef );
    1128             :     }
    1129             : 
    1130           0 :     return 1;
    1131             : }
    1132             : 
    1133             : 
    1134           0 : IMPL_LINK_NOARG(MenuBarManager, Highlight)
    1135             : {
    1136           0 :     return 0;
    1137             : }
    1138             : 
    1139           0 : sal_Bool MenuBarManager::MustBeHidden( PopupMenu* pPopupMenu, const Reference< XURLTransformer >& rTransformer )
    1140             : {
    1141             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MustBeHidden" );
    1142           0 :     if ( pPopupMenu )
    1143             :     {
    1144           0 :         URL               aTargetURL;
    1145           0 :         SvtCommandOptions aCmdOptions;
    1146             : 
    1147           0 :         sal_uInt16 nCount = pPopupMenu->GetItemCount();
    1148           0 :         sal_uInt16 nHideCount( 0 );
    1149             : 
    1150           0 :         for ( sal_uInt16 i = 0; i < nCount; i++ )
    1151             :         {
    1152           0 :             sal_uInt16 nId = pPopupMenu->GetItemId( i );
    1153           0 :             if ( nId > 0 )
    1154             :             {
    1155           0 :                 PopupMenu* pSubPopupMenu = pPopupMenu->GetPopupMenu( nId );
    1156           0 :                 if ( pSubPopupMenu )
    1157             :                 {
    1158           0 :                     if ( MustBeHidden( pSubPopupMenu, rTransformer ))
    1159             :                     {
    1160           0 :                         pPopupMenu->HideItem( nId );
    1161           0 :                         ++nHideCount;
    1162             :                     }
    1163             :                 }
    1164             :                 else
    1165             :                 {
    1166           0 :                     aTargetURL.Complete = pPopupMenu->GetItemCommand( nId );
    1167           0 :                     rTransformer->parseStrict( aTargetURL );
    1168             : 
    1169           0 :                     if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path ))
    1170           0 :                         ++nHideCount;
    1171             :                 }
    1172             :             }
    1173             :             else
    1174           0 :                 ++nHideCount;
    1175             :         }
    1176             : 
    1177           0 :         return ( nCount == nHideCount );
    1178             :     }
    1179             : 
    1180           0 :     return sal_True;
    1181             : }
    1182           0 : String MenuBarManager::RetrieveLabelFromCommand( const String& aCmdURL )
    1183             : {
    1184           0 :     return framework::RetrieveLabelFromCommand(aCmdURL, comphelper::getComponentContext(mxServiceFactory), m_xUICommandLabels,m_xFrame,m_aModuleIdentifier,m_bModuleIdentified,"Label");
    1185             : }
    1186             : 
    1187             : 
    1188             : 
    1189           0 : sal_Bool MenuBarManager::CreatePopupMenuController( MenuItemHandler* pMenuItemHandler )
    1190             : {
    1191             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::CreatePopupMenuController" );
    1192           0 :     rtl::OUString aItemCommand( pMenuItemHandler->aMenuItemURL );
    1193             : 
    1194             :     // Try instantiate a popup menu controller. It is stored in the menu item handler.
    1195           0 :     Sequence< Any > aSeq( 2 );
    1196           0 :     PropertyValue aPropValue;
    1197             : 
    1198           0 :     aPropValue.Name         = rtl::OUString( "ModuleName" );
    1199           0 :     aPropValue.Value      <<= m_aModuleIdentifier;
    1200           0 :     aSeq[0] <<= aPropValue;
    1201           0 :     aPropValue.Name         = rtl::OUString( "Frame" );
    1202           0 :     aPropValue.Value      <<= m_xFrame;
    1203           0 :     aSeq[1] <<= aPropValue;
    1204             : 
    1205             :     Reference< XComponentContext > xComponentContext(
    1206           0 :         comphelper::getComponentContext( getServiceFactory() ) );
    1207             : 
    1208             :     Reference< XPopupMenuController > xPopupMenuController(
    1209           0 :                                             m_xPopupMenuControllerRegistration->createInstanceWithArgumentsAndContext(
    1210             :                                                 aItemCommand,
    1211             :                                                 aSeq,
    1212           0 :                                                 xComponentContext ),
    1213           0 :                                             UNO_QUERY );
    1214             : 
    1215           0 :     if ( xPopupMenuController.is() )
    1216             :     {
    1217             :         // Provide our awt popup menu to the popup menu controller
    1218           0 :         pMenuItemHandler->xPopupMenuController = xPopupMenuController;
    1219           0 :         xPopupMenuController->setPopupMenu( pMenuItemHandler->xPopupMenu );
    1220           0 :         return sal_True;
    1221             :     }
    1222             : 
    1223           0 :     return sal_False;
    1224             : }
    1225             : 
    1226         236 : void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rFrame, const Reference< XDispatchProvider >& rDispatchProvider, const rtl::OUString& rModuleIdentifier, sal_Bool bDelete, sal_Bool bDeleteChildren )
    1227             : {
    1228             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenuManager" );
    1229         236 :     m_xFrame            = rFrame;
    1230         236 :     m_bActive           = sal_False;
    1231         236 :     m_bDeleteMenu       = bDelete;
    1232         236 :     m_bDeleteChildren   = bDeleteChildren;
    1233         236 :     m_pVCLMenu          = pMenu;
    1234         236 :     m_bInitialized      = sal_False;
    1235         236 :     m_bIsBookmarkMenu   = sal_False;
    1236         236 :     m_xDispatchProvider = rDispatchProvider;
    1237             : 
    1238         236 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
    1239         236 :     m_bShowMenuImages   = rSettings.GetUseImagesInMenus();
    1240         236 :     m_bRetrieveImages   = sal_False;
    1241             : 
    1242         236 :     sal_Int32 nAddonsURLPrefixLength = ADDONSPOPUPMENU_URL_PREFIX.getLength();
    1243             : 
    1244             :     // Add root as ui configuration listener
    1245         236 :     RetrieveImageManagers();
    1246             : 
    1247         236 :     if ( pMenu->IsMenuBar() && rFrame.is() )
    1248             :     {
    1249             :         // First merge all addon popup menus into our structure
    1250         236 :         sal_uInt16 nPos = 0;
    1251         236 :         for ( nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
    1252             :         {
    1253           0 :             sal_uInt16          nItemId  = pMenu->GetItemId( nPos );
    1254           0 :             ::rtl::OUString aCommand = pMenu->GetItemCommand( nItemId );
    1255           0 :             if ( nItemId == SID_MDIWINDOWLIST || aCommand == aSpecialWindowCommand)
    1256             :             {
    1257             :                 // Retrieve addon popup menus and add them to our menu bar
    1258           0 :                 Reference< com::sun::star::frame::XModel >      xModel;
    1259           0 :                 Reference< com::sun::star::frame::XController > xController( rFrame->getController(), UNO_QUERY );
    1260           0 :                 if ( xController.is() )
    1261           0 :                     xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY );
    1262           0 :                 framework::AddonMenuManager::MergeAddonPopupMenus( rFrame, xModel, nPos, (MenuBar *)pMenu );
    1263           0 :                 break;
    1264             :             }
    1265           0 :         }
    1266             : 
    1267             :         // Merge the Add-Ons help menu items into the Office help menu
    1268         236 :         framework::AddonMenuManager::MergeAddonHelpMenu( rFrame, (MenuBar *)pMenu );
    1269             :     }
    1270             : 
    1271         236 :     String      aEmpty;
    1272         236 :     sal_Bool    bAccessibilityEnabled( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() );
    1273         236 :     sal_uInt16 nItemCount = pMenu->GetItemCount();
    1274         236 :     ::rtl::OUString aItemCommand;
    1275         236 :     m_aMenuItemHandlerVector.reserve(nItemCount);
    1276         236 :     for ( sal_uInt16 i = 0; i < nItemCount; i++ )
    1277             :     {
    1278           0 :         sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i );
    1279             : 
    1280             :         // Set module identifier when provided from outside
    1281           0 :         if ( !rModuleIdentifier.isEmpty() )
    1282             :         {
    1283           0 :             m_aModuleIdentifier = rModuleIdentifier;
    1284           0 :             m_bModuleIdentified = sal_True;
    1285             :         }
    1286             : 
    1287           0 :         if (( pMenu->IsMenuBar() || bAccessibilityEnabled ) &&
    1288           0 :             ( pMenu->GetItemText( nItemId ).Len() == 0 ))
    1289             :         {
    1290           0 :             if ( !aItemCommand.isEmpty() )
    1291           0 :                 pMenu->SetItemText( nItemId, RetrieveLabelFromCommand( aItemCommand ));
    1292             :         }
    1293             : 
    1294           0 :         Reference< XDispatch > xDispatch;
    1295           0 :         Reference< XStatusListener > xStatusListener;
    1296           0 :         PopupMenu* pPopup = pMenu->GetPopupMenu( nItemId );
    1297           0 :         bool bItemShowMenuImages = m_bShowMenuImages;
    1298             :         // overwrite the show icons on menu option?
    1299           0 :         if (!bItemShowMenuImages)
    1300             :         {
    1301           0 :             MenuItemBits nBits =  pMenu->GetItemBits( nItemId );
    1302           0 :             bItemShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON );
    1303             :         }
    1304           0 :         if ( pPopup )
    1305             :         {
    1306             :             // Retrieve module identifier from Help Command entry
    1307           0 :             rtl::OUString aModuleIdentifier( rModuleIdentifier );
    1308           0 :             if ( pMenu->GetHelpCommand( nItemId ).Len() > 0 )
    1309             :             {
    1310           0 :                 aModuleIdentifier = pMenu->GetHelpCommand( nItemId );
    1311           0 :                 pMenu->SetHelpCommand( nItemId, aEmpty );
    1312             :             }
    1313             : 
    1314           0 :             if ( m_xPopupMenuControllerRegistration.is() &&
    1315           0 :                  pPopup->GetItemCount() == 0 &&
    1316           0 :                  m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() )
    1317             :                   )
    1318             :             {
    1319             :                 // Check if we have to create a popup menu for a uno based popup menu controller.
    1320             :                 // We have to set an empty popup menu into our menu structure so the controller also
    1321             :                 // works with inplace OLE. Remove old dummy popup menu!
    1322           0 :                 MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
    1323           0 :                 VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
    1324           0 :                 PopupMenu* pNewPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
    1325           0 :                 pMenu->SetPopupMenu( nItemId, pNewPopupMenu );
    1326           0 :                 pItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
    1327           0 :                 pItemHandler->aMenuItemURL = aItemCommand;
    1328           0 :                 m_aMenuItemHandlerVector.push_back( pItemHandler );
    1329           0 :                 delete pPopup;
    1330             : 
    1331           0 :                 if ( bAccessibilityEnabled )
    1332             :                 {
    1333           0 :                     if ( CreatePopupMenuController( pItemHandler ))
    1334           0 :                         pItemHandler->xPopupMenuController->updatePopupMenu();
    1335             :                 }
    1336           0 :                 lcl_CheckForChildren(pMenu, nItemId);
    1337             :             }
    1338           0 :             else if (( aItemCommand.getLength() > nAddonsURLPrefixLength ) &&
    1339           0 :                      ( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 ))
    1340             :             {
    1341             :                 // A special addon popup menu, must be created with a different ctor
    1342           0 :                 MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), m_xFrame, m_xURLTransformer,(AddonPopupMenu *)pPopup, bDeleteChildren, bDeleteChildren );
    1343           0 :                 AddMenu(pSubMenuManager,aItemCommand,nItemId);
    1344             :             }
    1345             :             else
    1346             :             {
    1347           0 :                 Reference< XDispatchProvider > xPopupMenuDispatchProvider( rDispatchProvider );
    1348             : 
    1349             :                 // Retrieve possible attributes struct
    1350           0 :                 MenuConfiguration::Attributes* pAttributes = (MenuConfiguration::Attributes *)(pMenu->GetUserValue( nItemId ));
    1351           0 :                 if ( pAttributes )
    1352           0 :                     xPopupMenuDispatchProvider = pAttributes->xDispatchProvider;
    1353             : 
    1354             :                 // Check if this is the help menu. Add menu item if needed
    1355           0 :                 if ( nItemId == SID_HELPMENU || aItemCommand == aSlotHelpMenu || aItemCommand == aCmdHelpMenu )
    1356             :                 {
    1357             :                     // Check if this is the help menu. Add menu item if needed
    1358           0 :                     CheckAndAddMenuExtension( pPopup );
    1359             :                 }
    1360           0 :                 else if (( nItemId == SID_ADDONLIST || aItemCommand == aSlotSpecialToolsMenu || aItemCommand == aCmdToolsMenu ) &&
    1361           0 :                         AddonMenuManager::HasAddonMenuElements() )
    1362             :                 {
    1363             :                     // Create addon popup menu if there exist elements and this is the tools popup menu
    1364           0 :                     AddonMenu*  pSubMenu = AddonMenuManager::CreateAddonMenu( rFrame );
    1365           0 :                     if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 ))
    1366             :                     {
    1367           0 :                         sal_uInt16 nCount = 0;
    1368           0 :                         if ( pPopup->GetItemType( nCount-1 ) != MENUITEM_SEPARATOR )
    1369           0 :                             pPopup->InsertSeparator();
    1370             : 
    1371             :                         // Use resource to load popup menu title
    1372           0 :                         String aAddonsStrRes = String( FwkResId( STR_MENU_ADDONS ));
    1373           0 :                         pPopup->InsertItem( ITEMID_ADDONLIST, aAddonsStrRes );
    1374           0 :                         pPopup->SetPopupMenu( ITEMID_ADDONLIST, pSubMenu );
    1375             : 
    1376             :                         // Set item command for popup menu to enable it for GetImageFromURL
    1377           0 :                         const ::rtl::OUString aSlotString( "slot:" );
    1378           0 :                         ::rtl::OUString aNewItemCommand( aSlotString );
    1379           0 :                         aNewItemCommand += ::rtl::OUString::valueOf( (sal_Int32)ITEMID_ADDONLIST );
    1380           0 :                         pPopup->SetItemCommand( ITEMID_ADDONLIST, aNewItemCommand );
    1381             :                     }
    1382             :                     else
    1383           0 :                         delete pSubMenu;
    1384             :                 }
    1385             : 
    1386           0 :                 if ( nItemId == ITEMID_ADDONLIST )
    1387             :                 {
    1388           0 :                     AddonMenu* pSubMenu = dynamic_cast< AddonMenu* >( pPopup );
    1389           0 :                     if ( pSubMenu )
    1390             :                     {
    1391           0 :                         MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), m_xFrame, m_xURLTransformer,pSubMenu, sal_True, sal_False );
    1392           0 :                         AddMenu(pSubMenuManager,aItemCommand,nItemId);
    1393           0 :                         pSubMenuManager->m_aMenuItemCommand = ::rtl::OUString();
    1394             : 
    1395             :                         // Set image for the addon popup menu item
    1396           0 :                         if ( bItemShowMenuImages && !pPopup->GetItemImage( ITEMID_ADDONLIST ))
    1397             :                         {
    1398           0 :                             Reference< XFrame > xTemp( rFrame );
    1399           0 :                             Image aImage = GetImageFromURL( xTemp, aItemCommand, false );
    1400           0 :                             if ( !!aImage )
    1401           0 :                                    pPopup->SetItemImage( ITEMID_ADDONLIST, aImage );
    1402             :                         }
    1403             :                     }
    1404             :                 }
    1405             :                 else
    1406             :                 {
    1407           0 :                     MenuBarManager* pSubMenuMgr = new MenuBarManager( getServiceFactory(), rFrame, m_xURLTransformer,rDispatchProvider, aModuleIdentifier, pPopup, bDeleteChildren, bDeleteChildren );
    1408           0 :                     AddMenu(pSubMenuMgr,aItemCommand,nItemId);
    1409           0 :                 }
    1410           0 :             }
    1411             :         }
    1412           0 :         else if ( pMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
    1413             :         {
    1414           0 :             if ( bItemShowMenuImages )
    1415             :             {
    1416           0 :                 if ( AddonMenuManager::IsAddonMenuId( nItemId ))
    1417             :                 {
    1418             :                     // Add-Ons uses images from different places
    1419           0 :                     Image           aImage;
    1420           0 :                     rtl::OUString   aImageId;
    1421             : 
    1422             :                     MenuConfiguration::Attributes* pMenuAttributes =
    1423           0 :                         (MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
    1424             : 
    1425           0 :                     if ( pMenuAttributes && !pMenuAttributes->aImageId.isEmpty() )
    1426             :                     {
    1427             :                         // Retrieve image id from menu attributes
    1428           0 :                         aImage = GetImageFromURL( m_xFrame, aImageId, false );
    1429             :                     }
    1430             : 
    1431           0 :                     if ( !aImage )
    1432             :                     {
    1433           0 :                         aImage = GetImageFromURL( m_xFrame, aItemCommand, false );
    1434           0 :                         if ( !aImage )
    1435           0 :                             aImage = AddonsOptions().GetImageFromURL( aItemCommand, false );
    1436             :                     }
    1437             : 
    1438           0 :                     if ( !!aImage )
    1439           0 :                         pMenu->SetItemImage( nItemId, aImage );
    1440             :                     else
    1441           0 :                         m_bRetrieveImages = sal_True;
    1442             :                 }
    1443           0 :                 m_bRetrieveImages = sal_True;
    1444             :             }
    1445             : 
    1446           0 :             MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
    1447           0 :             pItemHandler->aMenuItemURL = aItemCommand;
    1448             : 
    1449           0 :             if ( m_xPopupMenuControllerRegistration.is() &&
    1450           0 :                  m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
    1451             :             {
    1452             :                 // Check if we have to create a popup menu for a uno based popup menu controller.
    1453             :                 // We have to set an empty popup menu into our menu structure so the controller also
    1454             :                 // works with inplace OLE.
    1455           0 :                 VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
    1456           0 :                 PopupMenu* pPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
    1457           0 :                 pMenu->SetPopupMenu( pItemHandler->nItemId, pPopupMenu );
    1458           0 :                 pItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
    1459             : 
    1460           0 :                 if ( bAccessibilityEnabled && CreatePopupMenuController( pItemHandler ) )
    1461             :                 {
    1462           0 :                     pItemHandler->xPopupMenuController->updatePopupMenu();
    1463             :                 }
    1464             : 
    1465           0 :                 lcl_CheckForChildren(pMenu, pItemHandler->nItemId);
    1466             :             }
    1467             : 
    1468           0 :             m_aMenuItemHandlerVector.push_back( pItemHandler );
    1469             :         }
    1470           0 :     }
    1471             : 
    1472         236 :     if ( bAccessibilityEnabled )
    1473             :     {
    1474           0 :         RetrieveShortcuts( m_aMenuItemHandlerVector );
    1475           0 :         std::vector< MenuItemHandler* >::iterator p;
    1476           0 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
    1477             :         {
    1478           0 :             MenuItemHandler* pMenuItemHandler = *p;
    1479             : 
    1480             :             // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex
    1481             :             // Only non-popup menu items can have a short-cut
    1482           0 :             if ( pMenuItemHandler->aMenuItemURL == aCmdHelpIndex )
    1483             :             {
    1484           0 :                 KeyCode aKeyCode( KEY_F1 );
    1485           0 :                 pMenu->SetAccelKey( pMenuItemHandler->nItemId, aKeyCode );
    1486             :             }
    1487           0 :             else if ( pMenu->GetPopupMenu( pMenuItemHandler->nItemId ) == 0 )
    1488           0 :                 pMenu->SetAccelKey( pMenuItemHandler->nItemId, pMenuItemHandler->aKeyCode );
    1489             :         }
    1490             :     }
    1491             : 
    1492         236 :     SetHdl();
    1493         236 : }
    1494             : 
    1495           0 : void MenuBarManager::impl_RetrieveShortcutsFromConfiguration(
    1496             :     const Reference< XAcceleratorConfiguration >& rAccelCfg,
    1497             :     const Sequence< rtl::OUString >& rCommands,
    1498             :     std::vector< MenuItemHandler* >& aMenuShortCuts )
    1499             : {
    1500             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::impl_RetrieveShortcutsFromConfiguration" );
    1501           0 :     if ( rAccelCfg.is() )
    1502             :     {
    1503             :         try
    1504             :         {
    1505           0 :             com::sun::star::awt::KeyEvent aKeyEvent;
    1506           0 :             Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands );
    1507           0 :             for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ )
    1508             :             {
    1509           0 :                 if ( aSeqKeyCode[i] >>= aKeyEvent )
    1510           0 :                     aMenuShortCuts[i]->aKeyCode = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent );
    1511           0 :             }
    1512             :         }
    1513           0 :         catch ( const IllegalArgumentException& )
    1514             :         {
    1515             :         }
    1516             :     }
    1517           0 : }
    1518             : 
    1519           0 : void MenuBarManager::RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts )
    1520             : {
    1521             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RetrieveShortcuts" );
    1522           0 :     if ( !m_bModuleIdentified )
    1523             :     {
    1524           0 :         m_bModuleIdentified = sal_True;
    1525           0 :         Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext( getServiceFactory() ) );
    1526             : 
    1527             :         try
    1528             :         {
    1529           0 :             m_aModuleIdentifier = xModuleManager->identify( m_xFrame );
    1530             :         }
    1531           0 :         catch( const Exception& )
    1532             :         {
    1533           0 :         }
    1534             :     }
    1535             : 
    1536           0 :     if ( m_bModuleIdentified )
    1537             :     {
    1538           0 :         Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager );
    1539           0 :         Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager );
    1540           0 :         Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager );
    1541             : 
    1542           0 :         if ( !m_bAcceleratorCfg )
    1543             :         {
    1544             :             // Retrieve references on demand
    1545           0 :             m_bAcceleratorCfg = sal_True;
    1546           0 :             if ( !xDocAccelCfg.is() )
    1547             :             {
    1548           0 :                 Reference< XController > xController = m_xFrame->getController();
    1549           0 :                 Reference< XModel > xModel;
    1550           0 :                 if ( xController.is() )
    1551             :                 {
    1552           0 :                     xModel = xController->getModel();
    1553           0 :                     if ( xModel.is() )
    1554             :                     {
    1555           0 :                         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
    1556           0 :                         if ( xSupplier.is() )
    1557             :                         {
    1558           0 :                             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
    1559           0 :                             if ( xDocUICfgMgr.is() )
    1560             :                             {
    1561           0 :                                 xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY );
    1562           0 :                                 m_xDocAcceleratorManager = xDocAccelCfg;
    1563           0 :                             }
    1564           0 :                         }
    1565             :                     }
    1566           0 :                 }
    1567             :             }
    1568             : 
    1569           0 :             if ( !xModuleAccelCfg.is() )
    1570             :             {
    1571             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
    1572           0 :                     ModuleUIConfigurationManagerSupplier::create( comphelper::getComponentContext(getServiceFactory()) );
    1573             :                 try
    1574             :                 {
    1575           0 :                     Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
    1576           0 :                     if ( xUICfgMgr.is() )
    1577             :                     {
    1578           0 :                         xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY );
    1579           0 :                         m_xModuleAcceleratorManager = xModuleAccelCfg;
    1580           0 :                     }
    1581             :                 }
    1582           0 :                 catch ( const RuntimeException& )
    1583             :                 {
    1584           0 :                     throw;
    1585             :                 }
    1586           0 :                 catch ( const Exception& )
    1587             :                 {
    1588           0 :                 }
    1589             :             }
    1590             : 
    1591           0 :             if ( !xGlobalAccelCfg.is() )
    1592             :             {
    1593           0 :                 xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( comphelper::getComponentContext(getServiceFactory()) );
    1594           0 :                 m_xGlobalAcceleratorManager = xGlobalAccelCfg;
    1595             :             }
    1596             :         }
    1597             : 
    1598           0 :         KeyCode aEmptyKeyCode;
    1599           0 :         Sequence< rtl::OUString > aSeq( aMenuShortCuts.size() );
    1600           0 :         const sal_uInt32 nCount = aMenuShortCuts.size();
    1601           0 :         for ( sal_uInt32 i = 0; i < nCount; ++i )
    1602             :         {
    1603           0 :             aSeq[i] = aMenuShortCuts[i]->aMenuItemURL;
    1604           0 :             aMenuShortCuts[i]->aKeyCode = aEmptyKeyCode;
    1605             :         }
    1606             : 
    1607           0 :         if ( m_xGlobalAcceleratorManager.is() )
    1608           0 :             impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts );
    1609           0 :         if ( m_xModuleAcceleratorManager.is() )
    1610           0 :             impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts );
    1611           0 :         if ( m_xDocAcceleratorManager.is() )
    1612           0 :             impl_RetrieveShortcutsFromConfiguration( xDocAccelCfg, aSeq, aMenuShortCuts );
    1613             :     }
    1614           0 : }
    1615             : 
    1616         236 : void MenuBarManager::RetrieveImageManagers()
    1617             : {
    1618             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::RetrieveImageManagers" );
    1619         236 :     if ( !m_xDocImageManager.is() )
    1620             :     {
    1621         236 :         Reference< XController > xController = m_xFrame->getController();
    1622         236 :         Reference< XModel > xModel;
    1623         236 :         if ( xController.is() )
    1624             :         {
    1625         236 :             xModel = xController->getModel();
    1626         236 :             if ( xModel.is() )
    1627             :             {
    1628         236 :                 Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
    1629         236 :                 if ( xSupplier.is() )
    1630             :                 {
    1631         236 :                     Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
    1632         236 :                     m_xDocImageManager = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
    1633         236 :                     m_xDocImageManager->addConfigurationListener(
    1634             :                                             Reference< XUIConfigurationListener >(
    1635         236 :                                                 static_cast< OWeakObject* >( this ), UNO_QUERY ));
    1636         236 :                 }
    1637             :             }
    1638         236 :         }
    1639             :     }
    1640             : 
    1641         236 :     Reference< XModuleManager2 > xModuleManager;
    1642         236 :     if ( m_aModuleIdentifier.isEmpty() )
    1643         236 :         xModuleManager.set( ModuleManager::create( comphelper::getComponentContext( getServiceFactory() ) ) );
    1644             : 
    1645             :     try
    1646             :     {
    1647         236 :         if ( xModuleManager.is() )
    1648         236 :             m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >( m_xFrame, UNO_QUERY ) );
    1649             :     }
    1650           0 :     catch( const Exception& )
    1651             :     {
    1652             :     }
    1653             : 
    1654         236 :     if ( !m_xModuleImageManager.is() )
    1655             :     {
    1656             :         Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
    1657         236 :             ModuleUIConfigurationManagerSupplier::create( comphelper::getComponentContext(getServiceFactory()) );
    1658         236 :         Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
    1659         236 :         m_xModuleImageManager.set( xUICfgMgr->getImageManager(), UNO_QUERY );
    1660         236 :         m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
    1661         236 :                                                             static_cast< OWeakObject* >( this ), UNO_QUERY ));
    1662         236 :     }
    1663         236 : }
    1664             : 
    1665           0 : void MenuBarManager::FillMenuWithConfiguration(
    1666             :     sal_uInt16&                         nId,
    1667             :     Menu*                               pMenu,
    1668             :     const ::rtl::OUString&              rModuleIdentifier,
    1669             :     const Reference< XIndexAccess >&    rItemContainer,
    1670             :     const Reference< XURLTransformer >& rTransformer )
    1671             : {
    1672             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenuWithConfiguration" );
    1673           0 :     Reference< XDispatchProvider > xEmptyDispatchProvider;
    1674           0 :     MenuBarManager::FillMenu( nId, pMenu, rModuleIdentifier, rItemContainer, xEmptyDispatchProvider );
    1675             : 
    1676             :     // Merge add-on menu entries into the menu bar
    1677             :     MenuBarManager::MergeAddonMenus( static_cast< Menu* >( pMenu ),
    1678           0 :                                      AddonsOptions().GetMergeMenuInstructions(),
    1679           0 :                                      rModuleIdentifier );
    1680             : 
    1681           0 :     sal_Bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED );
    1682           0 :     if ( bHasDisabledEntries )
    1683             :     {
    1684           0 :         sal_uInt16 nCount = pMenu->GetItemCount();
    1685           0 :         for ( sal_uInt16 i = 0; i < nCount; i++ )
    1686             :         {
    1687           0 :             sal_uInt16 nID = pMenu->GetItemId( i );
    1688           0 :             if ( nID > 0 )
    1689             :             {
    1690           0 :                 PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nID );
    1691           0 :                 if ( pPopupMenu )
    1692             :                 {
    1693           0 :                     if ( MustBeHidden( pPopupMenu, rTransformer ))
    1694           0 :                         pMenu->HideItem( nId );
    1695             :                 }
    1696             :             }
    1697             :         }
    1698           0 :     }
    1699           0 : }
    1700             : 
    1701           0 : void MenuBarManager::FillMenu(
    1702             :     sal_uInt16&                           nId,
    1703             :     Menu*                                 pMenu,
    1704             :     const rtl::OUString&                  rModuleIdentifier,
    1705             :     const Reference< XIndexAccess >&      rItemContainer,
    1706             :     const Reference< XDispatchProvider >& rDispatchProvider )
    1707             : {
    1708             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillMenu" );
    1709             :     // Fill menu bar with container contents
    1710           0 :      for ( sal_Int32 n = 0; n < rItemContainer->getCount(); n++ )
    1711             :     {
    1712           0 :         Sequence< PropertyValue >       aProp;
    1713           0 :         rtl::OUString                   aCommandURL;
    1714           0 :         rtl::OUString                   aLabel;
    1715           0 :         rtl::OUString                   aHelpURL;
    1716           0 :         rtl::OUString                   aModuleIdentifier( rModuleIdentifier );
    1717           0 :         sal_Bool                        bShow(sal_True);
    1718           0 :         sal_Bool                        bEnabled(sal_True);
    1719           0 :         sal_uInt16                      nType = 0;
    1720           0 :         Reference< XIndexAccess >       xIndexContainer;
    1721           0 :         Reference< XDispatchProvider >  xDispatchProvider( rDispatchProvider );
    1722           0 :         sal_Int16 nStyle = 0;
    1723             :         try
    1724             :         {
    1725           0 :             if ( rItemContainer->getByIndex( n ) >>= aProp )
    1726             :             {
    1727           0 :                 for ( int i = 0; i < aProp.getLength(); i++ )
    1728             :                 {
    1729           0 :                     rtl::OUString aPropName = aProp[i].Name;
    1730           0 :                     if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_COMMANDURL, LEN_DESCRIPTOR_COMMANDURL ))
    1731           0 :                         aProp[i].Value >>= aCommandURL;
    1732           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_HELPURL, LEN_DESCRIPTOR_HELPURL ))
    1733           0 :                         aProp[i].Value >>= aHelpURL;
    1734           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_CONTAINER, LEN_DESCRIPTOR_CONTAINER ))
    1735           0 :                         aProp[i].Value >>= xIndexContainer;
    1736           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_LABEL, LEN_DESCRIPTOR_LABEL ))
    1737           0 :                         aProp[i].Value >>= aLabel;
    1738           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_TYPE, LEN_DESCRIPTOR_TYPE ))
    1739           0 :                         aProp[i].Value >>= nType;
    1740           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_MODULEIDENTIFIER, LEN_DESCRIPTOR_MODULEIDENTIFIER ))
    1741           0 :                         aProp[i].Value >>= aModuleIdentifier;
    1742           0 :                     else if ( aPropName.equalsAsciiL( ITEM_DESCRIPTOR_DISPATCHPROVIDER, LEN_DESCRIPTOR_DISPATCHPROVIDER ))
    1743           0 :                         aProp[i].Value >>= xDispatchProvider;
    1744           0 :                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_STYLE, LEN_DESCRIPTOR_STYLE ))
    1745           0 :                         aProp[i].Value >>= nStyle;
    1746           0 :                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ISVISIBLE, LEN_DESCRIPTOR_ISVISIBLE ))
    1747           0 :                         aProp[i].Value >>= bShow;
    1748           0 :                     else if ( aProp[i].Name.equalsAsciiL( ITEM_DESCRIPTOR_ENABLED, LEN_DESCRIPTOR_ENABLED ))
    1749           0 :                         aProp[i].Value >>= bEnabled;
    1750           0 :                 }
    1751             : 
    1752           0 :                 if ( nType == ::com::sun::star::ui::ItemType::DEFAULT )
    1753             :                 {
    1754           0 :                     pMenu->InsertItem( nId, aLabel );
    1755           0 :                     pMenu->SetItemCommand( nId, aCommandURL );
    1756             : 
    1757           0 :                     if ( nStyle )
    1758             :                     {
    1759           0 :                         MenuItemBits nBits = pMenu->GetItemBits( nId );
    1760           0 :                         if ( nStyle & ::com::sun::star::ui::ItemStyle::ICON )
    1761           0 :                            nBits |= MIB_ICON;
    1762           0 :                         if ( nStyle & ::com::sun::star::ui::ItemStyle::TEXT )
    1763           0 :                            nBits |= MIB_TEXT;
    1764           0 :                         if ( nStyle & ::com::sun::star::ui::ItemStyle::RADIO_CHECK )
    1765           0 :                            nBits |= MIB_RADIOCHECK;
    1766           0 :                         pMenu->SetItemBits( nId, nBits );
    1767             :                     }
    1768             : 
    1769           0 :                     if ( !bShow )
    1770           0 :                         pMenu->HideItem( nId );
    1771             : 
    1772           0 :                     if ( !bEnabled)
    1773           0 :                         pMenu->EnableItem( nId, sal_False );
    1774             : 
    1775           0 :                     if ( xIndexContainer.is() )
    1776             :                     {
    1777           0 :                         PopupMenu* pNewPopupMenu = new PopupMenu;
    1778           0 :                         pMenu->SetPopupMenu( nId, pNewPopupMenu );
    1779             : 
    1780           0 :                         if ( xDispatchProvider.is() )
    1781             :                         {
    1782             :                             // Use attributes struct to transport special dispatch provider
    1783           0 :                             MenuConfiguration::Attributes* pAttributes = new MenuConfiguration::Attributes;
    1784           0 :                             pAttributes->xDispatchProvider = xDispatchProvider;
    1785           0 :                             pMenu->SetUserValue( nId, (sal_uIntPtr)( pAttributes ));
    1786             :                         }
    1787             : 
    1788             :                         // Use help command to transport module identifier
    1789           0 :                         if ( !aModuleIdentifier.isEmpty() )
    1790           0 :                             pMenu->SetHelpCommand( nId, aModuleIdentifier );
    1791             : 
    1792           0 :                         ++nId;
    1793           0 :                         FillMenu( nId, pNewPopupMenu, aModuleIdentifier, xIndexContainer, xDispatchProvider );
    1794             :                     }
    1795             :                     else
    1796           0 :                         ++nId;
    1797             :                 }
    1798             :                 else
    1799             :                 {
    1800           0 :                     pMenu->InsertSeparator();
    1801           0 :                     ++nId;
    1802             :                 }
    1803             :             }
    1804             :         }
    1805           0 :         catch ( const IndexOutOfBoundsException& )
    1806             :         {
    1807             :             break;
    1808             :         }
    1809           0 :     }
    1810           0 : }
    1811             : 
    1812           0 : void MenuBarManager::MergeAddonMenus(
    1813             :     Menu* pMenuBar,
    1814             :     const MergeMenuInstructionContainer& aMergeInstructionContainer,
    1815             :     const ::rtl::OUString& rModuleIdentifier )
    1816             : {
    1817             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::MergeAddonMenus" );
    1818             :     // set start value for the item ID for the new addon menu items
    1819           0 :     sal_uInt16 nItemId = ADDONMENU_MERGE_ITEMID_START;
    1820             : 
    1821           0 :     const sal_uInt32 nCount = aMergeInstructionContainer.size();
    1822           0 :     for ( sal_uInt32 i = 0; i < nCount; i++ )
    1823             :     {
    1824           0 :         const MergeMenuInstruction& rMergeInstruction = aMergeInstructionContainer[i];
    1825             : 
    1826           0 :         if ( MenuBarMerger::IsCorrectContext( rMergeInstruction.aMergeContext, rModuleIdentifier ))
    1827             :         {
    1828           0 :             ::std::vector< ::rtl::OUString > aMergePath;
    1829             : 
    1830             :             // retrieve the merge path from the merge point string
    1831           0 :             MenuBarMerger::RetrieveReferencePath( rMergeInstruction.aMergePoint, aMergePath );
    1832             : 
    1833             :             // convert the sequence/sequence property value to a more convenient vector<>
    1834           0 :             AddonMenuContainer aMergeMenuItems;
    1835           0 :             MenuBarMerger::GetSubMenu( rMergeInstruction.aMergeMenu, aMergeMenuItems );
    1836             : 
    1837             :             // try to find the reference point for our merge operation
    1838           0 :             Menu* pMenu = pMenuBar;
    1839           0 :             ReferencePathInfo aResult = MenuBarMerger::FindReferencePath( aMergePath, pMenu );
    1840             : 
    1841           0 :             if ( aResult.eResult == RP_OK )
    1842             :             {
    1843             :                 // normal merge operation
    1844             :                 MenuBarMerger::ProcessMergeOperation( aResult.pPopupMenu,
    1845             :                                                       aResult.nPos,
    1846             :                                                       nItemId,
    1847             :                                                       rMergeInstruction.aMergeCommand,
    1848             :                                                       rMergeInstruction.aMergeCommandParameter,
    1849             :                                                       rModuleIdentifier,
    1850           0 :                                                       aMergeMenuItems );
    1851             :             }
    1852             :             else
    1853             :             {
    1854             :                 // fallback
    1855             :                 MenuBarMerger::ProcessFallbackOperation( aResult,
    1856             :                                                          nItemId,
    1857             :                                                          rMergeInstruction.aMergeCommand,
    1858             :                                                          rMergeInstruction.aMergeFallback,
    1859             :                                                          aMergePath,
    1860             :                                                          rModuleIdentifier,
    1861           0 :                                                          aMergeMenuItems );
    1862           0 :             }
    1863             :         }
    1864             :     }
    1865           0 : }
    1866             : 
    1867           0 : void MenuBarManager::SetItemContainer( const Reference< XIndexAccess >& rItemContainer )
    1868             : {
    1869             :     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::MenuBarManager::SetItemContainer" );
    1870             : 
    1871           0 :     ResetableGuard aGuard( m_aLock );
    1872             : 
    1873           0 :     Reference< XFrame > xFrame = m_xFrame;
    1874             : 
    1875           0 :     if ( !m_bModuleIdentified )
    1876             :     {
    1877           0 :         m_bModuleIdentified = sal_True;
    1878           0 :         Reference< XModuleManager2 > xModuleManager = ModuleManager::create( comphelper::getComponentContext(getServiceFactory()) );
    1879             : 
    1880             :         try
    1881             :         {
    1882           0 :             m_aModuleIdentifier = xModuleManager->identify( xFrame );
    1883             :         }
    1884           0 :         catch( const Exception& )
    1885             :         {
    1886           0 :         }
    1887             :     }
    1888             : 
    1889             :     // Clear MenuBarManager structures
    1890             :     {
    1891           0 :         SolarMutexGuard aSolarMutexGuard;
    1892             : 
    1893             :         // Check active state as we cannot change our VCL menu during activation by the user
    1894           0 :         if ( m_bActive )
    1895             :         {
    1896           0 :             m_xDeferedItemContainer = rItemContainer;
    1897           0 :             return;
    1898             :         }
    1899             : 
    1900           0 :         RemoveListener();
    1901           0 :         std::vector< MenuItemHandler* >::iterator p;
    1902           0 :         for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
    1903             :         {
    1904           0 :             MenuItemHandler* pItemHandler = *p;
    1905           0 :             pItemHandler->xMenuItemDispatch.clear();
    1906           0 :             pItemHandler->xSubMenuManager.clear();
    1907           0 :             delete pItemHandler;
    1908             :         }
    1909           0 :         m_aMenuItemHandlerVector.clear();
    1910             : 
    1911             :         // Remove top-level parts
    1912           0 :         m_pVCLMenu->Clear();
    1913             : 
    1914           0 :         sal_uInt16          nId = 1;
    1915             : 
    1916             :         // Fill menu bar with container contents
    1917           0 :         FillMenuWithConfiguration( nId, (Menu *)m_pVCLMenu, m_aModuleIdentifier, rItemContainer, m_xURLTransformer );
    1918             : 
    1919             :         // Refill menu manager again
    1920           0 :         Reference< XDispatchProvider > xDispatchProvider;
    1921           0 :         FillMenuManager( m_pVCLMenu, xFrame, xDispatchProvider, m_aModuleIdentifier, sal_False, sal_True );
    1922             : 
    1923             :         // add itself as frame action listener
    1924           0 :         m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
    1925           0 :     }
    1926             : }
    1927             : 
    1928           0 : void MenuBarManager::GetPopupController( PopupControllerCache& rPopupController )
    1929             : {
    1930             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::GetPopupController" );
    1931             : 
    1932           0 :     SolarMutexGuard aSolarMutexGuard;
    1933             : 
    1934           0 :     std::vector< MenuItemHandler* >::iterator p;
    1935           0 :     for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p )
    1936             :     {
    1937           0 :         MenuItemHandler* pItemHandler = *p;
    1938           0 :         if ( pItemHandler->xPopupMenuController.is() )
    1939             :         {
    1940           0 :             Reference< XDispatchProvider > xDispatchProvider( pItemHandler->xPopupMenuController, UNO_QUERY );
    1941             : 
    1942           0 :             PopupControllerEntry aPopupControllerEntry;
    1943           0 :             aPopupControllerEntry.m_xDispatchProvider = xDispatchProvider;
    1944             : 
    1945             :             // Just use the main part of the URL for popup menu controllers
    1946           0 :             sal_Int32     nQueryPart( 0 );
    1947           0 :             sal_Int32     nSchemePart( 0 );
    1948           0 :             rtl::OUString aMainURL( "vnd.sun.star.popup:" );
    1949           0 :             rtl::OUString aMenuURL( pItemHandler->aMenuItemURL );
    1950             : 
    1951           0 :             nSchemePart = aMenuURL.indexOf( ':' );
    1952           0 :             if (( nSchemePart > 0 ) &&
    1953           0 :                 ( aMenuURL.getLength() > ( nSchemePart+1 )))
    1954             :             {
    1955           0 :                 nQueryPart  = aMenuURL.indexOf( '?', nSchemePart );
    1956           0 :                 if ( nQueryPart > 0 )
    1957           0 :                     aMainURL += aMenuURL.copy( nSchemePart, nQueryPart-nSchemePart );
    1958           0 :                 else if ( nQueryPart == -1 )
    1959           0 :                     aMainURL += aMenuURL.copy( nSchemePart+1 );
    1960             : 
    1961             :                 rPopupController.insert( PopupControllerCache::value_type(
    1962           0 :                                            aMainURL, aPopupControllerEntry ));
    1963           0 :             }
    1964             :         }
    1965           0 :         if ( pItemHandler->xSubMenuManager.is() )
    1966             :         {
    1967           0 :             MenuBarManager* pMenuBarManager = (MenuBarManager*)(pItemHandler->xSubMenuManager.get());
    1968           0 :             if ( pMenuBarManager )
    1969           0 :                 pMenuBarManager->GetPopupController( rPopupController );
    1970             :         }
    1971           0 :     }
    1972           0 : }
    1973             : 
    1974         771 : const Reference< XMultiServiceFactory >& MenuBarManager::getServiceFactory()
    1975             : {
    1976         771 :     return mxServiceFactory;
    1977             : }
    1978             : 
    1979           0 : void MenuBarManager::AddMenu(MenuBarManager* pSubMenuManager,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId)
    1980             : {
    1981             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::AddMenu" );
    1982           0 :     Reference< XStatusListener > xSubMenuManager( static_cast< OWeakObject *>( pSubMenuManager ), UNO_QUERY );
    1983           0 :     m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( xSubMenuManager, UNO_QUERY ));
    1984             : 
    1985             :     // store menu item command as we later have to know which menu is active (see Activate handler)
    1986           0 :     pSubMenuManager->m_aMenuItemCommand = _sItemCommand;
    1987           0 :     Reference< XDispatch > xDispatch;
    1988             :     MenuItemHandler* pMenuItemHandler = new MenuItemHandler(
    1989             :                                                 _nItemId,
    1990             :                                                 xSubMenuManager,
    1991           0 :                                                 xDispatch );
    1992           0 :     pMenuItemHandler->aMenuItemURL = _sItemCommand;
    1993           0 :     m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
    1994           0 : }
    1995             : 
    1996           0 : sal_uInt16 MenuBarManager::FillItemCommand(::rtl::OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const
    1997             : {
    1998             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::FillItemCommand" );
    1999           0 :     sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex );
    2000             : 
    2001           0 :     _rItemCommand = _pMenu->GetItemCommand( nItemId );
    2002           0 :     if ( _rItemCommand.isEmpty() )
    2003             :     {
    2004           0 :         const static ::rtl::OUString aSlotString( "slot:" );
    2005           0 :         _rItemCommand = aSlotString;
    2006           0 :         _rItemCommand += ::rtl::OUString::valueOf( (sal_Int32)nItemId );
    2007           0 :         _pMenu->SetItemCommand( nItemId, _rItemCommand );
    2008             :     }
    2009           0 :     return nItemId;
    2010             : }
    2011           0 : void MenuBarManager::Init(const Reference< XFrame >& rFrame,AddonMenu* pAddonMenu,sal_Bool bDelete,sal_Bool bDeleteChildren,bool _bHandlePopUp)
    2012             : {
    2013             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "MenuBarManager::Init" );
    2014           0 :     m_bActive           = sal_False;
    2015           0 :     m_bDeleteMenu       = bDelete;
    2016           0 :     m_bDeleteChildren   = bDeleteChildren;
    2017           0 :     m_pVCLMenu          = pAddonMenu;
    2018           0 :     m_xFrame            = rFrame;
    2019           0 :     m_bInitialized      = sal_False;
    2020           0 :     m_bIsBookmarkMenu   = sal_True;
    2021             : 
    2022           0 :     rtl::OUString aModuleIdentifier;
    2023           0 :     m_xPopupMenuControllerRegistration = PopupMenuControllerFactory::create( comphelper::getComponentContext(getServiceFactory()) );
    2024             : 
    2025           0 :     Reference< XStatusListener > xStatusListener;
    2026           0 :     Reference< XDispatch > xDispatch;
    2027           0 :     sal_uInt16 nItemCount = pAddonMenu->GetItemCount();
    2028           0 :     ::rtl::OUString aItemCommand;
    2029           0 :     m_aMenuItemHandlerVector.reserve(nItemCount);
    2030           0 :     for ( sal_uInt16 i = 0; i < nItemCount; i++ )
    2031             :     {
    2032           0 :         sal_uInt16 nItemId = FillItemCommand(aItemCommand,pAddonMenu, i );
    2033             : 
    2034           0 :         PopupMenu* pPopupMenu = pAddonMenu->GetPopupMenu( nItemId );
    2035           0 :         if ( pPopupMenu )
    2036             :         {
    2037           0 :             Reference< XDispatchProvider > xDispatchProvider;
    2038           0 :             MenuBarManager* pSubMenuManager = new MenuBarManager( getServiceFactory(), rFrame, m_xURLTransformer,xDispatchProvider, aModuleIdentifier, pPopupMenu, _bHandlePopUp ? sal_False : bDeleteChildren, _bHandlePopUp ? sal_False : bDeleteChildren );
    2039             : 
    2040           0 :             Reference< XStatusListener > xSubMenuManager( static_cast< OWeakObject *>( pSubMenuManager ), UNO_QUERY );
    2041             : 
    2042             :             // store menu item command as we later have to know which menu is active (see Acivate handler)
    2043           0 :             pSubMenuManager->m_aMenuItemCommand = aItemCommand;
    2044             : 
    2045             :             MenuItemHandler* pMenuItemHandler = new MenuItemHandler(
    2046             :                                                         nItemId,
    2047             :                                                         xSubMenuManager,
    2048           0 :                                                         xDispatch );
    2049           0 :             m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
    2050             :         }
    2051             :         else
    2052             :         {
    2053           0 :             if ( pAddonMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
    2054             :             {
    2055           0 :                 MenuConfiguration::Attributes* pAddonAttributes = (MenuConfiguration::Attributes *)(pAddonMenu->GetUserValue( nItemId ));
    2056           0 :                 MenuItemHandler* pMenuItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch );
    2057             : 
    2058           0 :                 if ( pAddonAttributes )
    2059             :                 {
    2060             :                     // read additional attributes from attributes struct and AddonMenu implementation will delete all attributes itself!!
    2061           0 :                     pMenuItemHandler->aTargetFrame = pAddonAttributes->aTargetFrame;
    2062             :                 }
    2063             : 
    2064           0 :                 pMenuItemHandler->aMenuItemURL = aItemCommand;
    2065           0 :                 if ( _bHandlePopUp )
    2066             :                 {
    2067             :                     // Check if we have to create a popup menu for a uno based popup menu controller.
    2068             :                     // We have to set an empty popup menu into our menu structure so the controller also
    2069             :                     // works with inplace OLE.
    2070           0 :                     if ( m_xPopupMenuControllerRegistration.is() &&
    2071           0 :                         m_xPopupMenuControllerRegistration->hasController( aItemCommand, rtl::OUString() ))
    2072             :                     {
    2073           0 :                         VCLXPopupMenu* pVCLXPopupMenu = new VCLXPopupMenu;
    2074           0 :                         PopupMenu* pCtlPopupMenu = (PopupMenu *)pVCLXPopupMenu->GetMenu();
    2075           0 :                         pAddonMenu->SetPopupMenu( pMenuItemHandler->nItemId, pCtlPopupMenu );
    2076           0 :                         pMenuItemHandler->xPopupMenu = Reference< com::sun::star::awt::XPopupMenu >( (OWeakObject *)pVCLXPopupMenu, UNO_QUERY );
    2077             : 
    2078             :                     }
    2079             :                 }
    2080           0 :                 m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
    2081             :             }
    2082             :         }
    2083             :     }
    2084             : 
    2085           0 :     SetHdl();
    2086           0 : }
    2087             : 
    2088         236 : void MenuBarManager::SetHdl()
    2089             : {
    2090         236 :     m_pVCLMenu->SetHighlightHdl( LINK( this, MenuBarManager, Highlight ));
    2091         236 :     m_pVCLMenu->SetActivateHdl( LINK( this, MenuBarManager, Activate ));
    2092         236 :     m_pVCLMenu->SetDeactivateHdl( LINK( this, MenuBarManager, Deactivate ));
    2093         236 :     m_pVCLMenu->SetSelectHdl( LINK( this, MenuBarManager, Select ));
    2094             : 
    2095         236 :     if ( !m_xURLTransformer.is() && mxServiceFactory.is() )
    2096             :         m_xURLTransformer.set(
    2097             :              URLTransformer::create(
    2098           0 :                  ::comphelper::getComponentContext(mxServiceFactory)) );
    2099         236 : }
    2100             : 
    2101             : }
    2102             : 
    2103             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10