1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile: layoutmanager.cxx,v $
10  * $Revision: 1.72 $
11  *
12  * This file is part of OpenOffice.org.
13  *
14  * OpenOffice.org is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 3
16  * only, as published by the Free Software Foundation.
17  *
18  * OpenOffice.org is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License version 3 for more details
22  * (a copy is included in the LICENSE file that accompanied this code).
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * version 3 along with OpenOffice.org.  If not, see
26  * <http://www.openoffice.org/license.html>
27  * for a copy of the LGPLv3 License.
28  *
29  ************************************************************************/
30 
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 
34 //      my own includes
35 #include <services/layoutmanager.hxx>
36 #include <helpers.hxx>
37 #include <panelmanager.hxx>
38 #include <threadhelp/resetableguard.hxx>
39 #include <services.h>
40 
41 #include <framework/sfxhelperfunctions.hxx>
42 #include <framework/sfxhelperfunctions.hxx>
43 #include <uielement/menubarwrapper.hxx>
44 #include <framework/addonsoptions.hxx>
45 #include <uiconfiguration/windowstateconfiguration.hxx>
46 #include <classes/fwkresid.hxx>
47 #include <classes/resource.hrc>
48 #include <toolkit/helper/convert.hxx>
49 #include <uielement/progressbarwrapper.hxx>
50 #include <uiconfiguration/globalsettings.hxx>
51 #include <toolbarlayoutmanager.hxx>
52 
53 //      interface includes
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include <com/sun/star/beans/PropertyAttribute.hpp>
56 #include <com/sun/star/frame/XModel.hpp>
57 #include <com/sun/star/frame/FrameAction.hpp>
58 #include <com/sun/star/frame/XUIControllerRegistration.hpp>
59 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
60 #include <com/sun/star/awt/XTopWindow.hpp>
61 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
62 #include <com/sun/star/lang/SystemDependent.hpp>
63 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
64 #include <com/sun/star/awt/PosSize.hpp>
65 #include <com/sun/star/awt/XDevice.hpp>
66 #include <com/sun/star/awt/XSystemDependentWindowPeer.hpp>
67 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
68 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
69 #include <com/sun/star/ui/UIElementType.hpp>
70 #include <com/sun/star/container/XNameReplace.hpp>
71 #include <com/sun/star/container/XNameContainer.hpp>
72 #include <com/sun/star/frame/LayoutManagerEvents.hpp>
73 #include <com/sun/star/frame/XDispatchProvider.hpp>
74 #include <com/sun/star/frame/XDispatchHelper.hpp>
75 #include <com/sun/star/lang/DisposedException.hpp>
76 
77 //      other includes
78 #include <svtools/imgdef.hxx>
79 #include <tools/diagnose_ex.h>
80 #include <vcl/window.hxx>
81 #include <vcl/wrkwin.hxx>
82 #include <vcl/dockingarea.hxx>
83 #include <vcl/svapp.hxx>
84 #include <vcl/i18nhelp.hxx>
85 #include <vcl/wall.hxx>
86 #include <toolkit/unohlp.hxx>
87 #include <toolkit/awt/vclxwindow.hxx>
88 #include <toolkit/awt/vclxmenu.hxx>
89 #include <comphelper/mediadescriptor.hxx>
90 #include <comphelper/uno3.hxx>
91 #include <rtl/logfile.hxx>
92 #include <unotools/cmdoptions.hxx>
93 
94 #include <algorithm>
95 #include <boost/bind.hpp>
96 
97 //      using namespace
98 using namespace ::com::sun::star;
99 using namespace ::com::sun::star::uno;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::util;
102 using namespace ::com::sun::star::lang;
103 using namespace ::com::sun::star::container;
104 using namespace ::com::sun::star::ui;
105 using namespace ::com::sun::star::frame;
106 
107 
108 // ATTENTION!
109 // This value is directly copied from the sfx2 project.
110 // You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START)
111 static const sal_Int32 DOCKWIN_ID_BASE = 9800;
112 
113 namespace framework
114 {
115 
116 IMPLEMENT_FORWARD_XTYPEPROVIDER2( LayoutManager, LayoutManager_Base, LayoutManager_PBase )
117 IMPLEMENT_FORWARD_XINTERFACE2( LayoutManager, LayoutManager_Base, LayoutManager_PBase )
118 DEFINE_XSERVICEINFO_MULTISERVICE( LayoutManager, ::cppu::OWeakObject, SERVICENAME_LAYOUTMANAGER, IMPLEMENTATIONNAME_LAYOUTMANAGER)
119 DEFINE_INIT_SERVICE( LayoutManager, {} )
120 
121 LayoutManager::LayoutManager( const Reference< XMultiServiceFactory >& xServiceManager ) : LayoutManager_Base()
122         , ThreadHelpBase( &Application::GetSolarMutex())
123         , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex())
124         , LayoutManager_PBase( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
125         , m_xSMGR( xServiceManager )
126         , m_xURLTransformer( xServiceManager->createInstance( SERVICENAME_URLTRANSFORMER ), UNO_QUERY )
127         , m_xDisplayAccess( xServiceManager->createInstance( SERVICENAME_DISPLAYACCESS ), UNO_QUERY )
128         , m_nLockCount( 0 )
129         , m_bActive( false )
130         , m_bInplaceMenuSet( false )
131         , m_bDockingInProgress( false )
132         , m_bMenuVisible( true )
133         , m_bComponentAttached( false )
134         , m_bDoLayout( false )
135         , m_bVisible( true )
136         , m_bParentWindowVisible( false )
137         , m_bMustDoLayout( true )
138         , m_bAutomaticToolbars( true )
139         , m_bStoreWindowState( false )
140         , m_bHideCurrentUI( false )
141         , m_bGlobalSettings( false )
142         , m_bPreserveContentSize( false )
143         , m_bMenuBarCloser( false )
144         , m_pInplaceMenuBar( NULL )
145         , m_xModuleManager( Reference< XModuleManager >( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ))
146         , m_xUIElementFactoryManager( Reference< ui::XUIElementFactory >(
147                 xServiceManager->createInstance( SERVICENAME_UIELEMENTFACTORYMANAGER ), UNO_QUERY ))
148         , m_xPersistentWindowStateSupplier( Reference< XNameAccess >(
149                 xServiceManager->createInstance( SERVICENAME_WINDOWSTATECONFIGURATION ), UNO_QUERY ))
150         , m_pGlobalSettings( 0 )
151         , m_aStatusBarAlias( RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" ))
152         , m_aProgressBarAlias( RTL_CONSTASCII_USTRINGPARAM( "private:resource/progressbar/progressbar" ))
153         , m_aPropDocked( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_DOCKED ))
154         , m_aPropVisible( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_VISIBLE ))
155         , m_aPropDockingArea( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_DOCKINGAREA ))
156         , m_aPropDockPos( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_DOCKPOS ))
157         , m_aPropPos( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_POS ))
158         , m_aPropSize( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_SIZE ))
159         , m_aPropUIName( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_UINAME ))
160         , m_aPropStyle( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_STYLE ))
161         , m_aPropLocked( RTL_CONSTASCII_USTRINGPARAM( WINDOWSTATE_PROPERTY_LOCKED ))
162         , m_aCustomizeCmd( RTL_CONSTASCII_USTRINGPARAM( "ConfigureDialog" ))
163         , m_aListenerContainer( m_aLock.getShareableOslMutex() )
164         , m_pPanelManager( 0 )
165         , m_pToolbarManager( 0 )
166 {
167     // Initialize statusbar member
168     const sal_Bool bRefreshVisibility = sal_False;
169     m_aStatusBarElement.m_aType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "statusbar" ));
170     m_aStatusBarElement.m_aName = m_aStatusBarAlias;
171 
172     m_pToolbarManager = new ToolbarLayoutManager( xServiceManager, m_xUIElementFactoryManager, this );
173     m_xToolbarManager = uno::Reference< ui::XUIConfigurationListener >( static_cast< OWeakObject* >( m_pToolbarManager ), uno::UNO_QUERY );
174 
175     Application::AddEventListener( LINK( this, LayoutManager, SettingsChanged ) );
176 
177     m_aAsyncLayoutTimer.SetTimeout( 50 );
178     m_aAsyncLayoutTimer.SetTimeoutHdl( LINK( this, LayoutManager, AsyncLayoutHdl ) );
179 
180     registerProperty( LAYOUTMANAGER_PROPNAME_AUTOMATICTOOLBARS, LAYOUTMANAGER_PROPHANDLE_AUTOMATICTOOLBARS, css::beans::PropertyAttribute::TRANSIENT, &m_bAutomaticToolbars, ::getCppuType( &m_bAutomaticToolbars ) );
181     registerProperty( LAYOUTMANAGER_PROPNAME_HIDECURRENTUI, LAYOUTMANAGER_PROPHANDLE_HIDECURRENTUI, beans::PropertyAttribute::TRANSIENT, &m_bHideCurrentUI, ::getCppuType( &m_bHideCurrentUI ) );
182     registerProperty( LAYOUTMANAGER_PROPNAME_LOCKCOUNT, LAYOUTMANAGER_PROPHANDLE_LOCKCOUNT, beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY, &m_nLockCount, getCppuType( &m_nLockCount )  );
183     registerProperty( LAYOUTMANAGER_PROPNAME_MENUBARCLOSER, LAYOUTMANAGER_PROPHANDLE_MENUBARCLOSER, beans::PropertyAttribute::TRANSIENT, &m_bMenuBarCloser, ::getCppuType( &m_bMenuBarCloser ) );
184     registerPropertyNoMember( LAYOUTMANAGER_PROPNAME_REFRESHVISIBILITY, LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY, beans::PropertyAttribute::TRANSIENT, ::getCppuType( &bRefreshVisibility ), &bRefreshVisibility );
185     registerProperty( LAYOUTMANAGER_PROPNAME_PRESERVE_CONTENT_SIZE, LAYOUTMANAGER_PROPHANDLE_PRESERVE_CONTENT_SIZE, beans::PropertyAttribute::TRANSIENT, &m_bPreserveContentSize, ::getCppuType( &m_bPreserveContentSize ) );
186 }
187 
188 LayoutManager::~LayoutManager()
189 {
190     Application::RemoveEventListener( LINK( this, LayoutManager, SettingsChanged ) );
191     m_aAsyncLayoutTimer.Stop();
192 }
193 
194 // Internal helper function
195 void LayoutManager::impl_clearUpMenuBar()
196 {
197     implts_lock();
198 
199     // Clear up VCL menu bar to prepare shutdown
200     if ( m_xContainerWindow.is() )
201     {
202         vos::OGuard aGuard( Application::GetSolarMutex() );
203 
204         SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
205         if ( pSysWindow )
206         {
207             MenuBar* pSetMenuBar = 0;
208             if ( m_xInplaceMenuBar.is() )
209                 pSetMenuBar = (MenuBar *)m_pInplaceMenuBar->GetMenuBar();
210             else
211             {
212                 Reference< awt::XMenuBar > xMenuBar;
213 
214                 Reference< XPropertySet > xPropSet( m_xMenuBar, UNO_QUERY );
215                 if ( xPropSet.is() )
216                 {
217                     try
218                     {
219                         xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMenuBar" ))) >>= xMenuBar;
220                     }
221                     catch ( beans::UnknownPropertyException ) {}
222                     catch ( lang::WrappedTargetException ) {}
223                 }
224 
225                 VCLXMenu* pAwtMenuBar = VCLXMenu::GetImplementation( xMenuBar );
226                 if ( pAwtMenuBar )
227                     pSetMenuBar = (MenuBar*)pAwtMenuBar->GetMenu();
228             }
229 
230             MenuBar* pTopMenuBar = pSysWindow->GetMenuBar();
231             if ( pSetMenuBar == pTopMenuBar )
232                 pSysWindow->SetMenuBar( 0 );
233         }
234     }
235 
236     // reset inplace menubar manager
237     m_pInplaceMenuBar = 0;
238     if ( m_xInplaceMenuBar.is() )
239     {
240         m_xInplaceMenuBar->dispose();
241         m_xInplaceMenuBar.clear();
242     }
243 
244     Reference< XComponent > xComp( m_xMenuBar, UNO_QUERY );
245     if ( xComp.is() )
246         xComp->dispose();
247     m_xMenuBar.clear();
248     implts_unlock();
249 }
250 
251 void LayoutManager::implts_lock()
252 {
253     WriteGuard aWriteLock( m_aLock );
254     ++m_nLockCount;
255 }
256 
257 sal_Bool LayoutManager::implts_unlock()
258 {
259     WriteGuard aWriteLock( m_aLock );
260     m_nLockCount = std::max( --m_nLockCount, static_cast<sal_Int32>(0) );
261     return ( m_nLockCount == 0 );
262 }
263 
264 void LayoutManager::implts_reset( sal_Bool bAttached )
265 {
266     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
267     ReadGuard aReadLock( m_aLock );
268     Reference< XFrame > xFrame = m_xFrame;
269     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
270     Reference< XUIConfiguration > xModuleCfgMgr( m_xModuleCfgMgr, UNO_QUERY );
271     Reference< XUIConfiguration > xDocCfgMgr( m_xDocCfgMgr, UNO_QUERY );
272     Reference< XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
273     Reference< XMultiServiceFactory > xServiceManager( m_xSMGR );
274     Reference< XNameAccess > xPersistentWindowStateSupplier( m_xPersistentWindowStateSupplier );
275     Reference< awt::XWindowListener > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
276     ToolbarLayoutManager* pToolbarManager( m_pToolbarManager );
277     ::rtl::OUString aModuleIdentifier( m_aModuleIdentifier );
278     bool bAutomaticToolbars( m_bAutomaticToolbars );
279     aReadLock.unlock();
280     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
281 
282     implts_lock();
283 
284     Reference< XModel > xModel;
285     if ( xFrame.is() )
286     {
287         if ( bAttached )
288         {
289             ::rtl::OUString aOldModuleIdentifier( aModuleIdentifier );
290             try
291             {
292                 aModuleIdentifier = m_xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ) );
293             }
294             catch( Exception& ) {}
295 
296             if ( aModuleIdentifier.getLength() && aOldModuleIdentifier != aModuleIdentifier )
297             {
298                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier;
299                 if ( xServiceManager.is() )
300                     xModuleCfgSupplier = Reference< XModuleUIConfigurationManagerSupplier >(
301                         xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY );
302 
303                 if ( xModuleCfgMgr.is() )
304                 {
305                     try
306                     {
307                         // Remove listener to old module ui configuration manager
308                         xModuleCfgMgr->removeConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
309                     }
310                     catch ( Exception& ) {}
311                 }
312 
313                 try
314                 {
315                     // Add listener to new module ui configuration manager
316                     xModuleCfgMgr = Reference< XUIConfiguration >( xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier ), UNO_QUERY );
317                     if ( xModuleCfgMgr.is() )
318                         xModuleCfgMgr->addConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
319                 }
320                 catch ( Exception& ) {}
321 
322                 try
323                 {
324                     // Retrieve persistent window state reference for our new module
325                     if ( xPersistentWindowStateSupplier.is() )
326                         xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= xPersistentWindowState;
327                 }
328                 catch ( NoSuchElementException& ) {}
329                 catch ( WrappedTargetException& ) {}
330             }
331 
332             xModel = impl_getModelFromFrame( xFrame );
333             if ( xModel.is() )
334             {
335                 Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
336                 if ( xUIConfigurationManagerSupplier.is() )
337                 {
338                     if ( xDocCfgMgr.is() )
339                     {
340                         try
341                         {
342                             // Remove listener to old ui configuration manager
343                             xDocCfgMgr->removeConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
344                         }
345                         catch ( Exception& ) {}
346                     }
347 
348                     try
349                     {
350                         xDocCfgMgr = Reference< XUIConfiguration >( xUIConfigurationManagerSupplier->getUIConfigurationManager(), UNO_QUERY );
351                         if ( xDocCfgMgr.is() )
352                             xDocCfgMgr->addConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
353                     }
354                     catch ( Exception& ) {}
355                 }
356             }
357         }
358         else
359         {
360             // Remove configuration listeners before we can release our references
361             if ( xModuleCfgMgr.is() )
362             {
363                 try
364                 {
365                     xModuleCfgMgr->removeConfigurationListener(
366                         Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
367                 }
368                 catch ( Exception& ) {}
369             }
370 
371             if ( xDocCfgMgr.is() )
372             {
373                 try
374                 {
375                     xDocCfgMgr->removeConfigurationListener(
376                         Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
377                 }
378                 catch ( Exception& ) {}
379             }
380 
381             // Release references to our configuration managers as we currently don't have
382             // an attached module.
383             xModuleCfgMgr.clear();
384             xDocCfgMgr.clear();
385             xPersistentWindowState.clear();
386             aModuleIdentifier = ::rtl::OUString();
387         }
388 
389         Reference< XUIConfigurationManager > xModCfgMgr( xModuleCfgMgr, UNO_QUERY );
390         Reference< XUIConfigurationManager > xDokCfgMgr( xDocCfgMgr, UNO_QUERY );
391 
392         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
393         WriteGuard aWriteLock( m_aLock );
394         m_xModel = xModel;
395         m_aDockingArea = awt::Rectangle();
396         m_bComponentAttached = bAttached;
397         m_aModuleIdentifier = aModuleIdentifier;
398         m_xModuleCfgMgr = xModCfgMgr;
399         m_xDocCfgMgr = xDokCfgMgr;
400         m_xPersistentWindowState = xPersistentWindowState;
401         m_aStatusBarElement.m_bStateRead = sal_False; // reset state to read data again!
402         aWriteLock.unlock();
403         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
404 
405         // reset/notify toolbar layout manager
406         if ( pToolbarManager )
407         {
408             if ( bAttached )
409             {
410                 pToolbarManager->attach( xFrame, xModCfgMgr, xDokCfgMgr, xPersistentWindowState );
411                 uno::Reference< awt::XWindowPeer > xParent( xContainerWindow, UNO_QUERY );
412                 pToolbarManager->setParentWindow( xParent );
413                 if ( bAutomaticToolbars )
414                     pToolbarManager->createStaticToolbars();
415             }
416             else
417             {
418                 pToolbarManager->reset();
419                 implts_destroyElements();
420             }
421         }
422     }
423 
424     implts_unlock();
425 }
426 
427 sal_Bool LayoutManager::implts_isEmbeddedLayoutManager() const
428 {
429     ReadGuard aReadLock( m_aLock );
430     Reference< XFrame > xFrame = m_xFrame;
431     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
432     aReadLock.unlock();
433 
434     Reference< awt::XWindow > xFrameContainerWindow = xFrame->getContainerWindow();
435     if ( xFrameContainerWindow == xContainerWindow )
436         return sal_False;
437     else
438         return sal_True;
439 }
440 
441 void LayoutManager::implts_destroyElements()
442 {
443     WriteGuard aWriteLock( m_aLock );
444     uno::Reference< ui::XUIConfigurationListener > xThis( m_xToolbarManager );
445     ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
446     aWriteLock.unlock();
447 
448     if ( pToolbarManager )
449         pToolbarManager->destroyToolbars();
450 
451     implts_destroyStatusBar();
452 
453     aWriteLock.lock();
454     impl_clearUpMenuBar();
455     aWriteLock.unlock();
456 }
457 
458 void LayoutManager::implts_toggleFloatingUIElementsVisibility( sal_Bool bActive )
459 {
460     ReadGuard aReadLock( m_aLock );
461     uno::Reference< ui::XUIConfigurationListener > xThis( m_xToolbarManager );
462     ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
463     aReadLock.unlock();
464 
465     if ( pToolbarManager )
466         pToolbarManager->setFloatingToolbarsVisibility( bActive );
467 }
468 
469 uno::Reference< ui::XUIElement > LayoutManager::implts_findElement( const rtl::OUString& aName )
470 {
471     ::rtl::OUString aElementType;
472     ::rtl::OUString aElementName;
473 
474     parseResourceURL( aName, aElementType, aElementName );
475     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
476         return m_xMenuBar;
477     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == aName ))
478         return m_aStatusBarElement.m_xUIElement;
479     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ))
480         return m_aProgressBarElement.m_xUIElement;
481 
482     return uno::Reference< ui::XUIElement >();
483 }
484 
485 UIElement& LayoutManager::impl_findElement( const rtl::OUString& aName )
486 {
487     static UIElement aEmptyElement;
488 
489     ::rtl::OUString aElementType;
490     ::rtl::OUString aElementName;
491 
492     parseResourceURL( aName, aElementType, aElementName );
493     if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == aName ))
494         return m_aStatusBarElement;
495     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ))
496         return m_aProgressBarElement;
497 
498     return aEmptyElement;
499 }
500 
501 sal_Bool LayoutManager::implts_readWindowStateData( const rtl::OUString& aName, UIElement& rElementData )
502 {
503     sal_Bool bGetSettingsState( sal_False );
504 
505     WriteGuard aWriteLock( m_aLock );
506     Reference< XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
507     aWriteLock.unlock();
508 
509     if ( xPersistentWindowState.is() )
510     {
511         aWriteLock.lock();
512         sal_Bool bGlobalSettings( m_bGlobalSettings );
513         GlobalSettings* pGlobalSettings( 0 );
514         if ( m_pGlobalSettings == 0 )
515         {
516             m_pGlobalSettings = new GlobalSettings( m_xSMGR );
517             bGetSettingsState = sal_True;
518         }
519         pGlobalSettings = m_pGlobalSettings;
520         aWriteLock.unlock();
521 
522         try
523         {
524             Sequence< PropertyValue > aWindowState;
525             if ( xPersistentWindowState->hasByName( aName ) && (xPersistentWindowState->getByName( aName ) >>= aWindowState) )
526             {
527                 sal_Bool bValue( sal_False );
528                 for ( sal_Int32 n = 0; n < aWindowState.getLength(); n++ )
529                 {
530                     if ( aWindowState[n].Name == m_aPropDocked )
531                     {
532                         if ( aWindowState[n].Value >>= bValue )
533                             rElementData.m_bFloating = !bValue;
534                     }
535                     else if ( aWindowState[n].Name == m_aPropVisible )
536                     {
537                         if ( aWindowState[n].Value >>= bValue )
538                             rElementData.m_bVisible = bValue;
539                     }
540                     else if ( aWindowState[n].Name == m_aPropDockingArea )
541                     {
542                         ui::DockingArea eDockingArea;
543                         if ( aWindowState[n].Value >>= eDockingArea )
544                             rElementData.m_aDockedData.m_nDockedArea = sal_Int16( eDockingArea );
545                     }
546                     else if ( aWindowState[n].Name == m_aPropDockPos )
547                     {
548                         awt::Point aPoint;
549                         if ( aWindowState[n].Value >>= aPoint )
550                         {
551                             rElementData.m_aDockedData.m_aPos.X() = aPoint.X;
552                             rElementData.m_aDockedData.m_aPos.Y() = aPoint.Y;
553                         }
554                     }
555                     else if ( aWindowState[n].Name == m_aPropPos )
556                     {
557                         awt::Point aPoint;
558                         if ( aWindowState[n].Value >>= aPoint )
559                         {
560                             rElementData.m_aFloatingData.m_aPos.X() = aPoint.X;
561                             rElementData.m_aFloatingData.m_aPos.Y() = aPoint.Y;
562                         }
563                     }
564                     else if ( aWindowState[n].Name == m_aPropSize )
565                     {
566                         awt::Size aSize;
567                         if ( aWindowState[n].Value >>= aSize )
568                         {
569                             rElementData.m_aFloatingData.m_aSize.Width() = aSize.Width;
570                             rElementData.m_aFloatingData.m_aSize.Height() = aSize.Height;
571                         }
572                     }
573                     else if ( aWindowState[n].Name == m_aPropUIName )
574                         aWindowState[n].Value >>= rElementData.m_aUIName;
575                     else if ( aWindowState[n].Name == m_aPropStyle )
576                     {
577                         sal_Int32 nStyle = 0;
578                         if ( aWindowState[n].Value >>= nStyle )
579                             rElementData.m_nStyle = sal_Int16( nStyle );
580                     }
581                     else if ( aWindowState[n].Name == m_aPropLocked )
582                     {
583                         if ( aWindowState[n].Value >>= bValue )
584                             rElementData.m_aDockedData.m_bLocked = bValue;
585                     }
586                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXT ))
587                     {
588                         if ( aWindowState[n].Value >>= bValue )
589                             rElementData.m_bContextSensitive = bValue;
590                     }
591                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_NOCLOSE ))
592                     {
593                         if ( aWindowState[n].Value >>= bValue )
594                             rElementData.m_bNoClose = bValue;
595                     }
596                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_CONTEXTACTIVE ))
597                     {
598                         if ( aWindowState[n].Value >>= bValue )
599                             rElementData.m_bContextActive = bValue;
600                     }
601                     else if ( aWindowState[n].Name.equalsAscii( WINDOWSTATE_PROPERTY_SOFTCLOSE ))
602                     {
603                         if ( aWindowState[n].Value >>= bValue )
604                             rElementData.m_bSoftClose = bValue;
605                     }
606                 }
607             }
608 
609             // oversteer values with global settings
610             if ( pGlobalSettings && ( bGetSettingsState || bGlobalSettings ))
611             {
612                 if ( pGlobalSettings->HasStatesInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR ))
613                 {
614                     WriteGuard aWriteLock2( m_aLock );
615                     m_bGlobalSettings = sal_True;
616                     aWriteLock2.unlock();
617 
618                     uno::Any aValue;
619                     sal_Bool      bValue = sal_Bool();
620                     if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR,
621                                                         GlobalSettings::STATEINFO_LOCKED,
622                                                         aValue ))
623                         aValue >>= rElementData.m_aDockedData.m_bLocked;
624                     if ( pGlobalSettings->GetStateInfo( GlobalSettings::UIELEMENT_TYPE_TOOLBAR,
625                                                         GlobalSettings::STATEINFO_DOCKED,
626                                                         aValue ))
627                     {
628                         if ( aValue >>= bValue )
629                             rElementData.m_bFloating = !bValue;
630                     }
631                 }
632             }
633 
634             return sal_True;
635         }
636         catch ( NoSuchElementException& ) {}
637     }
638 
639     return sal_False;
640 }
641 
642 void LayoutManager::implts_writeWindowStateData( const rtl::OUString& aName, const UIElement& rElementData )
643 {
644     WriteGuard aWriteLock( m_aLock );
645     Reference< XNameAccess > xPersistentWindowState( m_xPersistentWindowState );
646 
647     // set flag to determine that we triggered the notification
648     m_bStoreWindowState = sal_True;
649     aWriteLock.unlock();
650 
651     sal_Bool bPersistent( sal_False );
652     Reference< XPropertySet > xPropSet( rElementData.m_xUIElement, UNO_QUERY );
653     if ( xPropSet.is() )
654     {
655         try
656         {
657             // Check persistent flag of the user interface element
658             xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ))) >>= bPersistent;
659         }
660         catch ( beans::UnknownPropertyException )
661         {
662             // Non-configurable elements should at least store their dimension/position
663             bPersistent = sal_True;
664         }
665         catch ( lang::WrappedTargetException ) {}
666     }
667 
668     if ( bPersistent && xPersistentWindowState.is() )
669     {
670         try
671         {
672             Sequence< PropertyValue > aWindowState( 8 );
673 
674             aWindowState[0].Name  = m_aPropDocked;
675             aWindowState[0].Value = makeAny( sal_Bool( !rElementData.m_bFloating ));
676             aWindowState[1].Name  = m_aPropVisible;
677             aWindowState[1].Value = makeAny( sal_Bool( rElementData.m_bVisible ));
678 
679             aWindowState[2].Name  = m_aPropDockingArea;
680             aWindowState[2].Value = makeAny( static_cast< DockingArea >( rElementData.m_aDockedData.m_nDockedArea ) );
681 
682             awt::Point aPos;
683             aPos.X = rElementData.m_aDockedData.m_aPos.X();
684             aPos.Y = rElementData.m_aDockedData.m_aPos.Y();
685             aWindowState[3].Name = m_aPropDockPos;
686             aWindowState[3].Value <<= aPos;
687 
688             aPos.X = rElementData.m_aFloatingData.m_aPos.X();
689             aPos.Y = rElementData.m_aFloatingData.m_aPos.Y();
690             aWindowState[4].Name = m_aPropPos;
691             aWindowState[4].Value <<= aPos;
692 
693             awt::Size aSize;
694             aSize.Width = rElementData.m_aFloatingData.m_aSize.Width();
695             aSize.Height = rElementData.m_aFloatingData.m_aSize.Height();
696             aWindowState[5].Name  = m_aPropSize;
697             aWindowState[5].Value <<= aSize;
698             aWindowState[6].Name  = m_aPropUIName;
699             aWindowState[6].Value = makeAny( rElementData.m_aUIName );
700             aWindowState[7].Name  = m_aPropLocked;
701             aWindowState[7].Value = makeAny( rElementData.m_aDockedData.m_bLocked );
702 
703             if ( xPersistentWindowState->hasByName( aName ))
704             {
705                 Reference< XNameReplace > xReplace( xPersistentWindowState, uno::UNO_QUERY );
706                 xReplace->replaceByName( aName, makeAny( aWindowState ));
707             }
708             else
709             {
710                 Reference< XNameContainer > xInsert( xPersistentWindowState, uno::UNO_QUERY );
711                 xInsert->insertByName( aName, makeAny( aWindowState ));
712             }
713         }
714         catch ( Exception& ) {}
715     }
716 
717     // Reset flag
718     aWriteLock.lock();
719     m_bStoreWindowState = sal_False;
720     aWriteLock.unlock();
721 }
722 
723 ::Size LayoutManager::implts_getContainerWindowOutputSize()
724 {
725     ::Size  aContainerWinSize;
726     Window* pContainerWindow( 0 );
727 
728     // Retrieve output size from container Window
729     vos::OGuard aGuard( Application::GetSolarMutex() );
730     pContainerWindow  = VCLUnoHelper::GetWindow( m_xContainerWindow );
731     if ( pContainerWindow )
732         aContainerWinSize = pContainerWindow->GetOutputSizePixel();
733 
734     return aContainerWinSize;
735 }
736 
737 Reference< XUIElement > LayoutManager::implts_createElement( const rtl::OUString& aName )
738 {
739     Reference< ui::XUIElement > xUIElement;
740 
741     ReadGuard   aReadLock( m_aLock );
742     Sequence< PropertyValue > aPropSeq( 2 );
743     aPropSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
744     aPropSeq[0].Value <<= m_xFrame;
745     aPropSeq[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
746     aPropSeq[1].Value <<= sal_True;
747 
748     try
749     {
750         xUIElement = m_xUIElementFactoryManager->createUIElement( aName, aPropSeq );
751     }
752     catch ( NoSuchElementException& ) {}
753     catch ( IllegalArgumentException& ) {}
754 
755     return xUIElement;
756 }
757 
758 void LayoutManager::implts_setVisibleState( sal_Bool bShow )
759 {
760     WriteGuard aWriteLock( m_aLock );
761     m_aStatusBarElement.m_bMasterHide = !bShow;
762     aWriteLock.unlock();
763 
764     implts_updateUIElementsVisibleState( bShow );
765 }
766 
767 void LayoutManager::implts_updateUIElementsVisibleState( sal_Bool bSetVisible )
768 {
769     // notify listeners
770     uno::Any a;
771     if ( bSetVisible )
772         implts_notifyListeners( frame::LayoutManagerEvents::VISIBLE, a );
773     else
774         implts_notifyListeners( frame::LayoutManagerEvents::INVISIBLE, a );
775     std::vector< Reference< awt::XWindow > > aWinVector;
776 
777     WriteGuard aWriteLock( m_aLock );
778     Reference< XUIElement >   xMenuBar( m_xMenuBar, UNO_QUERY );
779     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
780     Reference< XComponent >   xInplaceMenuBar( m_xInplaceMenuBar );
781     MenuBarManager*           pInplaceMenuBar( m_pInplaceMenuBar );
782     aWriteLock.unlock();
783 
784     bool bMustDoLayout(false);
785     if (( xMenuBar.is() || xInplaceMenuBar.is() ) && xContainerWindow.is() )
786     {
787         vos::OGuard aGuard( Application::GetSolarMutex() );
788 
789         MenuBar* pMenuBar( 0 );
790         if ( xInplaceMenuBar.is() )
791             pMenuBar = (MenuBar *)pInplaceMenuBar->GetMenuBar();
792         else
793         {
794             MenuBarWrapper* pMenuBarWrapper = SAL_STATIC_CAST( MenuBarWrapper*, xMenuBar.get() );
795             pMenuBar = (MenuBar *)pMenuBarWrapper->GetMenuBarManager()->GetMenuBar();
796         }
797 
798         SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
799         if ( pSysWindow )
800         {
801             if ( bSetVisible )
802                 pSysWindow->SetMenuBar( pMenuBar );
803             else
804                 pSysWindow->SetMenuBar( 0 );
805             bMustDoLayout = true;
806         }
807     }
808 
809     // Hide/show the statusbar according to bSetVisible
810     if ( bSetVisible )
811         bMustDoLayout = !implts_showStatusBar();
812     else
813         bMustDoLayout = !implts_hideStatusBar();
814 
815     aWriteLock.lock();
816     uno::Reference< ui::XUIConfigurationListener > xThis( m_xToolbarManager );
817     ToolbarLayoutManager* pToolbarManager( m_pToolbarManager );
818     aWriteLock.unlock();
819 
820     if ( pToolbarManager )
821     {
822         pToolbarManager->setVisible( bSetVisible );
823         bMustDoLayout = pToolbarManager->isLayoutDirty();
824     }
825 
826     if ( bMustDoLayout )
827         implts_doLayout_notify( sal_False );
828 }
829 
830 void LayoutManager::implts_setCurrentUIVisibility( sal_Bool bShow )
831 {
832     WriteGuard aWriteLock( m_aLock );
833     if ( !bShow && m_aStatusBarElement.m_bVisible && m_aStatusBarElement.m_xUIElement.is() )
834         m_aStatusBarElement.m_bMasterHide = true;
835     else if ( bShow && m_aStatusBarElement.m_bVisible )
836         m_aStatusBarElement.m_bMasterHide = false;
837     aWriteLock.unlock();
838 
839     implts_updateUIElementsVisibleState( bShow );
840 }
841 
842 void LayoutManager::implts_destroyStatusBar()
843 {
844     Reference< XComponent > xCompStatusBar;
845 
846     WriteGuard aWriteLock( m_aLock );
847     m_aStatusBarElement.m_aName = rtl::OUString();
848     xCompStatusBar = Reference< XComponent >( m_aStatusBarElement.m_xUIElement, UNO_QUERY );
849     m_aStatusBarElement.m_xUIElement.clear();
850     aWriteLock.unlock();
851 
852     if ( xCompStatusBar.is() )
853         xCompStatusBar->dispose();
854 
855     implts_destroyProgressBar();
856 }
857 
858 void LayoutManager::implts_createStatusBar( const rtl::OUString& aStatusBarName )
859 {
860     WriteGuard aWriteLock( m_aLock );
861     if ( !m_aStatusBarElement.m_xUIElement.is() )
862     {
863         implts_readStatusBarState( aStatusBarName );
864         m_aStatusBarElement.m_aName      = aStatusBarName;
865         m_aStatusBarElement.m_xUIElement = implts_createElement( aStatusBarName );
866     }
867     aWriteLock.unlock();
868 
869     implts_createProgressBar();
870 }
871 
872 void LayoutManager::implts_readStatusBarState( const rtl::OUString& rStatusBarName )
873 {
874     WriteGuard aWriteLock( m_aLock );
875     if ( !m_aStatusBarElement.m_bStateRead )
876     {
877         // Read persistent data for status bar if not yet read!
878         if ( implts_readWindowStateData( rStatusBarName, m_aStatusBarElement ))
879             m_aStatusBarElement.m_bStateRead = sal_True;
880     }
881 }
882 
883 void LayoutManager::implts_createProgressBar()
884 {
885     Reference< XUIElement > xStatusBar;
886     Reference< XUIElement > xProgressBar;
887     Reference< XUIElement > xProgressBarBackup;
888     Reference< awt::XWindow > xContainerWindow;
889 
890     WriteGuard aWriteLock( m_aLock );
891     xStatusBar = Reference< XUIElement >( m_aStatusBarElement.m_xUIElement, UNO_QUERY );
892     xProgressBar = Reference< XUIElement >( m_aProgressBarElement.m_xUIElement, UNO_QUERY );
893     xProgressBarBackup = m_xProgressBarBackup;
894     m_xProgressBarBackup.clear();
895     xContainerWindow = m_xContainerWindow;
896     aWriteLock.unlock();
897 
898     sal_Bool            bRecycled = xProgressBarBackup.is();
899     ProgressBarWrapper* pWrapper  = 0;
900     if ( bRecycled )
901         pWrapper = (ProgressBarWrapper*)xProgressBarBackup.get();
902     else if ( xProgressBar.is() )
903         pWrapper = (ProgressBarWrapper*)xProgressBar.get();
904     else
905         pWrapper = new ProgressBarWrapper();
906 
907     if ( xStatusBar.is() )
908     {
909         Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
910         pWrapper->setStatusBar( xWindow );
911     }
912     else
913     {
914         Reference< awt::XWindow > xStatusBarWindow = pWrapper->getStatusBar();
915 
916         vos::OGuard     aGuard( Application::GetSolarMutex() );
917         Window* pStatusBarWnd = VCLUnoHelper::GetWindow( xStatusBarWindow );
918         if ( !pStatusBarWnd )
919         {
920             Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
921             if ( pWindow )
922             {
923                 StatusBar* pStatusBar = new StatusBar( pWindow, WinBits( WB_LEFT | WB_3DLOOK ) );
924                 Reference< awt::XWindow > xStatusBarWindow2( VCLUnoHelper::GetInterface( pStatusBar ));
925                 pWrapper->setStatusBar( xStatusBarWindow2, sal_True );
926             }
927         }
928     }
929 
930     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
931     aWriteLock.lock();
932     m_aProgressBarElement.m_xUIElement = Reference< XUIElement >(
933         static_cast< cppu::OWeakObject* >( pWrapper ), UNO_QUERY );
934     aWriteLock.unlock();
935     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
936 
937     if ( bRecycled )
938         implts_showProgressBar();
939 }
940 
941 void LayoutManager::implts_backupProgressBarWrapper()
942 {
943     // SAFE -> ----------------------------------
944     WriteGuard aWriteLock(m_aLock);
945 
946     if (m_xProgressBarBackup.is())
947         return;
948 
949     // safe a backup copy of the current progress!
950     // This copy will be used automaticly inside createProgressBar() which is called
951     // implictly from implts_doLayout() .-)
952     m_xProgressBarBackup = m_aProgressBarElement.m_xUIElement;
953 
954     // remove the relation between this old progress bar and our old status bar.
955     // Otherwhise we work on disposed items ...
956     // The internal used ProgressBarWrapper can handle a NULL reference.
957     if ( m_xProgressBarBackup.is() )
958     {
959         ProgressBarWrapper* pWrapper = (ProgressBarWrapper*)m_xProgressBarBackup.get();
960         if ( pWrapper )
961             pWrapper->setStatusBar( Reference< awt::XWindow >(), sal_False );
962     }
963 
964     // prevent us from dispose() the m_aProgressBarElement.m_xUIElement inside implts_reset()
965     m_aProgressBarElement.m_xUIElement.clear();
966 
967     aWriteLock.unlock();
968     // <- SAFE ----------------------------------
969 }
970 
971 void LayoutManager::implts_destroyProgressBar()
972 {
973     // dont remove the progressbar in general
974     // We must reuse it if a new status bar is created later.
975     // Of course there exists one backup only.
976     // And further this backup will be released inside our dtor.
977     implts_backupProgressBarWrapper();
978 }
979 
980 void LayoutManager::implts_setStatusBarPosSize( const ::Point& rPos, const ::Size& rSize )
981 {
982     Reference< XUIElement > xStatusBar;
983     Reference< XUIElement > xProgressBar;
984     Reference< awt::XWindow > xContainerWindow;
985 
986     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
987     ReadGuard aReadLock( m_aLock );
988     xStatusBar = Reference< XUIElement >( m_aStatusBarElement.m_xUIElement, UNO_QUERY );
989     xProgressBar = Reference< XUIElement >( m_aProgressBarElement.m_xUIElement, UNO_QUERY );
990     xContainerWindow = m_xContainerWindow;
991 
992     Reference< awt::XWindow > xWindow;
993     if ( xStatusBar.is() )
994         xWindow = Reference< awt::XWindow >( xStatusBar->getRealInterface(), UNO_QUERY );
995     else if ( xProgressBar.is() )
996     {
997         ProgressBarWrapper* pWrapper = (ProgressBarWrapper*)xProgressBar.get();
998         if ( pWrapper )
999             xWindow = pWrapper->getStatusBar();
1000     }
1001     aReadLock.unlock();
1002     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1003 
1004     if ( xWindow.is() )
1005     {
1006         vos::OGuard     aGuard( Application::GetSolarMutex() );
1007         Window* pParentWindow = VCLUnoHelper::GetWindow( xContainerWindow );
1008         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1009         if ( pParentWindow && ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR ))
1010         {
1011             Window* pOldParentWindow = pWindow->GetParent();
1012             if ( pParentWindow != pOldParentWindow )
1013                 pWindow->SetParent( pParentWindow );
1014             ((StatusBar *)pWindow)->SetPosSizePixel( rPos, rSize );
1015         }
1016     }
1017 }
1018 
1019 sal_Bool LayoutManager::implts_showProgressBar()
1020 {
1021     Reference< XUIElement > xStatusBar;
1022     Reference< XUIElement > xProgressBar;
1023     Reference< awt::XWindow > xWindow;
1024 
1025     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1026     WriteGuard aWriteLock( m_aLock );
1027     xStatusBar = Reference< XUIElement >( m_aStatusBarElement.m_xUIElement, UNO_QUERY );
1028     xProgressBar = Reference< XUIElement >( m_aProgressBarElement.m_xUIElement, UNO_QUERY );
1029     sal_Bool bVisible( m_bVisible );
1030 
1031     m_aProgressBarElement.m_bVisible = sal_True;
1032     if ( bVisible )
1033     {
1034         if ( xStatusBar.is() && !m_aStatusBarElement.m_bMasterHide )
1035         {
1036             xWindow = Reference< awt::XWindow >( xStatusBar->getRealInterface(), UNO_QUERY );
1037         }
1038         else if ( xProgressBar.is() )
1039         {
1040             ProgressBarWrapper* pWrapper = (ProgressBarWrapper*)xProgressBar.get();
1041             if ( pWrapper )
1042                 xWindow = pWrapper->getStatusBar();
1043         }
1044     }
1045     aWriteLock.unlock();
1046     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1047 
1048     vos::OGuard aGuard( Application::GetSolarMutex() );
1049     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1050     if ( pWindow )
1051     {
1052         if ( !pWindow->IsVisible() )
1053         {
1054             implts_setOffset( pWindow->GetSizePixel().Height() );
1055             pWindow->Show();
1056             implts_doLayout_notify( sal_False );
1057         }
1058         return sal_True;
1059     }
1060 
1061     return sal_False;
1062 }
1063 
1064 sal_Bool LayoutManager::implts_hideProgressBar()
1065 {
1066     Reference< XUIElement > xProgressBar;
1067     Reference< awt::XWindow > xWindow;
1068     sal_Bool bHideStatusBar( sal_False );
1069 
1070     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1071     WriteGuard aWriteLock( m_aLock );
1072     xProgressBar = Reference< XUIElement >( m_aProgressBarElement.m_xUIElement, UNO_QUERY );
1073 
1074     sal_Bool bInternalStatusBar( sal_False );
1075     if ( xProgressBar.is() )
1076     {
1077         Reference< awt::XWindow > xStatusBar;
1078         ProgressBarWrapper* pWrapper = (ProgressBarWrapper*)xProgressBar.get();
1079         if ( pWrapper )
1080             xWindow = pWrapper->getStatusBar();
1081         Reference< ui::XUIElement > xStatusBarElement = m_aStatusBarElement.m_xUIElement;
1082         if ( xStatusBarElement.is() )
1083             xStatusBar = Reference< awt::XWindow >( xStatusBarElement->getRealInterface(), UNO_QUERY );
1084         bInternalStatusBar = xStatusBar != xWindow;
1085     }
1086     m_aProgressBarElement.m_bVisible = sal_False;
1087     implts_readStatusBarState( m_aStatusBarAlias );
1088     bHideStatusBar = !m_aStatusBarElement.m_bVisible;
1089     aWriteLock.unlock();
1090     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1091 
1092     vos::OGuard aGuard( Application::GetSolarMutex() );
1093     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1094     if ( pWindow && pWindow->IsVisible() && ( bHideStatusBar || bInternalStatusBar ))
1095     {
1096         implts_setOffset( 0 );
1097         pWindow->Hide();
1098         implts_doLayout_notify( sal_False );
1099         return sal_True;
1100     }
1101 
1102     return sal_False;
1103 }
1104 
1105 sal_Bool LayoutManager::implts_showStatusBar( sal_Bool bStoreState )
1106 {
1107     WriteGuard aWriteLock( m_aLock );
1108     Reference< ui::XUIElement > xStatusBar = m_aStatusBarElement.m_xUIElement;
1109     if ( bStoreState )
1110         m_aStatusBarElement.m_bVisible = sal_True;
1111     aWriteLock.unlock();
1112 
1113     if ( xStatusBar.is() )
1114     {
1115         Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
1116 
1117         vos::OGuard     aGuard( Application::GetSolarMutex() );
1118         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1119         if ( pWindow && !pWindow->IsVisible() )
1120         {
1121             implts_setOffset( pWindow->GetSizePixel().Height() );
1122             pWindow->Show();
1123             implts_doLayout_notify( sal_False );
1124             return sal_True;
1125         }
1126     }
1127 
1128     return sal_False;
1129 }
1130 
1131 sal_Bool LayoutManager::implts_hideStatusBar( sal_Bool bStoreState )
1132 {
1133     WriteGuard aWriteLock( m_aLock );
1134     Reference< ui::XUIElement > xStatusBar = m_aStatusBarElement.m_xUIElement;
1135     if ( bStoreState )
1136         m_aStatusBarElement.m_bVisible = sal_False;
1137     aWriteLock.unlock();
1138 
1139     if ( xStatusBar.is() )
1140     {
1141         Reference< awt::XWindow > xWindow( xStatusBar->getRealInterface(), UNO_QUERY );
1142 
1143         vos::OGuard     aGuard( Application::GetSolarMutex() );
1144         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1145         if ( pWindow && pWindow->IsVisible() )
1146         {
1147             implts_setOffset( 0 );
1148             pWindow->Hide();
1149             implts_doLayout_notify( sal_False );
1150             return sal_True;
1151         }
1152     }
1153 
1154     return sal_False;
1155 }
1156 
1157 void LayoutManager::implts_setOffset( const sal_Int32 nBottomOffset )
1158 {
1159     ::Rectangle aOffsetRect;
1160     setZeroRectangle( aOffsetRect );
1161     aOffsetRect.setHeight( nBottomOffset );
1162 
1163     // make sure that the toolbar manager refernence/pointer is valid
1164     uno::Reference< ui::XUIConfigurationListener > xThis( m_xToolbarManager );
1165     if ( xThis.is() )
1166         m_pToolbarManager->setDockingAreaOffsets( aOffsetRect );
1167 }
1168 
1169 void LayoutManager::implts_setInplaceMenuBar( const Reference< XIndexAccess >& xMergedMenuBar )
1170 throw (uno::RuntimeException)
1171 {
1172     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1173     WriteGuard aWriteLock( m_aLock );
1174 
1175     if ( !m_bInplaceMenuSet )
1176     {
1177         vos::OGuard aGuard( Application::GetSolarMutex() );
1178 
1179         // Reset old inplace menubar!
1180         m_pInplaceMenuBar = 0;
1181         if ( m_xInplaceMenuBar.is() )
1182             m_xInplaceMenuBar->dispose();
1183         m_xInplaceMenuBar.clear();
1184         m_bInplaceMenuSet = sal_False;
1185 
1186         if ( m_xFrame.is() && m_xContainerWindow.is() )
1187         {
1188             rtl::OUString aModuleIdentifier;
1189             Reference< XDispatchProvider > xDispatchProvider;
1190 
1191             MenuBar* pMenuBar = new MenuBar;
1192             m_pInplaceMenuBar = new MenuBarManager( m_xSMGR, m_xFrame, m_xURLTransformer,xDispatchProvider, aModuleIdentifier, pMenuBar, sal_True, sal_True );
1193             m_pInplaceMenuBar->SetItemContainer( xMergedMenuBar );
1194 
1195             SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1196             if ( pSysWindow )
1197                             pSysWindow->SetMenuBar( pMenuBar );
1198 
1199                 m_bInplaceMenuSet = sal_True;
1200             m_xInplaceMenuBar = Reference< XComponent >( (OWeakObject *)m_pInplaceMenuBar, UNO_QUERY );
1201         }
1202 
1203         aWriteLock.unlock();
1204         /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1205 
1206         implts_updateMenuBarClose();
1207     }
1208 }
1209 
1210 void LayoutManager::implts_resetInplaceMenuBar()
1211 throw (uno::RuntimeException)
1212 {
1213     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1214     WriteGuard aWriteLock( m_aLock );
1215     m_bInplaceMenuSet = sal_False;
1216 
1217     // if ( m_xMenuBar.is() &&
1218     if ( m_xContainerWindow.is() )
1219     {
1220         vos::OGuard     aGuard( Application::GetSolarMutex() );
1221         MenuBarWrapper* pMenuBarWrapper = SAL_STATIC_CAST( MenuBarWrapper*, m_xMenuBar.get() );
1222         SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1223         if ( pSysWindow )
1224         {
1225             if ( pMenuBarWrapper )
1226                                 pSysWindow->SetMenuBar( (MenuBar *)pMenuBarWrapper->GetMenuBarManager()->GetMenuBar() );
1227                         else
1228                                 pSysWindow->SetMenuBar( 0 );
1229         }
1230     }
1231 
1232     // Remove inplace menu bar
1233     m_pInplaceMenuBar = 0;
1234     if ( m_xInplaceMenuBar.is() )
1235         m_xInplaceMenuBar->dispose();
1236     m_xInplaceMenuBar.clear();
1237     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1238 }
1239 
1240 void SAL_CALL LayoutManager::attachFrame( const Reference< XFrame >& xFrame )
1241 throw (uno::RuntimeException)
1242 {
1243     WriteGuard aWriteLock( m_aLock );
1244     m_xFrame = xFrame;
1245 }
1246 
1247 void SAL_CALL LayoutManager::reset()
1248 throw (RuntimeException)
1249 {
1250     sal_Bool bComponentAttached( sal_False );
1251 
1252     ReadGuard aReadLock( m_aLock );
1253     bComponentAttached = m_bComponentAttached;
1254     aReadLock.unlock();
1255 
1256     implts_reset( sal_True );
1257 }
1258 
1259 void SAL_CALL LayoutManager::setInplaceMenuBar( sal_Int64 )
1260 throw (uno::RuntimeException)
1261 {
1262     OSL_ENSURE( sal_False, "This method is obsolete and should not be used!\n" );
1263 }
1264 
1265 void SAL_CALL LayoutManager::resetInplaceMenuBar()
1266 throw (uno::RuntimeException)
1267 {
1268     OSL_ENSURE( sal_False, "This method is obsolete and should not be used!\n" );
1269 }
1270 
1271 //---------------------------------------------------------------------------------------------------------
1272 // XMenuBarMergingAcceptor
1273 //---------------------------------------------------------------------------------------------------------
1274 sal_Bool SAL_CALL LayoutManager::setMergedMenuBar(
1275     const Reference< XIndexAccess >& xMergedMenuBar )
1276 throw (uno::RuntimeException)
1277 {
1278     implts_setInplaceMenuBar( xMergedMenuBar );
1279 
1280     uno::Any a;
1281     implts_notifyListeners( frame::LayoutManagerEvents::MERGEDMENUBAR, a );
1282     return sal_True;
1283 }
1284 
1285 void SAL_CALL LayoutManager::removeMergedMenuBar()
1286 throw (uno::RuntimeException)
1287 {
1288     implts_resetInplaceMenuBar();
1289 }
1290 
1291 awt::Rectangle SAL_CALL LayoutManager::getCurrentDockingArea()
1292 throw ( RuntimeException )
1293 {
1294     ReadGuard aReadLock( m_aLock );
1295     return m_aDockingArea;
1296 }
1297 
1298 Reference< XDockingAreaAcceptor > SAL_CALL LayoutManager::getDockingAreaAcceptor()
1299 throw (uno::RuntimeException)
1300 {
1301     ReadGuard aReadLock( m_aLock );
1302     return m_xDockingAreaAcceptor;
1303 }
1304 
1305 void SAL_CALL LayoutManager::setDockingAreaAcceptor( const Reference< ui::XDockingAreaAcceptor >& xDockingAreaAcceptor )
1306 throw ( RuntimeException )
1307 {
1308     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1309     WriteGuard aWriteLock( m_aLock );
1310 
1311     if (( m_xDockingAreaAcceptor == xDockingAreaAcceptor ) || !m_xFrame.is() )
1312         return;
1313 
1314     // IMPORTANT: Be sure to stop layout timer if don't have a docking area acceptor!
1315     if ( !xDockingAreaAcceptor.is() )
1316         m_aAsyncLayoutTimer.Stop();
1317 
1318     sal_Bool bAutomaticToolbars( m_bAutomaticToolbars );
1319     std::vector< Reference< awt::XWindow > > oldDockingAreaWindows;
1320 
1321     uno::Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
1322     ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
1323 
1324     if ( !xDockingAreaAcceptor.is() )
1325         m_aAsyncLayoutTimer.Stop();
1326 
1327     // Remove listener from old docking area acceptor
1328     if ( m_xDockingAreaAcceptor.is() )
1329     {
1330         Reference< awt::XWindow > xWindow( m_xDockingAreaAcceptor->getContainerWindow() );
1331         if ( xWindow.is() && ( m_xFrame->getContainerWindow() != m_xContainerWindow || !xDockingAreaAcceptor.is() ) )
1332             xWindow->removeWindowListener( Reference< awt::XWindowListener >( static_cast< OWeakObject * >( this ), UNO_QUERY ));
1333 
1334         m_aDockingArea = awt::Rectangle();
1335         if ( pToolbarManager )
1336             pToolbarManager->resetDockingArea();
1337 
1338         Window* pContainerWindow = VCLUnoHelper::GetWindow( xWindow );
1339         if ( pContainerWindow )
1340             pContainerWindow->RemoveChildEventListener( LINK( this, LayoutManager, WindowEventListener ) );
1341     }
1342 
1343     Reference< ui::XDockingAreaAcceptor > xOldDockingAreaAcceptor( m_xDockingAreaAcceptor );
1344     m_xDockingAreaAcceptor = xDockingAreaAcceptor;
1345     if ( m_xDockingAreaAcceptor.is() )
1346     {
1347         m_aDockingArea     = awt::Rectangle();
1348         m_xContainerWindow = m_xDockingAreaAcceptor->getContainerWindow();
1349         m_xContainerTopWindow.set( m_xContainerWindow, UNO_QUERY );
1350         m_xContainerWindow->addWindowListener( Reference< awt::XWindowListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
1351 
1352         // we always must keep a connection to the window of our frame for resize events
1353         if ( m_xContainerWindow != m_xFrame->getContainerWindow() )
1354             m_xFrame->getContainerWindow()->addWindowListener( Reference< awt::XWindowListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
1355 
1356         // #i37884# set initial visibility state - in the plugin case the container window is already shown
1357         // and we get no notification anymore
1358         {
1359             vos::OGuard aGuard( Application::GetSolarMutex() );
1360             Window* pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
1361             if( pContainerWindow )
1362                 m_bParentWindowVisible = pContainerWindow->IsVisible();
1363         }
1364 
1365         uno::Reference< awt::XWindowPeer > xParent( m_xContainerWindow, UNO_QUERY );
1366     }
1367 
1368     aWriteLock.unlock();
1369     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1370 
1371     if ( xDockingAreaAcceptor.is() )
1372     {
1373         vos::OGuard aGuard( Application::GetSolarMutex() );
1374 
1375         // Add layout manager as listener to get notifications about toolbar button activties
1376         Window* pContainerWindow = VCLUnoHelper::GetWindow( m_xContainerWindow );
1377         if ( pContainerWindow )
1378             pContainerWindow->AddChildEventListener( LINK( this, LayoutManager, WindowEventListener ) );
1379 
1380         // We have now a new container window, reparent all child windows!
1381         implts_reparentChildWindows();
1382     }
1383     else
1384         implts_destroyElements(); // remove all elements
1385 
1386     if ( !oldDockingAreaWindows.empty() )
1387     {
1388         // Reset docking area size for our old docking area acceptor
1389         awt::Rectangle aEmptyRect;
1390         xOldDockingAreaAcceptor->setDockingAreaSpace( aEmptyRect );
1391     }
1392 
1393     if ( xDockingAreaAcceptor.is() )
1394     {
1395         if ( bAutomaticToolbars )
1396         {
1397             lock();
1398             pToolbarManager->createStaticToolbars();
1399             unlock();
1400         }
1401         implts_doLayout( sal_True, sal_False );
1402     }
1403 }
1404 
1405 void LayoutManager::implts_reparentChildWindows()
1406 {
1407     WriteGuard aWriteLock( m_aLock );
1408     UIElement aStatusBarElement = m_aStatusBarElement;
1409     uno::Reference< awt::XWindow > xContainerWindow  = m_xContainerWindow;
1410     aWriteLock.unlock();
1411 
1412     uno::Reference< awt::XWindow > xStatusBarWindow;
1413     if ( aStatusBarElement.m_xUIElement.is() )
1414     {
1415         try
1416         {
1417             xStatusBarWindow = Reference< awt::XWindow >( aStatusBarElement.m_xUIElement->getRealInterface(), UNO_QUERY );
1418         }
1419         catch ( RuntimeException& ) { throw; }
1420         catch ( Exception& ) {}
1421     }
1422 
1423     if ( xStatusBarWindow.is() )
1424     {
1425         vos::OGuard     aGuard( Application::GetSolarMutex() );
1426         Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow );
1427         Window* pWindow          = VCLUnoHelper::GetWindow( xStatusBarWindow );
1428         if ( pWindow && pContainerWindow )
1429             pWindow->SetParent( pContainerWindow );
1430     }
1431 
1432     implts_resetMenuBar();
1433 
1434     aWriteLock.lock();
1435     uno::Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
1436     ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
1437     if ( pToolbarManager )
1438         pToolbarManager->setParentWindow( uno::Reference< awt::XWindowPeer >( xContainerWindow, uno::UNO_QUERY ));
1439     aWriteLock.unlock();
1440 }
1441 
1442 uno::Reference< ui::XUIElement > LayoutManager::implts_createDockingWindow( const ::rtl::OUString& aElementName )
1443 {
1444     Reference< XUIElement > xUIElement = implts_createElement( aElementName );
1445     return xUIElement;
1446 }
1447 
1448 IMPL_LINK( LayoutManager, WindowEventListener, VclSimpleEvent*, pEvent )
1449 {
1450     long nResult( 1 );
1451 
1452     if ( pEvent && pEvent->ISA( VclWindowEvent ))
1453     {
1454         Window* pWindow = static_cast< VclWindowEvent* >(pEvent)->GetWindow();
1455         if ( pWindow && pWindow->GetType() == WINDOW_TOOLBOX )
1456         {
1457             ReadGuard aReadLock( m_aLock );
1458             uno::Reference< ui::XUIConfigurationListener > xThis( m_xToolbarManager );
1459             ToolbarLayoutManager* pToolbarManager( m_pToolbarManager );
1460             aReadLock.unlock();
1461 
1462             if ( pToolbarManager )
1463                 nResult = pToolbarManager->childWindowEvent( pEvent );
1464         }
1465     }
1466 
1467     return nResult;
1468 }
1469 
1470 void SAL_CALL LayoutManager::createElement( const ::rtl::OUString& aName )
1471 throw (RuntimeException)
1472 {
1473     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::createElement" );
1474 
1475     ReadGuard aReadLock( m_aLock );
1476     Reference< XFrame > xFrame = m_xFrame;
1477     Reference< XURLTransformer > xURLTransformer = m_xURLTransformer;
1478     sal_Bool    bInPlaceMenu = m_bInplaceMenuSet;
1479     aReadLock.unlock();
1480 
1481     if ( !xFrame.is() )
1482         return;
1483 
1484     Reference< XModel >  xModel( impl_getModelFromFrame( xFrame ) );
1485 
1486     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1487     WriteGuard aWriteLock( m_aLock );
1488 
1489     bool bMustBeLayouted( false );
1490     bool bNotify( false );
1491 
1492     if ( m_xContainerWindow.is() && !implts_isPreviewModel( xModel ) ) // no UI elements on preview frames
1493     {
1494         ::rtl::OUString aElementType;
1495         ::rtl::OUString aElementName;
1496 
1497         parseResourceURL( aName, aElementType, aElementName );
1498 
1499         if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ) && m_pToolbarManager != NULL )
1500         {
1501             bNotify         = m_pToolbarManager->createToolbar( aName );
1502             bMustBeLayouted = m_pToolbarManager->isLayoutDirty();
1503         }
1504         else if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
1505         {
1506             // PB 2004-12-15 #i38743# don't create a menubar if frame isn't top
1507             if ( !bInPlaceMenu && !m_xMenuBar.is() && implts_isFrameOrWindowTop( xFrame ))
1508                 {
1509                 m_xMenuBar = implts_createElement( aName );
1510                 if ( m_xMenuBar.is() )
1511                 {
1512                     vos::OGuard aGuard( Application::GetSolarMutex() );
1513 
1514                     SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1515                     if ( pSysWindow )
1516                     {
1517                         Reference< awt::XMenuBar > xMenuBar;
1518 
1519                         Reference< XPropertySet > xPropSet( m_xMenuBar, UNO_QUERY );
1520                         if ( xPropSet.is() )
1521                         {
1522                             try
1523                             {
1524                                 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMenuBar" ))) >>= xMenuBar;
1525                             }
1526                             catch ( beans::UnknownPropertyException ) {}
1527                             catch ( lang::WrappedTargetException ) {}
1528                         }
1529 
1530                         if ( xMenuBar.is() )
1531                         {
1532                             VCLXMenu* pAwtMenuBar = VCLXMenu::GetImplementation( xMenuBar );
1533                             if ( pAwtMenuBar )
1534                             {
1535                                 MenuBar* pMenuBar = (MenuBar*)pAwtMenuBar->GetMenu();
1536                                 if ( pMenuBar )
1537                                 {
1538                                     pSysWindow->SetMenuBar( pMenuBar );
1539                                     pMenuBar->SetDisplayable( m_bMenuVisible );
1540                                     if ( m_bMenuVisible )
1541                                         bNotify = sal_True;
1542                                     implts_updateMenuBarClose();
1543                                 }
1544                             }
1545                         }
1546                     }
1547                 }
1548             }
1549             aWriteLock.unlock();
1550         }
1551         else if ( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && ( implts_isFrameOrWindowTop(xFrame) || implts_isEmbeddedLayoutManager() ))
1552         {
1553             implts_createStatusBar( aName );
1554             bNotify = sal_True;
1555         }
1556         else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ) && implts_isFrameOrWindowTop(xFrame) )
1557         {
1558             implts_createProgressBar();
1559             bNotify = sal_True;
1560         }
1561         else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
1562         {
1563             // Add layout manager as listener for docking and other window events
1564             uno::Reference< uno::XInterface > xThis( static_cast< OWeakObject* >(this), uno::UNO_QUERY );
1565             uno::Reference< ui::XUIElement > xUIElement( implts_createDockingWindow( aName ));
1566 
1567             if ( xUIElement.is() )
1568             {
1569                 impl_addWindowListeners( xThis, xUIElement );
1570                 m_pPanelManager->addDockingWindow( aName, xUIElement );
1571             }
1572 
1573             // The docking window is created by a factory method located in the sfx2 library.
1574 //            CreateDockingWindow( xFrame, aElementName );
1575         }
1576     }
1577 
1578     if ( bMustBeLayouted )
1579         implts_doLayout_notify( sal_True );
1580 
1581     if ( bNotify )
1582     {
1583         // UI element is invisible - provide information to listeners
1584         implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::makeAny( aName ) );
1585     }
1586 }
1587 
1588 void SAL_CALL LayoutManager::destroyElement( const ::rtl::OUString& aName )
1589 throw (RuntimeException)
1590 {
1591     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::destroyElement" );
1592 
1593     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1594     WriteGuard aWriteLock( m_aLock );
1595 
1596     bool            bMustBeLayouted( sal_False );
1597     bool            bMustBeDestroyed( sal_False );
1598     bool            bNotify( sal_False );
1599     ::rtl::OUString aElementType;
1600     ::rtl::OUString aElementName;
1601 
1602     Reference< XComponent > xComponent;
1603     parseResourceURL( aName, aElementType, aElementName );
1604 
1605     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
1606     {
1607         if ( !m_bInplaceMenuSet )
1608         {
1609             impl_clearUpMenuBar();
1610             m_xMenuBar.clear();
1611             bNotify = true;
1612         }
1613     }
1614     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) ||
1615              ( m_aStatusBarElement.m_aName == aName ))
1616     {
1617         aWriteLock.unlock();
1618         implts_destroyStatusBar();
1619         bMustBeLayouted = true;
1620         bNotify         = true;
1621     }
1622     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ))
1623     {
1624         aWriteLock.unlock();
1625         implts_createProgressBar();
1626         bMustBeLayouted = true;
1627         bNotify = sal_True;
1628     }
1629     else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ) && m_pToolbarManager != NULL )
1630     {
1631         aWriteLock.unlock();
1632         bNotify         = m_pToolbarManager->destroyToolbar( aName );
1633         bMustBeLayouted = m_pToolbarManager->isLayoutDirty();
1634     }
1635     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
1636     {
1637         uno::Reference< frame::XFrame > xFrame( m_xFrame );
1638         uno::Reference< lang::XMultiServiceFactory > xSMGR( m_xSMGR );
1639         aWriteLock.unlock();
1640 
1641         impl_setDockingWindowVisibility( xSMGR, xFrame, aElementName, false );
1642         bMustBeLayouted = false;
1643         bNotify         = false;
1644     }
1645     aWriteLock.unlock();
1646     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
1647 
1648     if ( bMustBeDestroyed )
1649     {
1650         if ( xComponent.is() )
1651             xComponent->dispose();
1652         bNotify = true;
1653     }
1654 
1655     if ( bMustBeLayouted )
1656         doLayout();
1657 
1658     if ( bNotify )
1659         implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_INVISIBLE, uno::makeAny( aName ) );
1660 }
1661 
1662 ::sal_Bool SAL_CALL LayoutManager::requestElement( const ::rtl::OUString& rResourceURL )
1663 throw (uno::RuntimeException)
1664 {
1665     bool            bResult( false );
1666     bool            bNotify( false );
1667     bool            bDoLayout( false );
1668     ::rtl::OUString aElementType;
1669     ::rtl::OUString aElementName;
1670 
1671     parseResourceURL( rResourceURL, aElementType, aElementName );
1672 
1673     WriteGuard aWriteLock( m_aLock );
1674 
1675     ::rtl::OString aResName = rtl::OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1676     RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) Element %s requested.", aResName.getStr() );
1677 
1678     if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == rResourceURL ))
1679     {
1680         implts_readStatusBarState( rResourceURL );
1681         if ( m_aStatusBarElement.m_bVisible && !m_aStatusBarElement.m_bMasterHide )
1682         {
1683             aWriteLock.unlock();
1684             createElement( rResourceURL );
1685 
1686             // There are some situation where we are not able to create an element.
1687             // Therefore we have to check the reference before further action.
1688             // See #i70019#
1689             uno::Reference< ui::XUIElement > xUIElement( m_aStatusBarElement.m_xUIElement );
1690             if ( xUIElement.is() )
1691             {
1692                 // we need VCL here to pass special flags to Show()
1693                 vos::OGuard     aGuard( Application::GetSolarMutex() );
1694                 Reference< awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY );
1695                 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1696                 if ( pWindow )
1697                 {
1698                     pWindow->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
1699                     bResult   = true;
1700                     bNotify   = true;
1701                     bDoLayout = true;
1702                 }
1703             }
1704         }
1705     }
1706     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ) )
1707     {
1708         aWriteLock.unlock();
1709         implts_showProgressBar();
1710         bResult   = true;
1711         bNotify   = true;
1712         bDoLayout = true;
1713     }
1714     else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ) && m_bVisible )
1715     {
1716         bool bComponentAttached( m_aModuleIdentifier.getLength() > 0 );
1717         uno::Reference< uno::XInterface > xThis( m_xToolbarManager, uno::UNO_QUERY );
1718         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
1719         aWriteLock.unlock();
1720 
1721         if ( pToolbarManager && bComponentAttached )
1722         {
1723                 bNotify   = pToolbarManager->requestToolbar( rResourceURL );
1724             bDoLayout = true;
1725             }
1726     }
1727     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
1728     {
1729         uno::Reference< frame::XFrame > xFrame( m_xFrame );
1730         aWriteLock.unlock();
1731 
1732         CreateDockingWindow( xFrame, aElementName );
1733     }
1734 
1735     if ( bNotify )
1736         implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::makeAny( rResourceURL ) );
1737 
1738     return bResult;
1739 }
1740 
1741 Reference< XUIElement > SAL_CALL LayoutManager::getElement( const ::rtl::OUString& aName )
1742 throw (RuntimeException)
1743 {
1744     Reference< XUIElement > xUIElement = implts_findElement( aName );
1745     if ( !xUIElement.is() )
1746     {
1747         ReadGuard aReadLock( m_aLock );
1748         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
1749         ToolbarLayoutManager*             pToolbarManager( m_pToolbarManager );
1750         aReadLock.unlock();
1751 
1752         if ( pToolbarManager )
1753             xUIElement = pToolbarManager->getToolbar( aName );
1754     }
1755 
1756     return xUIElement;
1757 }
1758 
1759 Sequence< Reference< ui::XUIElement > > SAL_CALL LayoutManager::getElements()
1760 throw (uno::RuntimeException)
1761 {
1762     ReadGuard aReadLock( m_aLock );
1763     uno::Reference< ui::XUIElement >  xMenuBar( m_xMenuBar );
1764     uno::Reference< ui::XUIElement >  xStatusBar( m_aStatusBarElement.m_xUIElement );
1765     uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
1766     ToolbarLayoutManager*             pToolbarManager( m_pToolbarManager );
1767     aReadLock.unlock();
1768 
1769     Sequence< Reference< ui::XUIElement > > aSeq;
1770     if ( pToolbarManager )
1771         aSeq = pToolbarManager->getToolbars();
1772 
1773     sal_Int32 nSize = aSeq.getLength();
1774     sal_Int32 nMenuBarIndex(-1);
1775     sal_Int32 nStatusBarIndex(-1);
1776     if ( xMenuBar.is() )
1777     {
1778         nMenuBarIndex = nSize;
1779         ++nSize;
1780     }
1781     if ( xStatusBar.is() )
1782     {
1783         nStatusBarIndex = nSize;
1784         ++nSize;
1785     }
1786 
1787     aSeq.realloc(nSize);
1788     if ( nMenuBarIndex >= 0 )
1789         aSeq[nMenuBarIndex] = xMenuBar;
1790     if ( nStatusBarIndex >= 0 )
1791         aSeq[nStatusBarIndex] = xStatusBar;
1792 
1793     return aSeq;
1794 }
1795 
1796 sal_Bool SAL_CALL LayoutManager::showElement( const ::rtl::OUString& aName )
1797 throw (RuntimeException)
1798 {
1799     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::showElement" );
1800 
1801     bool            bResult( false );
1802     bool            bNotify( false );
1803     bool            bMustLayout( false );
1804     ::rtl::OUString aElementType;
1805     ::rtl::OUString aElementName;
1806 
1807     parseResourceURL( aName, aElementType, aElementName );
1808 
1809     ::rtl::OString aResName = rtl::OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1810     RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) Element %s", aResName.getStr() );
1811 
1812     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
1813     {
1814         WriteGuard aWriteLock( m_aLock );
1815         m_bMenuVisible = sal_True;
1816         aWriteLock.unlock();
1817 
1818         bResult = implts_resetMenuBar();
1819         bNotify = bResult;
1820     }
1821     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == aName ))
1822     {
1823         WriteGuard aWriteLock( m_aLock );
1824         if ( m_aStatusBarElement.m_xUIElement.is() && !m_aStatusBarElement.m_bMasterHide &&
1825              implts_showStatusBar( sal_True ))
1826         {
1827             aWriteLock.unlock();
1828 
1829             implts_writeWindowStateData( m_aStatusBarAlias, m_aStatusBarElement );
1830             bMustLayout = true;
1831             bResult     = true;
1832             bNotify     = true;
1833         }
1834     }
1835     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ))
1836     {
1837         bNotify = bResult = implts_showProgressBar();
1838     }
1839     else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
1840     {
1841         ReadGuard aReadLock( m_aLock );
1842         uno::Reference< awt::XWindowListener > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
1843         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
1844         aReadLock.unlock();
1845 
1846         if ( pToolbarManager )
1847         {
1848             bNotify     = pToolbarManager->showToolbar( aName );
1849             bMustLayout = pToolbarManager->isLayoutDirty();
1850         }
1851     }
1852     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
1853     {
1854         ReadGuard aReadGuard( m_aLock );
1855         uno::Reference< frame::XFrame > xFrame( m_xFrame );
1856         uno::Reference< lang::XMultiServiceFactory > xSMGR( m_xSMGR );
1857         aReadGuard.unlock();
1858 
1859         impl_setDockingWindowVisibility( xSMGR, xFrame, aElementName, true );
1860     }
1861     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "toolpanel" ))
1862     {
1863         ReadGuard aReadGuard( m_aLock );
1864         uno::Reference< frame::XFrame > xFrame( m_xFrame );
1865         aReadGuard.unlock();
1866         ActivateToolPanel( m_xFrame, aName );
1867     }
1868 
1869     if ( bMustLayout )
1870         doLayout();
1871 
1872     if ( bNotify )
1873         implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_VISIBLE, uno::makeAny( aName ) );
1874 
1875     return bResult;
1876 }
1877 
1878 sal_Bool SAL_CALL LayoutManager::hideElement( const ::rtl::OUString& aName )
1879 throw (RuntimeException)
1880 {
1881     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::hideElement" );
1882 
1883     bool            bResult( false );
1884     bool            bNotify( false );
1885     bool            bMustLayout( false );
1886     ::rtl::OUString aElementType;
1887     ::rtl::OUString aElementName;
1888 
1889     parseResourceURL( aName, aElementType, aElementName );
1890     ::rtl::OString aResName = rtl::OUStringToOString( aElementName, RTL_TEXTENCODING_ASCII_US );
1891     RTL_LOGFILE_CONTEXT_TRACE1( aLog, "framework (cd100003) Element %s", aResName.getStr() );
1892 
1893     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
1894     {
1895         WriteGuard aWriteLock( m_aLock );
1896 
1897         if ( m_xContainerWindow.is() )
1898         {
1899             m_bMenuVisible = sal_False;
1900 
1901             vos::OGuard aGuard( Application::GetSolarMutex() );
1902             SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
1903             if ( pSysWindow )
1904             {
1905                 MenuBar* pMenuBar = pSysWindow->GetMenuBar();
1906                 if ( pMenuBar )
1907                 {
1908                     pMenuBar->SetDisplayable( sal_False );
1909                     bResult = true;
1910                     bNotify = true;
1911                 }
1912             }
1913         }
1914     }
1915     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == aName ))
1916     {
1917         WriteGuard aWriteLock( m_aLock );
1918         if ( m_aStatusBarElement.m_xUIElement.is() && !m_aStatusBarElement.m_bMasterHide &&
1919              implts_hideStatusBar( sal_True ))
1920         {
1921             implts_writeWindowStateData( m_aStatusBarAlias, m_aStatusBarElement );
1922             bMustLayout = sal_True;
1923             bNotify     = sal_True;
1924             bResult     = sal_True;
1925         }
1926     }
1927     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" ))
1928     {
1929         bResult = bNotify = implts_hideProgressBar();
1930     }
1931     else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
1932     {
1933         ReadGuard aReadLock( m_aLock );
1934         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
1935         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
1936         aReadLock.unlock();
1937 
1938         bNotify     = pToolbarManager->hideToolbar( aName );
1939         bMustLayout = pToolbarManager->isLayoutDirty();
1940     }
1941     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
1942     {
1943         ReadGuard aReadGuard( m_aLock );
1944         uno::Reference< frame::XFrame > xFrame( m_xFrame );
1945         uno::Reference< lang::XMultiServiceFactory > xSMGR( m_xSMGR );
1946         aReadGuard.unlock();
1947 
1948         impl_setDockingWindowVisibility( xSMGR, xFrame, aElementName, false );
1949     }
1950 
1951     if ( bMustLayout )
1952         doLayout();
1953 
1954     if ( bNotify )
1955         implts_notifyListeners( frame::LayoutManagerEvents::UIELEMENT_INVISIBLE, uno::makeAny( aName ) );
1956 
1957     return sal_False;
1958 }
1959 
1960 sal_Bool SAL_CALL LayoutManager::dockWindow( const ::rtl::OUString& aName, DockingArea DockingArea, const awt::Point& Pos )
1961 throw (RuntimeException)
1962 {
1963     ::rtl::OUString aElementType;
1964     ::rtl::OUString aElementName;
1965 
1966     parseResourceURL( aName, aElementType, aElementName );
1967     if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
1968     {
1969         ReadGuard aReadLock( m_aLock );
1970         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
1971         ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
1972         aReadLock.unlock();
1973 
1974         if ( pToolbarManager )
1975         {
1976             pToolbarManager->dockToolbar( aName, DockingArea, Pos );
1977             if ( pToolbarManager->isLayoutDirty() )
1978                 doLayout();
1979         }
1980     }
1981     return sal_False;
1982 }
1983 
1984 ::sal_Bool SAL_CALL LayoutManager::dockAllWindows( ::sal_Int16 /*nElementType*/ ) throw (uno::RuntimeException)
1985 {
1986     ReadGuard aReadLock( m_aLock );
1987     bool bResult( false );
1988     uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
1989     ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
1990     aReadLock.unlock();
1991 
1992     if ( pToolbarManager )
1993     {
1994         bResult = pToolbarManager->dockAllToolbars();
1995         if ( pToolbarManager->isLayoutDirty() )
1996             doLayout();
1997     }
1998     return bResult;
1999 }
2000 
2001 sal_Bool SAL_CALL LayoutManager::floatWindow( const ::rtl::OUString& aName )
2002 throw (RuntimeException)
2003 {
2004     bool bResult( false );
2005     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2006     {
2007         ReadGuard aReadLock( m_aLock );
2008         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
2009         ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
2010         aReadLock.unlock();
2011 
2012         if ( pToolbarManager )
2013         {
2014             bResult = pToolbarManager->floatToolbar( aName );
2015             if ( pToolbarManager->isLayoutDirty() )
2016                 doLayout();
2017         }
2018     }
2019     return bResult;
2020 }
2021 
2022 ::sal_Bool SAL_CALL LayoutManager::lockWindow( const ::rtl::OUString& aName )
2023 throw (uno::RuntimeException)
2024 {
2025     bool bResult( false );
2026     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2027     {
2028         ReadGuard aReadLock( m_aLock );
2029         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
2030         ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
2031         aReadLock.unlock();
2032 
2033         if ( pToolbarManager )
2034         {
2035             bResult = pToolbarManager->lockToolbar( aName );
2036             if ( pToolbarManager->isLayoutDirty() )
2037                 doLayout();
2038         }
2039     }
2040     return bResult;
2041 }
2042 
2043 ::sal_Bool SAL_CALL LayoutManager::unlockWindow( const ::rtl::OUString& aName )
2044 throw (uno::RuntimeException)
2045 {
2046     bool bResult( false );
2047     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2048     {
2049         ReadGuard aReadLock( m_aLock );
2050         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
2051         ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
2052         aReadLock.unlock();
2053 
2054         if ( pToolbarManager )
2055         {
2056             bResult = pToolbarManager->unlockToolbar( aName );
2057             if ( pToolbarManager->isLayoutDirty() )
2058                 doLayout();
2059         }
2060     }
2061     return bResult;
2062 }
2063 
2064 void SAL_CALL LayoutManager::setElementSize( const ::rtl::OUString& aName, const awt::Size& aSize )
2065 throw (RuntimeException)
2066 {
2067     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2068     {
2069         ReadGuard aReadLock( m_aLock );
2070         uno::Reference< uno::XInterface > xThis( m_xToolbarManager );
2071         ToolbarLayoutManager*             pToolbarManager = m_pToolbarManager;
2072         aReadLock.unlock();
2073 
2074         if ( pToolbarManager )
2075         {
2076             pToolbarManager->setToolbarSize( aName, aSize );
2077             if ( pToolbarManager->isLayoutDirty() )
2078                 doLayout();
2079         }
2080     }
2081 }
2082 
2083 void SAL_CALL LayoutManager::setElementPos( const ::rtl::OUString& aName, const awt::Point& aPos )
2084 throw (RuntimeException)
2085 {
2086     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2087     {
2088         ReadGuard aReadLock( m_aLock );
2089         uno::Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
2090         ToolbarLayoutManager* pToolbarManager( m_pToolbarManager );
2091         aReadLock.unlock();
2092 
2093         if ( pToolbarManager )
2094         {
2095             pToolbarManager->setToolbarPos( aName, aPos );
2096             if ( pToolbarManager->isLayoutDirty() )
2097                 doLayout();
2098         }
2099     }
2100 }
2101 
2102 void SAL_CALL LayoutManager::setElementPosSize( const ::rtl::OUString& aName, const awt::Point& aPos, const awt::Size& aSize )
2103 throw (RuntimeException)
2104 {
2105     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2106     {
2107         ReadGuard aReadLock( m_aLock );
2108         uno::Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
2109         ToolbarLayoutManager* pToolbarManager( m_pToolbarManager );
2110         aReadLock.unlock();
2111 
2112         if ( pToolbarManager )
2113         {
2114             pToolbarManager->setToolbarPosSize( aName, aPos, aSize );
2115             if ( pToolbarManager->isLayoutDirty() )
2116                 doLayout();
2117         }
2118     }
2119 }
2120 
2121 sal_Bool SAL_CALL LayoutManager::isElementVisible( const ::rtl::OUString& aName )
2122 throw (RuntimeException)
2123 {
2124     ::rtl::OUString aElementType;
2125     ::rtl::OUString aElementName;
2126 
2127     parseResourceURL( aName, aElementType, aElementName );
2128     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
2129     {
2130         ReadGuard aReadLock( m_aLock );
2131         if ( m_xContainerWindow.is() )
2132         {
2133             aReadLock.unlock();
2134 
2135             vos::OGuard aGuard( Application::GetSolarMutex() );
2136             SystemWindow* pSysWindow = getTopSystemWindow( m_xContainerWindow );
2137             if ( pSysWindow )
2138             {
2139                 MenuBar* pMenuBar = pSysWindow->GetMenuBar();
2140                 if ( pMenuBar && pMenuBar->IsDisplayable() )
2141                     return sal_True;
2142             }
2143             else
2144             {
2145                 aReadLock.lock();
2146                 return m_bMenuVisible;
2147             }
2148         }
2149     }
2150     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "statusbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "statusbar" )) || ( m_aStatusBarElement.m_aName == aName ))
2151     {
2152         if ( m_aStatusBarElement.m_xUIElement.is() )
2153         {
2154             Reference< awt::XWindow > xWindow( m_aStatusBarElement.m_xUIElement->getRealInterface(), UNO_QUERY );
2155             if ( xWindow.is() )
2156             {
2157                 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
2158                 if ( pWindow && pWindow->IsVisible() )
2159                     return sal_True;
2160                 else
2161                     return sal_False;
2162             }
2163         }
2164     }
2165     else if (( aElementType.equalsIgnoreAsciiCaseAscii( "progressbar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "progressbar" )))
2166     {
2167         if ( m_aProgressBarElement.m_xUIElement.is() )
2168             return m_aProgressBarElement.m_bVisible;
2169     }
2170     else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2171     {
2172         ReadGuard aReadLock( m_aLock );
2173         uno::Reference< frame::XLayoutManager > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2174         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2175         aReadLock.unlock();
2176 
2177         if ( pToolbarManager )
2178             return pToolbarManager->isToolbarVisible( aName );
2179     }
2180     else if ( aElementType.equalsIgnoreAsciiCaseAscii( "dockingwindow" ))
2181     {
2182         ReadGuard aReadGuard( m_aLock );
2183         uno::Reference< frame::XFrame > xFrame( m_xFrame );
2184         aReadGuard.unlock();
2185 
2186         return IsDockingWindowVisible( xFrame, aElementName );
2187     }
2188 
2189     return sal_False;
2190 }
2191 
2192 sal_Bool SAL_CALL LayoutManager::isElementFloating( const ::rtl::OUString& aName )
2193 throw (RuntimeException)
2194 {
2195     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2196     {
2197         ReadGuard aReadLock( m_aLock );
2198         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2199         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2200         aReadLock.unlock();
2201 
2202         if ( pToolbarManager )
2203             return pToolbarManager->isToolbarFloating( aName );
2204     }
2205 
2206     return sal_False;
2207 }
2208 
2209 sal_Bool SAL_CALL LayoutManager::isElementDocked( const ::rtl::OUString& aName )
2210 throw (RuntimeException)
2211 {
2212     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2213     {
2214         ReadGuard aReadLock( m_aLock );
2215         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2216         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2217         aReadLock.unlock();
2218 
2219         if ( pToolbarManager )
2220             return pToolbarManager->isToolbarDocked( aName );
2221     }
2222 
2223     return sal_False;
2224 }
2225 
2226 ::sal_Bool SAL_CALL LayoutManager::isElementLocked( const ::rtl::OUString& aName )
2227 throw (uno::RuntimeException)
2228 {
2229     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2230     {
2231         ReadGuard aReadLock( m_aLock );
2232         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2233         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2234         aReadLock.unlock();
2235 
2236         if ( pToolbarManager )
2237             return pToolbarManager->isToolbarLocked( aName );
2238     }
2239 
2240     return sal_False;
2241 }
2242 
2243 awt::Size SAL_CALL LayoutManager::getElementSize( const ::rtl::OUString& aName )
2244 throw (RuntimeException)
2245 {
2246     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2247     {
2248         ReadGuard aReadLock( m_aLock );
2249         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2250         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2251         aReadLock.unlock();
2252 
2253         if ( pToolbarManager )
2254             return pToolbarManager->getToolbarSize( aName );
2255     }
2256 
2257     return awt::Size();
2258 }
2259 
2260 awt::Point SAL_CALL LayoutManager::getElementPos( const ::rtl::OUString& aName )
2261 throw (RuntimeException)
2262 {
2263     if ( getElementTypeFromResourceURL( aName ).equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
2264     {
2265         ReadGuard aReadLock( m_aLock );
2266         uno::Reference< uno::XInterface > xToolbarManager( m_xToolbarManager, uno::UNO_QUERY );
2267         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2268         aReadLock.unlock();
2269 
2270         if ( pToolbarManager )
2271             return pToolbarManager->getToolbarPos( aName );
2272     }
2273 
2274     return awt::Point();
2275 }
2276 
2277 void SAL_CALL LayoutManager::lock()
2278 throw (RuntimeException)
2279 {
2280     implts_lock();
2281 
2282     ReadGuard aReadLock( m_aLock );
2283     sal_Int32 nLockCount( m_nLockCount );
2284     aReadLock.unlock();
2285 
2286     RTL_LOGFILE_TRACE1( "framework (cd100003) ::LayoutManager::lock lockCount=%d", nLockCount );
2287 #ifdef DBG_UTIL
2288     ByteString aStr("LayoutManager::lock ");
2289     aStr += ByteString::CreateFromInt32((long)this);
2290     aStr += " - ";
2291     aStr += ByteString::CreateFromInt32(nLockCount);
2292     DBG_TRACE( aStr.GetBuffer() );
2293 #endif
2294 
2295     Any a( nLockCount );
2296     implts_notifyListeners( frame::LayoutManagerEvents::LOCK, a );
2297 }
2298 
2299 void SAL_CALL LayoutManager::unlock()
2300 throw (RuntimeException)
2301 {
2302     sal_Bool bDoLayout( implts_unlock() );
2303 
2304     ReadGuard aReadLock( m_aLock );
2305     sal_Int32 nLockCount( m_nLockCount );
2306     aReadLock.unlock();
2307 
2308     RTL_LOGFILE_TRACE1( "framework (cd100003) ::LayoutManager::unlock lockCount=%d", nLockCount );
2309 #ifdef DBG_UTIL
2310     ByteString aStr("LayoutManager::unlock ");
2311     aStr += ByteString::CreateFromInt32((long)this);
2312     aStr += " - ";
2313     aStr += ByteString::CreateFromInt32(nLockCount);
2314     DBG_TRACE( aStr.GetBuffer() );
2315 #endif
2316     // conform to documentation: unlock with lock count == 0 means force a layout
2317 
2318     WriteGuard aWriteLock( m_aLock );
2319         if ( bDoLayout )
2320                 m_aAsyncLayoutTimer.Stop();
2321         aWriteLock.unlock();
2322 
2323     Any a( nLockCount );
2324     implts_notifyListeners( frame::LayoutManagerEvents::UNLOCK, a );
2325 
2326     if ( bDoLayout )
2327         implts_doLayout_notify( sal_True );
2328 }
2329 
2330 void SAL_CALL LayoutManager::doLayout()
2331 throw (RuntimeException)
2332 {
2333     implts_doLayout_notify( sal_True );
2334 }
2335 
2336 //---------------------------------------------------------------------------------------------------------
2337 //  ILayoutNotifications
2338 //---------------------------------------------------------------------------------------------------------
2339 void LayoutManager::requestLayout( Hint eHint )
2340 {
2341     if ( eHint == HINT_TOOLBARSPACE_HAS_CHANGED )
2342         doLayout();
2343 }
2344 
2345 void LayoutManager::implts_doLayout_notify( sal_Bool bOuterResize )
2346 {
2347     bool bLayouted = implts_doLayout( false, bOuterResize );
2348     if ( bLayouted )
2349         implts_notifyListeners( frame::LayoutManagerEvents::LAYOUT, Any() );
2350 }
2351 
2352 sal_Bool LayoutManager::implts_doLayout( sal_Bool bForceRequestBorderSpace, sal_Bool bOuterResize )
2353 {
2354     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::implts_doLayout" );
2355 
2356     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2357     ReadGuard aReadLock( m_aLock );
2358 
2359     if ( !m_xFrame.is() || !m_bParentWindowVisible )
2360         return sal_False;
2361 
2362     bool bPreserveContentSize( m_bPreserveContentSize );
2363     bool bMustDoLayout( m_bMustDoLayout );
2364     bool bNoLock = ( m_nLockCount == 0 );
2365     awt::Rectangle aCurrBorderSpace( m_aDockingArea );
2366     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2367     Reference< awt::XTopWindow2 > xContainerTopWindow( m_xContainerTopWindow );
2368     Reference< awt::XWindow > xComponentWindow( m_xFrame->getComponentWindow() );
2369     Reference< XDockingAreaAcceptor > xDockingAreaAcceptor( m_xDockingAreaAcceptor );
2370     aReadLock.unlock();
2371     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2372 
2373     sal_Bool bLayouted( sal_False );
2374 
2375     if ( bNoLock && xDockingAreaAcceptor.is() && xContainerWindow.is() && xComponentWindow.is() )
2376     {
2377         bLayouted = sal_True;
2378 
2379         WriteGuard aWriteGuard( m_aLock );
2380         m_bDoLayout = sal_True;
2381         aWriteGuard.unlock();
2382 
2383         awt::Rectangle aDockSpace( implts_calcDockingAreaSizes() );
2384         awt::Rectangle aBorderSpace( aDockSpace );
2385         sal_Bool       bGotRequestedBorderSpace( sal_True );
2386 
2387         // We have to add the height of a possible status bar
2388         aBorderSpace.Height += implts_getStatusBarSize().Height();
2389 
2390         if ( !equalRectangles( aBorderSpace, aCurrBorderSpace ) || bForceRequestBorderSpace || bMustDoLayout )
2391         {
2392             // we always resize the content window (instead of the complete container window) if we're not set up
2393             // to (attempt to) preserve the content window's size
2394             if ( bOuterResize && !bPreserveContentSize )
2395                 bOuterResize = sal_False;
2396 
2397             // maximized windows can resized their content window only, not their container window
2398             if ( bOuterResize && xContainerTopWindow.is() && xContainerTopWindow->getIsMaximized() )
2399                 bOuterResize = sal_False;
2400 
2401             // if the component window does not have a size (yet), then we can't use it to calc the container
2402             // window size
2403             awt::Rectangle aComponentRect = xComponentWindow->getPosSize();
2404             if ( bOuterResize && ( aComponentRect.Width == 0 ) && ( aComponentRect.Height == 0 ) )
2405                 bOuterResize = sal_False;
2406 
2407             bGotRequestedBorderSpace = sal_False;
2408             if ( bOuterResize )
2409             {
2410                 Reference< awt::XDevice > xDevice( xContainerWindow, uno::UNO_QUERY );
2411                 awt::DeviceInfo aContainerInfo  = xDevice->getInfo();
2412 
2413                 awt::Size aRequestedSize( aComponentRect.Width + aContainerInfo.LeftInset + aContainerInfo.RightInset + aBorderSpace.X + aBorderSpace.Width,
2414                                           aComponentRect.Height + aContainerInfo.TopInset  + aContainerInfo.BottomInset + aBorderSpace.Y + aBorderSpace.Height );
2415                 awt::Point aComponentPos( aBorderSpace.X, aBorderSpace.Y );
2416 
2417                 bGotRequestedBorderSpace = implts_resizeContainerWindow( aRequestedSize, aComponentPos );
2418             }
2419 
2420             // if we did not do an container window resize, or it failed, then use the DockingAcceptor as usual
2421             if ( !bGotRequestedBorderSpace )
2422                 bGotRequestedBorderSpace = xDockingAreaAcceptor->requestDockingAreaSpace( aBorderSpace );
2423 
2424             if ( bGotRequestedBorderSpace )
2425             {
2426                 aWriteGuard.lock();
2427                 m_aDockingArea = aBorderSpace;
2428                 m_bMustDoLayout = sal_False;
2429                 aWriteGuard.unlock();
2430             }
2431         }
2432 
2433         if ( bGotRequestedBorderSpace )
2434         {
2435             ::Size      aContainerSize;
2436             ::Size      aStatusBarSize;
2437 
2438             // Interim solution to let the layout method within the
2439             // toolbar layout manager.
2440             implts_setOffset( implts_getStatusBarSize().Height() );
2441             m_pToolbarManager->setDockingArea( aDockSpace );
2442 
2443             // Subtract status bar size from our container output size. Docking area windows
2444             // don't contain the status bar!
2445             aStatusBarSize = implts_getStatusBarSize();
2446             aContainerSize = implts_getContainerWindowOutputSize();
2447             aContainerSize.Height() -= aStatusBarSize.Height();
2448 
2449             m_pToolbarManager->doLayout(aContainerSize);
2450 
2451             // Position the status bar
2452             if ( aStatusBarSize.Height() > 0 )
2453             {
2454                 implts_setStatusBarPosSize( ::Point( 0, std::max(( aContainerSize.Height() ), long( 0 ))),
2455                                             ::Size( aContainerSize.Width(),aStatusBarSize.Height() ));
2456             }
2457 
2458             xDockingAreaAcceptor->setDockingAreaSpace( aBorderSpace );
2459 
2460             aWriteGuard.lock();
2461             m_bDoLayout = sal_False;
2462             aWriteGuard.unlock();
2463         }
2464     }
2465 
2466     return bLayouted;
2467 }
2468 
2469 sal_Bool LayoutManager::implts_resizeContainerWindow( const awt::Size& rContainerSize,
2470                                                       const awt::Point& rComponentPos )
2471 {
2472     ReadGuard aReadLock( m_aLock );
2473     Reference< awt::XWindow >               xContainerWindow    = m_xContainerWindow;
2474     Reference< awt::XTopWindow2 >           xContainerTopWindow = m_xContainerTopWindow;
2475     Reference< awt::XWindow >               xComponentWindow    = m_xFrame->getComponentWindow();
2476     Reference< container::XIndexAccess >    xDisplayAccess      = m_xDisplayAccess;
2477     aReadLock.unlock();
2478 
2479     // calculate the maximum size we have for the container window
2480     awt::Rectangle aWorkArea;
2481     try
2482     {
2483         sal_Int32 nDisplay = xContainerTopWindow->getDisplay();
2484         Reference< beans::XPropertySet > xDisplayInfo( xDisplayAccess->getByIndex( nDisplay ), UNO_QUERY_THROW );
2485         OSL_VERIFY( xDisplayInfo->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WorkArea" ) ) ) >>= aWorkArea );
2486     }
2487     catch( const Exception& )
2488     {
2489         DBG_UNHANDLED_EXCEPTION();
2490     }
2491 
2492     if (( aWorkArea.Width > 0 ) && ( aWorkArea.Height > 0 ))
2493     {
2494         if (( rContainerSize.Width > aWorkArea.Width ) || ( rContainerSize.Height > aWorkArea.Height ))
2495             return sal_False;
2496         // Strictly, this is not correct. If we have a multi-screen display (css.awt.DisplayAccess.MultiDisplay == true),
2497         // the the "effective work area" would be much larger than the work area of a single display, since we could in theory
2498         // position the container window across multiple screens.
2499         // However, this should suffice as a heuristics here ... (nobody really wants to check whether the different screens are
2500         // stacked horizontally or vertically, whether their work areas can really be combined, or are separated by non-work-areas,
2501         // and the like ... right?)
2502     }
2503 
2504     // resize our container window
2505     xContainerWindow->setPosSize( 0, 0, rContainerSize.Width, rContainerSize.Height, awt::PosSize::SIZE );
2506     // position the component window
2507     xComponentWindow->setPosSize( rComponentPos.X, rComponentPos.Y, 0, 0, awt::PosSize::POS );
2508     return sal_True;
2509 }
2510 
2511 void SAL_CALL LayoutManager::setVisible( sal_Bool bVisible )
2512 throw (uno::RuntimeException)
2513 {
2514     WriteGuard aWriteLock( m_aLock );
2515     sal_Bool bWasVisible( m_bVisible );
2516     m_bVisible = bVisible;
2517     aWriteLock.unlock();
2518 
2519     if ( bWasVisible != bVisible )
2520         implts_setVisibleState( bVisible );
2521 }
2522 
2523 sal_Bool SAL_CALL LayoutManager::isVisible()
2524 throw (uno::RuntimeException)
2525 {
2526     ReadGuard aReadLock( m_aLock );
2527     return m_bVisible;
2528 }
2529 
2530 ::Size LayoutManager::implts_getStatusBarSize()
2531 {
2532     ReadGuard aReadLock( m_aLock );
2533     bool bStatusBarVisible( isElementVisible( m_aStatusBarAlias ));
2534     bool bProgressBarVisible( isElementVisible( m_aProgressBarAlias ));
2535     bool bVisible( m_bVisible );
2536     Reference< XUIElement > xStatusBar( m_aStatusBarElement.m_xUIElement );
2537     Reference< XUIElement > xProgressBar( m_aProgressBarElement.m_xUIElement );
2538 
2539     Reference< awt::XWindow > xWindow;
2540     if ( bStatusBarVisible && bVisible && xStatusBar.is() )
2541         xWindow = Reference< awt::XWindow >( xStatusBar->getRealInterface(), UNO_QUERY );
2542     else if ( xProgressBar.is() && !xStatusBar.is() && bProgressBarVisible )
2543     {
2544         ProgressBarWrapper* pWrapper = (ProgressBarWrapper*)xProgressBar.get();
2545         if ( pWrapper )
2546             xWindow = pWrapper->getStatusBar();
2547     }
2548     aReadLock.unlock();
2549 
2550     if ( xWindow.is() )
2551     {
2552         awt::Rectangle aPosSize = xWindow->getPosSize();
2553         return ::Size( aPosSize.Width, aPosSize.Height );
2554     }
2555     else
2556         return ::Size();
2557 }
2558 
2559 awt::Rectangle LayoutManager::implts_calcDockingAreaSizes()
2560 {
2561     ReadGuard aReadLock( m_aLock );
2562     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2563     Reference< XDockingAreaAcceptor > xDockingAreaAcceptor( m_xDockingAreaAcceptor );
2564     aReadLock.unlock();
2565 
2566     awt::Rectangle aBorderSpace;
2567     if ( xDockingAreaAcceptor.is() && xContainerWindow.is() )
2568         aBorderSpace = m_pToolbarManager->getDockingArea();
2569 
2570     return aBorderSpace;
2571 }
2572 
2573 void LayoutManager::implts_setDockingAreaWindowSizes( const awt::Rectangle& /*rBorderSpace*/ )
2574 {
2575     ReadGuard aReadLock( m_aLock );
2576     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2577     aReadLock.unlock();
2578 
2579     uno::Reference< awt::XDevice > xDevice( xContainerWindow, uno::UNO_QUERY );
2580     // Convert relativ size to output size.
2581     awt::Rectangle  aRectangle           = xContainerWindow->getPosSize();
2582     awt::DeviceInfo aInfo                = xDevice->getInfo();
2583     awt::Size       aContainerClientSize = awt::Size( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset,
2584                                                       aRectangle.Height - aInfo.TopInset  - aInfo.BottomInset );
2585     ::Size          aStatusBarSize       = implts_getStatusBarSize();
2586 
2587     // Position the status bar
2588     if ( aStatusBarSize.Height() > 0 )
2589     {
2590         implts_setStatusBarPosSize( ::Point( 0, std::max(( aContainerClientSize.Height - aStatusBarSize.Height() ), long( 0 ))),
2591                                     ::Size( aContainerClientSize.Width, aStatusBarSize.Height() ));
2592     }
2593 }
2594 
2595 //---------------------------------------------------------------------------------------------------------
2596 //      XMenuCloser
2597 //---------------------------------------------------------------------------------------------------------
2598 void LayoutManager::implts_updateMenuBarClose()
2599 {
2600     WriteGuard aWriteLock( m_aLock );
2601     bool                      bShowCloser( m_bMenuBarCloser );
2602     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2603     aWriteLock.unlock();
2604 
2605     if ( xContainerWindow.is() )
2606     {
2607         vos::OGuard     aGuard( Application::GetSolarMutex() );
2608 
2609         SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
2610         if ( pSysWindow )
2611         {
2612             MenuBar* pMenuBar = pSysWindow->GetMenuBar();
2613             if ( pMenuBar )
2614             {
2615                 // TODO remove link on sal_False ?!
2616                 pMenuBar->ShowCloser( bShowCloser );
2617                 pMenuBar->SetCloserHdl( LINK( this, LayoutManager, MenuBarClose ));
2618             }
2619         }
2620     }
2621 }
2622 
2623 sal_Bool LayoutManager::implts_resetMenuBar()
2624 {
2625     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2626     WriteGuard aWriteLock( m_aLock );
2627     sal_Bool bMenuVisible( m_bMenuVisible );
2628     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2629 
2630     MenuBar* pSetMenuBar = 0;
2631     if ( m_xInplaceMenuBar.is() )
2632         pSetMenuBar = (MenuBar *)m_pInplaceMenuBar->GetMenuBar();
2633     else
2634     {
2635         MenuBarWrapper* pMenuBarWrapper = static_cast< MenuBarWrapper* >( m_xMenuBar.get() );
2636         if ( pMenuBarWrapper )
2637             pSetMenuBar = (MenuBar *)pMenuBarWrapper->GetMenuBarManager()->GetMenuBar();
2638     }
2639     aWriteLock.unlock();
2640     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2641 
2642     vos::OGuard aGuard( Application::GetSolarMutex() );
2643     SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
2644     if ( pSysWindow && bMenuVisible && pSetMenuBar )
2645     {
2646         pSysWindow->SetMenuBar( pSetMenuBar );
2647         pSetMenuBar->SetDisplayable( sal_True );
2648         return sal_True;
2649     }
2650 
2651     return sal_False;
2652 }
2653 
2654 void LayoutManager::implts_setMenuBarCloser(sal_Bool bCloserState)
2655 {
2656     WriteGuard aWriteLock( m_aLock );
2657     m_bMenuBarCloser = bCloserState;
2658     aWriteLock.unlock();
2659 
2660     implts_updateMenuBarClose();
2661 }
2662 
2663 IMPL_LINK( LayoutManager, MenuBarClose, MenuBar *, EMPTYARG )
2664 {
2665     ReadGuard aReadLock( m_aLock );
2666     uno::Reference< frame::XDispatchProvider >   xProvider(m_xFrame, uno::UNO_QUERY);
2667     uno::Reference< lang::XMultiServiceFactory > xSMGR    = m_xSMGR;
2668     aReadLock.unlock();
2669 
2670     if ( !xProvider.is())
2671         return 0;
2672 
2673     uno::Reference< frame::XDispatchHelper > xDispatcher(
2674         xSMGR->createInstance(SERVICENAME_DISPATCHHELPER), uno::UNO_QUERY_THROW);
2675 
2676     xDispatcher->executeDispatch(
2677         xProvider,
2678         ::rtl::OUString::createFromAscii(".uno:CloseWin"),
2679         ::rtl::OUString::createFromAscii("_self"),
2680         0,
2681         uno::Sequence< beans::PropertyValue >());
2682 
2683     return 0;
2684 }
2685 
2686 IMPL_LINK( LayoutManager, SettingsChanged, void*, EMPTYARG )
2687 {
2688     return 1;
2689 }
2690 
2691 //---------------------------------------------------------------------------------------------------------
2692 //  XLayoutManagerEventBroadcaster
2693 //---------------------------------------------------------------------------------------------------------
2694 void SAL_CALL LayoutManager::addLayoutManagerEventListener( const uno::Reference< frame::XLayoutManagerListener >& xListener )
2695 throw (uno::RuntimeException)
2696 {
2697     m_aListenerContainer.addInterface( ::getCppuType( (const uno::Reference< frame::XLayoutManagerListener >*)NULL ), xListener );
2698 }
2699 
2700 void SAL_CALL LayoutManager::removeLayoutManagerEventListener( const uno::Reference< frame::XLayoutManagerListener >& xListener )
2701 throw (uno::RuntimeException)
2702 {
2703     m_aListenerContainer.removeInterface( ::getCppuType( (const uno::Reference< frame::XLayoutManagerListener >*)NULL ), xListener );
2704 }
2705 
2706 void LayoutManager::implts_notifyListeners( short nEvent, uno::Any aInfoParam )
2707 {
2708     lang::EventObject                  aSource( static_cast< ::cppu::OWeakObject*>(this) );
2709     ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer( ::getCppuType( ( const uno::Reference< frame::XLayoutManagerListener >*) NULL ) );
2710     if (pContainer!=NULL)
2711     {
2712         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
2713         while (pIterator.hasMoreElements())
2714         {
2715             try
2716             {
2717                 ((frame::XLayoutManagerListener*)pIterator.next())->layoutEvent( aSource, nEvent, aInfoParam );
2718             }
2719             catch( uno::RuntimeException& )
2720             {
2721                 pIterator.remove();
2722             }
2723         }
2724     }
2725 }
2726 
2727 //---------------------------------------------------------------------------------------------------------
2728 //      XWindowListener
2729 //---------------------------------------------------------------------------------------------------------
2730 void SAL_CALL LayoutManager::windowResized( const awt::WindowEvent& aEvent )
2731 throw( uno::RuntimeException )
2732 {
2733     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2734     WriteGuard aWriteLock( m_aLock );
2735 
2736     if ( !m_xDockingAreaAcceptor.is() )
2737         return;
2738 
2739     // Request to set docking area space again.
2740     awt::Rectangle                    aDockingArea( m_aDockingArea );
2741     Reference< XDockingAreaAcceptor > xDockingAreaAcceptor( m_xDockingAreaAcceptor );
2742     Reference< awt::XWindow >         xContainerWindow( m_xContainerWindow );
2743 
2744     Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2745     if ( xIfac == aEvent.Source && m_bVisible )
2746     {
2747         // We have to call our resize handler at least once synchronously, as some
2748         // application modules need this. So we have to check if this is the first
2749         // call after the async layout time expired.
2750         m_bMustDoLayout = sal_True;
2751         if ( !m_aAsyncLayoutTimer.IsActive() )
2752         {
2753             const Link& aLink = m_aAsyncLayoutTimer.GetTimeoutHdl();
2754             if ( aLink.IsSet() )
2755                 aLink.Call( &m_aAsyncLayoutTimer );
2756         }
2757         if ( m_nLockCount == 0 )
2758             m_aAsyncLayoutTimer.Start();
2759     }
2760     else if ( m_xFrame.is() && aEvent.Source == m_xFrame->getContainerWindow() )
2761     {
2762         // the container window of my DockingAreaAcceptor is not the same as of my frame
2763         // I still have to resize my frames' window as nobody else will do it
2764         Reference< awt::XWindow > xComponentWindow( m_xFrame->getComponentWindow() );
2765         if( xComponentWindow.is() == sal_True )
2766         {
2767             uno::Reference< awt::XDevice > xDevice( m_xFrame->getContainerWindow(), uno::UNO_QUERY );
2768 
2769             // Convert relativ size to output size.
2770             awt::Rectangle  aRectangle = m_xFrame->getContainerWindow()->getPosSize();
2771             awt::DeviceInfo aInfo      = xDevice->getInfo();
2772             awt::Size       aSize(  aRectangle.Width  - aInfo.LeftInset - aInfo.RightInset  ,
2773                                     aRectangle.Height - aInfo.TopInset  - aInfo.BottomInset );
2774 
2775             // Resize our component window.
2776             xComponentWindow->setPosSize( 0, 0, aSize.Width, aSize.Height, awt::PosSize::POSSIZE );
2777         }
2778     }
2779 }
2780 
2781 void SAL_CALL LayoutManager::windowMoved( const awt::WindowEvent& ) throw( uno::RuntimeException )
2782 {
2783 }
2784 
2785 void SAL_CALL LayoutManager::windowShown( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
2786 {
2787     ReadGuard aReadLock( m_aLock );
2788     Reference< awt::XWindow >  xContainerWindow( m_xContainerWindow );
2789     bool                       bParentWindowVisible( m_bParentWindowVisible );
2790     aReadLock.unlock();
2791 
2792     Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2793     if ( xIfac == aEvent.Source )
2794     {
2795         bool bSetVisible = false;
2796 
2797         WriteGuard aWriteLock( m_aLock );
2798         m_bParentWindowVisible = true;
2799         bSetVisible = ( m_bParentWindowVisible != bParentWindowVisible );
2800         aWriteLock.unlock();
2801 
2802         if ( bSetVisible )
2803             implts_updateUIElementsVisibleState( sal_True );
2804     }
2805 }
2806 
2807 void SAL_CALL LayoutManager::windowHidden( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
2808 {
2809     ReadGuard aReadLock( m_aLock );
2810     Reference< awt::XWindow > xContainerWindow( m_xContainerWindow );
2811     bool                      bParentWindowVisible( m_bParentWindowVisible );
2812     aReadLock.unlock();
2813 
2814     Reference< XInterface > xIfac( xContainerWindow, UNO_QUERY );
2815     if ( xIfac == aEvent.Source )
2816     {
2817         bool bSetInvisible = false;
2818 
2819         WriteGuard aWriteLock( m_aLock );
2820         m_bParentWindowVisible = false;
2821         bSetInvisible = ( m_bParentWindowVisible != bParentWindowVisible );
2822         aWriteLock.unlock();
2823 
2824         if ( bSetInvisible )
2825             implts_updateUIElementsVisibleState( sal_False );
2826     }
2827 }
2828 
2829 IMPL_LINK( LayoutManager, AsyncLayoutHdl, Timer *, EMPTYARG )
2830 {
2831     ReadGuard aReadLock( m_aLock );
2832     m_aAsyncLayoutTimer.Stop();
2833 
2834     if( !m_xContainerWindow.is() )
2835         return 0;
2836 
2837     awt::Rectangle aDockingArea( m_aDockingArea );
2838     ::Size         aStatusBarSize( implts_getStatusBarSize() );
2839 
2840     // Subtract status bar height
2841     aDockingArea.Height -= aStatusBarSize.Height();
2842     aReadLock.unlock();
2843 
2844     implts_setDockingAreaWindowSizes( aDockingArea );
2845     implts_doLayout( sal_True, sal_False );
2846 
2847     return 0;
2848 }
2849 
2850 //---------------------------------------------------------------------------------------------------------
2851 //      XFrameActionListener
2852 //---------------------------------------------------------------------------------------------------------
2853 void SAL_CALL LayoutManager::frameAction( const FrameActionEvent& aEvent )
2854 throw ( RuntimeException )
2855 {
2856     if (( aEvent.Action == FrameAction_COMPONENT_ATTACHED ) || ( aEvent.Action == FrameAction_COMPONENT_REATTACHED ))
2857     {
2858         RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::frameAction (COMPONENT_ATTACHED|REATTACHED)" );
2859 
2860         WriteGuard aWriteLock( m_aLock );
2861         m_bComponentAttached = sal_True;
2862         m_bMustDoLayout = sal_True;
2863         aWriteLock.unlock();
2864 
2865         implts_reset( sal_True );
2866         implts_doLayout( sal_True, sal_False );
2867         implts_doLayout( sal_True, sal_True );
2868     }
2869     else if (( aEvent.Action == FrameAction_FRAME_UI_ACTIVATED ) || ( aEvent.Action == FrameAction_FRAME_UI_DEACTIVATING ))
2870     {
2871         RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::frameAction (FRAME_UI_ACTIVATED|DEACTIVATING)" );
2872 
2873         WriteGuard aWriteLock( m_aLock );
2874         m_bActive = ( aEvent.Action == FrameAction_FRAME_UI_ACTIVATED );
2875         aWriteLock.unlock();
2876 
2877         implts_toggleFloatingUIElementsVisibility( aEvent.Action == FrameAction_FRAME_UI_ACTIVATED );
2878     }
2879     else if ( aEvent.Action == FrameAction_COMPONENT_DETACHING )
2880     {
2881         RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::LayoutManager::frameAction (COMPONENT_DETACHING)" );
2882 
2883         WriteGuard aWriteLock( m_aLock );
2884         m_bComponentAttached = sal_False;
2885         aWriteLock.unlock();
2886 
2887         implts_reset( sal_False );
2888     }
2889 }
2890 
2891 // ______________________________________________
2892 
2893 void SAL_CALL LayoutManager::disposing( const lang::EventObject& rEvent )
2894 throw( RuntimeException )
2895 {
2896     sal_Bool bDisposeAndClear( sal_False );
2897 
2898     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2899     WriteGuard aWriteLock( m_aLock );
2900 
2901     if ( rEvent.Source == Reference< XInterface >( m_xFrame, UNO_QUERY ))
2902     {
2903         // Our frame gets disposed, release all our references that depends on a working frame reference.
2904         Application::RemoveEventListener( LINK( this, LayoutManager, SettingsChanged ) );
2905 
2906         // destroy all elements, it's possible that dettaching is NOT called!
2907         implts_destroyElements();
2908         impl_clearUpMenuBar();
2909         m_xMenuBar.clear();
2910         if ( m_xInplaceMenuBar.is() )
2911         {
2912             m_pInplaceMenuBar = 0;
2913             m_xInplaceMenuBar->dispose();
2914         }
2915         m_xInplaceMenuBar.clear();
2916         m_xContainerWindow.clear();
2917         m_xContainerTopWindow.clear();
2918 
2919         // forward disposing call to toolbar manager
2920         if ( m_pToolbarManager != NULL )
2921             m_pToolbarManager->disposing(rEvent);
2922 
2923         if ( m_xModuleCfgMgr.is() )
2924         {
2925             try
2926             {
2927                 Reference< XUIConfiguration > xModuleCfgMgr( m_xModuleCfgMgr, UNO_QUERY );
2928                 xModuleCfgMgr->removeConfigurationListener(
2929                     Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
2930             }
2931             catch ( Exception& ) {}
2932         }
2933 
2934         if ( m_xDocCfgMgr.is() )
2935         {
2936             try
2937             {
2938                 Reference< XUIConfiguration > xDocCfgMgr( m_xDocCfgMgr, UNO_QUERY );
2939                 xDocCfgMgr->removeConfigurationListener(
2940                     Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ));
2941             }
2942             catch ( Exception& ) {}
2943         }
2944 
2945         m_xDocCfgMgr.clear();
2946         m_xModuleCfgMgr.clear();
2947         m_xFrame.clear();
2948         delete m_pGlobalSettings;
2949         m_pGlobalSettings = 0;
2950                 m_xDockingAreaAcceptor = Reference< ui::XDockingAreaAcceptor >();
2951 
2952         bDisposeAndClear = sal_True;
2953     }
2954     else if ( rEvent.Source == Reference< XInterface >( m_xContainerWindow, UNO_QUERY ))
2955     {
2956         // Our container window gets disposed. Remove all user interface elements.
2957         uno::Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
2958         ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2959         if ( pToolbarManager )
2960         {
2961             uno::Reference< awt::XWindowPeer > aEmptyWindowPeer;
2962             pToolbarManager->setParentWindow( aEmptyWindowPeer );
2963         }
2964         impl_clearUpMenuBar();
2965         m_xMenuBar.clear();
2966         if ( m_xInplaceMenuBar.is() )
2967         {
2968             m_pInplaceMenuBar = 0;
2969             m_xInplaceMenuBar->dispose();
2970         }
2971         m_xInplaceMenuBar.clear();
2972         m_xContainerWindow.clear();
2973         m_xContainerTopWindow.clear();
2974     }
2975     else if ( rEvent.Source == Reference< XInterface >( m_xDocCfgMgr, UNO_QUERY ))
2976         m_xDocCfgMgr.clear();
2977     else if ( rEvent.Source == Reference< XInterface >( m_xModuleCfgMgr , UNO_QUERY ))
2978         m_xModuleCfgMgr.clear();
2979 
2980     aWriteLock.unlock();
2981     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
2982 
2983     // Send disposing to our listener when we have lost our frame.
2984     if ( bDisposeAndClear )
2985     {
2986         // Send message to all listener and forget her references.
2987         uno::Reference< frame::XLayoutManager > xThis( static_cast< ::cppu::OWeakObject* >(this), uno::UNO_QUERY );
2988         lang::EventObject aEvent( xThis );
2989         m_aListenerContainer.disposeAndClear( aEvent );
2990     }
2991 }
2992 
2993 void SAL_CALL LayoutManager::elementInserted( const ui::ConfigurationEvent& Event ) throw (uno::RuntimeException)
2994 {
2995     ReadGuard aReadLock( m_aLock );
2996     Reference< XFrame > xFrame( m_xFrame );
2997     Reference< ui::XUIConfigurationListener > xUICfgListener( m_xToolbarManager );
2998     ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
2999     aReadLock.unlock();
3000 
3001     if ( xFrame.is() )
3002     {
3003         ::rtl::OUString aElementType;
3004         ::rtl::OUString aElementName;
3005         bool            bRefreshLayout(false);
3006 
3007         parseResourceURL( Event.ResourceURL, aElementType, aElementName );
3008         if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
3009         {
3010             if ( xUICfgListener.is() )
3011             {
3012                 xUICfgListener->elementInserted( Event );
3013                 bRefreshLayout = pToolbarManager->isLayoutDirty();
3014             }
3015         }
3016         else if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_MENUBAR ))
3017         {
3018             Reference< XUIElement >         xUIElement = implts_findElement( Event.ResourceURL );
3019             Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
3020             if ( xElementSettings.is() )
3021             {
3022                 ::rtl::OUString aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
3023                 uno::Reference< XPropertySet > xPropSet( xElementSettings, uno::UNO_QUERY );
3024                 if ( xPropSet.is() )
3025                 {
3026                     if ( Event.Source == uno::Reference< uno::XInterface >( m_xDocCfgMgr, uno::UNO_QUERY ))
3027                         xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( m_xDocCfgMgr ));
3028                 }
3029                 xElementSettings->updateSettings();
3030             }
3031         }
3032 
3033         if ( bRefreshLayout )
3034             doLayout();
3035     }
3036 }
3037 
3038 void SAL_CALL LayoutManager::elementRemoved( const ui::ConfigurationEvent& Event ) throw (uno::RuntimeException)
3039 {
3040     ReadGuard aReadLock( m_aLock );
3041     Reference< frame::XFrame >                xFrame( m_xFrame );
3042     Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
3043     Reference< awt::XWindow >                 xContainerWindow( m_xContainerWindow );
3044     Reference< ui::XUIElement >               xMenuBar( m_xMenuBar );
3045     Reference< ui::XUIConfigurationManager >  xModuleCfgMgr( m_xModuleCfgMgr );
3046     Reference< ui::XUIConfigurationManager >  xDocCfgMgr( m_xDocCfgMgr );
3047     ToolbarLayoutManager*                     pToolbarManager = m_pToolbarManager;
3048     aReadLock.unlock();
3049 
3050     if ( xFrame.is() )
3051     {
3052        ::rtl::OUString aElementType;
3053        ::rtl::OUString aElementName;
3054        bool            bRefreshLayout(false);
3055 
3056        parseResourceURL( Event.ResourceURL, aElementType, aElementName );
3057         if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
3058         {
3059             if ( xToolbarManager.is() )
3060             {
3061                 xToolbarManager->elementRemoved( Event );
3062                 bRefreshLayout = pToolbarManager->isLayoutDirty();
3063             }
3064         }
3065         else
3066         {
3067             Reference< XUIElement > xUIElement = implts_findElement( Event.ResourceURL );
3068             Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
3069             if ( xElementSettings.is() )
3070             {
3071                 bool                      bNoSettings( false );
3072                 ::rtl::OUString           aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
3073                 Reference< XInterface >   xElementCfgMgr;
3074                 Reference< XPropertySet > xPropSet( xElementSettings, UNO_QUERY );
3075 
3076                 if ( xPropSet.is() )
3077                     xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr;
3078 
3079                 if ( !xElementCfgMgr.is() )
3080                     return;
3081 
3082                 // Check if the same UI configuration manager has changed => check further
3083                 if ( Event.Source == xElementCfgMgr )
3084                 {
3085                     // Same UI configuration manager where our element has its settings
3086                     if ( Event.Source == Reference< XInterface >( xDocCfgMgr, UNO_QUERY ))
3087                     {
3088                         // document settings removed
3089                         if ( xModuleCfgMgr->hasSettings( Event.ResourceURL ))
3090                         {
3091                             xPropSet->setPropertyValue( aConfigSourcePropName, makeAny( m_xModuleCfgMgr ));
3092                             xElementSettings->updateSettings();
3093                             return;
3094                         }
3095                     }
3096 
3097                     bNoSettings = true;
3098                 }
3099 
3100                 // No settings anymore, element must be destroyed
3101                     if ( xContainerWindow.is() && bNoSettings )
3102                 {
3103                     if ( aElementType.equalsIgnoreAsciiCaseAscii( "menubar" ) && aElementName.equalsIgnoreAsciiCaseAscii( "menubar" ))
3104                     {
3105                         SystemWindow* pSysWindow = getTopSystemWindow( xContainerWindow );
3106                         if ( pSysWindow && !m_bInplaceMenuSet )
3107                             pSysWindow->SetMenuBar( 0 );
3108 
3109                         Reference< XComponent > xComp( xMenuBar, UNO_QUERY );
3110                         if ( xComp.is() )
3111                             xComp->dispose();
3112 
3113                         WriteGuard aWriteLock( m_aLock );
3114                         m_xMenuBar.clear();
3115                     }
3116                 }
3117             }
3118         }
3119 
3120         if ( bRefreshLayout )
3121             doLayout();
3122     }
3123 }
3124 
3125 void SAL_CALL LayoutManager::elementReplaced( const ui::ConfigurationEvent& Event ) throw (uno::RuntimeException)
3126 {
3127     ReadGuard aReadLock( m_aLock );
3128     Reference< XFrame >                       xFrame( m_xFrame );
3129     Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
3130     ToolbarLayoutManager*                     pToolbarManager = m_pToolbarManager;
3131     aReadLock.unlock();
3132 
3133     if ( xFrame.is() )
3134     {
3135         ::rtl::OUString aElementType;
3136         ::rtl::OUString aElementName;
3137         bool            bRefreshLayout(false);
3138 
3139         parseResourceURL( Event.ResourceURL, aElementType, aElementName );
3140         if ( aElementType.equalsIgnoreAsciiCaseAscii( UIRESOURCETYPE_TOOLBAR ))
3141         {
3142             if ( xToolbarManager.is() )
3143             {
3144                 xToolbarManager->elementReplaced( Event );
3145                 bRefreshLayout = pToolbarManager->isLayoutDirty();
3146             }
3147         }
3148         else
3149         {
3150             Reference< XUIElement >         xUIElement = implts_findElement( Event.ResourceURL );
3151             Reference< XUIElementSettings > xElementSettings( xUIElement, UNO_QUERY );
3152             if ( xElementSettings.is() )
3153             {
3154                 ::rtl::OUString           aConfigSourcePropName( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
3155                 Reference< XInterface >   xElementCfgMgr;
3156                 Reference< XPropertySet > xPropSet( xElementSettings, UNO_QUERY );
3157 
3158                 if ( xPropSet.is() )
3159                     xPropSet->getPropertyValue( aConfigSourcePropName ) >>= xElementCfgMgr;
3160 
3161                 if ( !xElementCfgMgr.is() )
3162                     return;
3163 
3164                 // Check if the same UI configuration manager has changed => update settings
3165                 if ( Event.Source == xElementCfgMgr )
3166                     xElementSettings->updateSettings();
3167             }
3168         }
3169 
3170         if ( bRefreshLayout )
3171             doLayout();
3172     }
3173 }
3174 
3175 //---------------------------------------------------------------------------------------------------------
3176 //      OPropertySetHelper
3177 //---------------------------------------------------------------------------------------------------------
3178 sal_Bool SAL_CALL LayoutManager::convertFastPropertyValue( Any&       aConvertedValue,
3179                                                            Any&       aOldValue,
3180                                                            sal_Int32  nHandle,
3181                                                            const Any& aValue ) throw( lang::IllegalArgumentException )
3182 {
3183     return LayoutManager_PBase::convertFastPropertyValue( aConvertedValue, aOldValue, nHandle, aValue );
3184 }
3185 
3186 void SAL_CALL LayoutManager::setFastPropertyValue_NoBroadcast( sal_Int32       nHandle,
3187                                                                const uno::Any& aValue  ) throw( uno::Exception )
3188 {
3189     if ( nHandle != LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY )
3190         LayoutManager_PBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
3191 
3192     switch( nHandle )
3193     {
3194         case LAYOUTMANAGER_PROPHANDLE_MENUBARCLOSER:
3195             implts_updateMenuBarClose();
3196             break;
3197 
3198         case LAYOUTMANAGER_PROPHANDLE_REFRESHVISIBILITY:
3199         {
3200             sal_Bool bValue(sal_False);
3201             if (( aValue >>= bValue ) && bValue )
3202             {
3203                 ReadGuard aReadLock( m_aLock );
3204                 Reference< ui::XUIConfigurationListener > xToolbarManager( m_xToolbarManager );
3205                 ToolbarLayoutManager* pToolbarManager = m_pToolbarManager;
3206                 bool bAutomaticToolbars( m_bAutomaticToolbars );
3207                 aReadLock.unlock();
3208 
3209                 if ( pToolbarManager )
3210                     pToolbarManager->refreshToolbarsVisibility( bAutomaticToolbars );
3211             }
3212             break;
3213         }
3214 
3215         case LAYOUTMANAGER_PROPHANDLE_HIDECURRENTUI:
3216             implts_setCurrentUIVisibility( !m_bHideCurrentUI );
3217             break;
3218         default: break;
3219     }
3220 }
3221 
3222 void SAL_CALL LayoutManager::getFastPropertyValue( uno::Any& aValue, sal_Int32 nHandle ) const
3223 {
3224     LayoutManager_PBase::getFastPropertyValue( aValue, nHandle );
3225 }
3226 
3227 ::cppu::IPropertyArrayHelper& SAL_CALL LayoutManager::getInfoHelper()
3228 {
3229     static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
3230 
3231     if( pInfoHelper == NULL )
3232     {
3233         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
3234 
3235         if( pInfoHelper == NULL )
3236         {
3237             uno::Sequence< beans::Property > aProperties;
3238             describeProperties( aProperties );
3239             static ::cppu::OPropertyArrayHelper aInfoHelper( aProperties, sal_True );
3240             pInfoHelper = &aInfoHelper;
3241         }
3242     }
3243 
3244     return(*pInfoHelper);
3245 }
3246 
3247 uno::Reference< beans::XPropertySetInfo > SAL_CALL LayoutManager::getPropertySetInfo() throw (uno::RuntimeException)
3248 {
3249     static uno::Reference< beans::XPropertySetInfo >* pInfo = NULL;
3250 
3251     if( pInfo == NULL )
3252     {
3253         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
3254 
3255         if( pInfo == NULL )
3256         {
3257             static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
3258             pInfo = &xInfo;
3259         }
3260     }
3261 
3262     return (*pInfo);
3263 }
3264 
3265 } // namespace framework
3266