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 #include <uielement/statusbarwrapper.hxx>
28
29 //_________________________________________________________________________________________________________________
30 // my own includes
31 //_________________________________________________________________________________________________________________
32 #include <threadhelp/resetableguard.hxx>
33 #include <framework/actiontriggerhelper.hxx>
34 #include <uielement/constitemcontainer.hxx>
35 #include <uielement/rootitemcontainer.hxx>
36 #include <uielement/statusbar.hxx>
37 #include <helpid.hrc>
38
39 //_________________________________________________________________________________________________________________
40 // interface includes
41 //_________________________________________________________________________________________________________________
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
45 #include <com/sun/star/awt/XMenuBar.hpp>
46 #include <com/sun/star/container/XIndexContainer.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/ui/UIElementType.hpp>
49
50 //_________________________________________________________________________________________________________________
51 // other includes
52 //_________________________________________________________________________________________________________________
53 #include <comphelper/processfactory.hxx>
54 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
55 #include <toolkit/helper/vclunohelper.hxx>
56 #endif
57
58 #include <tools/solar.h>
59 #include <vcl/svapp.hxx>
60 #include <rtl/logfile.hxx>
61
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::beans;
64 using namespace com::sun::star::frame;
65 using namespace com::sun::star::lang;
66 using namespace com::sun::star::container;
67 using namespace com::sun::star::awt;
68 using namespace ::com::sun::star::ui;
69
70 namespace framework
71 {
72
StatusBarWrapper(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & xServiceManager)73 StatusBarWrapper::StatusBarWrapper(
74 const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
75 )
76 : UIConfigElementWrapperBase( UIElementType::STATUSBAR,xServiceManager )
77 {
78 }
79
~StatusBarWrapper()80 StatusBarWrapper::~StatusBarWrapper()
81 {
82 }
83
dispose()84 void SAL_CALL StatusBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException)
85 {
86 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
87
88 com::sun::star::lang::EventObject aEvent( xThis );
89 m_aListenerContainer.disposeAndClear( aEvent );
90
91 ResetableGuard aLock( m_aLock );
92 if ( !m_bDisposed )
93 {
94 if ( m_xStatusBarManager.is() )
95 m_xStatusBarManager->dispose();
96 m_xStatusBarManager.clear();
97 m_xConfigSource.clear();
98 m_xConfigData.clear();
99 m_xServiceFactory.clear();
100
101 m_bDisposed = sal_True;
102 }
103 else
104 throw DisposedException();
105 }
106
107 // XInitialization
initialize(const Sequence<Any> & aArguments)108 void SAL_CALL StatusBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
109 {
110 ResetableGuard aLock( m_aLock );
111
112 if ( m_bDisposed )
113 throw DisposedException();
114
115 if ( !m_bInitialized )
116 {
117 UIConfigElementWrapperBase::initialize( aArguments );
118
119 Reference< XFrame > xFrame( m_xWeakFrame );
120 if ( xFrame.is() && m_xConfigSource.is() )
121 {
122 // Create VCL based toolbar which will be filled with settings data
123 StatusBar* pStatusBar( 0 );
124 StatusBarManager* pStatusBarManager( 0 );
125 {
126 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
127 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
128 if ( pWindow )
129 {
130 sal_uLong nStyles = WinBits( WB_LEFT | WB_3DLOOK );
131
132 pStatusBar = new FrameworkStatusBar( pWindow, nStyles );
133 pStatusBarManager = new StatusBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pStatusBar );
134 ((FrameworkStatusBar*)pStatusBar)->SetStatusBarManager( pStatusBarManager );
135 m_xStatusBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pStatusBarManager ), UNO_QUERY );
136 pStatusBar->SetUniqueId( HID_STATUSBAR );
137 }
138 }
139
140 try
141 {
142 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
143 if ( m_xConfigData.is() && pStatusBar && pStatusBarManager )
144 {
145 // Fill statusbar with container contents
146 pStatusBarManager->FillStatusBar( m_xConfigData );
147 }
148 }
149 catch ( NoSuchElementException& )
150 {
151 }
152 }
153 }
154 }
155
156 // XUIElementSettings
updateSettings()157 void SAL_CALL StatusBarWrapper::updateSettings() throw ( RuntimeException )
158 {
159 ResetableGuard aLock( m_aLock );
160
161 if ( m_bDisposed )
162 throw DisposedException();
163
164 if ( m_bPersistent &&
165 m_xConfigSource.is() &&
166 m_xStatusBarManager.is() )
167 {
168 try
169 {
170 StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
171
172 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
173 if ( m_xConfigData.is() )
174 pStatusBarManager->FillStatusBar( m_xConfigData );
175 }
176 catch ( NoSuchElementException& )
177 {
178 }
179 }
180 }
181
getRealInterface()182 Reference< XInterface > SAL_CALL StatusBarWrapper::getRealInterface() throw ( RuntimeException )
183 {
184 ResetableGuard aLock( m_aLock );
185
186 if ( m_xStatusBarManager.is() )
187 {
188 StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
189 if ( pStatusBarManager )
190 {
191 Window* pWindow = (Window *)pStatusBarManager->GetStatusBar();
192 if ( pWindow )
193 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
194 }
195 }
196
197 return Reference< XInterface >();
198 }
199
200 } // namespace framework
201
202