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