1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: progressbarwrapper.cxx,v $
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>
38 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
41 #include <helper/statusindicator.hxx>
42 #include <threadhelp/resetableguard.hxx>
43 #include <uielement/statusindicatorinterfacewrapper.hxx>
45 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
58 //_________________________________________________________________________________________________________________
59 using namespace ::com::sun::star
;
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
68 // non exported definitions
69 //_________________________________________________________________________________________________________________
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
75 ProgressBarWrapper::ProgressBarWrapper() :
76 UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR
)
77 , m_bOwnsInstance( sal_False
)
83 ProgressBarWrapper::~ProgressBarWrapper()
88 void ProgressBarWrapper::setStatusBar( const uno::Reference
< awt::XWindow
>& rStatusBar
, sal_Bool bOwnsInstance
)
90 ResetableGuard
aGuard( m_aLock
);
95 if ( m_bOwnsInstance
)
97 // dispose XWindow reference our our status bar
98 uno::Reference
< lang::XComponent
> xComponent( m_xStatusBar
, uno::UNO_QUERY
);
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
);
119 return uno::Reference
< awt::XWindow
>();
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
);
137 xWindow
= m_xStatusBar
;
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
);
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
);
176 xWindow
= m_xStatusBar
;
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
);
206 xWindow
= m_xStatusBar
;
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
);
227 pStatusBar
->SetText( Text
);
232 void ProgressBarWrapper::setValue( ::sal_Int32 nValue
)
233 throw (uno::RuntimeException
)
235 uno::Reference
< awt::XWindow
> xWindow
;
237 sal_Bool
bSetValue( sal_False
);
240 ResetableGuard
aGuard( m_aLock
);
245 xWindow
= m_xStatusBar
;
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
;
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() );
286 void SAL_CALL
ProgressBarWrapper::initialize( const uno::Sequence
< uno::Any
>& )
287 throw (uno::Exception
, uno::RuntimeException
)
289 // dummy - do nothing
293 void SAL_CALL
ProgressBarWrapper::update()
294 throw (uno::RuntimeException
)
296 // dummy - do nothing
300 void SAL_CALL
ProgressBarWrapper::dispose()
301 throw (uno::RuntimeException
)
303 uno::Reference
< lang::XComponent
> xThis(
304 static_cast< cppu::OWeakObject
* >(this),
308 ResetableGuard
aLock( m_aLock
);
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
;
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
);
346 return uno::Reference
< uno::XInterface
>();
349 uno::Reference
< uno::XInterface
> xComp( m_xProgressBarIfacWrapper
);
352 StatusIndicatorInterfaceWrapper
* pWrapper
=
353 new StatusIndicatorInterfaceWrapper(
354 uno::Reference
< lang::XComponent
>(
355 static_cast< cppu::OWeakObject
* >( this ),
357 xComp
= uno::Reference
< uno::XInterface
>(
358 static_cast< cppu::OWeakObject
* >( pWrapper
),
360 m_xProgressBarIfacWrapper
= xComp
;
367 } // namespace framework