Remove duplicated include
[LibreOffice.git] / framework / inc / uielement / toolbarmanager.hxx
blobdc80fbcfa8357857aeb108922b45328bb877a927
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 <uielement/commandinfo.hxx>
24 #include <com/sun/star/container/XIndexAccess.hpp>
25 #include <com/sun/star/frame/XFrame.hpp>
26 #include <com/sun/star/frame/XStatusListener.hpp>
27 #include <com/sun/star/frame/XUIControllerFactory.hpp>
28 #include <com/sun/star/frame/XSubToolbarController.hpp>
29 #include <com/sun/star/frame/XLayoutManager.hpp>
30 #include <com/sun/star/frame/XToolbarController.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/ui/XImageManager.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/util/XURLTransformer.hpp>
36 #include <framework/addonsoptions.hxx>
38 #include <rtl/ustring.hxx>
39 #include <cppuhelper/implbase.hxx>
40 #include <comphelper/interfacecontainer4.hxx>
42 #include <tools/link.hxx>
43 #include <vcl/weld.hxx>
44 #include <vcl/window.hxx>
45 #include <vcl/timer.hxx>
46 #include <vcl/toolbox.hxx>
48 #include <mutex>
49 #include <unordered_map>
51 class PopupMenu;
52 class ToolBox;
53 class Menu;
55 namespace framework
58 class ImageOrientationController;
59 class ToolBarManager;
61 class ToolBarManagerImpl
63 public:
64 virtual ~ToolBarManagerImpl() = default;
65 virtual void Init() = 0;
66 virtual void Destroy() = 0;
67 virtual css::uno::Reference<css::awt::XWindow> GetInterface() = 0;
68 virtual void InsertItem(ToolBoxItemId nId,
69 const OUString& rCommandURL,
70 const OUString& rTooltip,
71 const OUString& rLabel,
72 ToolBoxItemBits nItemBits) = 0;
73 virtual void InsertSeparator() = 0;
74 virtual void InsertSpace() = 0;
75 virtual void InsertBreak() = 0;
76 virtual ToolBoxItemId GetItemId(sal_uInt16 nPos) = 0;
77 virtual ToolBoxItemId GetCurItemId() = 0;
78 virtual OUString GetItemCommand(ToolBoxItemId nId) = 0;
79 virtual sal_uInt16 GetItemCount() = 0;
80 virtual void SetItemCheckable(ToolBoxItemId nId) = 0;
81 virtual void HideItem(ToolBoxItemId nId, const OUString& rCommandURL) = 0;
82 virtual bool IsItemVisible(ToolBoxItemId nId, const OUString& rCommandURL) = 0;
83 virtual void Clear() = 0;
84 virtual void SetName(const OUString& rName) = 0;
85 virtual void SetHelpId(const OUString& rHelpId) = 0;
86 virtual bool WillUsePopupMode() = 0;
87 virtual bool IsReallyVisible() = 0;
88 virtual void SetIconSize(ToolBoxButtonSize eSize) = 0;
89 virtual vcl::ImageType GetImageSize() = 0;
90 virtual void ConnectCallbacks(ToolBarManager* pManager) = 0;
91 virtual void SetMenuType(ToolBoxMenuType eType) = 0;
92 virtual void MergeToolbar(ToolBoxItemId & rItemId,
93 sal_uInt16 nFirstItem,
94 const OUString& rModuleIdentifier,
95 CommandToInfoMap& rCommandMap,
96 MergeToolbarInstruction& rInstruction) = 0;
97 virtual void SetItemImage(ToolBoxItemId nId,
98 const OUString& rCommandURL,
99 const Image& rImage) = 0;
100 virtual void UpdateSize() = 0;
101 virtual void SetItemWindow(ToolBoxItemId nItemId, vcl::Window* pNewWindow) = 0;
104 typedef ::cppu::WeakImplHelper<
105 css::frame::XFrameActionListener,
106 css::lang::XComponent,
107 css::ui::XUIConfigurationListener
108 > ToolbarManager_Base;
110 class ToolBarManager final : public ToolbarManager_Base
112 public:
113 ToolBarManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
114 const css::uno::Reference< css::frame::XFrame >& rFrame,
115 OUString aResourceName,
116 ToolBox* pToolBar );
117 ToolBarManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
118 const css::uno::Reference< css::frame::XFrame >& rFrame,
119 OUString aResourceName,
120 weld::Toolbar* pToolBar,
121 weld::Builder* pBuilder );
122 virtual ~ToolBarManager() override;
124 ToolBox* GetToolBar() const;
126 // XFrameActionListener
127 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& Action ) override;
129 // XEventListener
130 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
132 // XUIConfigurationListener
133 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
134 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
135 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
137 // XComponent
138 void SAL_CALL dispose() override;
139 void SAL_CALL addEventListener( const css::uno::Reference< XEventListener >& xListener ) override;
140 void SAL_CALL removeEventListener( const css::uno::Reference< XEventListener >& xListener ) override;
142 void CheckAndUpdateImages();
143 void RequestImages();
144 void FillToolbar( const css::uno::Reference< css::container::XIndexAccess >& rToolBarData,
145 const css::uno::Reference< css::container::XIndexAccess >& rContextData,
146 const OUString& rContextToolbarName );
147 void FillAddonToolbar( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& rAddonToolbar );
148 void FillOverflowToolbar( ToolBox const * pParent );
149 void notifyRegisteredControllers( const OUString& aUIElementName, const OUString& aCommand );
150 void Destroy();
152 enum ExecuteCommand
154 EXEC_CMD_CLOSETOOLBAR,
155 EXEC_CMD_UNDOCKTOOLBAR,
156 EXEC_CMD_DOCKTOOLBAR,
157 EXEC_CMD_DOCKALLTOOLBARS
160 enum ClickAction
162 Click,
163 DblClick,
164 Execute
167 struct ExecuteInfo
169 OUString aToolbarResName;
170 ExecuteCommand nCmd;
171 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
172 css::uno::Reference< css::awt::XWindow > xWindow;
175 public:
176 void OnClick(bool bUseExecute = false);
177 void OnDropdownClick(bool bCreatePopupWindow = true);
179 DECL_LINK(DropdownClick, ToolBox *, void);
180 DECL_LINK(DoubleClick, ToolBox *, void);
181 DECL_LINK(Select, ToolBox *, void);
182 DECL_LINK( StateChanged, StateChangedType const *, void );
183 DECL_LINK( DataChanged, DataChangedEvent const *, void );
184 DECL_LINK( MiscOptionsChanged, LinkParamNone*, void );
186 DECL_LINK( MenuButton, ToolBox *, void );
187 DECL_LINK( MenuPreExecute, ToolBox *, void );
188 DECL_LINK( MenuSelect, Menu *, bool );
189 DECL_LINK(AsyncUpdateControllersHdl, Timer *, void);
190 DECL_LINK( OverflowEventListener, VclWindowEvent&, void );
191 DECL_STATIC_LINK( ToolBarManager, ExecuteHdl_Impl, void*, void );
193 private:
194 void Init();
195 void FillToolbarFromContainer(const css::uno::Reference< css::container::XIndexAccess >& rItemContainer,
196 const OUString& rResourceName, ToolBoxItemId& nId, ToolBoxItemId& nAddonId);
197 void ToggleButton(const OUString& rResourceName, std::u16string_view rCommand);
198 void AddCustomizeMenuItems(ToolBox const * pToolBar);
199 void InitImageManager();
200 void RemoveControllers();
201 void CreateControllers();
202 void UpdateControllers();
203 //for update controller via Support Visible
204 void UpdateController( const css::uno::Reference< css::frame::XToolbarController >& xController);
205 //end
206 void AddFrameActionListener();
207 void RefreshImages();
208 ToolBoxItemBits ConvertStyleToToolboxItemBits( sal_Int32 nStyle );
209 css::uno::Reference< css::frame::XModel > GetModelFromFrame() const;
210 bool IsPluginMode() const;
211 void HandleClick(ClickAction eAction);
212 void setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter);
213 void impl_elementChanged(bool _bRemove,const css::ui::ConfigurationEvent& Event );
215 typedef std::unordered_map< ToolBoxItemId, css::uno::Reference< css::frame::XStatusListener > > ToolBarControllerMap;
216 typedef ::std::vector< css::uno::Reference< css::frame::XSubToolbarController > > SubToolBarControllerVector;
217 typedef std::unordered_map<OUString, SubToolBarControllerVector> SubToolBarToSubToolBarControllerMap;
219 bool m_bDisposed : 1,
220 m_bFrameActionRegistered : 1,
221 m_bUpdateControllers : 1;
223 sal_Int16 m_eSymbolSize;
224 sal_uInt16 m_nContextMinPos;
226 std::unique_ptr<ToolBarManagerImpl> m_pImpl;
227 VclPtr<ToolBox> m_pToolBar;
228 weld::Toolbar* m_pWeldedToolBar;
230 OUString m_aModuleIdentifier;
231 OUString m_aResourceName;
232 OUString m_aContextResourceName;
234 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
235 css::uno::Reference< css::frame::XFrame > m_xFrame;
236 ToolBarControllerMap m_aControllerMap;
237 std::mutex m_mutex;
238 comphelper::OInterfaceContainerHelper4<XEventListener> m_aListenerContainer;
239 css::uno::Reference< css::uno::XComponentContext > m_xContext;
240 css::uno::Reference< css::frame::XUIControllerFactory > m_xToolbarControllerFactory;
241 css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager;
242 css::uno::Reference< css::ui::XImageManager > m_xDocImageManager;
244 CommandToInfoMap m_aCommandMap;
245 SubToolBarToSubToolBarControllerMap m_aSubToolBarControllerMap;
246 Timer m_aAsyncUpdateControllersTimer;
247 OUString m_sIconTheme;
249 rtl::Reference< ToolBarManager > m_aOverflowManager;
250 rtl::Reference< ImageOrientationController > m_aImageController;
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */