1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/config.h>
24 #include <string_view>
27 #include <uiconfiguration/globalsettings.hxx>
28 #include <framework/addonsoptions.hxx>
29 #include <uielement/uielement.hxx>
30 #include <services/layoutmanager.hxx>
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>
40 #include <cppuhelper/implbase.hxx>
45 class ToolbarLayoutManager
: public ::cppu::WeakImplHelper
< css::awt::XDockableWindowListener
,
46 css::ui::XUIConfigurationListener
,
47 css::awt::XWindowListener
>
50 enum { DOCKINGAREAS_COUNT
= 4 };
52 enum PreviewFrameDetection
59 ToolbarLayoutManager( css::uno::Reference
< css::uno::XComponentContext
> xContext
,
60 css::uno::Reference
< css::ui::XUIElementFactory
> xUIElementFactory
,
61 LayoutManager
* pParentLayouter
);
62 virtual ~ToolbarLayoutManager() override
;
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
);
70 void setParentWindow( const css::uno::Reference
< css::awt::XVclWindowPeer
>& xParentWindow
);
71 void setDockingAreaOffsets(const ::tools::Rectangle
& rOffsets
);
73 void resetDockingArea();
75 css::awt::Rectangle
getDockingArea();
76 void setDockingArea( const css::awt::Rectangle
& rDockingArea
);
78 bool isPreviewFrame();
81 bool isLayoutDirty() const { return m_bLayoutDirty
;}
82 void doLayout(const ::Size
& aContainerSize
);
84 // creation/destruction
85 void createStaticToolbars();
86 void destroyToolbars();
88 bool requestToolbar( const OUString
& rResourceURL
);
89 bool createToolbar( const OUString
& rResourceURL
);
90 bool destroyToolbar( std::u16string_view rResourceURL
);
93 bool showToolbar( std::u16string_view rResourceURL
);
94 bool hideToolbar( std::u16string_view rResourceURL
);
96 void refreshToolbarsVisibility( bool bAutomaticToolbars
);
97 void setFloatingToolbarsVisibility( bool bVisible
);
98 void setVisible(bool bVisible
);
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();
118 void updateToolbarsTips();
120 // child window notifications
121 void childWindowEvent( VclSimpleEvent
const * pEvent
);
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
;
130 virtual void SAL_CALL
disposing( const css::lang::EventObject
& aEvent
) override
;
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
;
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
;
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
;
153 enum DockingOperation
155 DOCKOP_BEFORE_COLROW
,
160 typedef std::vector
< UIElement
> UIElementVector
;
161 struct SingleRowColumnWindowData
163 SingleRowColumnWindowData()
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
;
176 sal_Int32 nStaticSize
;
178 sal_Int32 nRowColumn
;
181 // internal helper methods
183 bool implts_isParentWindowVisible() const;
184 ::tools::Rectangle
implts_calcDockingArea();
185 void implts_sortUIElements();
186 void implts_reparentToolbars();
187 OUString
implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber
) const;
188 void implts_setElementData( UIElement
& rUIElement
, const css::uno::Reference
< css::awt::XDockableWindow
>& rDockWindow
);
189 void implts_destroyDockingAreaWindows();
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
,
198 SingleRowColumnWindowData
& rRowColumnWindowData
,
199 const ::Size
& rContainerSize
);
200 void implts_setLayoutDirty();
201 void implts_setLayoutInProgress( bool bInProgress
= true );
203 // lookup/container methods
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
);
212 ::Size
implts_getTopBottomDockingAreaSizes();
213 void implts_getUIElementVectorCopy( UIElementVector
& rCopy
);
215 // internal docking methods
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
,
223 const ::tools::Rectangle
& rDockedElementRect
,
224 std::u16string_view rMovedElementName
,
225 const ::tools::Rectangle
& rMovedElementRect
);
226 ::tools::Rectangle
implts_calcTrackingAndElementRect( css::ui::DockingArea eDockingArea
,
228 UIElement
& rUIElement
,
229 const ::tools::Rectangle
& rTrackingRect
,
230 const ::tools::Rectangle
& rRowColumnRect
,
231 const ::Size
& rContainerWinSize
);
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
);
240 void implts_createAddonsToolBars();
241 void implts_createCustomToolBars();
242 void implts_createNonContextSensitiveToolBars();
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 );
246 bool implts_isToolbarCreationActive();
248 // persistence methods
250 bool implts_readWindowStateData( const OUString
& aName
, UIElement
& rElementData
);
251 void implts_writeWindowStateData( const UIElement
& rElementData
);
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
;
263 LayoutManager
* m_pParentLayouter
;
265 UIElementVector m_aUIElements
;
266 UIElement m_aDockUIElement
;
267 tools::Rectangle m_aDockingArea
;
268 tools::Rectangle m_aDockingAreaOffsets
;
269 DockingOperation m_eDockOperation
;
270 PreviewFrameDetection m_ePreviewDetection
;
272 std::unique_ptr
<AddonsOptions
> m_pAddonOptions
;
273 std::unique_ptr
<GlobalSettings
> m_pGlobalSettings
;
275 bool m_bComponentAttached
;
277 bool m_bGlobalSettings
;
278 bool m_bDockingInProgress
;
279 bool m_bLayoutInProgress
;
280 bool m_bToolbarCreation
;
283 } // namespace framework
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */