1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <uielement/progressbarwrapper.hxx>
22 #include <helper/statusindicator.hxx>
23 #include <uielement/statusindicatorinterfacewrapper.hxx>
25 #include <com/sun/star/ui/UIElementType.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <vcl/status.hxx>
29 #include <vcl/svapp.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
32 using namespace ::com::sun::star
;
36 ProgressBarWrapper::ProgressBarWrapper() :
37 UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR
)
38 , m_bOwnsInstance( false )
44 ProgressBarWrapper::~ProgressBarWrapper()
49 void ProgressBarWrapper::setStatusBar( const uno::Reference
< awt::XWindow
>& rStatusBar
, bool bOwnsInstance
)
56 if ( m_bOwnsInstance
)
58 // dispose XWindow reference our our status bar
59 uno::Reference
< lang::XComponent
> xComponent( m_xStatusBar
, uno::UNO_QUERY
);
62 if ( xComponent
.is() )
63 xComponent
->dispose();
65 catch ( const uno::Exception
& )
71 m_bOwnsInstance
= bOwnsInstance
;
72 m_xStatusBar
= rStatusBar
;
75 uno::Reference
< awt::XWindow
> ProgressBarWrapper::getStatusBar() const
80 return uno::Reference
< awt::XWindow
>();
85 // wrapped methods of ::com::sun::star::task::XStatusIndicator
86 void ProgressBarWrapper::start( const OUString
& Text
, ::sal_Int32 Range
)
87 throw (uno::RuntimeException
, std::exception
)
89 uno::Reference
< awt::XWindow
> xWindow
;
90 sal_Int32
nValue( 0 );
98 xWindow
= m_xStatusBar
;
106 SolarMutexGuard aSolarMutexGuard
;
107 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
108 if ( pWindow
&& pWindow
->GetType() == WINDOW_STATUSBAR
)
110 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
);
111 if ( !pStatusBar
->IsProgressMode() )
112 pStatusBar
->StartProgressMode( Text
);
115 pStatusBar
->SetUpdateMode( false );
116 pStatusBar
->EndProgressMode();
117 pStatusBar
->StartProgressMode( Text
);
118 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
119 pStatusBar
->SetUpdateMode( true );
121 pStatusBar
->Show( true, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
126 void ProgressBarWrapper::end()
127 throw (uno::RuntimeException
, std::exception
)
129 uno::Reference
< awt::XWindow
> xWindow
;
137 xWindow
= m_xStatusBar
;
144 SolarMutexGuard aSolarMutexGuard
;
145 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
146 if ( pWindow
&& pWindow
->GetType() == WINDOW_STATUSBAR
)
148 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
);
149 if ( pStatusBar
->IsProgressMode() )
150 pStatusBar
->EndProgressMode();
155 void ProgressBarWrapper::setText( const OUString
& Text
)
156 throw (uno::RuntimeException
, std::exception
)
158 uno::Reference
< awt::XWindow
> xWindow
;
159 sal_Int32
nValue( 0 );
167 xWindow
= m_xStatusBar
;
174 SolarMutexGuard aSolarMutexGuard
;
175 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
176 if ( pWindow
&& pWindow
->GetType() == WINDOW_STATUSBAR
)
178 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
);
179 if( pStatusBar
->IsProgressMode() )
181 pStatusBar
->SetUpdateMode( false );
182 pStatusBar
->EndProgressMode();
183 pStatusBar
->StartProgressMode( Text
);
184 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
185 pStatusBar
->SetUpdateMode( true );
188 pStatusBar
->SetText( Text
);
193 void ProgressBarWrapper::setValue( ::sal_Int32 nValue
)
194 throw (uno::RuntimeException
, std::exception
)
196 uno::Reference
< awt::XWindow
> xWindow
;
198 bool bSetValue( false );
206 xWindow
= m_xStatusBar
;
211 fVal
= ( double( nValue
) / double( m_nRange
)) * 100;
212 fVal
= std::max( double( 0 ), std::min( fVal
, double( 100 )));
215 if ( m_nValue
!= sal_Int32( fVal
))
217 m_nValue
= sal_Int32( fVal
);
225 if ( xWindow
.is() && bSetValue
)
227 SolarMutexGuard aSolarMutexGuard
;
228 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWindow
);
229 if ( pWindow
&& pWindow
->GetType() == WINDOW_STATUSBAR
)
231 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
);
232 if ( !pStatusBar
->IsProgressMode() )
233 pStatusBar
->StartProgressMode( aText
);
234 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
239 void ProgressBarWrapper::reset()
240 throw (uno::RuntimeException
, std::exception
)
242 setText( OUString() );
247 void SAL_CALL
ProgressBarWrapper::initialize( const uno::Sequence
< uno::Any
>& )
248 throw (uno::Exception
, uno::RuntimeException
, std::exception
)
250 // dummy - do nothing
254 void SAL_CALL
ProgressBarWrapper::update()
255 throw (uno::RuntimeException
, std::exception
)
257 // dummy - do nothing
261 void SAL_CALL
ProgressBarWrapper::dispose()
262 throw (uno::RuntimeException
, std::exception
)
264 uno::Reference
< lang::XComponent
> xThis(
265 static_cast< cppu::OWeakObject
* >(this),
276 lang::EventObject
aEvent( xThis
);
277 m_aListenerContainer
.disposeAndClear( aEvent
);
280 if ( m_bOwnsInstance
)
284 uno::Reference
< lang::XComponent
> xComponent( m_xStatusBar
, uno::UNO_QUERY
);
285 if ( xComponent
.is() )
286 xComponent
->dispose();
288 catch ( const lang::DisposedException
& )
293 m_xStatusBar
.clear();
299 uno::Reference
< uno::XInterface
> SAL_CALL
ProgressBarWrapper::getRealInterface()
300 throw (uno::RuntimeException
, std::exception
)
305 return uno::Reference
< uno::XInterface
>();
308 uno::Reference
< uno::XInterface
> xComp( m_xProgressBarIfacWrapper
);
311 StatusIndicatorInterfaceWrapper
* pWrapper
=
312 new StatusIndicatorInterfaceWrapper(
313 uno::Reference
< lang::XComponent
>(
314 static_cast< cppu::OWeakObject
* >( this ),
316 xComp
= uno::Reference
< uno::XInterface
>(
317 static_cast< cppu::OWeakObject
* >( pWrapper
),
319 m_xProgressBarIfacWrapper
= xComp
;
326 } // namespace framework
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */