16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <uielement/statusbarwrapper.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir //	my own includes
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
33cdf0e10cSrcweir #include <framework/actiontriggerhelper.hxx>
34cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
35cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
36cdf0e10cSrcweir #include <uielement/statusbar.hxx>
37cdf0e10cSrcweir #include <helpid.hrc>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir //	interface includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
43cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
44cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
45cdf0e10cSrcweir #include <com/sun/star/awt/XMenuBar.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
48cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir //	other includes
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
54cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
55*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <tools/solar.h>
59cdf0e10cSrcweir #include <vcl/svapp.hxx>
60cdf0e10cSrcweir #include <rtl/logfile.hxx>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir using namespace com::sun::star::uno;
63cdf0e10cSrcweir using namespace com::sun::star::beans;
64cdf0e10cSrcweir using namespace com::sun::star::frame;
65cdf0e10cSrcweir using namespace com::sun::star::lang;
66cdf0e10cSrcweir using namespace com::sun::star::container;
67cdf0e10cSrcweir using namespace com::sun::star::awt;
68cdf0e10cSrcweir using namespace ::com::sun::star::ui;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir namespace framework
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 
StatusBarWrapper(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & xServiceManager)73cdf0e10cSrcweir StatusBarWrapper::StatusBarWrapper(
74cdf0e10cSrcweir 	const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
75cdf0e10cSrcweir 	)
76cdf0e10cSrcweir  :	UIConfigElementWrapperBase( UIElementType::STATUSBAR,xServiceManager )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
~StatusBarWrapper()80cdf0e10cSrcweir StatusBarWrapper::~StatusBarWrapper()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
dispose()84cdf0e10cSrcweir void SAL_CALL StatusBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     com::sun::star::lang::EventObject aEvent( xThis );
89cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
92cdf0e10cSrcweir     if ( !m_bDisposed )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         if ( m_xStatusBarManager.is() )
95cdf0e10cSrcweir             m_xStatusBarManager->dispose();
96cdf0e10cSrcweir         m_xStatusBarManager.clear();
97cdf0e10cSrcweir         m_xConfigSource.clear();
98cdf0e10cSrcweir         m_xConfigData.clear();
99cdf0e10cSrcweir         m_xServiceFactory.clear();
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         m_bDisposed = sal_True;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir     else
104cdf0e10cSrcweir         throw DisposedException();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & aArguments)108cdf0e10cSrcweir void SAL_CALL StatusBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     if ( m_bDisposed )
113cdf0e10cSrcweir         throw DisposedException();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     if ( !m_bInitialized )
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         UIConfigElementWrapperBase::initialize( aArguments );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         Reference< XFrame > xFrame( m_xWeakFrame );
120cdf0e10cSrcweir         if ( xFrame.is() && m_xConfigSource.is() )
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             // Create VCL based toolbar which will be filled with settings data
123cdf0e10cSrcweir             StatusBar*        pStatusBar( 0 );
124cdf0e10cSrcweir             StatusBarManager* pStatusBarManager( 0 );
125cdf0e10cSrcweir             {
126cdf0e10cSrcweir                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
127cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
128cdf0e10cSrcweir                 if ( pWindow )
129cdf0e10cSrcweir                 {
130cdf0e10cSrcweir                     sal_uLong nStyles = WinBits( WB_LEFT | WB_3DLOOK );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir                     pStatusBar = new FrameworkStatusBar( pWindow, nStyles );
133cdf0e10cSrcweir                     pStatusBarManager = new StatusBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pStatusBar );
134cdf0e10cSrcweir                     ((FrameworkStatusBar*)pStatusBar)->SetStatusBarManager( pStatusBarManager );
135cdf0e10cSrcweir                     m_xStatusBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pStatusBarManager ), UNO_QUERY );
136cdf0e10cSrcweir                     pStatusBar->SetUniqueId( HID_STATUSBAR );
137cdf0e10cSrcweir                 }
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir             try
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
143cdf0e10cSrcweir                 if ( m_xConfigData.is() && pStatusBar && pStatusBarManager )
144cdf0e10cSrcweir                 {
145cdf0e10cSrcweir                     // Fill statusbar with container contents
146cdf0e10cSrcweir                     pStatusBarManager->FillStatusBar( m_xConfigData );
147cdf0e10cSrcweir                 }
148cdf0e10cSrcweir             }
149cdf0e10cSrcweir             catch ( NoSuchElementException& )
150cdf0e10cSrcweir             {
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // XUIElementSettings
updateSettings()157cdf0e10cSrcweir void SAL_CALL StatusBarWrapper::updateSettings() throw ( RuntimeException )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     if ( m_bDisposed )
162cdf0e10cSrcweir         throw DisposedException();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     if ( m_bPersistent &&
165cdf0e10cSrcweir          m_xConfigSource.is() &&
166cdf0e10cSrcweir          m_xStatusBarManager.is() )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         try
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
173cdf0e10cSrcweir             if ( m_xConfigData.is() )
174cdf0e10cSrcweir                 pStatusBarManager->FillStatusBar( m_xConfigData );
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         catch ( NoSuchElementException& )
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
getRealInterface()182cdf0e10cSrcweir Reference< XInterface > SAL_CALL StatusBarWrapper::getRealInterface() throw ( RuntimeException )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     if ( m_xStatusBarManager.is() )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
189cdf0e10cSrcweir         if ( pStatusBarManager )
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             Window* pWindow = (Window *)pStatusBarManager->GetStatusBar();
192cdf0e10cSrcweir             if ( pWindow )
193cdf0e10cSrcweir                 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
194cdf0e10cSrcweir         }
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     return Reference< XInterface >();
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir } // namespace framework
201cdf0e10cSrcweir 
202