Update git submodules
[LibreOffice.git] / framework / inc / uielement / menubarmanager.hxx
blob8b14158aee6efca6bb35fbaa7d45a4c3652d3212
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <unordered_map>
25 #include <utility>
26 #include <vector>
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>
42 #include <rtl/ustring.hxx>
43 #include <vcl/menu.hxx>
44 #include <vcl/timer.hxx>
45 #include <comphelper/compbase.hxx>
46 #include <cppuhelper/weakref.hxx>
47 #include <framework/addonsoptions.hxx>
48 #include <toolkit/awt/vclxmenu.hxx>
50 namespace framework
53 struct PopupControllerEntry
55 css::uno::WeakReference< css::frame::XDispatchProvider > m_xDispatchProvider;
58 typedef std::unordered_map< OUString, PopupControllerEntry > PopupControllerCache;
60 class MenuBarManager final :
61 public comphelper::WeakComponentImplHelper<
62 css::frame::XStatusListener,
63 css::frame::XFrameActionListener,
64 css::ui::XUIConfigurationListener,
65 css::awt::XSystemDependentMenuPeer>
67 public:
68 MenuBarManager(
69 const css::uno::Reference< css::uno::XComponentContext >& xContext,
70 const css::uno::Reference< css::frame::XFrame >& rFrame,
71 const css::uno::Reference< css::util::XURLTransformer >& _xURLTransformer,
72 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
73 const OUString& aModuleIdentifier,
74 Menu* pMenu,
75 bool bDelete,
76 bool bHasMenuBar = true );
78 virtual ~MenuBarManager() override;
80 // XStatusListener
81 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
83 // XFrameActionListener
84 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& Action ) override;
86 // XEventListener
87 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
89 // XUIConfigurationListener
90 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
91 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
92 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
94 // XSystemDependentMenuPeer
95 virtual css::uno::Any SAL_CALL getMenuHandle( const css::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) override;
97 DECL_LINK( Select, Menu *, bool );
99 Menu* GetMenuBar() const { return m_pVCLMenu; }
101 // Configuration methods
102 static void FillMenuWithConfiguration( sal_uInt16& nId, Menu* pMenu,
103 const OUString& rModuleIdentifier,
104 const css::uno::Reference< css::container::XIndexAccess >& rItemContainer,
105 const css::uno::Reference< css::util::XURLTransformer >& rTransformer );
106 static void FillMenu( sal_uInt16& nId,
107 Menu* pMenu,
108 const OUString& rModuleIdentifier,
109 const css::uno::Reference< css::container::XIndexAccess >& rItemContainer,
110 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider );
112 void FillMenuManager( Menu* pMenu,
113 const css::uno::Reference< css::frame::XFrame >& rFrame,
114 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
115 const OUString& rModuleIdentifier,
116 bool bDelete );
117 void SetItemContainer( const css::uno::Reference< css::container::XIndexAccess >& rItemContainer );
118 void GetPopupController( PopupControllerCache& rPopupController );
120 private:
121 DECL_LINK( Activate, Menu *, bool );
122 DECL_LINK( Deactivate, Menu *, bool );
123 DECL_LINK( AsyncSettingsHdl, Timer *, void );
125 void disposing(std::unique_lock<std::mutex>&) override;
126 void RemoveListener();
127 void RequestImages();
128 void RetrieveImageManagers();
129 static bool MustBeHidden( PopupMenu* pPopupMenu, const css::uno::Reference< css::util::XURLTransformer >& rTransformer );
130 OUString RetrieveLabelFromCommand(const OUString& rCmdURL);
132 struct MenuItemHandler
134 MenuItemHandler( sal_uInt16 aItemId,
135 rtl::Reference< MenuBarManager > xManager,
136 css::uno::Reference< css::frame::XDispatch > xDispatch ) :
137 nItemId( aItemId ),
138 bMadeInvisible ( false ),
139 xSubMenuManager(std::move( xManager )),
140 xMenuItemDispatch(std::move( xDispatch )) {}
142 sal_uInt16 nItemId;
143 bool bMadeInvisible;
144 OUString aTargetFrame;
145 OUString aMenuItemURL;
146 OUString aParsedItemURL;
147 rtl::Reference< MenuBarManager > xSubMenuManager;
148 css::uno::Reference< css::frame::XDispatch > xMenuItemDispatch;
149 css::uno::Reference< css::frame::XPopupMenuController > xPopupMenuController;
150 rtl::Reference< VCLXPopupMenu > xPopupMenu;
151 vcl::KeyCode aKeyCode;
154 void RetrieveShortcuts( std::vector< std::unique_ptr<MenuItemHandler> >& aMenuShortCuts );
155 void SetAcceleratorKeys(Menu* pMenu);
156 static void FillMenuImages( css::uno::Reference< css::frame::XFrame > const & xFrame, Menu* _pMenu, bool bShowMenuImages );
157 static void impl_RetrieveShortcutsFromConfiguration( const css::uno::Reference< css::ui::XAcceleratorConfiguration >& rAccelCfg,
158 const css::uno::Sequence< OUString >& rCommands,
159 std::vector< std::unique_ptr<MenuItemHandler> >& aMenuShortCuts );
160 static void MergeAddonMenus( Menu* pMenuBar, const MergeMenuInstructionContainer&, const OUString& aModuleIdentifier );
162 MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId );
163 bool CreatePopupMenuController( MenuItemHandler* pMenuItemHandler,
164 const css::uno::Reference< css::frame::XDispatchProvider >& rDispatchProvider,
165 const OUString& rModuleIdentifier );
166 void AddMenu(MenuBarManager* pSubMenuManager,const OUString& _sItemCommand,sal_uInt16 _nItemId);
167 static sal_uInt16 FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex);
168 void SetHdl();
170 bool m_bDeleteMenu;
171 bool m_bActive;
172 bool m_bShowMenuImages;
173 bool m_bRetrieveImages;
174 bool m_bAcceleratorCfg;
175 bool m_bHasMenuBar;
176 OUString m_aModuleIdentifier;
177 VclPtr<Menu> m_pVCLMenu;
178 css::uno::Reference< css::frame::XFrame > m_xFrame;
179 css::uno::Reference< css::frame::XUIControllerFactory > m_xPopupMenuControllerFactory;
180 ::std::vector< std::unique_ptr<MenuItemHandler> > m_aMenuItemHandlerVector;
181 css::uno::Reference< css::frame::XDispatchProvider > m_xDispatchProvider;
182 css::uno::Reference< css::ui::XImageManager > m_xDocImageManager;
183 css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager;
184 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager;
185 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager;
186 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager;
187 css::uno::Reference< css::uno::XComponentContext > m_xContext;
188 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
189 css::uno::Reference< css::container::XIndexAccess > m_xDeferredItemContainer;
190 OUString m_sIconTheme;
191 Timer m_aAsyncSettingsTimer;
194 } // namespace
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */