LibreOffice Module framework (master) 1
toolbarmanager.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
23
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>
35
37
38#include <rtl/ustring.hxx>
41
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>
47
48#include <mutex>
49#include <unordered_map>
50
51class PopupMenu;
52class ToolBox;
53class Menu;
54
55namespace framework
56{
57
58class ImageOrientationController;
59class ToolBarManager;
60
62{
63public:
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;
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;
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;
102};
103
104typedef ::cppu::WeakImplHelper<
105 css::frame::XFrameActionListener,
106 css::lang::XComponent,
107 css::ui::XUIConfigurationListener
109
111{
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;
123
124 ToolBox* GetToolBar() const;
125
126 // XFrameActionListener
127 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& Action ) override;
128
129 // XEventListener
130 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
131
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;
136
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;
141
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();
151
153 {
158 };
159
161 {
164 Execute
165 };
166
168 {
171 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
172 css::uno::Reference< css::awt::XWindow > xWindow;
173 };
174
175 public:
176 void OnClick(bool bUseExecute = false);
177 void OnDropdownClick(bool bCreatePopupWindow = true);
178
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 );
185
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 );
192
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
207 void RefreshImages();
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 );
214
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;
218
219 bool m_bDisposed : 1,
222
223 sal_Int16 m_eSymbolSize;
225
226 std::unique_ptr<ToolBarManagerImpl> m_pImpl;
229
233
234 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
235 css::uno::Reference< css::frame::XFrame > m_xFrame;
237 std::mutex m_mutex;
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;
243
247 OUString m_sIconTheme;
248
251};
252
253}
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ToolBoxItemId GetItemId(sal_uInt16 nPos)=0
virtual void InsertBreak()=0
virtual OUString GetItemCommand(ToolBoxItemId nId)=0
virtual void HideItem(ToolBoxItemId nId, const OUString &rCommandURL)=0
virtual vcl::ImageType GetImageSize()=0
virtual void InsertSpace()=0
virtual bool IsReallyVisible()=0
virtual void InsertItem(ToolBoxItemId nId, const OUString &rCommandURL, const OUString &rTooltip, const OUString &rLabel, ToolBoxItemBits nItemBits)=0
virtual ToolBoxItemId GetCurItemId()=0
virtual void MergeToolbar(ToolBoxItemId &rItemId, sal_uInt16 nFirstItem, const OUString &rModuleIdentifier, CommandToInfoMap &rCommandMap, MergeToolbarInstruction &rInstruction)=0
virtual void ConnectCallbacks(ToolBarManager *pManager)=0
virtual void SetItemCheckable(ToolBoxItemId nId)=0
virtual void SetName(const OUString &rName)=0
virtual sal_uInt16 GetItemCount()=0
virtual void SetItemWindow(ToolBoxItemId nItemId, vcl::Window *pNewWindow)=0
virtual void SetIconSize(ToolBoxButtonSize eSize)=0
virtual ~ToolBarManagerImpl()=default
virtual bool WillUsePopupMode()=0
virtual css::uno::Reference< css::awt::XWindow > GetInterface()=0
virtual void SetHelpId(const OUString &rHelpId)=0
virtual void SetMenuType(ToolBoxMenuType eType)=0
virtual void SetItemImage(ToolBoxItemId nId, const OUString &rCommandURL, const Image &rImage)=0
virtual bool IsItemVisible(ToolBoxItemId nId, const OUString &rCommandURL)=0
virtual void InsertSeparator()=0
void OnClick(bool bUseExecute=false)
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
DECL_LINK(OverflowEventListener, VclWindowEvent &, void)
virtual void SAL_CALL elementRemoved(const css::ui::ConfigurationEvent &Event) override
DECL_LINK(MenuSelect, Menu *, bool)
DECL_LINK(Select, ToolBox *, void)
void OnDropdownClick(bool bCreatePopupWindow=true)
void ToggleButton(const OUString &rResourceName, std::u16string_view rCommand)
css::uno::Reference< css::frame::XUIControllerFactory > m_xToolbarControllerFactory
css::uno::Reference< css::ui::XImageManager > m_xDocImageManager
void UpdateController(const css::uno::Reference< css::frame::XToolbarController > &xController)
css::uno::Reference< css::frame::XModel > GetModelFromFrame() const
void AddCustomizeMenuItems(ToolBox const *pToolBar)
DECL_LINK(AsyncUpdateControllersHdl, Timer *, void)
ToolBarManager(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, OUString aResourceName, ToolBox *pToolBar)
DECL_LINK(MenuButton, ToolBox *, void)
void FillOverflowToolbar(ToolBox const *pParent)
DECL_LINK(DropdownClick, ToolBox *, void)
CommandToInfoMap m_aCommandMap
DECL_LINK(MenuPreExecute, ToolBox *, void)
css::uno::Reference< css::frame::XFrame > m_xFrame
virtual void SAL_CALL elementReplaced(const css::ui::ConfigurationEvent &Event) override
std::unique_ptr< ToolBarManagerImpl > m_pImpl
DECL_STATIC_LINK(ToolBarManager, ExecuteHdl_Impl, void *, void)
rtl::Reference< ToolBarManager > m_aOverflowManager
virtual void SAL_CALL elementInserted(const css::ui::ConfigurationEvent &Event) override
void notifyRegisteredControllers(const OUString &aUIElementName, const OUString &aCommand)
void FillAddonToolbar(const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > &rAddonToolbar)
::std::vector< css::uno::Reference< css::frame::XSubToolbarController > > SubToolBarControllerVector
DECL_LINK(DoubleClick, ToolBox *, void)
void HandleClick(ClickAction eAction)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
rtl::Reference< ImageOrientationController > m_aImageController
void SAL_CALL dispose() override
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &Action) override
VclPtr< ToolBox > m_pToolBar
DECL_LINK(StateChanged, StateChangedType const *, void)
void FillToolbar(const css::uno::Reference< css::container::XIndexAccess > &rToolBarData, const css::uno::Reference< css::container::XIndexAccess > &rContextData, const OUString &rContextToolbarName)
css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager
void SAL_CALL addEventListener(const css::uno::Reference< XEventListener > &xListener) override
ToolBarControllerMap m_aControllerMap
ToolBarManager(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, OUString aResourceName, weld::Toolbar *pToolBar, weld::Builder *pBuilder)
void setToolBarImage(const Image &_aImage, const CommandToInfoMap::const_iterator &_pIter)
void FillToolbarFromContainer(const css::uno::Reference< css::container::XIndexAccess > &rItemContainer, const OUString &rResourceName, ToolBoxItemId &nId, ToolBoxItemId &nAddonId)
virtual ~ToolBarManager() override
void impl_elementChanged(bool _bRemove, const css::ui::ConfigurationEvent &Event)
std::unordered_map< ToolBoxItemId, css::uno::Reference< css::frame::XStatusListener > > ToolBarControllerMap
comphelper::OInterfaceContainerHelper4< XEventListener > m_aListenerContainer
ToolBoxItemBits ConvertStyleToToolboxItemBits(sal_Int32 nStyle)
css::uno::Reference< css::uno::XComponentContext > m_xContext
weld::Toolbar * m_pWeldedToolBar
void SAL_CALL removeEventListener(const css::uno::Reference< XEventListener > &xListener) override
DECL_LINK(DataChanged, DataChangedEvent const *, void)
SubToolBarToSubToolBarControllerMap m_aSubToolBarControllerMap
ToolBox * GetToolBar() const
DECL_LINK(MiscOptionsChanged, LinkParamNone *, void)
std::unordered_map< OUString, SubToolBarControllerVector > SubToolBarToSubToolBarControllerMap
::cppu::WeakImplHelper< css::frame::XFrameActionListener, css::lang::XComponent, css::ui::XUIConfigurationListener > ToolbarManager_Base
std::unordered_map< OUString, CommandInfo > CommandToInfoMap
Definition: commandinfo.hxx:41
css::uno::Reference< css::frame::XLayoutManager > xLayoutManager
css::uno::Reference< css::awt::XWindow > xWindow
OUString aCommand
ToolBoxMenuType
ToolBoxButtonSize
ToolBoxItemBits
StateChangedType