update dev300-m58
[ooovba.git] / framework / source / uielement / progressbarwrapper.cxx
blobe35aec55f6aaaa00bc504399365c4bb0ce2a5661
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: progressbarwrapper.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #ifndef __FRAMEWORK_UIELEMENT_PROGRESSBARWRAPPER_HXX_
35 #include <uielement/progressbarwrapper.hxx>
36 #endif
38 //_________________________________________________________________________________________________________________
39 // my own includes
40 //_________________________________________________________________________________________________________________
41 #include <helper/statusindicator.hxx>
42 #include <threadhelp/resetableguard.hxx>
43 #include <uielement/statusindicatorinterfacewrapper.hxx>
45 //_________________________________________________________________________________________________________________
46 // interface includes
47 //_________________________________________________________________________________________________________________
48 #include <com/sun/star/ui/UIElementType.hpp>
50 //_________________________________________________________________________________________________________________
51 // includes of other projects
52 //_________________________________________________________________________________________________________________
53 #include <vcl/svapp.hxx>
54 #include <toolkit/helper/vclunohelper.hxx>
56 //_________________________________________________________________________________________________________________
57 // namespace
58 //_________________________________________________________________________________________________________________
59 using namespace ::com::sun::star;
61 namespace framework{
63 //_________________________________________________________________________________________________________________
64 // non exported const
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
68 // non exported definitions
69 //_________________________________________________________________________________________________________________
71 //_________________________________________________________________________________________________________________
72 // declarations
73 //_________________________________________________________________________________________________________________
75 ProgressBarWrapper::ProgressBarWrapper() :
76 UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR )
77 , m_bOwnsInstance( sal_False )
78 , m_nRange( 100 )
79 , m_nValue( 0 )
83 ProgressBarWrapper::~ProgressBarWrapper()
87 // public interfaces
88 void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, sal_Bool bOwnsInstance )
90 ResetableGuard aGuard( m_aLock );
92 if ( m_bDisposed )
93 return;
95 if ( m_bOwnsInstance )
97 // dispose XWindow reference our our status bar
98 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
99 try
101 if ( xComponent.is() )
102 xComponent->dispose();
104 catch ( uno::Exception& )
107 m_xStatusBar.clear();
110 m_bOwnsInstance = bOwnsInstance;
111 m_xStatusBar = rStatusBar;
114 uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
116 ResetableGuard aGuard( m_aLock );
118 if ( m_bDisposed )
119 return uno::Reference< awt::XWindow >();
121 return m_xStatusBar;
124 // wrapped methods of ::com::sun::star::task::XStatusIndicator
125 void ProgressBarWrapper::start( const ::rtl::OUString& Text, ::sal_Int32 Range )
126 throw (uno::RuntimeException)
128 uno::Reference< awt::XWindow > xWindow;
129 sal_Int32 nValue( 0 );
132 ResetableGuard aGuard( m_aLock );
134 if ( m_bDisposed )
135 return;
137 xWindow = m_xStatusBar;
138 m_nValue = 0;
139 m_nRange = Range;
140 nValue = m_nValue;
143 if ( xWindow.is() )
145 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
146 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
147 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
149 StatusBar* pStatusBar = (StatusBar *)pWindow;
150 if ( !pStatusBar->IsProgressMode() )
151 pStatusBar->StartProgressMode( Text );
152 else
154 pStatusBar->SetUpdateMode( FALSE );
155 pStatusBar->EndProgressMode();
156 pStatusBar->StartProgressMode( Text );
157 pStatusBar->SetProgressValue( USHORT( nValue ));
158 pStatusBar->SetUpdateMode( TRUE );
160 pStatusBar->Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
165 void ProgressBarWrapper::end()
166 throw (uno::RuntimeException)
168 uno::Reference< awt::XWindow > xWindow;
171 ResetableGuard aGuard( m_aLock );
173 if ( m_bDisposed )
174 return;
176 xWindow = m_xStatusBar;
177 m_nRange = 100;
178 m_nValue = 0;
181 if ( xWindow.is() )
183 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
184 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
185 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
187 StatusBar* pStatusBar = (StatusBar *)pWindow;
188 if ( pStatusBar->IsProgressMode() )
189 pStatusBar->EndProgressMode();
194 void ProgressBarWrapper::setText( const ::rtl::OUString& Text )
195 throw (uno::RuntimeException)
197 uno::Reference< awt::XWindow > xWindow;
198 sal_Int32 nValue( 0 );
201 ResetableGuard aGuard( m_aLock );
203 if ( m_bDisposed )
204 return;
206 xWindow = m_xStatusBar;
207 m_aText = Text;
208 nValue = m_nValue;
211 if ( xWindow.is() )
213 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
214 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
215 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
217 StatusBar* pStatusBar = (StatusBar *)pWindow;
218 if( pStatusBar->IsProgressMode() )
220 pStatusBar->SetUpdateMode( FALSE );
221 pStatusBar->EndProgressMode();
222 pStatusBar->StartProgressMode( Text );
223 pStatusBar->SetProgressValue( USHORT( nValue ));
224 pStatusBar->SetUpdateMode( TRUE );
226 else
227 pStatusBar->SetText( Text );
232 void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
233 throw (uno::RuntimeException)
235 uno::Reference< awt::XWindow > xWindow;
236 rtl::OUString aText;
237 sal_Bool bSetValue( sal_False );
240 ResetableGuard aGuard( m_aLock );
242 if ( m_bDisposed )
243 return;
245 xWindow = m_xStatusBar;
247 double fVal( 0 );
248 if ( m_nRange > 0 )
250 fVal = ( double( nValue ) / double( m_nRange )) * 100;
251 fVal = std::max( double( 0 ), std::min( fVal, double( 100 )));
254 if ( m_nValue != sal_Int32( fVal ))
256 m_nValue = sal_Int32( fVal );
257 bSetValue = sal_True;
260 nValue = m_nValue;
261 aText = m_aText;
264 if ( xWindow.is() && bSetValue )
266 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
267 Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
268 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR )
270 StatusBar* pStatusBar = (StatusBar *)pWindow;
271 if ( !pStatusBar->IsProgressMode() )
272 pStatusBar->StartProgressMode( aText );
273 pStatusBar->SetProgressValue( USHORT( nValue ));
278 void ProgressBarWrapper::reset()
279 throw (uno::RuntimeException)
281 setText( rtl::OUString() );
282 setValue( 0 );
285 // XInitialization
286 void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
287 throw (uno::Exception, uno::RuntimeException)
289 // dummy - do nothing
292 // XUpdatable
293 void SAL_CALL ProgressBarWrapper::update()
294 throw (uno::RuntimeException)
296 // dummy - do nothing
299 // XComponent
300 void SAL_CALL ProgressBarWrapper::dispose()
301 throw (uno::RuntimeException)
303 uno::Reference< lang::XComponent > xThis(
304 static_cast< cppu::OWeakObject* >(this),
305 uno::UNO_QUERY );
308 ResetableGuard aLock( m_aLock );
310 if ( m_bDisposed )
311 return;
315 lang::EventObject aEvent( xThis );
316 m_aListenerContainer.disposeAndClear( aEvent );
318 ResetableGuard aLock( m_aLock );
319 if ( m_bOwnsInstance )
323 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
324 if ( xComponent.is() )
325 xComponent->dispose();
327 catch ( lang::DisposedException& )
332 m_xStatusBar.clear();
333 m_bDisposed = sal_True;
337 // XUIElement
338 uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
339 throw (uno::RuntimeException)
341 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
342 // Ready for multithreading
343 ResetableGuard aLock( m_aLock );
345 if ( m_bDisposed )
346 return uno::Reference< uno::XInterface >();
347 else
349 uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
350 if ( !xComp.is() )
352 StatusIndicatorInterfaceWrapper* pWrapper =
353 new StatusIndicatorInterfaceWrapper(
354 uno::Reference< lang::XComponent >(
355 static_cast< cppu::OWeakObject* >( this ),
356 uno::UNO_QUERY ));
357 xComp = uno::Reference< uno::XInterface >(
358 static_cast< cppu::OWeakObject* >( pWrapper ),
359 uno::UNO_QUERY );
360 m_xProgressBarIfacWrapper = xComp;
363 return xComp;
367 } // namespace framework