cid#1607171 Data race condition
[LibreOffice.git] / framework / inc / services / layoutmanager.hxx
blob3b0b57e39132382ef89b29159601f8becdca375b
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/menubarmanager.hxx>
23 #include <uielement/uielement.hxx>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/frame/XLayoutManager2.hpp>
27 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
28 #include <com/sun/star/frame/XModuleManager2.hpp>
29 #include <com/sun/star/awt/XWindowListener.hpp>
30 #include <com/sun/star/util/XURLTransformer.hpp>
31 #include <com/sun/star/ui/XUIElementFactoryManager.hpp>
32 #include <com/sun/star/ui/DockingArea.hpp>
33 #include <com/sun/star/awt/XTopWindow2.hpp>
35 #include <cppuhelper/basemutex.hxx>
36 #include <cppuhelper/propshlp.hxx>
37 #include <cppuhelper/implbase.hxx>
38 #include <comphelper/multicontainer2.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <comphelper/propertycontainer.hxx>
41 #include <comphelper/uno3.hxx>
42 #include <vcl/timer.hxx>
44 class MenuBar;
46 namespace framework
48 class MenuBarWrapper;
49 class ProgressBarWrapper;
50 class ToolbarLayoutManager;
51 class GlobalSettings;
52 namespace detail
54 class InfoHelperBuilder;
56 typedef ::cppu::WeakImplHelper < css::lang::XServiceInfo
57 , css::frame::XLayoutManager2
58 , css::awt::XWindowListener
59 > LayoutManager_Base;
60 typedef ::comphelper::OPropertyContainer LayoutManager_PBase;
61 class LayoutManager final : public LayoutManager_Base ,
62 private cppu::BaseMutex,
63 public ::cppu::OBroadcastHelper ,
64 public LayoutManager_PBase
66 public:
67 LayoutManager( const css::uno::Reference< css::uno::XComponentContext >& xContext );
68 virtual ~LayoutManager() override;
70 /** declaration of XInterface, XTypeProvider, XServiceInfo */
71 DECLARE_XINTERFACE()
72 DECLARE_XTYPEPROVIDER()
73 virtual OUString SAL_CALL getImplementationName() override
75 return u"com.sun.star.comp.framework.LayoutManager"_ustr;
78 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
80 return cppu::supportsService(this, ServiceName);
83 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
85 css::uno::Sequence< OUString > aSeq { u"com.sun.star.frame.LayoutManager"_ustr };
86 return aSeq;
89 // XLayoutManager
90 virtual void SAL_CALL attachFrame( const css::uno::Reference< css::frame::XFrame >& Frame ) override;
91 virtual void SAL_CALL reset() override;
92 virtual css::awt::Rectangle SAL_CALL getCurrentDockingArea( ) override;
93 virtual css::uno::Reference< css::ui::XDockingAreaAcceptor > SAL_CALL getDockingAreaAcceptor() override;
94 virtual void SAL_CALL setDockingAreaAcceptor( const css::uno::Reference< css::ui::XDockingAreaAcceptor >& xDockingAreaAcceptor ) final override;
95 virtual void SAL_CALL createElement( const OUString& aName ) override;
96 virtual void SAL_CALL destroyElement( const OUString& aName ) override;
97 virtual sal_Bool SAL_CALL requestElement( const OUString& ResourceURL ) override;
98 virtual css::uno::Reference< css::ui::XUIElement > SAL_CALL getElement( const OUString& aName ) override;
99 virtual css::uno::Sequence< css::uno::Reference< css::ui::XUIElement > > SAL_CALL getElements( ) override;
100 virtual sal_Bool SAL_CALL showElement( const OUString& aName ) override;
101 virtual sal_Bool SAL_CALL hideElement( const OUString& aName ) override;
102 virtual sal_Bool SAL_CALL dockWindow( const OUString& aName, css::ui::DockingArea DockingArea, const css::awt::Point& Pos ) override;
103 virtual sal_Bool SAL_CALL dockAllWindows( ::sal_Int16 nElementType ) override;
104 virtual sal_Bool SAL_CALL floatWindow( const OUString& aName ) override;
105 virtual sal_Bool SAL_CALL lockWindow( const OUString& ResourceURL ) override;
106 virtual sal_Bool SAL_CALL unlockWindow( const OUString& ResourceURL ) override;
107 virtual void SAL_CALL setElementSize( const OUString& aName, const css::awt::Size& aSize ) override;
108 virtual void SAL_CALL setElementPos( const OUString& aName, const css::awt::Point& aPos ) override;
109 virtual void SAL_CALL setElementPosSize( const OUString& aName, const css::awt::Point& aPos, const css::awt::Size& aSize ) override;
110 virtual sal_Bool SAL_CALL isElementVisible( const OUString& aName ) override;
111 virtual sal_Bool SAL_CALL isElementFloating( const OUString& aName ) override;
112 virtual sal_Bool SAL_CALL isElementDocked( const OUString& aName ) override;
113 virtual sal_Bool SAL_CALL isElementLocked( const OUString& ResourceURL ) override;
114 virtual css::awt::Size SAL_CALL getElementSize( const OUString& aName ) override;
115 virtual css::awt::Point SAL_CALL getElementPos( const OUString& aName ) override;
116 virtual void SAL_CALL lock( ) override;
117 virtual void SAL_CALL unlock( ) override;
118 virtual void SAL_CALL doLayout( ) override;
119 virtual void SAL_CALL setVisible( sal_Bool bVisible ) override;
120 virtual sal_Bool SAL_CALL isVisible() override;
122 // XMenuBarMergingAcceptor
124 virtual sal_Bool SAL_CALL setMergedMenuBar( const css::uno::Reference< css::container::XIndexAccess >& xMergedMenuBar ) override;
125 virtual void SAL_CALL removeMergedMenuBar( ) override;
127 // XWindowListener
128 virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) override;
129 virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) override;
130 virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) override;
131 virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override;
133 // XFrameActionListener
134 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) override;
136 // XEventListener
137 using cppu::OPropertySetHelper::disposing;
138 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override;
140 // XUIConfigurationListener
141 virtual void SAL_CALL elementInserted( const css::ui::ConfigurationEvent& Event ) override;
142 virtual void SAL_CALL elementRemoved( const css::ui::ConfigurationEvent& Event ) override;
143 virtual void SAL_CALL elementReplaced( const css::ui::ConfigurationEvent& Event ) override;
145 // XLayoutManagerEventBroadcaster
146 virtual void SAL_CALL addLayoutManagerEventListener( const css::uno::Reference< css::frame::XLayoutManagerListener >& aLayoutManagerListener ) override;
147 virtual void SAL_CALL removeLayoutManagerEventListener( const css::uno::Reference< css::frame::XLayoutManagerListener >& aLayoutManagerListener ) override;
149 DECL_LINK( MenuBarClose, void *, void);
150 DECL_LINK( WindowEventListener, VclWindowEvent&, void );
152 // called from ToolbarLayoutManager
153 void requestLayout();
155 /// Reading of settings - shared with ToolbarLayoutManager.
156 static bool readWindowStateData( const OUString& rName, UIElement& rElementData,
157 const css::uno::Reference< css::container::XNameAccess > &rPersistentWindowState,
158 std::unique_ptr<GlobalSettings> &rGlobalSettings, bool &bInGlobalSettings,
159 const css::uno::Reference< css::uno::XComponentContext > &rComponentContext );
161 private:
162 DECL_LINK(AsyncLayoutHdl, Timer *, void);
164 // menu bar
166 void implts_createMenuBar( const OUString& rMenuBarName );
167 void impl_clearUpMenuBar();
168 void implts_reset( bool bAttach );
169 void implts_updateMenuBarClose();
170 bool implts_resetMenuBar();
171 void implts_createMSCompatibleMenuBar(const OUString& rName);
173 // locking
175 void implts_lock();
176 bool implts_unlock();
178 // query
180 css::uno::Reference< css::ui::XUIElement > implts_findElement( std::u16string_view aName );
182 bool implts_readWindowStateData( const OUString& rName, UIElement& rElementData );
183 void implts_writeWindowStateData( const OUString& rName, const UIElement& rElementData );
184 void implts_destroyElements();
185 void implts_toggleFloatingUIElementsVisibility( bool bActive );
186 void implts_reparentChildWindows();
187 css::uno::Reference< css::ui::XUIElement > implts_createDockingWindow( const OUString& aElementName );
189 bool implts_isEmbeddedLayoutManager() const;
190 css::uno::Reference< css::ui::XUIElement > implts_createElement( const OUString& aName );
192 // layouting methods
193 bool implts_resizeContainerWindow( const css::awt::Size& rContainerSize, const css::awt::Point& rComponentPos );
194 ::Size implts_getContainerWindowOutputSize();
196 void implts_setDockingAreaWindowSizes();
197 css::awt::Rectangle implts_calcDockingAreaSizes();
198 bool implts_doLayout( bool bForceRequestBorderSpace, bool bOuterResize );
199 void implts_doLayout_notify( bool bOuterResize );
201 // internal methods to control status/progress bar
202 ::Size implts_getStatusBarSize();
203 void implts_destroyStatusBar();
204 void implts_createStatusBar( const OUString& rStatusBarName );
205 void implts_createProgressBar();
206 void implts_destroyProgressBar();
207 void implts_setStatusBarPosSize( const ::Point& rPos, const ::Size& rSize );
208 bool implts_showStatusBar( bool bStoreState=false );
209 bool implts_hideStatusBar( bool bStoreState=false );
210 void implts_readStatusBarState( const OUString& rStatusBarName );
211 bool implts_showProgressBar();
212 bool implts_hideProgressBar();
213 void implts_backupProgressBarWrapper();
214 void implts_setOffset( const sal_Int32 nBottomOffset );
216 /// @throws css::uno::RuntimeException
217 void implts_setInplaceMenuBar(
218 const css::uno::Reference< css::container::XIndexAccess >& xMergedMenuBar );
219 /// @throws css::uno::RuntimeException
220 void implts_resetInplaceMenuBar();
222 void implts_setVisibleState( bool bShow );
223 void implts_updateUIElementsVisibleState( bool bShow );
224 void implts_setCurrentUIVisibility( bool bShow );
225 void implts_notifyListeners(short nEvent, const css::uno::Any& rInfoParam);
227 // OPropertySetHelper
229 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
230 const css::uno::Any& aValue ) override;
231 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
232 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
234 css::uno::Reference< css::uno::XComponentContext > m_xContext; /** reference to factory, which has created this instance. */
235 css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer;
236 css::uno::Reference< css::frame::XFrame > m_xFrame;
237 css::uno::Reference< css::ui::XUIConfigurationManager > m_xModuleCfgMgr;
238 css::uno::Reference< css::ui::XUIConfigurationManager > m_xDocCfgMgr;
239 css::uno::Reference< css::awt::XWindow > m_xContainerWindow;
240 css::uno::Reference< css::awt::XTopWindow2 > m_xContainerTopWindow;
241 sal_Int32 m_nLockCount;
242 bool m_bInplaceMenuSet;
243 bool m_bMenuVisible;
244 bool m_bVisible;
245 bool m_bParentWindowVisible;
246 bool m_bMustDoLayout;
247 bool m_bAutomaticToolbars;
248 bool m_bHideCurrentUI;
249 bool m_bGlobalSettings;
250 bool m_bPreserveContentSize;
251 bool m_bMenuBarCloseButton;
252 css::awt::Rectangle m_aDockingArea;
253 css::uno::Reference< css::ui::XDockingAreaAcceptor > m_xDockingAreaAcceptor;
254 rtl::Reference< MenuBarManager > m_xInplaceMenuBar;
255 rtl::Reference< MenuBarWrapper > m_xMenuBar;
256 UIElement m_aStatusBarElement;
257 UIElement m_aProgressBarElement;
258 rtl::Reference< ProgressBarWrapper > m_xProgressBarBackup;
259 css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager;
260 css::uno::Reference< css::ui::XUIElementFactoryManager > m_xUIElementFactoryManager;
261 css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState;
262 css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowStateSupplier;
263 std::unique_ptr<GlobalSettings> m_pGlobalSettings;
264 OUString m_aModuleIdentifier;
265 Timer m_aAsyncLayoutTimer;
266 comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer; // container for ALL Listener
267 rtl::Reference< ToolbarLayoutManager > m_xToolbarManager;
269 friend class detail::InfoHelperBuilder;
272 } // namespace framework
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */