1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 
31 #include <uielement/statusbarwrapper.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //	my own includes
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/resetableguard.hxx>
37 #include <framework/actiontriggerhelper.hxx>
38 #include <uielement/constitemcontainer.hxx>
39 #include <uielement/rootitemcontainer.hxx>
40 #include <uielement/statusbar.hxx>
41 #include <helpid.hrc>
42 
43 //_________________________________________________________________________________________________________________
44 //	interface includes
45 //_________________________________________________________________________________________________________________
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
49 #include <com/sun/star/awt/XMenuBar.hpp>
50 #include <com/sun/star/container/XIndexContainer.hpp>
51 #include <com/sun/star/container/XNameAccess.hpp>
52 #include <com/sun/star/ui/UIElementType.hpp>
53 
54 //_________________________________________________________________________________________________________________
55 //	other includes
56 //_________________________________________________________________________________________________________________
57 #include <comphelper/processfactory.hxx>
58 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
59 #include <toolkit/unohlp.hxx>
60 #endif
61 
62 #include <tools/solar.h>
63 #include <vcl/svapp.hxx>
64 #include <rtl/logfile.hxx>
65 
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::beans;
68 using namespace com::sun::star::frame;
69 using namespace com::sun::star::lang;
70 using namespace com::sun::star::container;
71 using namespace com::sun::star::awt;
72 using namespace ::com::sun::star::ui;
73 
74 namespace framework
75 {
76 
77 StatusBarWrapper::StatusBarWrapper(
78 	const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
79 	)
80  :	UIConfigElementWrapperBase( UIElementType::STATUSBAR,xServiceManager )
81 {
82 }
83 
84 StatusBarWrapper::~StatusBarWrapper()
85 {
86 }
87 
88 void SAL_CALL StatusBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException)
89 {
90     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
91 
92     com::sun::star::lang::EventObject aEvent( xThis );
93     m_aListenerContainer.disposeAndClear( aEvent );
94 
95     ResetableGuard aLock( m_aLock );
96     if ( !m_bDisposed )
97     {
98         if ( m_xStatusBarManager.is() )
99             m_xStatusBarManager->dispose();
100         m_xStatusBarManager.clear();
101         m_xConfigSource.clear();
102         m_xConfigData.clear();
103         m_xServiceFactory.clear();
104 
105         m_bDisposed = sal_True;
106     }
107     else
108         throw DisposedException();
109 }
110 
111 // XInitialization
112 void SAL_CALL StatusBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
113 {
114     ResetableGuard aLock( m_aLock );
115 
116     if ( m_bDisposed )
117         throw DisposedException();
118 
119     if ( !m_bInitialized )
120     {
121         UIConfigElementWrapperBase::initialize( aArguments );
122 
123         Reference< XFrame > xFrame( m_xWeakFrame );
124         if ( xFrame.is() && m_xConfigSource.is() )
125         {
126             // Create VCL based toolbar which will be filled with settings data
127             StatusBar*        pStatusBar( 0 );
128             StatusBarManager* pStatusBarManager( 0 );
129             {
130                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
131                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
132                 if ( pWindow )
133                 {
134                     sal_uLong nStyles = WinBits( WB_LEFT | WB_3DLOOK );
135 
136                     pStatusBar = new FrameworkStatusBar( pWindow, nStyles );
137                     pStatusBarManager = new StatusBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pStatusBar );
138                     ((FrameworkStatusBar*)pStatusBar)->SetStatusBarManager( pStatusBarManager );
139                     m_xStatusBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pStatusBarManager ), UNO_QUERY );
140                     pStatusBar->SetUniqueId( HID_STATUSBAR );
141                 }
142             }
143 
144             try
145             {
146                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
147                 if ( m_xConfigData.is() && pStatusBar && pStatusBarManager )
148                 {
149                     // Fill statusbar with container contents
150                     pStatusBarManager->FillStatusBar( m_xConfigData );
151                 }
152             }
153             catch ( NoSuchElementException& )
154             {
155             }
156         }
157     }
158 }
159 
160 // XUIElementSettings
161 void SAL_CALL StatusBarWrapper::updateSettings() throw ( RuntimeException )
162 {
163     ResetableGuard aLock( m_aLock );
164 
165     if ( m_bDisposed )
166         throw DisposedException();
167 
168     if ( m_bPersistent &&
169          m_xConfigSource.is() &&
170          m_xStatusBarManager.is() )
171     {
172         try
173         {
174             StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
175 
176             m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
177             if ( m_xConfigData.is() )
178                 pStatusBarManager->FillStatusBar( m_xConfigData );
179         }
180         catch ( NoSuchElementException& )
181         {
182         }
183     }
184 }
185 
186 Reference< XInterface > SAL_CALL StatusBarWrapper::getRealInterface() throw ( RuntimeException )
187 {
188     ResetableGuard aLock( m_aLock );
189 
190     if ( m_xStatusBarManager.is() )
191     {
192         StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
193         if ( pStatusBarManager )
194         {
195             Window* pWindow = (Window *)pStatusBarManager->GetStatusBar();
196             if ( pWindow )
197                 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
198         }
199     }
200 
201     return Reference< XInterface >();
202 }
203 
204 } // namespace framework
205 
206