LibreOffice Module framework (master) 1
toolbarlayoutmanager.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 <string_view>
25#include <vector>
26
31
32#include <com/sun/star/ui/XUIConfigurationManager.hpp>
33#include <com/sun/star/awt/XWindowListener.hpp>
34#include <com/sun/star/ui/XUIElementFactory.hpp>
35#include <com/sun/star/ui/DockingArea.hpp>
36#include <com/sun/star/awt/XWindow2.hpp>
37#include <com/sun/star/awt/XDockableWindow.hpp>
38#include <com/sun/star/awt/XDockableWindowListener.hpp>
39
41
42namespace framework
43{
44
45class ToolbarLayoutManager : public ::cppu::WeakImplHelper< css::awt::XDockableWindowListener,
46 css::ui::XUIConfigurationListener,
47 css::awt::XWindowListener >
48{
49 public:
50 enum { DOCKINGAREAS_COUNT = 4 };
51
53 {
57 };
58
59 ToolbarLayoutManager( css::uno::Reference< css::uno::XComponentContext > xContext,
60 css::uno::Reference< css::ui::XUIElementFactory > xUIElementFactory,
61 LayoutManager* pParentLayouter );
62 virtual ~ToolbarLayoutManager() override;
63
64 void reset();
65 void attach( const css::uno::Reference< css::frame::XFrame >& xFrame,
66 const css::uno::Reference< css::ui::XUIConfigurationManager >& xModuleCfgMgr,
67 const css::uno::Reference< css::ui::XUIConfigurationManager >& xDocCfgMgr,
68 const css::uno::Reference< css::container::XNameAccess >& xPersistentWindowState );
69
70 void setParentWindow( const css::uno::Reference< css::awt::XVclWindowPeer >& xParentWindow );
71 void setDockingAreaOffsets(const ::tools::Rectangle& rOffsets);
72
73 void resetDockingArea();
74
75 css::awt::Rectangle getDockingArea();
76 void setDockingArea( const css::awt::Rectangle& rDockingArea );
77
78 bool isPreviewFrame();
79
80 // layouting
81 bool isLayoutDirty() const { return m_bLayoutDirty;}
82 void doLayout(const ::Size& aContainerSize);
83
84 // creation/destruction
86 void destroyToolbars();
87
88 bool requestToolbar( const OUString& rResourceURL );
89 bool createToolbar( const OUString& rResourceURL );
90 bool destroyToolbar( std::u16string_view rResourceURL );
91
92 // visibility
93 bool showToolbar( std::u16string_view rResourceURL );
94 bool hideToolbar( std::u16string_view rResourceURL );
95
96 void refreshToolbarsVisibility( bool bAutomaticToolbars );
98 void setVisible(bool bVisible);
99
100 // docking and further functions
101 bool dockToolbar( std::u16string_view rResourceURL, css::ui::DockingArea eDockingArea, const css::awt::Point& aPos );
102 bool dockAllToolbars();
103 bool floatToolbar( std::u16string_view rResourceURL );
104 bool lockToolbar( std::u16string_view rResourceURL );
105 bool unlockToolbar( std::u16string_view rResourceURL );
106 void setToolbarPos( std::u16string_view rResourceURL, const css::awt::Point& aPos );
107 void setToolbarSize( std::u16string_view rResourceURL, const css::awt::Size& aSize );
108 void setToolbarPosSize( std::u16string_view rResourceURL, const css::awt::Point& aPos, const css::awt::Size& aSize );
109 bool isToolbarVisible( std::u16string_view rResourceURL );
110 bool isToolbarFloating( std::u16string_view rResourceURL );
111 bool isToolbarDocked( std::u16string_view rResourceURL );
112 bool isToolbarLocked( std::u16string_view rResourceURL );
113 css::awt::Point getToolbarPos( std::u16string_view rResourceURL );
114 css::awt::Size getToolbarSize( std::u16string_view rResourceURL );
115 css::uno::Reference< css::ui::XUIElement > getToolbar( std::u16string_view aName );
116 css::uno::Sequence< css::uno::Reference< css::ui::XUIElement > > getToolbars();
117
118 void updateToolbarsTips();
119
120 // child window notifications
121 void childWindowEvent( VclSimpleEvent const * pEvent );
122
123 // XInterface
124
125 virtual void SAL_CALL acquire() noexcept override;
126 virtual void SAL_CALL release() noexcept override;
127 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
128
129 // XEventListener
130 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
131
132 // XWindowListener
133 virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) override;
134 virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) override;
135 virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) override;
136 virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override;
137
138 // XDockableWindowListener
139 virtual void SAL_CALL startDocking( const css::awt::DockingEvent& e ) override;
140 virtual css::awt::DockingData SAL_CALL docking( const css::awt::DockingEvent& e ) override;
141 virtual void SAL_CALL endDocking( const css::awt::EndDockingEvent& e ) override;
142 virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const css::lang::EventObject& e ) override;
143 virtual void SAL_CALL toggleFloatingMode( const css::lang::EventObject& e ) override;
144 virtual void SAL_CALL closed( const css::lang::EventObject& e ) override;
145 virtual void SAL_CALL endPopupMode( const css::awt::EndPopupModeEvent& e ) override;
146
147 // XUIConfigurationListener
148 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
149 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
150 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
151
152 private:
154 {
158 };
159
160 typedef std::vector< UIElement > UIElementVector;
162 {
164 : nVarSize(0)
165 , nStaticSize(0)
166 , nSpace(0)
167 , nRowColumn(0)
168 {}
169
170 std::vector< OUString > aUIElementNames;
171 std::vector< css::uno::Reference< css::awt::XWindow > > aRowColumnWindows;
172 std::vector< css::awt::Rectangle > aRowColumnWindowSizes;
173 std::vector< sal_Int32 > aRowColumnSpace;
174 css::awt::Rectangle aRowColumnRect;
175 sal_Int32 nVarSize;
176 sal_Int32 nStaticSize;
177 sal_Int32 nSpace;
178 sal_Int32 nRowColumn;
179 };
180
181 // internal helper methods
182
183 bool implts_isParentWindowVisible() const;
187 OUString implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const;
188 void implts_setElementData( UIElement& rUIElement, const css::uno::Reference< css::awt::XDockableWindow >& rDockWindow );
190
191 // layout methods
192
193 void implts_setDockingAreaWindowSizes( const css::awt::Rectangle& rBorderSpace );
194 css::awt::Point implts_findNextCascadeFloatingPos();
195 void implts_renumberRowColumnData( css::ui::DockingArea eDockingArea, const UIElement& rUIElement );
196 void implts_calcWindowPosSizeOnSingleRowColumn( sal_Int32 nDockingArea,
197 sal_Int32 nOffset,
198 SingleRowColumnWindowData& rRowColumnWindowData,
199 const ::Size& rContainerSize );
201 void implts_setLayoutInProgress( bool bInProgress = true );
202
203 // lookup/container methods
204
205 UIElement implts_findToolbar( std::u16string_view aName );
206 UIElement implts_findToolbar( const css::uno::Reference< css::uno::XInterface >& xToolbar );
207 UIElement& impl_findToolbar( std::u16string_view aName );
208 css::uno::Reference< css::awt::XWindow > implts_getXWindow( std::u16string_view aName );
209 vcl::Window* implts_getWindow( std::u16string_view aName );
210 bool implts_insertToolbar( const UIElement& rUIElement );
211 void implts_setToolbar( const UIElement& rUIElement );
214
215 // internal docking methods
216
217 ::tools::Rectangle implts_calcHotZoneRect( const ::tools::Rectangle& rRect, sal_Int32 nHotZoneOffset );
218 void implts_calcDockingPosSize( UIElement& aUIElement, DockingOperation& eDockOperation, ::tools::Rectangle& rTrackingRect, const Point& rMousePos );
219 DockingOperation implts_determineDockingOperation( css::ui::DockingArea DockingArea, const ::tools::Rectangle& rRowColRect, const Point& rMousePos );
220 ::tools::Rectangle implts_getWindowRectFromRowColumn( css::ui::DockingArea DockingArea, const SingleRowColumnWindowData& rRowColumnWindowData, const ::Point& rMousePos, std::u16string_view rExcludeElementName );
221 ::tools::Rectangle implts_determineFrontDockingRect( css::ui::DockingArea eDockingArea,
222 sal_Int32 nRowCol,
223 const ::tools::Rectangle& rDockedElementRect,
224 std::u16string_view rMovedElementName,
225 const ::tools::Rectangle& rMovedElementRect );
226 ::tools::Rectangle implts_calcTrackingAndElementRect( css::ui::DockingArea eDockingArea,
227 sal_Int32 nRowCol,
228 UIElement& rUIElement,
229 const ::tools::Rectangle& rTrackingRect,
230 const ::tools::Rectangle& rRowColumnRect,
231 const ::Size& rContainerWinSize );
232
233 void implts_getDockingAreaElementInfos( css::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData );
234 void implts_getDockingAreaElementInfoOnSingleRowCol( css::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData );
235 void implts_findNextDockingPos( css::ui::DockingArea DockingArea, const ::Size& aUIElementSize, css::awt::Point& rVirtualPos, ::Point& rPixelPos );
236 void implts_setTrackingRect( css::ui::DockingArea eDockingArea, const ::Point& rMousePos, ::tools::Rectangle& rTrackingRect );
237
238 // creation methods
239
243 void implts_createCustomToolBars( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& aCustomTbxSeq );
244 void implts_createCustomToolBar( const OUString& aTbxResName, const OUString& aTitle );
245 void implts_setToolbarCreation( bool bStart = true );
247
248 // persistence methods
249
250 bool implts_readWindowStateData( const OUString& aName, UIElement& rElementData );
251 void implts_writeWindowStateData( const UIElement& rElementData );
252
253 // members
254
255 css::uno::Reference< css::uno::XComponentContext > m_xContext;
256 css::uno::Reference< css::frame::XFrame > m_xFrame;
257 css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow;
258 css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT];
259 css::uno::Reference< css::ui::XUIElementFactory > m_xUIElementFactoryManager;
260 css::uno::Reference< css::ui::XUIConfigurationManager > m_xModuleCfgMgr;
261 css::uno::Reference< css::ui::XUIConfigurationManager > m_xDocCfgMgr;
262 css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState;
264
271
272 std::unique_ptr<AddonsOptions> m_pAddonOptions;
273 std::unique_ptr<GlobalSettings> m_pGlobalSettings;
274
281};
282
283} // namespace framework
284
285/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL prepareToggleFloatingMode(const css::lang::EventObject &e) override
void setFloatingToolbarsVisibility(bool bVisible)
css::uno::Reference< css::awt::XWindow > implts_getXWindow(std::u16string_view aName)
virtual void SAL_CALL elementRemoved(const css::ui::ConfigurationEvent &Event) override
css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow
css::uno::Reference< css::ui::XUIConfigurationManager > m_xDocCfgMgr
virtual void SAL_CALL endDocking(const css::awt::EndDockingEvent &e) override
vcl::Window * implts_getWindow(std::u16string_view aName)
void implts_createCustomToolBars(const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > &aCustomTbxSeq)
css::uno::Reference< css::uno::XComponentContext > m_xContext
ToolbarLayoutManager(css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::ui::XUIElementFactory > xUIElementFactory, LayoutManager *pParentLayouter)
css::uno::Reference< css::ui::XUIElement > getToolbar(std::u16string_view aName)
::tools::Rectangle implts_calcHotZoneRect(const ::tools::Rectangle &rRect, sal_Int32 nHotZoneOffset)
virtual void SAL_CALL toggleFloatingMode(const css::lang::EventObject &e) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
void setDockingAreaOffsets(const ::tools::Rectangle &rOffsets)
::tools::Rectangle implts_determineFrontDockingRect(css::ui::DockingArea eDockingArea, sal_Int32 nRowCol, const ::tools::Rectangle &rDockedElementRect, std::u16string_view rMovedElementName, const ::tools::Rectangle &rMovedElementRect)
void implts_setDockingAreaWindowSizes(const css::awt::Rectangle &rBorderSpace)
void setParentWindow(const css::uno::Reference< css::awt::XVclWindowPeer > &xParentWindow)
void implts_setToolbarCreation(bool bStart=true)
::tools::Rectangle implts_getWindowRectFromRowColumn(css::ui::DockingArea DockingArea, const SingleRowColumnWindowData &rRowColumnWindowData, const ::Point &rMousePos, std::u16string_view rExcludeElementName)
bool floatToolbar(std::u16string_view rResourceURL)
UIElement & impl_findToolbar(std::u16string_view aName)
UIElement implts_findToolbar(std::u16string_view aName)
css::uno::Reference< css::frame::XFrame > m_xFrame
css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT]
virtual void SAL_CALL elementReplaced(const css::ui::ConfigurationEvent &Event) override
OUString implts_generateGenericAddonToolbarTitle(sal_Int32 nNumber) const
void implts_setTrackingRect(css::ui::DockingArea eDockingArea, const ::Point &rMousePos, ::tools::Rectangle &rTrackingRect)
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
void childWindowEvent(VclSimpleEvent const *pEvent)
std::unique_ptr< AddonsOptions > m_pAddonOptions
std::unique_ptr< GlobalSettings > m_pGlobalSettings
void refreshToolbarsVisibility(bool bAutomaticToolbars)
::tools::Rectangle implts_calcTrackingAndElementRect(css::ui::DockingArea eDockingArea, sal_Int32 nRowCol, UIElement &rUIElement, const ::tools::Rectangle &rTrackingRect, const ::tools::Rectangle &rRowColumnRect, const ::Size &rContainerWinSize)
css::uno::Reference< css::ui::XUIElementFactory > m_xUIElementFactoryManager
bool showToolbar(std::u16string_view rResourceURL)
void setToolbarSize(std::u16string_view rResourceURL, const css::awt::Size &aSize)
void implts_renumberRowColumnData(css::ui::DockingArea eDockingArea, const UIElement &rUIElement)
virtual void SAL_CALL closed(const css::lang::EventObject &e) override
bool isToolbarVisible(std::u16string_view rResourceURL)
css::uno::Reference< css::ui::XUIConfigurationManager > m_xModuleCfgMgr
void setToolbarPos(std::u16string_view rResourceURL, const css::awt::Point &aPos)
virtual void SAL_CALL elementInserted(const css::ui::ConfigurationEvent &Event) override
bool isToolbarFloating(std::u16string_view rResourceURL)
bool lockToolbar(std::u16string_view rResourceURL)
void implts_setToolbar(const UIElement &rUIElement)
bool implts_insertToolbar(const UIElement &rUIElement)
void implts_writeWindowStateData(const UIElement &rElementData)
virtual void SAL_CALL endPopupMode(const css::awt::EndPopupModeEvent &e) override
void implts_calcDockingPosSize(UIElement &aUIElement, DockingOperation &eDockOperation, ::tools::Rectangle &rTrackingRect, const Point &rMousePos)
bool unlockToolbar(std::u16string_view rResourceURL)
void attach(const css::uno::Reference< css::frame::XFrame > &xFrame, const css::uno::Reference< css::ui::XUIConfigurationManager > &xModuleCfgMgr, const css::uno::Reference< css::ui::XUIConfigurationManager > &xDocCfgMgr, const css::uno::Reference< css::container::XNameAccess > &xPersistentWindowState)
UIElement implts_findToolbar(const css::uno::Reference< css::uno::XInterface > &xToolbar)
void implts_setElementData(UIElement &rUIElement, const css::uno::Reference< css::awt::XDockableWindow > &rDockWindow)
virtual css::awt::DockingData SAL_CALL docking(const css::awt::DockingEvent &e) override
void implts_setLayoutInProgress(bool bInProgress=true)
css::awt::Size getToolbarSize(std::u16string_view rResourceURL)
void implts_getDockingAreaElementInfos(css::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData > &rRowColumnsWindowData)
css::awt::Point getToolbarPos(std::u16string_view rResourceURL)
virtual void SAL_CALL windowShown(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &aEvent) override
std::vector< UIElement > UIElementVector
bool dockToolbar(std::u16string_view rResourceURL, css::ui::DockingArea eDockingArea, const css::awt::Point &aPos)
void setToolbarPosSize(std::u16string_view rResourceURL, const css::awt::Point &aPos, const css::awt::Size &aSize)
void doLayout(const ::Size &aContainerSize)
void implts_getUIElementVectorCopy(UIElementVector &rCopy)
bool hideToolbar(std::u16string_view rResourceURL)
virtual void SAL_CALL startDocking(const css::awt::DockingEvent &e) override
bool createToolbar(const OUString &rResourceURL)
bool isToolbarLocked(std::u16string_view rResourceURL)
void implts_findNextDockingPos(css::ui::DockingArea DockingArea, const ::Size &aUIElementSize, css::awt::Point &rVirtualPos, ::Point &rPixelPos)
bool requestToolbar(const OUString &rResourceURL)
virtual void SAL_CALL windowHidden(const css::lang::EventObject &aEvent) override
void implts_createCustomToolBar(const OUString &aTbxResName, const OUString &aTitle)
bool destroyToolbar(std::u16string_view rResourceURL)
bool implts_readWindowStateData(const OUString &aName, UIElement &rElementData)
css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState
void implts_calcWindowPosSizeOnSingleRowColumn(sal_Int32 nDockingArea, sal_Int32 nOffset, SingleRowColumnWindowData &rRowColumnWindowData, const ::Size &rContainerSize)
void implts_getDockingAreaElementInfoOnSingleRowCol(css::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData &rRowColumnWindowData)
void setDockingArea(const css::awt::Rectangle &rDockingArea)
css::uno::Sequence< css::uno::Reference< css::ui::XUIElement > > getToolbars()
DockingOperation implts_determineDockingOperation(css::ui::DockingArea DockingArea, const ::tools::Rectangle &rRowColRect, const Point &rMousePos)
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &aEvent) override
bool isToolbarDocked(std::u16string_view rResourceURL)
virtual void SAL_CALL acquire() noexcept override
Type
std::vector< css::uno::Reference< css::awt::XWindow > > aRowColumnWindows
bool bVisible
unsigned char sal_Bool