bump product version to 7.6.3.2-android
[LibreOffice.git] / framework / source / layoutmanager / layoutmanager.cxx
blob13a21a7b77146a63b0b3a91b623bd8769af55014
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 #include <memory>
21 #include <config_feature_desktop.h>
23 #include <properties.h>
24 #include <services/layoutmanager.hxx>
25 #include "helpers.hxx"
27 #include <framework/sfxhelperfunctions.hxx>
28 #include <uielement/menubarwrapper.hxx>
29 #include <uielement/progressbarwrapper.hxx>
30 #include <uiconfiguration/globalsettings.hxx>
31 #include <uiconfiguration/windowstateproperties.hxx>
32 #include "toolbarlayoutmanager.hxx"
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/frame/ModuleManager.hpp>
37 #include <com/sun/star/frame/XModel.hpp>
38 #include <com/sun/star/frame/FrameAction.hpp>
39 #include <com/sun/star/awt/PosSize.hpp>
40 #include <com/sun/star/awt/XDevice.hpp>
41 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
42 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
43 #include <com/sun/star/ui/theWindowStateConfiguration.hpp>
44 #include <com/sun/star/ui/theUIElementFactoryManager.hpp>
45 #include <com/sun/star/container/XNameReplace.hpp>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/frame/LayoutManagerEvents.hpp>
48 #include <com/sun/star/frame/XDispatchProvider.hpp>
49 #include <com/sun/star/frame/DispatchHelper.hpp>
50 #include <com/sun/star/lang/DisposedException.hpp>
51 #include <com/sun/star/util/URLTransformer.hpp>
53 #include <comphelper/lok.hxx>
54 #include <comphelper/propertyvalue.hxx>
55 #include <vcl/status.hxx>
56 #include <vcl/settings.hxx>
57 #include <vcl/window.hxx>
58 #include <vcl/svapp.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <toolkit/awt/vclxmenu.hxx>
61 #include <comphelper/uno3.hxx>
62 #include <officecfg/Office/Compatibility.hxx>
64 #include <rtl/ref.hxx>
65 #include <sal/log.hxx>
66 #include <o3tl/string_view.hxx>
68 #include <algorithm>
70 // using namespace
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::ui;
78 using namespace ::com::sun::star::frame;
80 constexpr OUStringLiteral STATUS_BAR_ALIAS = u"private:resource/statusbar/statusbar";
82 namespace framework
85 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LayoutManager, LayoutManager_Base, LayoutManager_PBase )
86 IMPLEMENT_FORWARD_XINTERFACE2( LayoutManager, LayoutManager_Base, LayoutManager_PBase )
88 LayoutManager::LayoutManager( const Reference< XComponentContext >& xContext ) :
89 ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >(m_aMutex)
90 , LayoutManager_PBase( *static_cast< ::cppu::OBroadcastHelper* >(this) )
91 , m_xContext( xContext )
92 , m_xURLTransformer( URLTransformer::create(xContext) )
93 , m_nLockCount( 0 )
94 , m_bInplaceMenuSet( false )
95 , m_bMenuVisible( true )
96 , m_bVisible( true )
97 , m_bParentWindowVisible( false )
98 , m_bMustDoLayout( true )
99 #if HAVE_FEATURE_DESKTOP
100 , m_bAutomaticToolbars( true )
101 #else
102 , m_bAutomaticToolbars( false )
103 #endif
104 , m_bHideCurrentUI( false )
105 , m_bGlobalSettings( false )
106 , m_bPreserveContentSize( false )
107 , m_bMenuBarCloseButton( false )
108 , m_xModuleManager( ModuleManager::create( xContext ))
109 , m_xUIElementFactoryManager( ui::theUIElementFactoryManager::get(xContext) )
110 , m_xPersistentWindowStateSupplier( ui::theWindowStateConfiguration::get( xContext ) )
111 , m_aAsyncLayoutTimer( "framework::LayoutManager m_aAsyncLayoutTimer" )
112 , m_aListenerContainer( m_aMutex )
114 // Initialize statusbar member
115 m_aStatusBarElement.m_aType = "statusbar";
116 m_aStatusBarElement.m_aName = STATUS_BAR_ALIAS;
118 if (!comphelper::LibreOfficeKit::isActive())
120 m_xToolbarManager = new ToolbarLayoutManager( xContext, Reference<XUIElementFactory>(m_xUIElementFactoryManager, UNO_QUERY_THROW), this );
123 m_aAsyncLayoutTimer.SetPriority( TaskPriority::HIGH_IDLE );
124 m_aAsyncLayoutTimer.SetTimeout( 50 );
125 m_aAsyncLayoutTimer.SetInvokeHandler( LINK( this, LayoutManager, AsyncLayoutHdl ) );
127 registerProperty( LAYOUTMANAGER_PROPNAME_ASCII_AUTOMATICTOOLBARS, LAYOUTMANAGER_PROPHANDLE_AUTOMATICTOOLBARS, css::beans::PropertyAttribute::TRANSIENT, &m_bAutomaticToolbars, cppu::UnoType<decltype(m_bAutomaticToolbars)>::get() );
128 registerProperty( LAYOUTMANAGER_PROPNAME_ASCII_HIDECURRENTUI, LAYOUTMANAGER_PROPHANDLE_HIDECURRENTUI, beans::PropertyAttribute::TRANSIENT, &m_bHideCurrentUI, cppu::UnoType<decltype(m_bHideCurrentUI)>::get() );
129 registerProperty( LAYOUTMANAGER_PROPNAME_ASCII_LOCKCOUNT, LAYOUTMANAGER_PROPHANDLE_LOCKCOUNT, beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY, &m_nLockCount, cppu::UnoType<decltype(m_nLockCount)>::get() );
130 registerProperty( LAYOUTMANAGER_PROPNAME_MENUBARCLOSER, LAYOUTMANAGER_PROPHANDLE_MENUBARCLOSER, beans::PropertyAttribute::TRANSIENT, &m_bMenuBarCloseButton, cppu::UnoType<decltype(m_bMenuBarCloseButton)>::get() );
131 registerPropertyNoMember( LAYOUTMANAGER_PROPNAME_ASCII_REFRESHVISIBILITY, LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY, beans::PropertyAttribute::TRANSIENT, cppu::UnoType<bool>::get(), css::uno::Any(false) );
132 registerProperty( LAYOUTMANAGER_PROPNAME_ASCII_PRESERVE_CONTENT_SIZE, LAYOUTMANAGER_PROPHANDLE_PRESERVE_CONTENT_SIZE, beans::PropertyAttribute::TRANSIENT, &m_bPreserveContentSize, cppu::UnoType<decltype(m_bPreserveContentSize)>::get() );
133 registerPropertyNoMember( LAYOUTMANAGER_PROPNAME_ASCII_REFRESHTOOLTIP, LAYOUTMANAGER_PROPHANDLE_REFRESHTOOLTIP, beans::PropertyAttribute::TRANSIENT, cppu::UnoType<bool>::get(), css::uno::Any(false) );
136 LayoutManager::~LayoutManager()
138 m_aAsyncLayoutTimer.Stop();
139 setDockingAreaAcceptor(nullptr);
140 m_pGlobalSettings.reset();
143 void LayoutManager::implts_createMenuBar(const OUString& rMenuBarName)
145 SolarMutexGuard aWriteLock;
147 // Create a customized menu if compatibility mode is on
148 if (m_aModuleIdentifier == "com.sun.star.text.TextDocument" && officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::get())
150 implts_createMSCompatibleMenuBar(rMenuBarName);
153 // Create the default menubar otherwise
154 if (m_bInplaceMenuSet || m_xMenuBar.is())
155 return;
157 m_xMenuBar = implts_createElement( rMenuBarName );
158 if ( !m_xMenuBar.is() )
159 return;
161 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
162 if ( !pSysWindow )
163 return;
165 Reference< awt::XMenuBar > xMenuBar;
167 Reference< XPropertySet > xPropSet( m_xMenuBar, UNO_QUERY );
168 if ( xPropSet.is() )
172 xPropSet->getPropertyValue("XMenuBar") >>= xMenuBar;
174 catch (const beans::UnknownPropertyException&)
177 catch (const lang::WrappedTargetException&)
182 if ( !xMenuBar.is() )
183 return;
185 VCLXMenu* pAwtMenuBar = dynamic_cast<VCLXMenu*>( xMenuBar.get() );
186 if ( pAwtMenuBar )
188 MenuBar* pMenuBar = static_cast<MenuBar*>(pAwtMenuBar->GetMenu());
189 if ( pMenuBar )
191 pSysWindow->SetMenuBar(pMenuBar);
192 pMenuBar->SetDisplayable( m_bMenuVisible );
193 implts_updateMenuBarClose();
198 // Internal helper function
199 void LayoutManager::impl_clearUpMenuBar()
201 implts_lock();
203 // Clear up VCL menu bar to prepare shutdown
204 if ( m_xContainerWindow.is() )
206 SolarMutexGuard aGuard;
208 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
209 if ( pSysWindow )
211 MenuBar* pSetMenuBar = nullptr;
212 if ( m_xInplaceMenuBar.is() )
213 pSetMenuBar = static_cast<MenuBar *>(m_xInplaceMenuBar->GetMenuBar());
214 else
216 Reference< awt::XMenuBar > xMenuBar;
218 Reference< XPropertySet > xPropSet( m_xMenuBar, UNO_QUERY );
219 if ( xPropSet.is() )
223 xPropSet->getPropertyValue("XMenuBar") >>= xMenuBar;
225 catch (const beans::UnknownPropertyException&)
228 catch (const lang::WrappedTargetException&)
233 VCLXMenu* pAwtMenuBar = dynamic_cast<VCLXMenu*>( xMenuBar.get() );
234 if ( pAwtMenuBar )
235 pSetMenuBar = static_cast<MenuBar*>(pAwtMenuBar->GetMenu());
238 MenuBar* pTopMenuBar = pSysWindow->GetMenuBar();
239 if ( pSetMenuBar == pTopMenuBar )
240 pSysWindow->SetMenuBar( nullptr );
244 // reset inplace menubar manager
245 VclPtr<Menu> pMenuBar;
246 if (m_xInplaceMenuBar.is())
248 pMenuBar = m_xInplaceMenuBar->GetMenuBar();
249 m_xInplaceMenuBar->dispose();
250 m_xInplaceMenuBar.clear();
252 pMenuBar.disposeAndClear();
253 m_bInplaceMenuSet = false;
255 Reference< XComponent > xComp( m_xMenuBar, UNO_QUERY );
256 if ( xComp.is() )
257 xComp->dispose();
258 m_xMenuBar.clear();
259 implts_unlock();
262 void LayoutManager::implts_lock()
264 SolarMutexGuard g;
265 ++m_nLockCount;
268 bool LayoutManager::implts_unlock()
270 SolarMutexGuard g;
271 m_nLockCount = std::max( m_nLockCount-1, static_cast<sal_Int32>(0) );
272 return ( m_nLockCount == 0 );
275 void LayoutManager::implts_reset( bool bAttached )
277 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
278 SolarMutexClearableGuard aReadLock;
279 Reference< XFrame > xFrame = m_xFrame;
280 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
281 Reference< XUIConfiguration > xModuleCfgMgr( m_xModuleCfgMgr, UNO_QUERY );
282 Reference< XUIConfiguration > xDocCfgMgr( m_xDocCfgMgr, UNO_QUERY );
283 Reference< XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
284 Reference< XComponentContext > xContext( m_xContext );
285 Reference< XNameAccess > xPersistentWindowStateSupplier( m_xPersistentWindowStateSupplier );
286 rtl::Reference<ToolbarLayoutManager> xToolbarManager( m_xToolbarManager );
287 OUString aModuleIdentifier( m_aModuleIdentifier );
288 bool bAutomaticToolbars( m_bAutomaticToolbars );
289 aReadLock.clear();
290 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
292 implts_lock();
294 Reference< XModel > xModel;
295 if ( xFrame.is() )
297 if ( bAttached )
299 OUString aOldModuleIdentifier( aModuleIdentifier );
302 aModuleIdentifier = m_xModuleManager->identify( xFrame );
304 catch( const Exception& ) {}
306 if ( !aModuleIdentifier.isEmpty() && aOldModuleIdentifier != aModuleIdentifier )
308 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier;
309 if ( xContext.is() )
310 xModuleCfgSupplier = theModuleUIConfigurationManagerSupplier::get( xContext );
312 if ( xModuleCfgMgr.is() )
316 // Remove listener to old module ui configuration manager
317 xModuleCfgMgr->removeConfigurationListener( Reference< XUIConfigurationListener >(this) );
319 catch (const Exception&)
326 // Add listener to new module ui configuration manager
327 xModuleCfgMgr.set( xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier ), UNO_QUERY );
328 if ( xModuleCfgMgr.is() )
329 xModuleCfgMgr->addConfigurationListener( Reference< XUIConfigurationListener >(this) );
331 catch (const Exception&)
337 // Retrieve persistent window state reference for our new module
338 if ( xPersistentWindowStateSupplier.is() )
339 xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= xPersistentWindowState;
341 catch (const NoSuchElementException&)
344 catch (const WrappedTargetException&)
349 xModel = impl_getModelFromFrame( xFrame );
350 if ( xModel.is() )
352 Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
353 if ( xUIConfigurationManagerSupplier.is() )
355 if ( xDocCfgMgr.is() )
359 // Remove listener to old ui configuration manager
360 xDocCfgMgr->removeConfigurationListener( Reference< XUIConfigurationListener >(this) );
362 catch (const Exception&)
369 xDocCfgMgr.set( xUIConfigurationManagerSupplier->getUIConfigurationManager(), UNO_QUERY );
370 if ( xDocCfgMgr.is() )
371 xDocCfgMgr->addConfigurationListener( Reference< XUIConfigurationListener >(this) );
373 catch (const Exception&)
379 else
381 // Remove configuration listeners before we can release our references
382 if ( xModuleCfgMgr.is() )
386 xModuleCfgMgr->removeConfigurationListener(
387 Reference< XUIConfigurationListener >(this) );
389 catch (const Exception&)
394 if ( xDocCfgMgr.is() )
398 xDocCfgMgr->removeConfigurationListener(
399 Reference< XUIConfigurationListener >(this) );
401 catch (const Exception&)
406 // Release references to our configuration managers as we currently don't have
407 // an attached module.
408 xModuleCfgMgr.clear();
409 xDocCfgMgr.clear();
410 xPersistentWindowState.clear();
411 aModuleIdentifier.clear();
414 Reference< XUIConfigurationManager > xModCfgMgr( xModuleCfgMgr, UNO_QUERY );
415 Reference< XUIConfigurationManager > xDokCfgMgr( xDocCfgMgr, UNO_QUERY );
417 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
418 SolarMutexClearableGuard aWriteLock;
419 m_aDockingArea = awt::Rectangle();
420 m_aModuleIdentifier = aModuleIdentifier;
421 m_xModuleCfgMgr = xModCfgMgr;
422 m_xDocCfgMgr = xDokCfgMgr;
423 m_xPersistentWindowState = xPersistentWindowState;
424 m_aStatusBarElement.m_bStateRead = false; // reset state to read data again!
425 aWriteLock.clear();
426 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
428 // reset/notify toolbar layout manager
429 if ( xToolbarManager.is() )
431 if ( bAttached )
433 xToolbarManager->attach( xFrame, xModCfgMgr, xDokCfgMgr, xPersistentWindowState );
434 uno::Reference< awt::XVclWindowPeer > xParent( xContainerWindow, UNO_QUERY );
435 xToolbarManager->setParentWindow( xParent );
436 if ( bAutomaticToolbars )
437 xToolbarManager->createStaticToolbars();
439 else
441 xToolbarManager->reset();
442 implts_destroyElements();
447 implts_unlock();
450 bool LayoutManager::implts_isEmbeddedLayoutManager() const
452 SolarMutexClearableGuard aReadLock;
453 Reference< XFrame > xFrame = m_xFrame;
454 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
455 aReadLock.clear();
457 Reference< awt::XWindow > xFrameContainerWindow = xFrame->getContainerWindow();
458 return xFrameContainerWindow != xContainerWindow;
461 void LayoutManager::implts_destroyElements()
463 SolarMutexResettableGuard aWriteLock;
464 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
465 aWriteLock.clear();
467 if ( pToolbarManager )
468 pToolbarManager->destroyToolbars();
470 implts_destroyStatusBar();
472 aWriteLock.reset();
473 impl_clearUpMenuBar();
474 aWriteLock.clear();
477 void LayoutManager::implts_toggleFloatingUIElementsVisibility( bool bActive )
479 SolarMutexClearableGuard aReadLock;
480 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
481 aReadLock.clear();
483 if ( pToolbarManager )
484 pToolbarManager->setFloatingToolbarsVisibility( bActive );
487 uno::Reference< ui::XUIElement > LayoutManager::implts_findElement( std::u16string_view aName )
489 OUString aElementType;
490 OUString aElementName;
492 parseResourceURL( aName, aElementType, aElementName );
493 if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
494 aElementName.equalsIgnoreAsciiCase("menubar") )
495 return m_xMenuBar;
496 else if (( aElementType.equalsIgnoreAsciiCase("statusbar") &&
497 aElementName.equalsIgnoreAsciiCase("statusbar") ) ||
498 ( m_aStatusBarElement.m_aName == aName ))
499 return m_aStatusBarElement.m_xUIElement;
500 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
501 aElementName.equalsIgnoreAsciiCase("progressbar") )
502 return m_aProgressBarElement.m_xUIElement;
504 return uno::Reference< ui::XUIElement >();
507 bool LayoutManager::implts_readWindowStateData( const OUString& aName, UIElement& rElementData )
509 return readWindowStateData( aName, rElementData, m_xPersistentWindowState,
510 m_pGlobalSettings, m_bGlobalSettings, m_xContext );
513 bool LayoutManager::readWindowStateData( const OUString& aName, UIElement& rElementData,
514 const Reference< XNameAccess > &rPersistentWindowState,
515 std::unique_ptr<GlobalSettings> &rGlobalSettings, bool &bInGlobalSettings,
516 const Reference< XComponentContext > &rComponentContext )
518 if ( !rPersistentWindowState.is() )
519 return false;
521 bool bGetSettingsState( false );
523 SolarMutexClearableGuard aWriteLock;
524 bool bGlobalSettings( bInGlobalSettings );
525 if ( rGlobalSettings == nullptr )
527 rGlobalSettings.reset( new GlobalSettings( rComponentContext ) );
528 bGetSettingsState = true;
530 GlobalSettings* pGlobalSettings = rGlobalSettings.get();
531 aWriteLock.clear();
535 Sequence< PropertyValue > aWindowState;
536 if ( rPersistentWindowState->hasByName( aName ) && (rPersistentWindowState->getByName( aName ) >>= aWindowState) )
538 bool bValue( false );
539 for ( PropertyValue const & rProp : std::as_const(aWindowState) )
541 if ( rProp.Name == WINDOWSTATE_PROPERTY_DOCKED )
543 if ( rProp.Value >>= bValue )
544 rElementData.m_bFloating = !bValue;
546 else if ( rProp.Name == WINDOWSTATE_PROPERTY_VISIBLE )
548 if ( rProp.Value >>= bValue )
549 rElementData.m_bVisible = bValue;
551 else if ( rProp.Name == WINDOWSTATE_PROPERTY_DOCKINGAREA )
553 ui::DockingArea eDockingArea;
554 if ( rProp.Value >>= eDockingArea )
555 rElementData.m_aDockedData.m_nDockedArea = eDockingArea;
557 else if ( rProp.Name == WINDOWSTATE_PROPERTY_DOCKPOS )
559 awt::Point aPoint;
560 if (rProp.Value >>= aPoint)
562 //tdf#90256 repair these broken Docking positions
563 if (aPoint.X < 0)
564 aPoint.X = SAL_MAX_INT32;
565 if (aPoint.Y < 0)
566 aPoint.Y = SAL_MAX_INT32;
567 rElementData.m_aDockedData.m_aPos = aPoint;
570 else if ( rProp.Name == WINDOWSTATE_PROPERTY_POS )
572 awt::Point aPoint;
573 if ( rProp.Value >>= aPoint )
574 rElementData.m_aFloatingData.m_aPos = aPoint;
576 else if ( rProp.Name == WINDOWSTATE_PROPERTY_SIZE )
578 awt::Size aSize;
579 if ( rProp.Value >>= aSize )
580 rElementData.m_aFloatingData.m_aSize = aSize;
582 else if ( rProp.Name == WINDOWSTATE_PROPERTY_UINAME )
583 rProp.Value >>= rElementData.m_aUIName;
584 else if ( rProp.Name == WINDOWSTATE_PROPERTY_STYLE )
586 sal_Int32 nStyle = 0;
587 if ( rProp.Value >>= nStyle )
588 rElementData.m_nStyle = static_cast<ButtonType>( nStyle );
590 else if ( rProp.Name == WINDOWSTATE_PROPERTY_LOCKED )
592 if ( rProp.Value >>= bValue )
593 rElementData.m_aDockedData.m_bLocked = bValue;
595 else if ( rProp.Name == WINDOWSTATE_PROPERTY_CONTEXT )
597 if ( rProp.Value >>= bValue )
598 rElementData.m_bContextSensitive = bValue;
600 else if ( rProp.Name == WINDOWSTATE_PROPERTY_NOCLOSE )
602 if ( rProp.Value >>= bValue )
603 rElementData.m_bNoClose = bValue;
608 // oversteer values with global settings
609 if (bGetSettingsState || bGlobalSettings)
611 if ( pGlobalSettings->HasToolbarStatesInfo())
614 SolarMutexGuard aWriteLock2;
615 bInGlobalSettings = true;
618 uno::Any aValue;
619 if ( pGlobalSettings->GetToolbarStateInfo(
620 GlobalSettings::STATEINFO_LOCKED,
621 aValue ))
622 aValue >>= rElementData.m_aDockedData.m_bLocked;
623 if ( pGlobalSettings->GetToolbarStateInfo(
624 GlobalSettings::STATEINFO_DOCKED,
625 aValue ))
627 bool bValue;
628 if ( aValue >>= bValue )
629 rElementData.m_bFloating = !bValue;
634 const bool bDockingSupportCrippled = !StyleSettings::GetDockingFloatsSupported();
635 if (bDockingSupportCrippled)
636 rElementData.m_bFloating = false;
638 return true;
640 catch (const NoSuchElementException&)
644 return false;
647 void LayoutManager::implts_writeWindowStateData( const OUString& aName, const UIElement& rElementData )
649 SolarMutexClearableGuard aWriteLock;
650 Reference< XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
652 aWriteLock.clear();
654 bool bPersistent( false );
655 Reference< XPropertySet > xPropSet( rElementData.m_xUIElement, UNO_QUERY );
656 if ( xPropSet.is() )
660 // Check persistent flag of the user interface element
661 xPropSet->getPropertyValue("Persistent") >>= bPersistent;
663 catch (const beans::UnknownPropertyException&)
665 // Non-configurable elements should at least store their dimension/position
666 bPersistent = true;
668 catch (const lang::WrappedTargetException&)
673 if ( !(bPersistent && xPersistentWindowState.is()) )
674 return;
678 Sequence< PropertyValue > aWindowState{
679 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_DOCKED, !rElementData.m_bFloating),
680 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_VISIBLE, rElementData.m_bVisible),
681 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_DOCKINGAREA,
682 rElementData.m_aDockedData.m_nDockedArea),
683 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_DOCKPOS,
684 rElementData.m_aDockedData.m_aPos),
685 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_POS,
686 rElementData.m_aFloatingData.m_aPos),
687 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_SIZE,
688 rElementData.m_aFloatingData.m_aSize),
689 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_UINAME, rElementData.m_aUIName),
690 comphelper::makePropertyValue(WINDOWSTATE_PROPERTY_LOCKED,
691 rElementData.m_aDockedData.m_bLocked)
694 if ( xPersistentWindowState->hasByName( aName ))
696 Reference< XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY );
697 xReplace->replaceByName( aName, Any( aWindowState ));
699 else
701 Reference< XNameContainer > xInsert( xPersistentWindowState, uno::UNO_QUERY );
702 xInsert->insertByName( aName, Any( aWindowState ));
705 catch (const Exception&)
710 ::Size LayoutManager::implts_getContainerWindowOutputSize()
712 ::Size aContainerWinSize;
713 vcl::Window* pContainerWindow( nullptr );
715 // Retrieve output size from container Window
716 SolarMutexGuard aGuard;
717 pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
718 if ( pContainerWindow )
719 aContainerWinSize = pContainerWindow->GetOutputSizePixel();
721 return aContainerWinSize;
724 Reference< XUIElement > LayoutManager::implts_createElement( const OUString& aName )
726 Reference< ui::XUIElement > xUIElement;
728 SolarMutexGuard g;
729 Sequence< PropertyValue > aPropSeq{ comphelper::makePropertyValue("Frame", m_xFrame),
730 comphelper::makePropertyValue("Persistent", true) };
734 xUIElement = m_xUIElementFactoryManager->createUIElement( aName, aPropSeq );
736 catch (const NoSuchElementException&)
739 catch (const IllegalArgumentException&)
743 return xUIElement;
746 void LayoutManager::implts_setVisibleState( bool bShow )
749 SolarMutexGuard aWriteLock;
750 m_aStatusBarElement.m_bMasterHide = !bShow;
753 implts_updateUIElementsVisibleState( bShow );
756 void LayoutManager::implts_updateUIElementsVisibleState( bool bSetVisible )
758 // notify listeners
759 uno::Any a;
760 if ( bSetVisible )
761 implts_notifyListeners( frame::LayoutManagerEvents::VISIBLE, a );
762 else
763 implts_notifyListeners( frame::LayoutManagerEvents::INVISIBLE, a );
765 SolarMutexResettableGuard aWriteLock;
766 Reference< XUIElement > xMenuBar = m_xMenuBar;
767 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
768 rtl::Reference< MenuBarManager > xInplaceMenuBar( m_xInplaceMenuBar );
769 aWriteLock.clear();
771 if (( xMenuBar.is() || xInplaceMenuBar.is() ) && xContainerWindow.is() )
773 SolarMutexGuard aGuard;
775 MenuBar* pMenuBar( nullptr );
776 if ( xInplaceMenuBar.is() )
777 pMenuBar = static_cast<MenuBar *>(xInplaceMenuBar->GetMenuBar());
778 else
780 MenuBarWrapper* pMenuBarWrapper = static_cast< MenuBarWrapper* >(xMenuBar.get());
781 pMenuBar = static_cast<MenuBar *>(pMenuBarWrapper->GetMenuBarManager()->GetMenuBar());
784 SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
785 if ( pSysWindow )
787 if ( bSetVisible )
789 pSysWindow->SetMenuBar(pMenuBar);
791 else
792 pSysWindow->SetMenuBar( nullptr );
796 bool bMustDoLayout;
797 // Hide/show the statusbar according to bSetVisible
798 if ( bSetVisible )
799 bMustDoLayout = !implts_showStatusBar();
800 else
801 bMustDoLayout = !implts_hideStatusBar();
803 aWriteLock.reset();
804 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
805 aWriteLock.clear();
807 if ( pToolbarManager )
809 pToolbarManager->setVisible( bSetVisible );
810 bMustDoLayout = pToolbarManager->isLayoutDirty();
813 if ( bMustDoLayout )
814 implts_doLayout_notify( false );
817 void LayoutManager::implts_setCurrentUIVisibility( bool bShow )
820 SolarMutexGuard aWriteLock;
821 if (!bShow && m_aStatusBarElement.m_bVisible && m_aStatusBarElement.m_xUIElement.is())
822 m_aStatusBarElement.m_bMasterHide = true;
823 else if (bShow && m_aStatusBarElement.m_bVisible)
824 m_aStatusBarElement.m_bMasterHide = false;
827 implts_updateUIElementsVisibleState( bShow );
830 void LayoutManager::implts_destroyStatusBar()
832 Reference< XComponent > xCompStatusBar;
834 SolarMutexClearableGuard aWriteLock;
835 m_aStatusBarElement.m_aName.clear();
836 xCompStatusBar.set( m_aStatusBarElement.m_xUIElement, UNO_QUERY );
837 m_aStatusBarElement.m_xUIElement.clear();
838 aWriteLock.clear();
840 if ( xCompStatusBar.is() )
841 xCompStatusBar->dispose();
843 implts_destroyProgressBar();
846 void LayoutManager::implts_createStatusBar( const OUString& aStatusBarName )
849 SolarMutexGuard aWriteLock;
850 if (!m_aStatusBarElement.m_xUIElement.is())
852 implts_readStatusBarState(aStatusBarName);
853 m_aStatusBarElement.m_aName = aStatusBarName;
854 m_aStatusBarElement.m_xUIElement = implts_createElement(aStatusBarName);
858 implts_createProgressBar();
861 void LayoutManager::implts_readStatusBarState( const OUString& rStatusBarName )
863 SolarMutexGuard g;
864 if ( !m_aStatusBarElement.m_bStateRead )
866 // Read persistent data for status bar if not yet read!
867 if ( implts_readWindowStateData( rStatusBarName, m_aStatusBarElement ))
868 m_aStatusBarElement.m_bStateRead = true;
872 void LayoutManager::implts_createProgressBar()
874 Reference< XUIElement > xStatusBar;
875 Reference< XUIElement > xProgressBar;
876 Reference< XUIElement > xProgressBarBackup;
877 Reference< awt::XWindow > xContainerWindow;
879 SolarMutexResettableGuard aWriteLock;
880 xStatusBar = m_aStatusBarElement.m_xUIElement;
881 xProgressBar = m_aProgressBarElement.m_xUIElement;
882 xProgressBarBackup = m_xProgressBarBackup;
883 m_xProgressBarBackup.clear();
884 xContainerWindow = m_xContainerWindow;
885 aWriteLock.clear();
887 bool bRecycled = xProgressBarBackup.is();
888 rtl::Reference<ProgressBarWrapper> pWrapper;
889 if ( bRecycled )
890 pWrapper = static_cast<ProgressBarWrapper*>(xProgressBarBackup.get());
891 else if ( xProgressBar.is() )
892 pWrapper = static_cast<ProgressBarWrapper*>(xProgressBar.get());
893 else
894 pWrapper = new ProgressBarWrapper();
896 if ( xStatusBar.is() )
898 Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
899 pWrapper->setStatusBar( xWindow );
901 else
903 Reference< awt::XWindow > xStatusBarWindow = pWrapper->getStatusBar();
905 SolarMutexGuard aGuard;
906 VclPtr<vcl::Window> pStatusBarWnd = VCLUnoHelper::GetWindow( xStatusBarWindow );
907 if ( !pStatusBarWnd )
909 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
910 if ( pWindow )
912 VclPtrInstance<StatusBar> pStatusBar( pWindow, WinBits( WB_LEFT | WB_3DLOOK ) );
913 Reference< awt::XWindow > xStatusBarWindow2( VCLUnoHelper::GetInterface( pStatusBar ));
914 pWrapper->setStatusBar( xStatusBarWindow2, true );
919 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
920 aWriteLock.reset();
921 m_aProgressBarElement.m_xUIElement = pWrapper;
922 aWriteLock.clear();
923 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
925 if ( bRecycled )
926 implts_showProgressBar();
929 void LayoutManager::implts_backupProgressBarWrapper()
931 SolarMutexGuard g;
933 if (m_xProgressBarBackup.is())
934 return;
936 // safe a backup copy of the current progress!
937 // This copy will be used automatically inside createProgressBar() which is called
938 // implicitly from implts_doLayout() .-)
939 m_xProgressBarBackup = m_aProgressBarElement.m_xUIElement;
941 // remove the relation between this old progress bar and our old status bar.
942 // Otherwise we work on disposed items ...
943 // The internal used ProgressBarWrapper can handle a NULL reference.
944 if ( m_xProgressBarBackup.is() )
946 ProgressBarWrapper* pWrapper = static_cast<ProgressBarWrapper*>(m_xProgressBarBackup.get());
947 if ( pWrapper )
948 pWrapper->setStatusBar( Reference< awt::XWindow >() );
951 // prevent us from dispose() the m_aProgressBarElement.m_xUIElement inside implts_reset()
952 m_aProgressBarElement.m_xUIElement.clear();
955 void LayoutManager::implts_destroyProgressBar()
957 // don't remove the progressbar in general
958 // We must reuse it if a new status bar is created later.
959 // Of course there exists one backup only.
960 // And further this backup will be released inside our dtor.
961 implts_backupProgressBarWrapper();
964 void LayoutManager::implts_setStatusBarPosSize( const ::Point& rPos, const ::Size& rSize )
966 Reference< XUIElement > xStatusBar;
967 Reference< XUIElement > xProgressBar;
968 Reference< awt::XWindow > xContainerWindow;
970 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
971 SolarMutexClearableGuard aReadLock;
972 xStatusBar = m_aStatusBarElement.m_xUIElement;
973 xProgressBar = m_aProgressBarElement.m_xUIElement;
974 xContainerWindow = m_xContainerWindow;
976 Reference< awt::XWindow > xWindow;
977 if ( xStatusBar.is() )
978 xWindow.set( xStatusBar->getRealInterface(), UNO_QUERY );
979 else if ( xProgressBar.is() )
981 ProgressBarWrapper* pWrapper = static_cast<ProgressBarWrapper*>(xProgressBar.get());
982 if ( pWrapper )
983 xWindow = pWrapper->getStatusBar();
985 aReadLock.clear();
986 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
988 if ( !xWindow.is() )
989 return;
991 SolarMutexGuard aGuard;
992 VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow( xContainerWindow );
993 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
994 if ( pParentWindow && ( pWindow && pWindow->GetType() == WindowType::STATUSBAR ))
996 vcl::Window* pOldParentWindow = pWindow->GetParent();
997 if ( pParentWindow != pOldParentWindow )
998 pWindow->SetParent( pParentWindow );
999 static_cast<StatusBar *>(pWindow.get())->SetPosSizePixel( rPos, rSize );
1003 bool LayoutManager::implts_showProgressBar()
1005 Reference< XUIElement > xStatusBar;
1006 Reference< XUIElement > xProgressBar;
1007 Reference< awt::XWindow > xWindow;
1009 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1010 SolarMutexGuard aWriteLock;
1011 xStatusBar = m_aStatusBarElement.m_xUIElement;
1012 xProgressBar = m_aProgressBarElement.m_xUIElement;
1013 bool bVisible( m_bVisible );
1015 m_aProgressBarElement.m_bVisible = true;
1016 if ( bVisible )
1018 if ( xStatusBar.is() && !m_aStatusBarElement.m_bMasterHide )
1020 xWindow.set( xStatusBar->getRealInterface(), UNO_QUERY );
1022 else if ( xProgressBar.is() )
1024 ProgressBarWrapper* pWrapper = static_cast<ProgressBarWrapper*>(xProgressBar.get());
1025 if ( pWrapper )
1026 xWindow = pWrapper->getStatusBar();
1030 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1031 if ( pWindow )
1033 if ( !pWindow->IsVisible() )
1035 implts_setOffset( pWindow->GetSizePixel().Height() );
1036 pWindow->Show();
1037 implts_doLayout_notify( false );
1039 return true;
1042 return false;
1045 bool LayoutManager::implts_hideProgressBar()
1047 Reference< XUIElement > xProgressBar;
1048 Reference< awt::XWindow > xWindow;
1049 bool bHideStatusBar( false );
1051 SolarMutexGuard g;
1052 xProgressBar = m_aProgressBarElement.m_xUIElement;
1054 bool bInternalStatusBar( false );
1055 if ( xProgressBar.is() )
1057 Reference< awt::XWindow > xStatusBar;
1058 ProgressBarWrapper* pWrapper = static_cast<ProgressBarWrapper*>(xProgressBar.get());
1059 if ( pWrapper )
1060 xWindow = pWrapper->getStatusBar();
1061 Reference< ui::XUIElement > xStatusBarElement = m_aStatusBarElement.m_xUIElement;
1062 if ( xStatusBarElement.is() )
1063 xStatusBar.set( xStatusBarElement->getRealInterface(), UNO_QUERY );
1064 bInternalStatusBar = xStatusBar != xWindow;
1066 m_aProgressBarElement.m_bVisible = false;
1067 implts_readStatusBarState( STATUS_BAR_ALIAS );
1068 bHideStatusBar = !m_aStatusBarElement.m_bVisible;
1070 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1071 if ( pWindow && pWindow->IsVisible() && ( bHideStatusBar || bInternalStatusBar ))
1073 implts_setOffset( 0 );
1074 pWindow->Hide();
1075 implts_doLayout_notify( false );
1076 return true;
1079 return false;
1082 bool LayoutManager::implts_showStatusBar( bool bStoreState )
1084 SolarMutexClearableGuard aWriteLock;
1085 Reference< ui::XUIElement > xStatusBar = m_aStatusBarElement.m_xUIElement;
1086 if ( bStoreState )
1087 m_aStatusBarElement.m_bVisible = true;
1088 aWriteLock.clear();
1090 if ( xStatusBar.is() )
1092 Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
1094 SolarMutexGuard aGuard;
1095 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1096 if ( pWindow && !pWindow->IsVisible() )
1098 implts_setOffset( pWindow->GetSizePixel().Height() );
1099 pWindow->Show();
1100 implts_doLayout_notify( false );
1101 return true;
1105 return false;
1108 bool LayoutManager::implts_hideStatusBar( bool bStoreState )
1110 SolarMutexClearableGuard aWriteLock;
1111 Reference< ui::XUIElement > xStatusBar = m_aStatusBarElement.m_xUIElement;
1112 if ( bStoreState )
1113 m_aStatusBarElement.m_bVisible = false;
1114 aWriteLock.clear();
1116 if ( xStatusBar.is() )
1118 Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
1120 SolarMutexGuard aGuard;
1121 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1122 if ( pWindow && pWindow->IsVisible() )
1124 implts_setOffset( 0 );
1125 pWindow->Hide();
1126 implts_doLayout_notify( false );
1127 return true;
1131 return false;
1134 void LayoutManager::implts_setOffset( const sal_Int32 nBottomOffset )
1136 if ( m_xToolbarManager.is() )
1137 m_xToolbarManager->setDockingAreaOffsets({ 0, 0, 0, nBottomOffset });
1140 void LayoutManager::implts_setInplaceMenuBar( const Reference< XIndexAccess >& xMergedMenuBar )
1142 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1143 SolarMutexClearableGuard aWriteLock;
1145 if ( m_bInplaceMenuSet )
1146 return;
1148 SolarMutexGuard aGuard;
1150 // Reset old inplace menubar!
1151 VclPtr<Menu> pOldMenuBar;
1152 if (m_xInplaceMenuBar.is())
1154 pOldMenuBar = m_xInplaceMenuBar->GetMenuBar();
1155 m_xInplaceMenuBar->dispose();
1156 m_xInplaceMenuBar.clear();
1158 pOldMenuBar.disposeAndClear();
1160 m_bInplaceMenuSet = false;
1162 if ( m_xFrame.is() && m_xContainerWindow.is() )
1164 Reference< XDispatchProvider > xDispatchProvider;
1166 VclPtr<MenuBar> pMenuBar = VclPtr<MenuBar>::Create();
1167 m_xInplaceMenuBar = new MenuBarManager( m_xContext, m_xFrame, m_xURLTransformer, xDispatchProvider, OUString(), pMenuBar, true );
1168 m_xInplaceMenuBar->SetItemContainer( xMergedMenuBar );
1170 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1171 if ( pSysWindow )
1172 pSysWindow->SetMenuBar(pMenuBar);
1174 m_bInplaceMenuSet = true;
1177 aWriteLock.clear();
1178 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1180 implts_updateMenuBarClose();
1183 void LayoutManager::implts_resetInplaceMenuBar()
1185 SolarMutexGuard g;
1186 m_bInplaceMenuSet = false;
1188 if ( m_xContainerWindow.is() )
1190 SolarMutexGuard aGuard;
1191 MenuBarWrapper* pMenuBarWrapper = static_cast< MenuBarWrapper* >(m_xMenuBar.get());
1192 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1193 if ( pSysWindow )
1195 if ( pMenuBarWrapper )
1196 pSysWindow->SetMenuBar(static_cast<MenuBar *>(pMenuBarWrapper->GetMenuBarManager()->GetMenuBar()));
1197 else
1198 pSysWindow->SetMenuBar(nullptr);
1202 // Remove inplace menu bar
1203 VclPtr<Menu> pMenuBar;
1204 if (m_xInplaceMenuBar.is())
1206 pMenuBar = m_xInplaceMenuBar->GetMenuBar();
1207 m_xInplaceMenuBar->dispose();
1208 m_xInplaceMenuBar.clear();
1210 pMenuBar.disposeAndClear();
1213 void SAL_CALL LayoutManager::attachFrame( const Reference< XFrame >& xFrame )
1215 SolarMutexGuard g;
1216 m_xFrame = xFrame;
1219 void SAL_CALL LayoutManager::reset()
1221 implts_reset( true );
1224 // XMenuBarMergingAcceptor
1226 sal_Bool SAL_CALL LayoutManager::setMergedMenuBar(
1227 const Reference< XIndexAccess >& xMergedMenuBar )
1229 implts_setInplaceMenuBar( xMergedMenuBar );
1231 uno::Any a;
1232 implts_notifyListeners( frame::LayoutManagerEvents::MERGEDMENUBAR, a );
1233 return true;
1236 void SAL_CALL LayoutManager::removeMergedMenuBar()
1238 implts_resetInplaceMenuBar();
1241 awt::Rectangle SAL_CALL LayoutManager::getCurrentDockingArea()
1243 SolarMutexGuard g;
1244 return m_aDockingArea;
1247 Reference< XDockingAreaAcceptor > SAL_CALL LayoutManager::getDockingAreaAcceptor()
1249 SolarMutexGuard g;
1250 return m_xDockingAreaAcceptor;
1253 void SAL_CALL LayoutManager::setDockingAreaAcceptor( const Reference< ui::XDockingAreaAcceptor >& xDockingAreaAcceptor )
1255 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1256 SolarMutexClearableGuard aWriteLock;
1258 if (( m_xDockingAreaAcceptor == xDockingAreaAcceptor ) || !m_xFrame.is() )
1259 return;
1261 // IMPORTANT: Be sure to stop layout timer if don't have a docking area acceptor!
1262 if ( !xDockingAreaAcceptor.is() )
1263 m_aAsyncLayoutTimer.Stop();
1265 bool bAutomaticToolbars( m_bAutomaticToolbars );
1267 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1269 if ( !xDockingAreaAcceptor.is() )
1270 m_aAsyncLayoutTimer.Stop();
1272 // Remove listener from old docking area acceptor
1273 if ( m_xDockingAreaAcceptor.is() )
1275 Reference< awt::XWindow > xWindow( m_xDockingAreaAcceptor->getContainerWindow() );
1276 if ( xWindow.is() && ( m_xFrame->getContainerWindow() != m_xContainerWindow || !xDockingAreaAcceptor.is() ) )
1277 xWindow->removeWindowListener( Reference< awt::XWindowListener >(this) );
1279 m_aDockingArea = awt::Rectangle();
1280 if ( pToolbarManager )
1281 pToolbarManager->resetDockingArea();
1283 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow( xWindow );
1284 if ( pContainerWindow )
1285 pContainerWindow->RemoveChildEventListener( LINK( this, LayoutManager, WindowEventListener ) );
1288 m_xDockingAreaAcceptor = xDockingAreaAcceptor;
1289 if ( m_xDockingAreaAcceptor.is() )
1291 m_aDockingArea = awt::Rectangle();
1292 m_xContainerWindow = m_xDockingAreaAcceptor->getContainerWindow();
1293 m_xContainerTopWindow.set( m_xContainerWindow, UNO_QUERY );
1294 m_xContainerWindow->addWindowListener( Reference< awt::XWindowListener >(this) );
1296 // we always must keep a connection to the window of our frame for resize events
1297 if ( m_xContainerWindow != m_xFrame->getContainerWindow() )
1298 m_xFrame->getContainerWindow()->addWindowListener( Reference< awt::XWindowListener >(this) );
1300 // #i37884# set initial visibility state - in the plugin case the container window is already shown
1301 // and we get no notification anymore
1303 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
1304 if( pContainerWindow )
1305 m_bParentWindowVisible = pContainerWindow->IsVisible();
1309 aWriteLock.clear();
1310 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1312 if ( xDockingAreaAcceptor.is() )
1314 SolarMutexGuard aGuard;
1316 // Add layout manager as listener to get notifications about toolbar button activities
1317 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
1318 if ( pContainerWindow )
1319 pContainerWindow->AddChildEventListener( LINK( this, LayoutManager, WindowEventListener ) );
1321 // We have now a new container window, reparent all child windows!
1322 implts_reparentChildWindows();
1324 else
1325 implts_destroyElements(); // remove all elements
1327 if ( pToolbarManager && xDockingAreaAcceptor.is() )
1329 if ( bAutomaticToolbars )
1331 lock();
1332 pToolbarManager->createStaticToolbars();
1333 unlock();
1335 implts_doLayout( true, false );
1339 void LayoutManager::implts_reparentChildWindows()
1341 SolarMutexResettableGuard aWriteLock;
1342 UIElement aStatusBarElement = m_aStatusBarElement;
1343 uno::Reference< awt::XWindow > xContainerWindow = m_xContainerWindow;
1344 aWriteLock.clear();
1346 uno::Reference< awt::XWindow > xStatusBarWindow;
1347 if ( aStatusBarElement.m_xUIElement.is() )
1351 xStatusBarWindow.set( aStatusBarElement.m_xUIElement->getRealInterface(), UNO_QUERY );
1353 catch (const RuntimeException&)
1355 throw;
1357 catch (const Exception&)
1362 if ( xStatusBarWindow.is() )
1364 SolarMutexGuard aGuard;
1365 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow );
1366 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xStatusBarWindow );
1367 if ( pWindow && pContainerWindow )
1368 pWindow->SetParent( pContainerWindow );
1371 implts_resetMenuBar();
1373 aWriteLock.reset();
1374 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1375 if ( pToolbarManager )
1376 pToolbarManager->setParentWindow( uno::Reference< awt::XVclWindowPeer >( xContainerWindow, uno::UNO_QUERY ));
1377 aWriteLock.clear();
1380 uno::Reference< ui::XUIElement > LayoutManager::implts_createDockingWindow( const OUString& aElementName )
1382 Reference< XUIElement > xUIElement = implts_createElement( aElementName );
1383 return xUIElement;
1386 IMPL_LINK( LayoutManager, WindowEventListener, VclWindowEvent&, rEvent, void )
1388 vcl::Window* pWindow = rEvent.GetWindow();
1389 if ( pWindow && pWindow->GetType() == WindowType::TOOLBOX )
1391 SolarMutexClearableGuard aReadLock;
1392 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
1393 aReadLock.clear();
1395 if ( pToolbarManager )
1396 pToolbarManager->childWindowEvent( &rEvent );
1400 void SAL_CALL LayoutManager::createElement( const OUString& aName )
1402 SAL_INFO( "fwk", "LayoutManager::createElement " << aName );
1404 SolarMutexClearableGuard aReadLock;
1405 Reference< XFrame > xFrame = m_xFrame;
1406 aReadLock.clear();
1408 if ( !xFrame.is() )
1409 return;
1411 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1412 SolarMutexClearableGuard aWriteLock;
1414 bool bMustBeLayouted( false );
1415 bool bNotify( false );
1417 bool bPreviewFrame;
1418 if (m_xToolbarManager.is())
1419 // Assumes that we created the ToolbarLayoutManager with our frame, if
1420 // not then we're somewhat fouled up ...
1421 bPreviewFrame = m_xToolbarManager->isPreviewFrame();
1422 else
1424 Reference< XModel > xModel( impl_getModelFromFrame( xFrame ) );
1425 bPreviewFrame = implts_isPreviewModel( xModel );
1428 if ( m_xContainerWindow.is() && !bPreviewFrame ) // no UI elements on preview frames
1430 OUString aElementType;
1431 OUString aElementName;
1433 parseResourceURL( aName, aElementType, aElementName );
1435 if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ) && m_xToolbarManager.is() )
1437 bNotify = m_xToolbarManager->createToolbar( aName );
1438 bMustBeLayouted = m_xToolbarManager->isLayoutDirty();
1440 else if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
1441 aElementName.equalsIgnoreAsciiCase("menubar") &&
1442 implts_isFrameOrWindowTop(xFrame) )
1444 implts_createMenuBar( aName );
1445 if (m_bMenuVisible)
1446 bNotify = true;
1448 aWriteLock.clear();
1450 else if ( aElementType.equalsIgnoreAsciiCase("statusbar") &&
1451 ( implts_isFrameOrWindowTop(xFrame) || implts_isEmbeddedLayoutManager() ))
1453 implts_createStatusBar( aName );
1454 bNotify = true;
1456 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
1457 aElementName.equalsIgnoreAsciiCase("progressbar") &&
1458 implts_isFrameOrWindowTop(xFrame) )
1460 implts_createProgressBar();
1461 bNotify = true;
1463 else if ( aElementType.equalsIgnoreAsciiCase("dockingwindow"))
1465 // Add layout manager as listener for docking and other window events
1466 uno::Reference< uno::XInterface > xThis( static_cast< OWeakObject* >(this), uno::UNO_QUERY );
1467 uno::Reference< ui::XUIElement > xUIElement( implts_createDockingWindow( aName ));
1469 if ( xUIElement.is() )
1471 impl_addWindowListeners( xThis, xUIElement );
1474 // The docking window is created by a factory method located in the sfx2 library.
1475 // CreateDockingWindow( xFrame, aElementName );
1479 if ( bMustBeLayouted )
1480 implts_doLayout_notify( true );
1482 if ( bNotify )
1484 // UI element is invisible - provide information to listeners
1485 implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::Any( aName ) );
1489 void SAL_CALL LayoutManager::destroyElement( const OUString& aName )
1491 SAL_INFO( "fwk", "LayoutManager::destroyElement " << aName );
1493 bool bMustBeLayouted(false);
1494 bool bNotify(false);
1495 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1497 SolarMutexClearableGuard aWriteLock;
1499 OUString aElementType;
1500 OUString aElementName;
1502 parseResourceURL(aName, aElementType, aElementName);
1504 if (aElementType.equalsIgnoreAsciiCase("menubar")
1505 && aElementName.equalsIgnoreAsciiCase("menubar"))
1507 if (!m_bInplaceMenuSet)
1509 impl_clearUpMenuBar();
1510 m_xMenuBar.clear();
1511 bNotify = true;
1514 else if ((aElementType.equalsIgnoreAsciiCase("statusbar")
1515 && aElementName.equalsIgnoreAsciiCase("statusbar"))
1516 || (m_aStatusBarElement.m_aName == aName))
1518 aWriteLock.clear();
1519 implts_destroyStatusBar();
1520 bMustBeLayouted = true;
1521 bNotify = true;
1523 else if (aElementType.equalsIgnoreAsciiCase("progressbar")
1524 && aElementName.equalsIgnoreAsciiCase("progressbar"))
1526 aWriteLock.clear();
1527 implts_createProgressBar();
1528 bMustBeLayouted = true;
1529 bNotify = true;
1531 else if (aElementType.equalsIgnoreAsciiCase(UIRESOURCETYPE_TOOLBAR)
1532 && m_xToolbarManager.is())
1534 aWriteLock.clear();
1535 bNotify = m_xToolbarManager->destroyToolbar(aName);
1536 bMustBeLayouted = m_xToolbarManager->isLayoutDirty();
1538 else if (aElementType.equalsIgnoreAsciiCase("dockingwindow"))
1540 uno::Reference<frame::XFrame> xFrame(m_xFrame);
1541 uno::Reference<XComponentContext> xContext(m_xContext);
1542 aWriteLock.clear();
1544 impl_setDockingWindowVisibility(xContext, xFrame, aElementName, false);
1545 bMustBeLayouted = false;
1546 bNotify = false;
1549 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1551 if ( bMustBeLayouted )
1552 doLayout();
1554 if ( bNotify )
1555 implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_INVISIBLE, uno::Any( aName ) );
1558 sal_Bool SAL_CALL LayoutManager::requestElement( const OUString& rResourceURL )
1560 bool bResult( false );
1561 bool bNotify( false );
1562 OUString aElementType;
1563 OUString aElementName;
1565 parseResourceURL( rResourceURL, aElementType, aElementName );
1567 SolarMutexClearableGuard aWriteLock;
1569 OString aResName = OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1570 SAL_INFO( "fwk", "LayoutManager::requestElement " << aResName );
1572 if (( aElementType.equalsIgnoreAsciiCase("statusbar") &&
1573 aElementName.equalsIgnoreAsciiCase("statusbar") ) ||
1574 ( m_aStatusBarElement.m_aName == rResourceURL ))
1576 implts_readStatusBarState( rResourceURL );
1577 if ( m_aStatusBarElement.m_bVisible && !m_aStatusBarElement.m_bMasterHide )
1579 aWriteLock.clear();
1580 createElement( rResourceURL );
1582 // There are some situation where we are not able to create an element.
1583 // Therefore we have to check the reference before further action.
1584 // See #i70019#
1585 uno::Reference< ui::XUIElement > xUIElement( m_aStatusBarElement.m_xUIElement );
1586 if ( xUIElement.is() )
1588 // we need VCL here to pass special flags to Show()
1589 SolarMutexGuard aGuard;
1590 Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY );
1591 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1592 if ( pWindow )
1594 pWindow->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate );
1595 bResult = true;
1596 bNotify = true;
1601 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
1602 aElementName.equalsIgnoreAsciiCase("progressbar") )
1604 aWriteLock.clear();
1605 implts_showProgressBar();
1606 bResult = true;
1607 bNotify = true;
1609 else if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ) && m_bVisible )
1611 bool bComponentAttached( !m_aModuleIdentifier.isEmpty() );
1612 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1613 aWriteLock.clear();
1615 if ( pToolbarManager && bComponentAttached )
1617 bNotify = pToolbarManager->requestToolbar( rResourceURL );
1620 else if ( aElementType.equalsIgnoreAsciiCase("dockingwindow"))
1622 uno::Reference< frame::XFrame > xFrame( m_xFrame );
1623 aWriteLock.clear();
1625 CreateDockingWindow( xFrame, aElementName );
1628 if ( bNotify )
1629 implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::Any( rResourceURL ) );
1631 return bResult;
1634 Reference< XUIElement > SAL_CALL LayoutManager::getElement( const OUString& aName )
1636 Reference< XUIElement > xUIElement = implts_findElement( aName );
1637 if ( !xUIElement.is() )
1639 SolarMutexClearableGuard aReadLock;
1640 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
1641 aReadLock.clear();
1643 if ( pToolbarManager )
1644 xUIElement = pToolbarManager->getToolbar( aName );
1647 return xUIElement;
1650 Sequence< Reference< ui::XUIElement > > SAL_CALL LayoutManager::getElements()
1652 SolarMutexClearableGuard aReadLock;
1653 uno::Reference< ui::XUIElement > xMenuBar( m_xMenuBar );
1654 uno::Reference< ui::XUIElement > xStatusBar( m_aStatusBarElement.m_xUIElement );
1655 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
1656 aReadLock.clear();
1658 Sequence< Reference< ui::XUIElement > > aSeq;
1659 if ( pToolbarManager )
1660 aSeq = pToolbarManager->getToolbars();
1662 sal_Int32 nSize = aSeq.getLength();
1663 sal_Int32 nMenuBarIndex(-1);
1664 sal_Int32 nStatusBarIndex(-1);
1665 if ( xMenuBar.is() )
1667 nMenuBarIndex = nSize;
1668 ++nSize;
1670 if ( xStatusBar.is() )
1672 nStatusBarIndex = nSize;
1673 ++nSize;
1676 aSeq.realloc(nSize);
1677 auto pSeq = aSeq.getArray();
1678 if ( nMenuBarIndex >= 0 )
1679 pSeq[nMenuBarIndex] = xMenuBar;
1680 if ( nStatusBarIndex >= 0 )
1681 pSeq[nStatusBarIndex] = xStatusBar;
1683 return aSeq;
1686 sal_Bool SAL_CALL LayoutManager::showElement( const OUString& aName )
1688 bool bResult( false );
1689 bool bNotify( false );
1690 bool bMustLayout( false );
1691 OUString aElementType;
1692 OUString aElementName;
1694 parseResourceURL( aName, aElementType, aElementName );
1696 OString aResName = OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1697 SAL_INFO( "fwk", "LayoutManager::showElement " << aResName );
1699 if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
1700 aElementName.equalsIgnoreAsciiCase("menubar") )
1703 SolarMutexGuard aWriteLock;
1704 m_bMenuVisible = true;
1707 bResult = implts_resetMenuBar();
1708 bNotify = bResult;
1710 else if (( aElementType.equalsIgnoreAsciiCase("statusbar") &&
1711 aElementName.equalsIgnoreAsciiCase("statusbar") ) ||
1712 ( m_aStatusBarElement.m_aName == aName ))
1714 SolarMutexClearableGuard aWriteLock;
1715 if ( m_aStatusBarElement.m_xUIElement.is() && !m_aStatusBarElement.m_bMasterHide &&
1716 implts_showStatusBar( true ))
1718 aWriteLock.clear();
1720 implts_writeWindowStateData( STATUS_BAR_ALIAS, m_aStatusBarElement );
1721 bMustLayout = true;
1722 bResult = true;
1723 bNotify = true;
1726 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
1727 aElementName.equalsIgnoreAsciiCase("progressbar") )
1729 bNotify = bResult = implts_showProgressBar();
1731 else if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
1733 SolarMutexClearableGuard aReadLock;
1734 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1735 aReadLock.clear();
1737 if ( pToolbarManager )
1739 bNotify = pToolbarManager->showToolbar( aName );
1740 bMustLayout = pToolbarManager->isLayoutDirty();
1743 else if ( aElementType.equalsIgnoreAsciiCase("dockingwindow"))
1745 SolarMutexClearableGuard aReadGuard;
1746 uno::Reference< frame::XFrame > xFrame( m_xFrame );
1747 uno::Reference< XComponentContext > xContext( m_xContext );
1748 aReadGuard.clear();
1750 impl_setDockingWindowVisibility( xContext, xFrame, aElementName, true );
1753 if ( bMustLayout )
1754 doLayout();
1756 if ( bNotify )
1757 implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::Any( aName ) );
1759 return bResult;
1762 sal_Bool SAL_CALL LayoutManager::hideElement( const OUString& aName )
1764 bool bNotify( false );
1765 bool bMustLayout( false );
1766 OUString aElementType;
1767 OUString aElementName;
1769 parseResourceURL( aName, aElementType, aElementName );
1770 OString aResName = OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1771 SAL_INFO( "fwk", "LayoutManager::hideElement " << aResName );
1773 if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
1774 aElementName.equalsIgnoreAsciiCase("menubar") )
1776 SolarMutexGuard g;
1778 if ( m_xContainerWindow.is() )
1780 m_bMenuVisible = false;
1782 SolarMutexGuard aGuard;
1783 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1784 if ( pSysWindow )
1786 MenuBar* pMenuBar = pSysWindow->GetMenuBar();
1787 if ( pMenuBar )
1789 pMenuBar->SetDisplayable( false );
1790 bNotify = true;
1795 else if (( aElementType.equalsIgnoreAsciiCase("statusbar") &&
1796 aElementName.equalsIgnoreAsciiCase("statusbar") ) ||
1797 ( m_aStatusBarElement.m_aName == aName ))
1799 SolarMutexGuard g;
1800 if ( m_aStatusBarElement.m_xUIElement.is() && !m_aStatusBarElement.m_bMasterHide &&
1801 implts_hideStatusBar( true ))
1803 implts_writeWindowStateData( STATUS_BAR_ALIAS, m_aStatusBarElement );
1804 bMustLayout = true;
1805 bNotify = true;
1808 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
1809 aElementName.equalsIgnoreAsciiCase("progressbar") )
1811 bNotify = implts_hideProgressBar();
1813 else if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
1815 SolarMutexClearableGuard aReadLock;
1816 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1817 aReadLock.clear();
1819 if ( pToolbarManager )
1821 bNotify = pToolbarManager->hideToolbar( aName );
1822 bMustLayout = pToolbarManager->isLayoutDirty();
1825 else if ( aElementType.equalsIgnoreAsciiCase("dockingwindow"))
1827 SolarMutexClearableGuard aReadGuard;
1828 uno::Reference< frame::XFrame > xFrame( m_xFrame );
1829 uno::Reference< XComponentContext > xContext( m_xContext );
1830 aReadGuard.clear();
1832 impl_setDockingWindowVisibility( xContext, xFrame, aElementName, false );
1835 if ( bMustLayout )
1836 doLayout();
1838 if ( bNotify )
1839 implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_INVISIBLE, uno::Any( aName ) );
1841 return false;
1844 sal_Bool SAL_CALL LayoutManager::dockWindow( const OUString& aName, DockingArea DockingArea, const awt::Point& Pos )
1846 OUString aElementType;
1847 OUString aElementName;
1849 parseResourceURL( aName, aElementType, aElementName );
1850 if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
1852 SolarMutexClearableGuard aReadLock;
1853 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1854 aReadLock.clear();
1856 if ( pToolbarManager )
1858 pToolbarManager->dockToolbar( aName, DockingArea, Pos );
1859 if ( pToolbarManager->isLayoutDirty() )
1860 doLayout();
1863 return false;
1866 sal_Bool SAL_CALL LayoutManager::dockAllWindows( ::sal_Int16 /*nElementType*/ )
1868 SolarMutexClearableGuard aReadLock;
1869 bool bResult( false );
1870 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1871 aReadLock.clear();
1873 if ( pToolbarManager )
1875 bResult = pToolbarManager->dockAllToolbars();
1876 if ( pToolbarManager->isLayoutDirty() )
1877 doLayout();
1879 return bResult;
1882 sal_Bool SAL_CALL LayoutManager::floatWindow( const OUString& aName )
1884 bool bResult( false );
1885 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1887 SolarMutexClearableGuard aReadLock;
1888 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1889 aReadLock.clear();
1891 if ( pToolbarManager )
1893 bResult = pToolbarManager->floatToolbar( aName );
1894 if ( pToolbarManager->isLayoutDirty() )
1895 doLayout();
1898 return bResult;
1901 sal_Bool SAL_CALL LayoutManager::lockWindow( const OUString& aName )
1903 bool bResult( false );
1904 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1906 SolarMutexClearableGuard aReadLock;
1907 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1908 aReadLock.clear();
1910 if ( pToolbarManager )
1912 bResult = pToolbarManager->lockToolbar( aName );
1913 if ( pToolbarManager->isLayoutDirty() )
1914 doLayout();
1917 return bResult;
1920 sal_Bool SAL_CALL LayoutManager::unlockWindow( const OUString& aName )
1922 bool bResult( false );
1923 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1925 SolarMutexClearableGuard aReadLock;
1926 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1927 aReadLock.clear();
1929 if ( pToolbarManager )
1931 bResult = pToolbarManager->unlockToolbar( aName );
1932 if ( pToolbarManager->isLayoutDirty() )
1933 doLayout();
1936 return bResult;
1939 void SAL_CALL LayoutManager::setElementSize( const OUString& aName, const awt::Size& aSize )
1941 if ( !o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1942 return;
1944 SolarMutexClearableGuard aReadLock;
1945 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
1946 aReadLock.clear();
1948 if ( pToolbarManager )
1950 pToolbarManager->setToolbarSize( aName, aSize );
1951 if ( pToolbarManager->isLayoutDirty() )
1952 doLayout();
1956 void SAL_CALL LayoutManager::setElementPos( const OUString& aName, const awt::Point& aPos )
1958 if ( !o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1959 return;
1961 SolarMutexClearableGuard aReadLock;
1962 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
1963 aReadLock.clear();
1965 if ( pToolbarManager )
1967 pToolbarManager->setToolbarPos( aName, aPos );
1968 if ( pToolbarManager->isLayoutDirty() )
1969 doLayout();
1973 void SAL_CALL LayoutManager::setElementPosSize( const OUString& aName, const awt::Point& aPos, const awt::Size& aSize )
1975 if ( !o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
1976 return;
1978 SolarMutexClearableGuard aReadLock;
1979 ToolbarLayoutManager* pToolbarManager( m_xToolbarManager.get() );
1980 aReadLock.clear();
1982 if ( pToolbarManager )
1984 pToolbarManager->setToolbarPosSize( aName, aPos, aSize );
1985 if ( pToolbarManager->isLayoutDirty() )
1986 doLayout();
1990 sal_Bool SAL_CALL LayoutManager::isElementVisible( const OUString& aName )
1992 OUString aElementType;
1993 OUString aElementName;
1995 parseResourceURL( aName, aElementType, aElementName );
1996 if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
1997 aElementName.equalsIgnoreAsciiCase("menubar") )
1999 SolarMutexResettableGuard aReadLock;
2000 if ( m_xContainerWindow.is() )
2002 aReadLock.clear();
2004 SolarMutexGuard aGuard;
2005 SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
2006 if ( pSysWindow )
2008 MenuBar* pMenuBar = pSysWindow->GetMenuBar();
2009 if ( pMenuBar && pMenuBar->IsDisplayable() )
2010 return true;
2012 else
2014 aReadLock.reset();
2015 return m_bMenuVisible;
2019 else if (( aElementType.equalsIgnoreAsciiCase("statusbar") &&
2020 aElementName.equalsIgnoreAsciiCase("statusbar") ) ||
2021 ( m_aStatusBarElement.m_aName == aName ))
2023 if ( m_aStatusBarElement.m_xUIElement.is() )
2025 Reference< awt::XWindow > xWindow( m_aStatusBarElement.m_xUIElement->getRealInterface(), UNO_QUERY );
2026 if ( xWindow.is() )
2028 SolarMutexGuard g;
2029 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2030 if ( pWindow && pWindow->IsVisible() )
2031 return true;
2032 else
2033 return false;
2037 else if ( aElementType.equalsIgnoreAsciiCase("progressbar") &&
2038 aElementName.equalsIgnoreAsciiCase("progressbar") )
2040 if ( m_aProgressBarElement.m_xUIElement.is() )
2041 return m_aProgressBarElement.m_bVisible;
2043 else if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
2045 SolarMutexClearableGuard aReadLock;
2046 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2047 aReadLock.clear();
2049 if ( pToolbarManager )
2050 return pToolbarManager->isToolbarVisible( aName );
2052 else if ( aElementType.equalsIgnoreAsciiCase("dockingwindow"))
2054 SolarMutexClearableGuard aReadGuard;
2055 uno::Reference< frame::XFrame > xFrame( m_xFrame );
2056 aReadGuard.clear();
2058 return IsDockingWindowVisible( xFrame, aElementName );
2061 return false;
2064 sal_Bool SAL_CALL LayoutManager::isElementFloating( const OUString& aName )
2066 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
2068 SolarMutexClearableGuard aReadLock;
2069 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2070 aReadLock.clear();
2072 if ( pToolbarManager )
2073 return pToolbarManager->isToolbarFloating( aName );
2076 return false;
2079 sal_Bool SAL_CALL LayoutManager::isElementDocked( const OUString& aName )
2081 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
2083 SolarMutexClearableGuard aReadLock;
2084 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2085 aReadLock.clear();
2087 if ( pToolbarManager )
2088 return pToolbarManager->isToolbarDocked( aName );
2091 return false;
2094 sal_Bool SAL_CALL LayoutManager::isElementLocked( const OUString& aName )
2096 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
2098 SolarMutexClearableGuard aReadLock;
2099 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2100 aReadLock.clear();
2102 if ( pToolbarManager )
2103 return pToolbarManager->isToolbarLocked( aName );
2106 return false;
2109 awt::Size SAL_CALL LayoutManager::getElementSize( const OUString& aName )
2111 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
2113 SolarMutexClearableGuard aReadLock;
2114 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2115 aReadLock.clear();
2117 if ( pToolbarManager )
2118 return pToolbarManager->getToolbarSize( aName );
2121 return awt::Size();
2124 awt::Point SAL_CALL LayoutManager::getElementPos( const OUString& aName )
2126 if ( o3tl::equalsIgnoreAsciiCase(getElementTypeFromResourceURL( aName ), UIRESOURCETYPE_TOOLBAR ))
2128 SolarMutexClearableGuard aReadLock;
2129 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2130 aReadLock.clear();
2132 if ( pToolbarManager )
2133 return pToolbarManager->getToolbarPos( aName );
2136 return awt::Point();
2139 void SAL_CALL LayoutManager::lock()
2141 implts_lock();
2143 SolarMutexClearableGuard aReadLock;
2144 sal_Int32 nLockCount( m_nLockCount );
2145 aReadLock.clear();
2147 SAL_INFO( "fwk", "LayoutManager::lock " << reinterpret_cast<sal_Int64>(this) << " - " << nLockCount );
2149 Any a( nLockCount );
2150 implts_notifyListeners( frame::LayoutManagerEvents::LOCK, a );
2153 void SAL_CALL LayoutManager::unlock()
2155 bool bDoLayout( implts_unlock() );
2157 SolarMutexClearableGuard aReadLock;
2158 sal_Int32 nLockCount( m_nLockCount );
2159 aReadLock.clear();
2161 SAL_INFO( "fwk", "LayoutManager::unlock " << reinterpret_cast<sal_Int64>(this) << " - " << nLockCount);
2163 // conform to documentation: unlock with lock count == 0 means force a layout
2166 SolarMutexGuard aWriteLock;
2167 if (bDoLayout)
2168 m_aAsyncLayoutTimer.Stop();
2171 Any a( nLockCount );
2172 implts_notifyListeners( frame::LayoutManagerEvents::UNLOCK, a );
2174 if ( bDoLayout )
2175 implts_doLayout_notify( true );
2178 void SAL_CALL LayoutManager::doLayout()
2180 implts_doLayout_notify( true );
2183 // ILayoutNotifications
2185 void LayoutManager::requestLayout()
2187 doLayout();
2190 void LayoutManager::implts_doLayout_notify( bool bOuterResize )
2192 bool bLayouted = implts_doLayout( false, bOuterResize );
2193 if ( bLayouted )
2194 implts_notifyListeners( frame::LayoutManagerEvents::LAYOUT, Any() );
2197 bool LayoutManager::implts_doLayout( bool bForceRequestBorderSpace, bool bOuterResize )
2199 SAL_INFO( "fwk", "LayoutManager::implts_doLayout" );
2201 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2202 SolarMutexClearableGuard aReadLock;
2204 if ( !m_xFrame.is() || !m_bParentWindowVisible )
2205 return false;
2207 bool bPreserveContentSize( m_bPreserveContentSize );
2208 bool bMustDoLayout( m_bMustDoLayout );
2209 bool bNoLock = ( m_nLockCount == 0 );
2210 awt::Rectangle aCurrBorderSpace( m_aDockingArea );
2211 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2212 Reference< awt::XTopWindow2 > xContainerTopWindow( m_xContainerTopWindow );
2213 Reference< awt::XWindow > xComponentWindow;
2214 try {
2215 xComponentWindow = m_xFrame->getComponentWindow();
2216 } catch (css::lang::DisposedException &) {
2217 // There can be a race between one thread calling Frame::dispose
2218 // (framework/source/services/frame.cxx) -> Frame::disableLayoutManager
2219 // -> LayoutManager::attachFrame(null) setting m_xFrame to null, and
2220 // the main thread firing the timer-triggered
2221 // LayoutManager::AsyncLayoutHdl -> LayoutManager::implts_doLayout and
2222 // calling into the in-dispose m_xFrame here, so silently ignore a
2223 // DisposedException here:
2224 return false;
2226 Reference< XDockingAreaAcceptor > xDockingAreaAcceptor( m_xDockingAreaAcceptor );
2227 aReadLock.clear();
2228 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2230 bool bLayouted( false );
2232 if ( bNoLock && xDockingAreaAcceptor.is() && xContainerWindow.is() && xComponentWindow.is() )
2234 bLayouted = true;
2236 awt::Rectangle aDockSpace( implts_calcDockingAreaSizes() );
2237 awt::Rectangle aBorderSpace( aDockSpace );
2238 bool bGotRequestedBorderSpace( true );
2240 // We have to add the height of a possible status bar
2241 aBorderSpace.Height += implts_getStatusBarSize().Height();
2243 if ( !equalRectangles( aBorderSpace, aCurrBorderSpace ) || bForceRequestBorderSpace || bMustDoLayout )
2245 // we always resize the content window (instead of the complete container window) if we're not set up
2246 // to (attempt to) preserve the content window's size
2247 if ( bOuterResize && !bPreserveContentSize )
2248 bOuterResize = false;
2250 // maximized windows can resized their content window only, not their container window
2251 if ( bOuterResize && xContainerTopWindow.is() && xContainerTopWindow->getIsMaximized() )
2252 bOuterResize = false;
2254 // if the component window does not have a size (yet), then we can't use it to calc the container
2255 // window size
2256 awt::Rectangle aComponentRect = xComponentWindow->getPosSize();
2257 if ( bOuterResize && ( aComponentRect.Width == 0 ) && ( aComponentRect.Height == 0 ) )
2258 bOuterResize = false;
2260 bGotRequestedBorderSpace = false;
2261 if ( bOuterResize )
2263 Reference< awt::XDevice > xDevice( xContainerWindow, uno::UNO_QUERY );
2264 awt::DeviceInfo aContainerInfo = xDevice->getInfo();
2266 awt::Size aRequestedSize( aComponentRect.Width + aContainerInfo.LeftInset + aContainerInfo.RightInset + aBorderSpace.X + aBorderSpace.Width,
2267 aComponentRect.Height + aContainerInfo.TopInset + aContainerInfo.BottomInset + aBorderSpace.Y + aBorderSpace.Height );
2268 awt::Point aComponentPos( aBorderSpace.X, aBorderSpace.Y );
2270 bGotRequestedBorderSpace = implts_resizeContainerWindow( aRequestedSize, aComponentPos );
2273 // if we did not do a container window resize, or it failed, then use the DockingAcceptor as usual
2274 if ( !bGotRequestedBorderSpace )
2275 bGotRequestedBorderSpace = xDockingAreaAcceptor->requestDockingAreaSpace( aBorderSpace );
2277 if ( bGotRequestedBorderSpace )
2279 SolarMutexGuard aWriteGuard;
2280 m_aDockingArea = aBorderSpace;
2281 m_bMustDoLayout = false;
2285 if ( bGotRequestedBorderSpace )
2287 ::Size aContainerSize;
2288 ::Size aStatusBarSize;
2290 // Interim solution to let the layout method within the
2291 // toolbar layout manager.
2292 implts_setOffset( implts_getStatusBarSize().Height() );
2293 if ( m_xToolbarManager.is() )
2294 m_xToolbarManager->setDockingArea( aDockSpace );
2296 // Subtract status bar size from our container output size. Docking area windows
2297 // don't contain the status bar!
2298 aStatusBarSize = implts_getStatusBarSize();
2299 aContainerSize = implts_getContainerWindowOutputSize();
2300 aContainerSize.AdjustHeight( -(aStatusBarSize.Height()) );
2302 if ( m_xToolbarManager.is() )
2303 m_xToolbarManager->doLayout(aContainerSize);
2305 // Position the status bar
2306 if ( aStatusBarSize.Height() > 0 )
2308 implts_setStatusBarPosSize( ::Point( 0, std::max(( aContainerSize.Height() ), tools::Long( 0 ))),
2309 ::Size( aContainerSize.Width(),aStatusBarSize.Height() ));
2312 xDockingAreaAcceptor->setDockingAreaSpace( aBorderSpace );
2316 return bLayouted;
2319 bool LayoutManager::implts_resizeContainerWindow( const awt::Size& rContainerSize,
2320 const awt::Point& rComponentPos )
2322 SolarMutexClearableGuard aReadLock;
2323 Reference< awt::XWindow > xContainerWindow = m_xContainerWindow;
2324 Reference< awt::XTopWindow2 > xContainerTopWindow = m_xContainerTopWindow;
2325 Reference< awt::XWindow > xComponentWindow = m_xFrame->getComponentWindow();
2326 aReadLock.clear();
2328 // calculate the maximum size we have for the container window
2329 sal_Int32 nDisplay = xContainerTopWindow->getDisplay();
2330 tools::Rectangle aWorkArea = Application::GetScreenPosSizePixel( nDisplay );
2332 if (!aWorkArea.IsEmpty())
2334 if (( rContainerSize.Width > aWorkArea.GetWidth() ) || ( rContainerSize.Height > aWorkArea.GetHeight() ))
2335 return false;
2336 // Strictly, this is not correct. If we have a multi-screen display (css.awt.DisplayAccess.MultiDisplay == true),
2337 // the "effective work area" would be much larger than the work area of a single display, since we could in theory
2338 // position the container window across multiple screens.
2339 // However, this should suffice as a heuristics here ... (nobody really wants to check whether the different screens are
2340 // stacked horizontally or vertically, whether their work areas can really be combined, or are separated by non-work-areas,
2341 // and the like ... right?)
2344 // resize our container window
2345 xContainerWindow->setPosSize( 0, 0, rContainerSize.Width, rContainerSize.Height, awt::PosSize::SIZE );
2346 // position the component window
2347 xComponentWindow->setPosSize( rComponentPos.X, rComponentPos.Y, 0, 0, awt::PosSize::POS );
2348 return true;
2351 void SAL_CALL LayoutManager::setVisible( sal_Bool bVisible )
2353 SolarMutexClearableGuard aWriteLock;
2354 bool bWasVisible( m_bVisible );
2355 m_bVisible = bVisible;
2356 aWriteLock.clear();
2358 if ( bWasVisible != bool(bVisible) )
2359 implts_setVisibleState( bVisible );
2362 sal_Bool SAL_CALL LayoutManager::isVisible()
2364 SolarMutexGuard g;
2365 return m_bVisible;
2368 ::Size LayoutManager::implts_getStatusBarSize()
2370 SolarMutexClearableGuard aReadLock;
2371 bool bStatusBarVisible( isElementVisible( STATUS_BAR_ALIAS ));
2372 bool bProgressBarVisible( isElementVisible( "private:resource/progressbar/progressbar" ));
2373 bool bVisible( m_bVisible );
2374 Reference< XUIElement > xStatusBar( m_aStatusBarElement.m_xUIElement );
2375 Reference< XUIElement > xProgressBar( m_aProgressBarElement.m_xUIElement );
2377 Reference< awt::XWindow > xWindow;
2378 if ( bStatusBarVisible && bVisible && xStatusBar.is() )
2379 xWindow.set( xStatusBar->getRealInterface(), UNO_QUERY );
2380 else if ( xProgressBar.is() && !xStatusBar.is() && bProgressBarVisible )
2382 ProgressBarWrapper* pWrapper = static_cast<ProgressBarWrapper*>(xProgressBar.get());
2383 if ( pWrapper )
2384 xWindow = pWrapper->getStatusBar();
2386 aReadLock.clear();
2388 if ( xWindow.is() )
2390 awt::Rectangle aPosSize = xWindow->getPosSize();
2391 return ::Size( aPosSize.Width, aPosSize.Height );
2393 else
2394 return ::Size();
2397 awt::Rectangle LayoutManager::implts_calcDockingAreaSizes()
2399 SolarMutexClearableGuard aReadLock;
2400 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2401 Reference< XDockingAreaAcceptor > xDockingAreaAcceptor( m_xDockingAreaAcceptor );
2402 aReadLock.clear();
2404 awt::Rectangle aBorderSpace;
2405 if ( m_xToolbarManager.is() && xDockingAreaAcceptor.is() && xContainerWindow.is() )
2406 aBorderSpace = m_xToolbarManager->getDockingArea();
2408 return aBorderSpace;
2411 void LayoutManager::implts_setDockingAreaWindowSizes()
2413 SolarMutexClearableGuard aReadLock;
2414 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2415 aReadLock.clear();
2417 uno::Reference< awt::XDevice > xDevice( xContainerWindow, uno::UNO_QUERY );
2418 // Convert relative size to output size.
2419 awt::Rectangle aRectangle = xContainerWindow->getPosSize();
2420 awt::DeviceInfo aInfo = xDevice->getInfo();
2421 awt::Size aContainerClientSize( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset,
2422 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
2423 ::Size aStatusBarSize = implts_getStatusBarSize();
2425 // Position the status bar
2426 if ( aStatusBarSize.Height() > 0 )
2428 implts_setStatusBarPosSize( ::Point( 0, std::max(( aContainerClientSize.Height - aStatusBarSize.Height() ), tools::Long( 0 ))),
2429 ::Size( aContainerClientSize.Width, aStatusBarSize.Height() ));
2433 void LayoutManager::implts_updateMenuBarClose()
2435 SolarMutexClearableGuard aWriteLock;
2436 bool bShowCloseButton( m_bMenuBarCloseButton );
2437 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2438 aWriteLock.clear();
2440 if ( !xContainerWindow.is() )
2441 return;
2443 SolarMutexGuard aGuard;
2445 SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
2446 if ( pSysWindow )
2448 MenuBar* pMenuBar = pSysWindow->GetMenuBar();
2449 if ( pMenuBar )
2451 // TODO remove link on sal_False ?!
2452 pMenuBar->ShowCloseButton(bShowCloseButton);
2453 pMenuBar->SetCloseButtonClickHdl(LINK(this, LayoutManager, MenuBarClose));
2458 bool LayoutManager::implts_resetMenuBar()
2460 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2461 SolarMutexGuard aWriteLock;
2462 bool bMenuVisible( m_bMenuVisible );
2463 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2465 MenuBar* pSetMenuBar = nullptr;
2466 if ( m_xInplaceMenuBar.is() )
2467 pSetMenuBar = static_cast<MenuBar *>(m_xInplaceMenuBar->GetMenuBar());
2468 else
2470 MenuBarWrapper* pMenuBarWrapper = static_cast< MenuBarWrapper* >( m_xMenuBar.get() );
2471 if ( pMenuBarWrapper )
2472 pSetMenuBar = static_cast<MenuBar*>(pMenuBarWrapper->GetMenuBarManager()->GetMenuBar());
2475 SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
2476 if ( pSysWindow && bMenuVisible && pSetMenuBar )
2478 pSysWindow->SetMenuBar(pSetMenuBar);
2479 pSetMenuBar->SetDisplayable( true );
2480 return true;
2483 return false;
2486 void LayoutManager::implts_createMSCompatibleMenuBar( const OUString& aName )
2488 SolarMutexGuard aWriteLock;
2490 // Find Form menu in the original menubar
2491 m_xMenuBar = implts_createElement( aName );
2492 uno::Reference< XUIElementSettings > xMenuBarSettings(m_xMenuBar, UNO_QUERY);
2493 uno::Reference< container::XIndexReplace > xMenuIndex(xMenuBarSettings->getSettings(true), UNO_QUERY);
2495 sal_Int32 nFormsMenu = -1;
2496 for (sal_Int32 nIndex = 0; nIndex < xMenuIndex->getCount(); ++nIndex)
2498 uno::Sequence< beans::PropertyValue > aProps;
2499 xMenuIndex->getByIndex( nIndex ) >>= aProps;
2500 OUString aCommand;
2501 for ( beans::PropertyValue const & rProp : std::as_const(aProps) )
2503 if (rProp.Name == "CommandURL")
2505 rProp.Value >>= aCommand;
2506 break;
2510 if (aCommand == ".uno:FormatFormMenu")
2511 nFormsMenu = nIndex;
2513 assert(nFormsMenu != -1);
2515 // Create the MS compatible Form menu
2516 css::uno::Reference< css::ui::XUIElement > xFormsMenu = implts_createElement( "private:resource/menubar/mscompatibleformsmenu" );
2517 if(!xFormsMenu.is())
2518 return;
2520 // Merge the MS compatible Form menu into the menubar
2521 uno::Reference< XUIElementSettings > xFormsMenuSettings(xFormsMenu, UNO_QUERY);
2522 uno::Reference< container::XIndexAccess > xFormsMenuIndex(xFormsMenuSettings->getSettings(true));
2524 assert(xFormsMenuIndex->getCount() >= 1);
2525 uno::Sequence< beans::PropertyValue > aNewFormsMenu;
2526 xFormsMenuIndex->getByIndex( 0 ) >>= aNewFormsMenu;
2527 xMenuIndex->replaceByIndex(nFormsMenu, uno::Any(aNewFormsMenu));
2529 setMergedMenuBar( xMenuIndex );
2531 // Clear up the temporal forms menubar
2532 Reference< XComponent > xFormsMenuComp( xFormsMenu, UNO_QUERY );
2533 if ( xFormsMenuComp.is() )
2534 xFormsMenuComp->dispose();
2535 xFormsMenu.clear();
2538 IMPL_LINK_NOARG(LayoutManager, MenuBarClose, void*, void)
2540 SolarMutexClearableGuard aReadLock;
2541 uno::Reference< frame::XDispatchProvider > xProvider(m_xFrame, uno::UNO_QUERY);
2542 uno::Reference< XComponentContext > xContext( m_xContext );
2543 aReadLock.clear();
2545 if ( !xProvider.is())
2546 return;
2548 uno::Reference< frame::XDispatchHelper > xDispatcher = frame::DispatchHelper::create( xContext );
2550 xDispatcher->executeDispatch(
2551 xProvider,
2552 ".uno:CloseWin",
2553 "_self",
2555 uno::Sequence< beans::PropertyValue >());
2558 // XLayoutManagerEventBroadcaster
2560 void SAL_CALL LayoutManager::addLayoutManagerEventListener( const uno::Reference< frame::XLayoutManagerListener >& xListener )
2562 m_aListenerContainer.addInterface( cppu::UnoType<frame::XLayoutManagerListener>::get(), xListener );
2565 void SAL_CALL LayoutManager::removeLayoutManagerEventListener( const uno::Reference< frame::XLayoutManagerListener >& xListener )
2567 m_aListenerContainer.removeInterface( cppu::UnoType<frame::XLayoutManagerListener>::get(), xListener );
2570 void LayoutManager::implts_notifyListeners(short nEvent, const uno::Any& rInfoParam)
2572 comphelper::OInterfaceContainerHelper2* pContainer = m_aListenerContainer.getContainer( cppu::UnoType<frame::XLayoutManagerListener>::get());
2573 if (pContainer==nullptr)
2574 return;
2576 lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>(this) );
2577 comphelper::OInterfaceIteratorHelper2 pIterator(*pContainer);
2578 while (pIterator.hasMoreElements())
2582 static_cast<frame::XLayoutManagerListener*>(pIterator.next())->layoutEvent(aSource, nEvent, rInfoParam);
2584 catch( const uno::RuntimeException& )
2586 pIterator.remove();
2591 // XWindowListener
2593 void SAL_CALL LayoutManager::windowResized( const awt::WindowEvent& aEvent )
2595 SolarMutexGuard g;
2596 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2598 Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2599 if ( xIfac == aEvent.Source && m_bVisible )
2601 // We have to call our resize handler at least once synchronously, as some
2602 // application modules need this. So we have to check if this is the first
2603 // call after the async layout time expired.
2604 m_bMustDoLayout = true;
2605 if ( !m_aAsyncLayoutTimer.IsActive() )
2607 m_aAsyncLayoutTimer.Invoke();
2608 if ( m_nLockCount == 0 )
2609 m_aAsyncLayoutTimer.Start();
2612 else if ( m_xFrame.is() && aEvent.Source == m_xFrame->getContainerWindow() )
2614 // the container window of my DockingAreaAcceptor is not the same as of my frame
2615 // I still have to resize my frames' window as nobody else will do it
2616 Reference< awt::XWindow > xComponentWindow( m_xFrame->getComponentWindow() );
2617 if( xComponentWindow.is() )
2619 uno::Reference< awt::XDevice > xDevice( m_xFrame->getContainerWindow(), uno::UNO_QUERY );
2621 // Convert relative size to output size.
2622 awt::Rectangle aRectangle = m_xFrame->getContainerWindow()->getPosSize();
2623 awt::DeviceInfo aInfo = xDevice->getInfo();
2624 awt::Size aSize( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset ,
2625 aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );
2627 // Resize our component window.
2628 xComponentWindow->setPosSize( 0, 0, aSize.Width, aSize.Height, awt::PosSize::POSSIZE );
2633 void SAL_CALL LayoutManager::windowMoved( const awt::WindowEvent& )
2637 void SAL_CALL LayoutManager::windowShown( const lang::EventObject& aEvent )
2639 SolarMutexClearableGuard aReadLock;
2640 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2641 bool bParentWindowVisible( m_bParentWindowVisible );
2642 aReadLock.clear();
2644 Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2645 if ( xIfac == aEvent.Source )
2647 SolarMutexClearableGuard aWriteLock;
2648 m_bParentWindowVisible = true;
2649 bool bSetVisible = ( m_bParentWindowVisible != bParentWindowVisible );
2650 aWriteLock.clear();
2652 if ( bSetVisible )
2653 implts_updateUIElementsVisibleState( true );
2657 void SAL_CALL LayoutManager::windowHidden( const lang::EventObject& aEvent )
2659 SolarMutexClearableGuard aReadLock;
2660 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2661 bool bParentWindowVisible( m_bParentWindowVisible );
2662 aReadLock.clear();
2664 Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2665 if ( xIfac == aEvent.Source )
2667 SolarMutexClearableGuard aWriteLock;
2668 m_bParentWindowVisible = false;
2669 bool bSetInvisible = ( m_bParentWindowVisible != bParentWindowVisible );
2670 aWriteLock.clear();
2672 if ( bSetInvisible )
2673 implts_updateUIElementsVisibleState( false );
2677 IMPL_LINK_NOARG(LayoutManager, AsyncLayoutHdl, Timer *, void)
2680 SolarMutexGuard aReadLock;
2682 if (!m_xContainerWindow.is())
2683 return;
2686 implts_setDockingAreaWindowSizes();
2687 implts_doLayout( true, false );
2690 // XFrameActionListener
2692 void SAL_CALL LayoutManager::frameAction( const FrameActionEvent& aEvent )
2694 if (( aEvent.Action == FrameAction_COMPONENT_ATTACHED ) || ( aEvent.Action == FrameAction_COMPONENT_REATTACHED ))
2696 SAL_INFO( "fwk", "LayoutManager::frameAction (COMPONENT_ATTACHED|REATTACHED)" );
2699 SolarMutexGuard aWriteLock;
2700 m_bMustDoLayout = true;
2703 implts_reset( true );
2704 implts_doLayout( true, false );
2705 implts_doLayout( true, true );
2707 else if (( aEvent.Action == FrameAction_FRAME_UI_ACTIVATED ) || ( aEvent.Action == FrameAction_FRAME_UI_DEACTIVATING ))
2709 SAL_INFO( "fwk", "LayoutManager::frameAction (FRAME_UI_ACTIVATED|DEACTIVATING)" );
2711 implts_toggleFloatingUIElementsVisibility( aEvent.Action == FrameAction_FRAME_UI_ACTIVATED );
2713 else if ( aEvent.Action == FrameAction_COMPONENT_DETACHING )
2715 SAL_INFO( "fwk", "LayoutManager::frameAction (COMPONENT_DETACHING)" );
2717 implts_reset( false );
2721 void SAL_CALL LayoutManager::disposing( const lang::EventObject& rEvent )
2723 bool bDisposeAndClear( false );
2725 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2727 SolarMutexGuard aWriteLock;
2729 if (rEvent.Source == Reference<XInterface>(m_xFrame, UNO_QUERY))
2731 // Our frame gets disposed, release all our references that depends on a working frame reference.
2733 setDockingAreaAcceptor(Reference<ui::XDockingAreaAcceptor>());
2735 // destroy all elements, it's possible that detaching is NOT called!
2736 implts_destroyElements();
2737 impl_clearUpMenuBar();
2738 m_xMenuBar.clear();
2739 VclPtr<Menu> pMenuBar;
2740 if (m_xInplaceMenuBar.is())
2742 pMenuBar = m_xInplaceMenuBar->GetMenuBar();
2743 m_xInplaceMenuBar->dispose();
2744 m_xInplaceMenuBar.clear();
2746 pMenuBar.disposeAndClear();
2747 m_xContainerWindow.clear();
2748 m_xContainerTopWindow.clear();
2750 // forward disposing call to toolbar manager
2751 if (m_xToolbarManager.is())
2752 m_xToolbarManager->disposing(rEvent);
2754 if (m_xModuleCfgMgr.is())
2758 Reference<XUIConfiguration> xModuleCfgMgr(m_xModuleCfgMgr, UNO_QUERY);
2759 xModuleCfgMgr->removeConfigurationListener(Reference<XUIConfigurationListener>(this));
2761 catch (const Exception&)
2766 if (m_xDocCfgMgr.is())
2770 Reference<XUIConfiguration> xDocCfgMgr(m_xDocCfgMgr, UNO_QUERY);
2771 xDocCfgMgr->removeConfigurationListener(Reference<XUIConfigurationListener>(this));
2773 catch (const Exception&)
2778 m_xDocCfgMgr.clear();
2779 m_xModuleCfgMgr.clear();
2780 m_xFrame.clear();
2781 m_pGlobalSettings.reset();
2783 bDisposeAndClear = true;
2785 else if (rEvent.Source == Reference<XInterface>(m_xContainerWindow, UNO_QUERY))
2787 // Our container window gets disposed. Remove all user interface elements.
2788 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
2789 if (pToolbarManager)
2791 uno::Reference<awt::XVclWindowPeer> aEmptyWindowPeer;
2792 pToolbarManager->setParentWindow(aEmptyWindowPeer);
2794 impl_clearUpMenuBar();
2795 m_xMenuBar.clear();
2796 VclPtr<Menu> pMenuBar;
2797 if (m_xInplaceMenuBar.is())
2799 pMenuBar = m_xInplaceMenuBar->GetMenuBar();
2800 m_xInplaceMenuBar->dispose();
2801 m_xInplaceMenuBar.clear();
2803 pMenuBar.disposeAndClear();
2804 m_xContainerWindow.clear();
2805 m_xContainerTopWindow.clear();
2807 else if (rEvent.Source == Reference<XInterface>(m_xDocCfgMgr, UNO_QUERY))
2808 m_xDocCfgMgr.clear();
2809 else if (rEvent.Source == Reference<XInterface>(m_xModuleCfgMgr, UNO_QUERY))
2810 m_xModuleCfgMgr.clear();
2812 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2814 // Send disposing to our listener when we have lost our frame.
2815 if ( bDisposeAndClear )
2817 // Send message to all listener and forget her references.
2818 uno::Reference< frame::XLayoutManager > xThis(this);
2819 lang::EventObject aEvent( xThis );
2820 m_aListenerContainer.disposeAndClear( aEvent );
2824 void SAL_CALL LayoutManager::elementInserted( const ui::ConfigurationEvent& Event )
2826 SolarMutexClearableGuard aReadLock;
2827 Reference< XFrame > xFrame( m_xFrame );
2828 rtl::Reference< ToolbarLayoutManager > xToolbarManager( m_xToolbarManager );
2829 aReadLock.clear();
2831 if ( !xFrame.is() )
2832 return;
2834 OUString aElementType;
2835 OUString aElementName;
2836 bool bRefreshLayout(false);
2838 parseResourceURL( Event.ResourceURL, aElementType, aElementName );
2839 if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
2841 if ( xToolbarManager.is() )
2843 xToolbarManager->elementInserted( Event );
2844 bRefreshLayout = xToolbarManager->isLayoutDirty();
2847 else if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_MENUBAR ))
2849 Reference< XUIElement > xUIElement = implts_findElement( Event.ResourceURL );
2850 Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
2851 if ( xElementSettings.is() )
2853 uno::Reference< XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY );
2854 if ( xPropSet.is() )
2856 if ( Event.Source == uno::Reference< uno::XInterface >( m_xDocCfgMgr, uno::UNO_QUERY ))
2857 xPropSet->setPropertyValue( "ConfigurationSource", Any( m_xDocCfgMgr ));
2859 xElementSettings->updateSettings();
2863 if ( bRefreshLayout )
2864 doLayout();
2867 void SAL_CALL LayoutManager::elementRemoved( const ui::ConfigurationEvent& Event )
2869 SolarMutexClearableGuard aReadLock;
2870 Reference< frame::XFrame > xFrame( m_xFrame );
2871 rtl::Reference< ToolbarLayoutManager > xToolbarManager( m_xToolbarManager );
2872 Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2873 Reference< ui::XUIElement > xMenuBar( m_xMenuBar );
2874 Reference< ui::XUIConfigurationManager > xModuleCfgMgr( m_xModuleCfgMgr );
2875 Reference< ui::XUIConfigurationManager > xDocCfgMgr( m_xDocCfgMgr );
2876 aReadLock.clear();
2878 if ( !xFrame.is() )
2879 return;
2881 OUString aElementType;
2882 OUString aElementName;
2883 bool bRefreshLayout(false);
2885 parseResourceURL( Event.ResourceURL, aElementType, aElementName );
2886 if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
2888 if ( xToolbarManager.is() )
2890 xToolbarManager->elementRemoved( Event );
2891 bRefreshLayout = xToolbarManager->isLayoutDirty();
2894 else
2896 Reference< XUIElement > xUIElement = implts_findElement( Event.ResourceURL );
2897 Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
2898 if ( xElementSettings.is() )
2900 bool bNoSettings( false );
2901 OUString aConfigSourcePropName( "ConfigurationSource" );
2902 Reference< XInterface > xElementCfgMgr;
2903 Reference< XPropertySet > xPropSet( xElementSettings, UNO_QUERY );
2905 if ( xPropSet.is() )
2906 xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr;
2908 if ( !xElementCfgMgr.is() )
2909 return;
2911 // Check if the same UI configuration manager has changed => check further
2912 if ( Event.Source == xElementCfgMgr )
2914 // Same UI configuration manager where our element has its settings
2915 if ( Event.Source == Reference< XInterface >( xDocCfgMgr, UNO_QUERY ))
2917 // document settings removed
2918 if ( xModuleCfgMgr->hasSettings( Event.ResourceURL ))
2920 xPropSet->setPropertyValue( aConfigSourcePropName, Any( m_xModuleCfgMgr ));
2921 xElementSettings->updateSettings();
2922 return;
2926 bNoSettings = true;
2929 // No settings anymore, element must be destroyed
2930 if ( xContainerWindow.is() && bNoSettings )
2932 if ( aElementType.equalsIgnoreAsciiCase("menubar") &&
2933 aElementName.equalsIgnoreAsciiCase("menubar") )
2935 SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
2936 if ( pSysWindow && !m_bInplaceMenuSet )
2937 pSysWindow->SetMenuBar( nullptr );
2939 Reference< XComponent > xComp( xMenuBar, UNO_QUERY );
2940 if ( xComp.is() )
2941 xComp->dispose();
2943 SolarMutexGuard g;
2944 m_xMenuBar.clear();
2950 if ( bRefreshLayout )
2951 doLayout();
2954 void SAL_CALL LayoutManager::elementReplaced( const ui::ConfigurationEvent& Event )
2956 SolarMutexClearableGuard aReadLock;
2957 Reference< XFrame > xFrame( m_xFrame );
2958 rtl::Reference< ToolbarLayoutManager > xToolbarManager( m_xToolbarManager );
2959 aReadLock.clear();
2961 if ( !xFrame.is() )
2962 return;
2964 OUString aElementType;
2965 OUString aElementName;
2966 bool bRefreshLayout(false);
2968 parseResourceURL( Event.ResourceURL, aElementType, aElementName );
2969 if ( aElementType.equalsIgnoreAsciiCase( UIRESOURCETYPE_TOOLBAR ))
2971 if ( xToolbarManager.is() )
2973 xToolbarManager->elementReplaced( Event );
2974 bRefreshLayout = xToolbarManager->isLayoutDirty();
2977 else
2979 Reference< XUIElement > xUIElement = implts_findElement( Event.ResourceURL );
2980 Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
2981 if ( xElementSettings.is() )
2983 Reference< XInterface > xElementCfgMgr;
2984 Reference< XPropertySet > xPropSet( xElementSettings, UNO_QUERY );
2986 if ( xPropSet.is() )
2987 xPropSet->getPropertyValue( "ConfigurationSource" ) >>= xElementCfgMgr;
2989 if ( !xElementCfgMgr.is() )
2990 return;
2992 // Check if the same UI configuration manager has changed => update settings
2993 if ( Event.Source == xElementCfgMgr )
2994 xElementSettings->updateSettings();
2998 if ( bRefreshLayout )
2999 doLayout();
3002 void SAL_CALL LayoutManager::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
3003 const uno::Any& aValue )
3005 if ( (nHandle != LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY) && (nHandle != LAYOUTMANAGER_PROPHANDLE_REFRESHTOOLTIP) )
3006 LayoutManager_PBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
3008 switch( nHandle )
3010 case LAYOUTMANAGER_PROPHANDLE_MENUBARCLOSER:
3011 implts_updateMenuBarClose();
3012 break;
3014 case LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY:
3016 bool bValue(false);
3017 if (( aValue >>= bValue ) && bValue )
3019 SolarMutexClearableGuard aReadLock;
3020 ToolbarLayoutManager* pToolbarManager = m_xToolbarManager.get();
3021 bool bAutomaticToolbars( m_bAutomaticToolbars );
3022 aReadLock.clear();
3024 if ( pToolbarManager )
3025 pToolbarManager->refreshToolbarsVisibility( bAutomaticToolbars );
3027 break;
3030 case LAYOUTMANAGER_PROPHANDLE_HIDECURRENTUI:
3031 implts_setCurrentUIVisibility( !m_bHideCurrentUI );
3032 break;
3034 case LAYOUTMANAGER_PROPHANDLE_REFRESHTOOLTIP:
3035 if (m_xToolbarManager.is())
3036 m_xToolbarManager->updateToolbarsTips();
3037 break;
3039 default: break;
3043 namespace detail
3045 class InfoHelperBuilder
3047 private:
3048 std::unique_ptr<::cppu::OPropertyArrayHelper> m_pInfoHelper;
3049 public:
3050 explicit InfoHelperBuilder(const LayoutManager &rManager)
3052 uno::Sequence< beans::Property > aProperties;
3053 rManager.describeProperties(aProperties);
3054 m_pInfoHelper.reset( new ::cppu::OPropertyArrayHelper(aProperties, true) );
3056 InfoHelperBuilder(const InfoHelperBuilder&) = delete;
3057 InfoHelperBuilder& operator=(const InfoHelperBuilder&) = delete;
3059 ::cppu::OPropertyArrayHelper& getHelper() { return *m_pInfoHelper; }
3063 ::cppu::IPropertyArrayHelper& SAL_CALL LayoutManager::getInfoHelper()
3065 static detail::InfoHelperBuilder INFO(*this);
3066 return INFO.getHelper();
3069 uno::Reference< beans::XPropertySetInfo > SAL_CALL LayoutManager::getPropertySetInfo()
3071 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3073 return xInfo;
3076 } // namespace framework
3078 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
3079 com_sun_star_comp_framework_LayoutManager_get_implementation(
3080 css::uno::XComponentContext *context,
3081 css::uno::Sequence<css::uno::Any> const &)
3083 return cppu::acquire(new framework::LayoutManager(context));
3086 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */