LCOV - code coverage report
Current view: top level - framework/inc/uielement - menubarmanager.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 4 5 80.0 %
Date: 2014-11-03 Functions: 3 7 42.9 %
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             : #ifndef INCLUDED_FRAMEWORK_INC_UIELEMENT_MENUBARMANAGER_HXX
      21             : #define INCLUDED_FRAMEWORK_INC_UIELEMENT_MENUBARMANAGER_HXX
      22             : 
      23             : /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
      24             :                with solaris headers ...
      25             : */
      26             : #include <vector>
      27             : 
      28             : #include <stdtypes.h>
      29             : 
      30             : #include <com/sun/star/frame/XFrame.hpp>
      31             : #include <com/sun/star/frame/XDispatch.hpp>
      32             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      33             : #include <com/sun/star/frame/FeatureStateEvent.hpp>
      34             : #include <com/sun/star/frame/XFrameActionListener.hpp>
      35             : #include <com/sun/star/beans/PropertyValue.hpp>
      36             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      37             : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
      38             : #include <com/sun/star/container/XIndexAccess.hpp>
      39             : #include <com/sun/star/container/XNameAccess.hpp>
      40             : #include <com/sun/star/lang/XComponent.hpp>
      41             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      42             : #include <com/sun/star/frame/XUIControllerFactory.hpp>
      43             : #include <com/sun/star/ui/XUIConfigurationListener.hpp>
      44             : #include <com/sun/star/ui/XImageManager.hpp>
      45             : #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
      46             : #include <com/sun/star/util/XURLTransformer.hpp>
      47             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      48             : 
      49             : #include <rtl/ustring.hxx>
      50             : #include <vcl/menu.hxx>
      51             : #include <vcl/accel.hxx>
      52             : #include <vcl/timer.hxx>
      53             : #include <toolkit/awt/vclxmenu.hxx>
      54             : #include <cppuhelper/weak.hxx>
      55             : #include <cppuhelper/interfacecontainer.hxx>
      56             : #include <framework/addonsoptions.hxx>
      57             : 
      58             : namespace framework
      59             : {
      60             : 
      61           0 : struct PopupControllerEntry
      62             : {
      63             :     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XDispatchProvider > m_xDispatchProvider;
      64             : };
      65             : 
      66             : typedef boost::unordered_map< OUString, PopupControllerEntry, OUStringHash, ::std::equal_to< OUString > > PopupControllerCache;
      67             : 
      68             : class BmkMenu;
      69             : class AddonMenu;
      70             : class AddonPopupMenu;
      71             : class MenuBarManager : public com::sun::star::frame::XStatusListener                ,
      72             :                        public com::sun::star::frame::XFrameActionListener           ,
      73             :                        public com::sun::star::ui::XUIConfigurationListener          ,
      74             :                        public com::sun::star::lang::XComponent                      ,
      75             :                        public com::sun::star::awt::XSystemDependentMenuPeer         ,
      76             :                        public ::cppu::OWeakObject
      77             : {
      78             :     protected:
      79             :         MenuBarManager(
      80             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
      81             :             const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
      82             :             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
      83             :             AddonMenu*          pAddonMenu,
      84             :             bool            bDelete,
      85             :             bool            bDeleteChildren );
      86             : 
      87             :         MenuBarManager(
      88             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
      89             :             const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
      90             :             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
      91             :             AddonPopupMenu*     pAddonMenu,
      92             :             bool            bDelete,
      93             :             bool            bDeleteChildren );
      94             : 
      95             :     public:
      96             :         MenuBarManager(
      97             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
      98             :             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
      99             :             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
     100             :             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
     101             :             const OUString& aModuleIdentifier,
     102             :             Menu* pMenu,
     103             :             bool bDelete,
     104             :             bool bDeleteChildren );
     105             : 
     106             :         virtual ~MenuBarManager();
     107             : 
     108             :         // XInterface
     109             :         virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
     110             :         virtual void SAL_CALL release() throw() SAL_OVERRIDE;
     111             :         virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     112             : 
     113             :         // XComponent
     114             :         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             :         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     116             :         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     117             : 
     118             :         // XStatusListener
     119             :         virtual void SAL_CALL statusChanged( const com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     120             : 
     121             :         // XFrameActionListener
     122             :         virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     123             : 
     124             :         // XEventListener
     125             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     126             : 
     127             :         // XUIConfigurationListener
     128             :         virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     129             :         virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     130             :         virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     131             : 
     132             :         // XSystemDependentMenuPeer
     133             :         virtual ::com::sun::star::uno::Any SAL_CALL getMenuHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     134             : 
     135             :         DECL_LINK( Select, Menu * );
     136             : 
     137        1666 :         Menu*   GetMenuBar() const { return m_pVCLMenu; }
     138             : 
     139             :         // Configuration methods
     140             :         static void FillMenuWithConfiguration( sal_uInt16& nId, Menu* pMenu,
     141             :                                                const OUString& rModuleIdentifier,
     142             :                                                const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
     143             :                                                const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
     144             :         static void FillMenu( sal_uInt16& nId,
     145             :                               Menu* pMenu,
     146             :                               const OUString& rModuleIdentifier,
     147             :                               const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
     148             :                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider );
     149             : 
     150             :         void FillMenuManager( Menu* pMenu,
     151             :                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     152             :                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
     153             :                               const OUString& rModuleIdentifier,
     154             :                               bool bDelete,
     155             :                               bool bDeleteChildren );
     156             :         void SetItemContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer );
     157             :         void GetPopupController( PopupControllerCache& rPopupController );
     158             : 
     159             :     protected:
     160             :         DECL_LINK(Highlight, void *);
     161             :         DECL_LINK( Activate, Menu * );
     162             :         DECL_LINK( Deactivate, Menu * );
     163             :         DECL_LINK( AsyncSettingsHdl, Timer * );
     164             : 
     165             :         void RemoveListener();
     166             :         void RequestImages();
     167             :         void RetrieveImageManagers();
     168             :         static bool MustBeHidden( PopupMenu* pPopupMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
     169             :         OUString RetrieveLabelFromCommand(const OUString& rCmdURL);
     170             : 
     171             :     private:
     172             : 
     173             :         void Destroy();
     174             : 
     175      445054 :         struct MenuItemHandler
     176             :         {
     177      445054 :             MenuItemHandler( sal_uInt16             aItemId,
     178             :                              ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xManager,
     179             :                              ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
     180             :                              nItemId( aItemId ),
     181             :                              bCheckHide( true ),
     182             :                              xSubMenuManager( xManager ),
     183      445054 :                              xMenuItemDispatch( rDispatch ) {}
     184             : 
     185             :             sal_uInt16                                                                                      nItemId;
     186             :             bool                                                                                    bCheckHide;
     187             :             OUString                                                                             aTargetFrame;
     188             :             OUString                                                                             aMenuItemURL;
     189             :             OUString                                                                             aFilter;
     190             :             OUString                                                                             aPassword;
     191             :             OUString                                                                             aTitle;
     192             :             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >                xSubMenuManager;
     193             :             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >                      xMenuItemDispatch;
     194             :             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XPopupMenuController >           xPopupMenuController;
     195             :             ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >                       xPopupMenu;
     196             :             vcl::KeyCode                                                                                aKeyCode;
     197             :         };
     198             : 
     199             :         void             RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts );
     200             :         void             CreatePicklistArguments(
     201             :                             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgsList,
     202             :                             const MenuItemHandler* );
     203             :         void             CheckAndAddMenuExtension( Menu* pMenu );
     204             :         static void      impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg,
     205             :                                                                   const ::com::sun::star::uno::Sequence< OUString >& rCommands,
     206             :                                                                   std::vector< MenuItemHandler* >& aMenuShortCuts );
     207             :         static void      MergeAddonMenus( Menu* pMenuBar, const MergeMenuInstructionContainer&, const OUString& aModuleIdentifier );
     208             : 
     209             :         MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId );
     210             :         bool         CreatePopupMenuController( MenuItemHandler* pMenuItemHandler );
     211             :         void             AddMenu(MenuBarManager* pSubMenuManager,const OUString& _sItemCommand,sal_uInt16 _nItemId);
     212             :         sal_uInt16           FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const;
     213             :         void             Init(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,AddonMenu* pAddonMenu,bool bDelete,bool bDeleteChildren,bool _bHandlePopUp = false);
     214             :         void             SetHdl();
     215             : 
     216             :         bool                                                                               m_bDisposed : 1,
     217             :                                                                                                m_bInitialized : 1,
     218             :                                                                                                m_bDeleteMenu : 1,
     219             :                                                                                                m_bDeleteChildren : 1,
     220             :                                                                                                m_bActive : 1,
     221             :                                                                                                m_bIsBookmarkMenu : 1,
     222             :                                                                                                m_bShowMenuImages : 1;
     223             :         bool                                                                               m_bRetrieveImages : 1,
     224             :                                                                                                m_bAcceleratorCfg : 1;
     225             :         bool                                                                               m_bModuleIdentified;
     226             :         OUString                                                                        m_aMenuItemCommand;
     227             :         OUString                                                                        m_aModuleIdentifier;
     228             :         Menu*                                                                                  m_pVCLMenu;
     229             :         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >                    m_xFrame;
     230             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >           m_xUICommandLabels;
     231             :         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerFactory > m_xPopupMenuControllerFactory;
     232             :         ::std::vector< MenuItemHandler* >                                                      m_aMenuItemHandlerVector;
     233             :         osl::Mutex m_mutex;
     234             :         ::cppu::OMultiTypeInterfaceContainerHelper                                             m_aListenerContainer;   /// container for ALL Listener
     235             :         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >         m_xDispatchProvider;
     236             :         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xDocImageManager;
     237             :         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xModuleImageManager;
     238             :         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xDocAcceleratorManager;
     239             :         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xModuleAcceleratorManager;
     240             :         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xGlobalAcceleratorManager;
     241             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >           m_xContext;
     242             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >            m_xURLTransformer;
     243             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >          m_xDeferedItemContainer;
     244             :         OUString                                                                               m_sIconTheme;
     245             :         Timer                                                                                  m_aAsyncSettingsTimer;
     246             : };
     247             : 
     248             : } // namespace
     249             : 
     250             : #endif
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10