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