Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <uielement/statusbarwrapper.hxx>
22 :
23 : #include <threadhelp/resetableguard.hxx>
24 : #include <framework/actiontriggerhelper.hxx>
25 : #include <uielement/constitemcontainer.hxx>
26 : #include <uielement/rootitemcontainer.hxx>
27 : #include <uielement/statusbar.hxx>
28 : #include <helpid.hrc>
29 :
30 : #include <com/sun/star/lang/XServiceInfo.hpp>
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
33 : #include <com/sun/star/awt/XMenuBar.hpp>
34 : #include <com/sun/star/container/XIndexContainer.hpp>
35 : #include <com/sun/star/container/XNameAccess.hpp>
36 : #include <com/sun/star/ui/UIElementType.hpp>
37 :
38 : #include <comphelper/processfactory.hxx>
39 : #include <toolkit/unohlp.hxx>
40 :
41 : #include <tools/solar.h>
42 : #include <vcl/svapp.hxx>
43 : #include <rtl/logfile.hxx>
44 :
45 : using namespace com::sun::star::uno;
46 : using namespace com::sun::star::beans;
47 : using namespace com::sun::star::frame;
48 : using namespace com::sun::star::lang;
49 : using namespace com::sun::star::container;
50 : using namespace com::sun::star::awt;
51 : using namespace ::com::sun::star::ui;
52 :
53 : namespace framework
54 : {
55 :
56 236 : StatusBarWrapper::StatusBarWrapper(
57 : const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
58 : )
59 236 : : UIConfigElementWrapperBase( UIElementType::STATUSBAR,xServiceManager )
60 : {
61 236 : }
62 :
63 126 : StatusBarWrapper::~StatusBarWrapper()
64 : {
65 126 : }
66 :
67 63 : void SAL_CALL StatusBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException)
68 : {
69 63 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
70 :
71 63 : com::sun::star::lang::EventObject aEvent( xThis );
72 63 : m_aListenerContainer.disposeAndClear( aEvent );
73 :
74 63 : ResetableGuard aLock( m_aLock );
75 63 : if ( !m_bDisposed )
76 : {
77 63 : if ( m_xStatusBarManager.is() )
78 63 : m_xStatusBarManager->dispose();
79 63 : m_xStatusBarManager.clear();
80 63 : m_xConfigSource.clear();
81 63 : m_xConfigData.clear();
82 63 : m_xServiceFactory.clear();
83 :
84 63 : m_bDisposed = sal_True;
85 : }
86 : else
87 63 : throw DisposedException();
88 63 : }
89 :
90 : // XInitialization
91 236 : void SAL_CALL StatusBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
92 : {
93 236 : ResetableGuard aLock( m_aLock );
94 :
95 236 : if ( m_bDisposed )
96 0 : throw DisposedException();
97 :
98 236 : if ( !m_bInitialized )
99 : {
100 236 : UIConfigElementWrapperBase::initialize( aArguments );
101 :
102 236 : Reference< XFrame > xFrame( m_xWeakFrame );
103 236 : if ( xFrame.is() && m_xConfigSource.is() )
104 : {
105 : // Create VCL based toolbar which will be filled with settings data
106 236 : StatusBar* pStatusBar( 0 );
107 236 : StatusBarManager* pStatusBarManager( 0 );
108 : {
109 236 : SolarMutexGuard aSolarMutexGuard;
110 236 : Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
111 236 : if ( pWindow )
112 : {
113 236 : sal_uLong nStyles = WinBits( WB_LEFT | WB_3DLOOK );
114 :
115 236 : pStatusBar = new FrameworkStatusBar( pWindow, nStyles );
116 236 : pStatusBarManager = new StatusBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pStatusBar );
117 236 : ((FrameworkStatusBar*)pStatusBar)->SetStatusBarManager( pStatusBarManager );
118 236 : m_xStatusBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pStatusBarManager ), UNO_QUERY );
119 236 : pStatusBar->SetUniqueId( HID_STATUSBAR );
120 236 : }
121 : }
122 :
123 : try
124 : {
125 236 : m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
126 0 : if ( m_xConfigData.is() && pStatusBar && pStatusBarManager )
127 : {
128 : // Fill statusbar with container contents
129 0 : pStatusBarManager->FillStatusBar( m_xConfigData );
130 : }
131 : }
132 236 : catch ( const NoSuchElementException& )
133 : {
134 : }
135 236 : }
136 236 : }
137 236 : }
138 :
139 : // XUIElementSettings
140 0 : void SAL_CALL StatusBarWrapper::updateSettings() throw ( RuntimeException )
141 : {
142 0 : ResetableGuard aLock( m_aLock );
143 :
144 0 : if ( m_bDisposed )
145 0 : throw DisposedException();
146 :
147 0 : if ( m_bPersistent &&
148 0 : m_xConfigSource.is() &&
149 0 : m_xStatusBarManager.is() )
150 : {
151 : try
152 : {
153 0 : StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
154 :
155 0 : m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
156 0 : if ( m_xConfigData.is() )
157 0 : pStatusBarManager->FillStatusBar( m_xConfigData );
158 : }
159 0 : catch ( const NoSuchElementException& )
160 : {
161 : }
162 0 : }
163 0 : }
164 :
165 5020 : Reference< XInterface > SAL_CALL StatusBarWrapper::getRealInterface() throw ( RuntimeException )
166 : {
167 5020 : ResetableGuard aLock( m_aLock );
168 :
169 5020 : if ( m_xStatusBarManager.is() )
170 : {
171 5020 : StatusBarManager* pStatusBarManager = static_cast< StatusBarManager *>( m_xStatusBarManager.get() );
172 5020 : if ( pStatusBarManager )
173 : {
174 5020 : Window* pWindow = (Window *)pStatusBarManager->GetStatusBar();
175 5020 : if ( pWindow )
176 5020 : return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
177 : }
178 : }
179 :
180 0 : return Reference< XInterface >();
181 : }
182 :
183 : } // namespace framework
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|