LibreOffice Module framework (master) 1
menubarmanager.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/config.h>
23
24#include <unordered_map>
25#include <utility>
26#include <vector>
27
28#include <com/sun/star/frame/XFrame.hpp>
29#include <com/sun/star/frame/XDispatch.hpp>
30#include <com/sun/star/frame/XDispatchProvider.hpp>
31#include <com/sun/star/frame/FeatureStateEvent.hpp>
32#include <com/sun/star/frame/XFrameActionListener.hpp>
33#include <com/sun/star/frame/XPopupMenuController.hpp>
34#include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
35#include <com/sun/star/container/XIndexAccess.hpp>
36#include <com/sun/star/frame/XUIControllerFactory.hpp>
37#include <com/sun/star/ui/XUIConfigurationListener.hpp>
38#include <com/sun/star/ui/XImageManager.hpp>
39#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
40#include <com/sun/star/util/XURLTransformer.hpp>
41
42#include <rtl/ustring.hxx>
43#include <vcl/menu.hxx>
44#include <vcl/timer.hxx>
48
49namespace framework
50{
51
53{
54 css::uno::WeakReference< css::frame::XDispatchProvider > m_xDispatchProvider;
55};
56
57typedef std::unordered_map< OUString, PopupControllerEntry > PopupControllerCache;
58
59class MenuBarManager final :
61 css::frame::XStatusListener,
62 css::frame::XFrameActionListener,
63 css::ui::XUIConfigurationListener,
64 css::awt::XSystemDependentMenuPeer>
65{
66 public:
68 const css::uno::Reference< css::uno::XComponentContext >& xContext,
69 const css::uno::Reference< css::frame::XFrame >& rFrame,
70 const css::uno::Reference< css::util::XURLTransformer >& _xURLTransformer,
71 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
72 const OUString& aModuleIdentifier,
73 Menu* pMenu,
74 bool bDelete,
75 bool bHasMenuBar = true );
76
77 virtual ~MenuBarManager() override;
78
79 // XStatusListener
80 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
81
82 // XFrameActionListener
83 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& Action ) override;
84
85 // XEventListener
86 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
87
88 // XUIConfigurationListener
89 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
90 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
91 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
92
93 // XSystemDependentMenuPeer
94 virtual css::uno::Any SAL_CALL getMenuHandle( const css::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) override;
95
96 DECL_LINK( Select, Menu *, bool );
97
98 Menu* GetMenuBar() const { return m_pVCLMenu; }
99
100 // Configuration methods
101 static void FillMenuWithConfiguration( sal_uInt16& nId, Menu* pMenu,
102 const OUString& rModuleIdentifier,
103 const css::uno::Reference< css::container::XIndexAccess >& rItemContainer,
104 const css::uno::Reference< css::util::XURLTransformer >& rTransformer );
105 static void FillMenu( sal_uInt16& nId,
106 Menu* pMenu,
107 const OUString& rModuleIdentifier,
108 const css::uno::Reference< css::container::XIndexAccess >& rItemContainer,
109 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider );
110
111 void FillMenuManager( Menu* pMenu,
112 const css::uno::Reference< css::frame::XFrame >& rFrame,
113 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
114 const OUString& rModuleIdentifier,
115 bool bDelete );
116 void SetItemContainer( const css::uno::Reference< css::container::XIndexAccess >& rItemContainer );
117 void GetPopupController( PopupControllerCache& rPopupController );
118
119 private:
120 DECL_LINK( Activate, Menu *, bool );
121 DECL_LINK( Deactivate, Menu *, bool );
122 DECL_LINK( AsyncSettingsHdl, Timer *, void );
123
124 void disposing(std::unique_lock<std::mutex>&) override;
125 void RemoveListener();
126 void RequestImages();
128 static bool MustBeHidden( PopupMenu* pPopupMenu, const css::uno::Reference< css::util::XURLTransformer >& rTransformer );
129 OUString RetrieveLabelFromCommand(const OUString& rCmdURL);
130
132 {
133 MenuItemHandler( sal_uInt16 aItemId,
134 css::uno::Reference< css::frame::XStatusListener > xManager,
135 css::uno::Reference< css::frame::XDispatch > xDispatch ) :
136 nItemId( aItemId ),
137 bMadeInvisible ( false ),
138 xSubMenuManager(std::move( xManager )),
139 xMenuItemDispatch(std::move( xDispatch )) {}
140
141 sal_uInt16 nItemId;
143 OUString aTargetFrame;
144 OUString aMenuItemURL;
146 css::uno::Reference< css::frame::XStatusListener > xSubMenuManager;
147 css::uno::Reference< css::frame::XDispatch > xMenuItemDispatch;
148 css::uno::Reference< css::frame::XPopupMenuController > xPopupMenuController;
149 css::uno::Reference< css::awt::XPopupMenu > xPopupMenu;
151 };
152
153 void RetrieveShortcuts( std::vector< std::unique_ptr<MenuItemHandler> >& aMenuShortCuts );
154 static void FillMenuImages( css::uno::Reference< css::frame::XFrame > const & xFrame, Menu* _pMenu, bool bShowMenuImages );
155 static void impl_RetrieveShortcutsFromConfiguration( const css::uno::Reference< css::ui::XAcceleratorConfiguration >& rAccelCfg,
156 const css::uno::Sequence< OUString >& rCommands,
157 std::vector< std::unique_ptr<MenuItemHandler> >& aMenuShortCuts );
158 static void MergeAddonMenus( Menu* pMenuBar, const MergeMenuInstructionContainer&, const OUString& aModuleIdentifier );
159
160 MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId );
161 bool CreatePopupMenuController( MenuItemHandler* pMenuItemHandler,
162 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
163 const OUString& rModuleIdentifier );
164 void AddMenu(MenuBarManager* pSubMenuManager,const OUString& _sItemCommand,sal_uInt16 _nItemId);
165 sal_uInt16 FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const;
166 void SetHdl();
167
176 css::uno::Reference< css::frame::XFrame > m_xFrame;
177 css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuControllerFactory;
178 ::std::vector< std::unique_ptr<MenuItemHandler> > m_aMenuItemHandlerVector;
179 css::uno::Reference< css::frame::XDispatchProvider > m_xDispatchProvider;
180 css::uno::Reference< css::ui::XImageManager > m_xDocImageManager;
181 css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager;
182 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager;
183 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager;
184 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager;
185 css::uno::Reference< css::uno::XComponentContext > m_xContext;
186 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
187 css::uno::Reference< css::container::XIndexAccess > m_xDeferredItemContainer;
188 OUString m_sIconTheme;
190};
191
192} // namespace
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &Action) override
css::uno::Reference< css::frame::XDispatchProvider > m_xDispatchProvider
css::uno::Reference< css::uno::XComponentContext > m_xContext
static bool MustBeHidden(PopupMenu *pPopupMenu, const css::uno::Reference< css::util::XURLTransformer > &rTransformer)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual css::uno::Any SAL_CALL getMenuHandle(const css::uno::Sequence< sal_Int8 > &ProcessId, sal_Int16 SystemType) override
css::uno::Reference< css::ui::XImageManager > m_xDocImageManager
static void FillMenuImages(css::uno::Reference< css::frame::XFrame > const &xFrame, Menu *_pMenu, bool bShowMenuImages)
void AddMenu(MenuBarManager *pSubMenuManager, const OUString &_sItemCommand, sal_uInt16 _nItemId)
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager
bool CreatePopupMenuController(MenuItemHandler *pMenuItemHandler, const css::uno::Reference< css::frame::XDispatchProvider > &rDispatchProvider, const OUString &rModuleIdentifier)
css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuControllerFactory
void RetrieveShortcuts(std::vector< std::unique_ptr< MenuItemHandler > > &aMenuShortCuts)
sal_uInt16 FillItemCommand(OUString &_rItemCommand, Menu *_pMenu, sal_uInt16 _nIndex) const
virtual void SAL_CALL elementRemoved(const css::ui::ConfigurationEvent &Event) override
css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager
static void MergeAddonMenus(Menu *pMenuBar, const MergeMenuInstructionContainer &, const OUString &aModuleIdentifier)
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager
::std::vector< std::unique_ptr< MenuItemHandler > > m_aMenuItemHandlerVector
DECL_LINK(Select, Menu *, bool)
virtual ~MenuBarManager() override
void FillMenuManager(Menu *pMenu, const css::uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Reference< css::frame::XDispatchProvider > &rDispatchProvider, const OUString &rModuleIdentifier, bool bDelete)
DECL_LINK(Deactivate, Menu *, bool)
DECL_LINK(Activate, Menu *, bool)
void GetPopupController(PopupControllerCache &rPopupController)
OUString RetrieveLabelFromCommand(const OUString &rCmdURL)
virtual void SAL_CALL elementInserted(const css::ui::ConfigurationEvent &Event) override
void SetItemContainer(const css::uno::Reference< css::container::XIndexAccess > &rItemContainer)
MenuBarManager(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Reference< css::util::XURLTransformer > &_xURLTransformer, const css::uno::Reference< css::frame::XDispatchProvider > &rDispatchProvider, const OUString &aModuleIdentifier, Menu *pMenu, bool bDelete, bool bHasMenuBar=true)
css::uno::Reference< css::frame::XFrame > m_xFrame
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager
css::uno::Reference< css::container::XIndexAccess > m_xDeferredItemContainer
MenuItemHandler * GetMenuItemHandler(sal_uInt16 nItemId)
DECL_LINK(AsyncSettingsHdl, Timer *, void)
static void impl_RetrieveShortcutsFromConfiguration(const css::uno::Reference< css::ui::XAcceleratorConfiguration > &rAccelCfg, const css::uno::Sequence< OUString > &rCommands, std::vector< std::unique_ptr< MenuItemHandler > > &aMenuShortCuts)
static void FillMenuWithConfiguration(sal_uInt16 &nId, Menu *pMenu, const OUString &rModuleIdentifier, const css::uno::Reference< css::container::XIndexAccess > &rItemContainer, const css::uno::Reference< css::util::XURLTransformer > &rTransformer)
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
virtual void SAL_CALL elementReplaced(const css::ui::ConfigurationEvent &Event) override
static void FillMenu(sal_uInt16 &nId, Menu *pMenu, const OUString &rModuleIdentifier, const css::uno::Reference< css::container::XIndexAccess > &rItemContainer, const css::uno::Reference< css::frame::XDispatchProvider > &rDispatchProvider)
Reference< XDispatch > xDispatch
::std::vector< MergeMenuInstruction > MergeMenuInstructionContainer
std::unordered_map< OUString, PopupControllerEntry > PopupControllerCache
css::uno::Reference< css::frame::XDispatch > xMenuItemDispatch
MenuItemHandler(sal_uInt16 aItemId, css::uno::Reference< css::frame::XStatusListener > xManager, css::uno::Reference< css::frame::XDispatch > xDispatch)
css::uno::Reference< css::frame::XStatusListener > xSubMenuManager
css::uno::Reference< css::frame::XPopupMenuController > xPopupMenuController
css::uno::Reference< css::awt::XPopupMenu > xPopupMenu
css::uno::WeakReference< css::frame::XDispatchProvider > m_xDispatchProvider