Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / layoutmanager / toolbarlayoutmanager.hxx
blob6a1df781dde30ae2932bec2c89aad7f4d4af2851
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 #ifndef INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
21 #define INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
23 /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
24 with solaris headers ...
26 #include <vector>
28 #include <uiconfiguration/globalsettings.hxx>
29 #include <framework/addonsoptions.hxx>
30 #include <uielement/uielement.hxx>
31 #include <services/layoutmanager.hxx>
33 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
34 #include <com/sun/star/awt/XWindowListener.hpp>
35 #include <com/sun/star/ui/XUIElementFactory.hpp>
36 #include <com/sun/star/ui/DockingArea.hpp>
37 #include <com/sun/star/awt/XWindow2.hpp>
38 #include <com/sun/star/awt/XDockableWindow.hpp>
39 #include <com/sun/star/awt/XDockableWindowListener.hpp>
41 #include <cppuhelper/implbase.hxx>
43 namespace framework
46 class ToolbarLayoutManager : public ::cppu::WeakImplHelper< css::awt::XDockableWindowListener,
47 css::ui::XUIConfigurationListener,
48 css::awt::XWindowListener >
50 public:
51 enum { DOCKINGAREAS_COUNT = 4 };
53 enum PreviewFrameDetection
55 PREVIEWFRAME_UNKNOWN,
56 PREVIEWFRAME_NO,
57 PREVIEWFRAME_YES
60 ToolbarLayoutManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
61 const css::uno::Reference< css::ui::XUIElementFactory >& xUIElementFactory,
62 LayoutManager* pParentLayouter );
63 virtual ~ToolbarLayoutManager() override;
65 void reset();
66 void attach( const css::uno::Reference< css::frame::XFrame >& xFrame,
67 const css::uno::Reference< css::ui::XUIConfigurationManager >& xModuleCfgMgr,
68 const css::uno::Reference< css::ui::XUIConfigurationManager >& xDocCfgMgr,
69 const css::uno::Reference< css::container::XNameAccess >& xPersistentWindowState );
71 void setParentWindow( const css::uno::Reference< css::awt::XWindowPeer >& xParentWindow );
72 void setDockingAreaOffsets(const ::tools::Rectangle& rOffsets);
74 void resetDockingArea();
76 css::awt::Rectangle getDockingArea();
77 void setDockingArea( const css::awt::Rectangle& rDockingArea );
79 bool isPreviewFrame();
81 // layouting
82 bool isLayoutDirty() const { return m_bLayoutDirty;}
83 void doLayout(const ::Size& aContainerSize);
85 // creation/destruction
86 void createStaticToolbars();
87 void destroyToolbars();
89 bool requestToolbar( const OUString& rResourceURL );
90 bool createToolbar( const OUString& rResourceURL );
91 bool destroyToolbar( const OUString& rResourceURL );
93 // visibility
94 bool showToolbar( const OUString& rResourceURL );
95 bool hideToolbar( const OUString& rResourceURL );
97 void refreshToolbarsVisibility( bool bAutomaticToolbars );
98 void setFloatingToolbarsVisibility( bool bVisible );
99 void setVisible(bool bVisible);
101 // docking and further functions
102 bool dockToolbar( const OUString& rResourceURL, css::ui::DockingArea eDockingArea, const css::awt::Point& aPos );
103 bool dockAllToolbars();
104 bool floatToolbar( const OUString& rResourceURL );
105 bool lockToolbar( const OUString& rResourceURL );
106 bool unlockToolbar( const OUString& rResourceURL );
107 void setToolbarPos( const OUString& rResourceURL, const css::awt::Point& aPos );
108 void setToolbarSize( const OUString& rResourceURL, const css::awt::Size& aSize );
109 void setToolbarPosSize( const OUString& rResourceURL, const css::awt::Point& aPos, const css::awt::Size& aSize );
110 bool isToolbarVisible( const OUString& rResourceURL );
111 bool isToolbarFloating( const OUString& rResourceURL );
112 bool isToolbarDocked( const OUString& rResourceURL );
113 bool isToolbarLocked( const OUString& rResourceURL );
114 css::awt::Point getToolbarPos( const OUString& rResourceURL );
115 css::awt::Size getToolbarSize( const OUString& rResourceURL );
116 css::uno::Reference< css::ui::XUIElement > getToolbar( const OUString& aName );
117 css::uno::Sequence< css::uno::Reference< css::ui::XUIElement > > getToolbars();
119 // child window notifications
120 void childWindowEvent( VclSimpleEvent const * pEvent );
122 // XInterface
124 virtual void SAL_CALL acquire() throw() override;
125 virtual void SAL_CALL release() throw() override;
126 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
128 // XEventListener
129 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
131 // XWindowListener
132 virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) override;
133 virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) override;
134 virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) override;
135 virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override;
137 // XDockableWindowListener
138 virtual void SAL_CALL startDocking( const css::awt::DockingEvent& e ) override;
139 virtual css::awt::DockingData SAL_CALL docking( const css::awt::DockingEvent& e ) override;
140 virtual void SAL_CALL endDocking( const css::awt::EndDockingEvent& e ) override;
141 virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const css::lang::EventObject& e ) override;
142 virtual void SAL_CALL toggleFloatingMode( const css::lang::EventObject& e ) override;
143 virtual void SAL_CALL closed( const css::lang::EventObject& e ) override;
144 virtual void SAL_CALL endPopupMode( const css::awt::EndPopupModeEvent& e ) override;
146 // XUIConfigurationListener
147 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
148 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
149 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
151 private:
152 enum DockingOperation
154 DOCKOP_BEFORE_COLROW,
155 DOCKOP_ON_COLROW,
156 DOCKOP_AFTER_COLROW
159 typedef std::vector< UIElement > UIElementVector;
160 struct SingleRowColumnWindowData
162 SingleRowColumnWindowData()
163 : nVarSize(0)
164 , nStaticSize(0)
165 , nSpace(0)
166 , nRowColumn(0)
169 std::vector< OUString > aUIElementNames;
170 std::vector< css::uno::Reference< css::awt::XWindow > > aRowColumnWindows;
171 std::vector< css::awt::Rectangle > aRowColumnWindowSizes;
172 std::vector< sal_Int32 > aRowColumnSpace;
173 css::awt::Rectangle aRowColumnRect;
174 sal_Int32 nVarSize;
175 sal_Int32 nStaticSize;
176 sal_Int32 nSpace;
177 sal_Int32 nRowColumn;
180 // internal helper methods
182 bool implts_isParentWindowVisible() const;
183 ::tools::Rectangle implts_calcDockingArea();
184 void implts_sortUIElements();
185 void implts_reparentToolbars();
186 OUString implts_generateGenericAddonToolbarTitle( sal_Int32 nNumber ) const;
187 void implts_setElementData( UIElement& rUIElement, const css::uno::Reference< css::awt::XDockableWindow >& rDockWindow );
188 void implts_destroyDockingAreaWindows();
190 // layout methods
192 void implts_setDockingAreaWindowSizes( const css::awt::Rectangle& rBorderSpace );
193 css::awt::Point implts_findNextCascadeFloatingPos();
194 void implts_renumberRowColumnData( css::ui::DockingArea eDockingArea, const UIElement& rUIElement );
195 void implts_calcWindowPosSizeOnSingleRowColumn( sal_Int32 nDockingArea,
196 sal_Int32 nOffset,
197 SingleRowColumnWindowData& rRowColumnWindowData,
198 const ::Size& rContainerSize );
199 void implts_setLayoutDirty();
200 void implts_setLayoutInProgress( bool bInProgress = true );
202 // lookup/container methods
204 UIElement implts_findToolbar( const OUString& aName );
205 UIElement implts_findToolbar( const css::uno::Reference< css::uno::XInterface >& xToolbar );
206 UIElement& impl_findToolbar( const OUString& aName );
207 css::uno::Reference< css::awt::XWindow > implts_getXWindow( const OUString& aName );
208 vcl::Window* implts_getWindow( const OUString& aName );
209 bool implts_insertToolbar( const UIElement& rUIElement );
210 void implts_setToolbar( const UIElement& rUIElement );
211 ::Size implts_getTopBottomDockingAreaSizes();
212 void implts_getUIElementVectorCopy( UIElementVector& rCopy );
214 // internal docking methods
216 ::tools::Rectangle implts_calcHotZoneRect( const ::tools::Rectangle& rRect, sal_Int32 nHotZoneOffset );
217 void implts_calcDockingPosSize( UIElement& aUIElement, DockingOperation& eDockOperation, ::tools::Rectangle& rTrackingRect, const Point& rMousePos );
218 DockingOperation implts_determineDockingOperation( css::ui::DockingArea DockingArea, const ::tools::Rectangle& rRowColRect, const Point& rMousePos );
219 ::tools::Rectangle implts_getWindowRectFromRowColumn( css::ui::DockingArea DockingArea, const SingleRowColumnWindowData& rRowColumnWindowData, const ::Point& rMousePos, const OUString& rExcludeElementName );
220 ::tools::Rectangle implts_determineFrontDockingRect( css::ui::DockingArea eDockingArea,
221 sal_Int32 nRowCol,
222 const ::tools::Rectangle& rDockedElementRect,
223 const OUString& rMovedElementName,
224 const ::tools::Rectangle& rMovedElementRect );
225 ::tools::Rectangle implts_calcTrackingAndElementRect( css::ui::DockingArea eDockingArea,
226 sal_Int32 nRowCol,
227 UIElement& rUIElement,
228 const ::tools::Rectangle& rTrackingRect,
229 const ::tools::Rectangle& rRowColumnRect,
230 const ::Size& rContainerWinSize );
232 void implts_getDockingAreaElementInfos( css::ui::DockingArea DockingArea, std::vector< SingleRowColumnWindowData >& rRowColumnsWindowData );
233 void implts_getDockingAreaElementInfoOnSingleRowCol( css::ui::DockingArea, sal_Int32 nRowCol, SingleRowColumnWindowData& rRowColumnWindowData );
234 void implts_findNextDockingPos( css::ui::DockingArea DockingArea, const ::Size& aUIElementSize, css::awt::Point& rVirtualPos, ::Point& rPixelPos );
235 void implts_setTrackingRect( css::ui::DockingArea eDockingArea, const ::Point& rMousePos, ::tools::Rectangle& rTrackingRect );
237 // creation methods
239 void implts_createAddonsToolBars();
240 void implts_createCustomToolBars();
241 void implts_createNonContextSensitiveToolBars();
242 void implts_createCustomToolBars( const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > >& aCustomTbxSeq );
243 void implts_createCustomToolBar( const OUString& aTbxResName, const OUString& aTitle );
244 void implts_setToolbarCreation( bool bStart = true );
245 bool implts_isToolbarCreationActive();
247 // persistence methods
249 bool implts_readWindowStateData( const OUString& aName, UIElement& rElementData );
250 void implts_writeWindowStateData( const UIElement& rElementData );
252 // members
254 css::uno::Reference< css::uno::XComponentContext > m_xContext;
255 css::uno::Reference< css::frame::XFrame > m_xFrame;
256 css::uno::Reference< css::awt::XWindow2 > m_xContainerWindow;
257 css::uno::Reference< css::awt::XWindow > m_xDockAreaWindows[DOCKINGAREAS_COUNT];
258 css::uno::Reference< css::ui::XUIElementFactory > m_xUIElementFactoryManager;
259 css::uno::Reference< css::ui::XUIConfigurationManager > m_xModuleCfgMgr;
260 css::uno::Reference< css::ui::XUIConfigurationManager > m_xDocCfgMgr;
261 css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState;
262 LayoutManager* m_pParentLayouter;
264 UIElementVector m_aUIElements;
265 UIElement m_aDockUIElement;
266 tools::Rectangle m_aDockingArea;
267 tools::Rectangle m_aDockingAreaOffsets;
268 DockingOperation m_eDockOperation;
269 PreviewFrameDetection m_ePreviewDetection;
271 std::unique_ptr<AddonsOptions> m_pAddonOptions;
272 std::unique_ptr<GlobalSettings> m_pGlobalSettings;
274 bool m_bComponentAttached;
275 bool m_bLayoutDirty;
276 bool m_bGlobalSettings;
277 bool m_bDockingInProgress;
278 bool m_bLayoutInProgress;
279 bool m_bToolbarCreation;
282 } // namespace framework
284 #endif // INCLUDED_FRAMEWORK_SOURCE_LAYOUTMANAGER_TOOLBARLAYOUTMANAGER_HXX
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */