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 <uielement/statusindicatorinterfacewrapper.hxx>
24 #include <com/sun/star/ui/UIElementType.hpp>
25 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <vcl/status.hxx>
28 #include <vcl/svapp.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
31 using namespace ::com::sun::star
;
35 ProgressBarWrapper::ProgressBarWrapper() :
36 UIElementWrapperBase( css::ui::UIElementType::PROGRESSBAR
)
37 , m_bOwnsInstance( false )
43 ProgressBarWrapper::~ProgressBarWrapper()
48 void ProgressBarWrapper::setStatusBar( const uno::Reference
< awt::XWindow
>& rStatusBar
, bool bOwnsInstance
)
55 if ( m_bOwnsInstance
)
57 // dispose XWindow reference of our status bar
60 if ( m_xStatusBar
.is() )
61 m_xStatusBar
->dispose();
63 catch ( const uno::Exception
& )
69 m_bOwnsInstance
= bOwnsInstance
;
70 m_xStatusBar
= rStatusBar
;
73 uno::Reference
< awt::XWindow
> ProgressBarWrapper::getStatusBar() const
78 return uno::Reference
< awt::XWindow
>();
83 // wrapped methods of css::task::XStatusIndicator
84 void ProgressBarWrapper::start( const OUString
& Text
, ::sal_Int32 Range
)
86 uno::Reference
< awt::XWindow
> xWindow
;
87 sal_Int32
nValue( 0 );
95 xWindow
= m_xStatusBar
;
104 SolarMutexGuard aSolarMutexGuard
;
105 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
106 if ( !(pWindow
&& pWindow
->GetType() == WindowType::STATUSBAR
) )
109 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
.get());
110 if ( !pStatusBar
->IsProgressMode() )
111 pStatusBar
->StartProgressMode( Text
);
114 pStatusBar
->SetUpdateMode( false );
115 pStatusBar
->EndProgressMode();
116 pStatusBar
->StartProgressMode( Text
);
117 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
118 pStatusBar
->SetUpdateMode( true );
120 pStatusBar
->Show( true, ShowFlags::NoFocusChange
| ShowFlags::NoActivate
);
123 void ProgressBarWrapper::end()
125 uno::Reference
< awt::XWindow
> xWindow
;
133 xWindow
= m_xStatusBar
;
140 SolarMutexGuard aSolarMutexGuard
;
141 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
142 if ( pWindow
&& pWindow
->GetType() == WindowType::STATUSBAR
)
144 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
.get());
145 if ( pStatusBar
->IsProgressMode() )
146 pStatusBar
->EndProgressMode();
151 void ProgressBarWrapper::setText( const OUString
& Text
)
153 uno::Reference
< awt::XWindow
> xWindow
;
154 sal_Int32
nValue( 0 );
162 xWindow
= m_xStatusBar
;
170 SolarMutexGuard aSolarMutexGuard
;
171 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
172 if ( !(pWindow
&& pWindow
->GetType() == WindowType::STATUSBAR
) )
175 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
.get());
176 if( pStatusBar
->IsProgressMode() )
178 pStatusBar
->SetUpdateMode( false );
179 pStatusBar
->EndProgressMode();
180 pStatusBar
->StartProgressMode( Text
);
181 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
182 pStatusBar
->SetUpdateMode( true );
185 pStatusBar
->SetText( Text
);
188 void ProgressBarWrapper::setValue( ::sal_Int32 nValue
)
190 uno::Reference
< awt::XWindow
> xWindow
;
192 bool bSetValue( false );
200 xWindow
= m_xStatusBar
;
205 fVal
= ( double( nValue
) / double( m_nRange
)) * 100;
206 fVal
= std::clamp( fVal
, 0.0, 100.0 );
209 if ( m_nValue
!= sal_Int32( fVal
))
211 m_nValue
= sal_Int32( fVal
);
219 if ( xWindow
.is() && bSetValue
)
221 SolarMutexGuard aSolarMutexGuard
;
222 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
223 if ( pWindow
&& pWindow
->GetType() == WindowType::STATUSBAR
)
225 StatusBar
* pStatusBar
= static_cast<StatusBar
*>(pWindow
.get());
226 if ( !pStatusBar
->IsProgressMode() )
227 pStatusBar
->StartProgressMode( aText
);
228 pStatusBar
->SetProgressValue( sal_uInt16( nValue
));
233 void ProgressBarWrapper::reset()
235 setText( OUString() );
240 void SAL_CALL
ProgressBarWrapper::initialize( const uno::Sequence
< uno::Any
>& )
242 // dummy - do nothing
246 void SAL_CALL
ProgressBarWrapper::update()
248 // dummy - do nothing
252 void SAL_CALL
ProgressBarWrapper::dispose()
254 uno::Reference
< lang::XComponent
> xThis(this);
264 lang::EventObject
aEvent( xThis
);
265 m_aListenerContainer
.disposeAndClear( aEvent
);
268 if ( m_bOwnsInstance
)
272 if ( m_xStatusBar
.is() )
273 m_xStatusBar
->dispose();
275 catch ( const lang::DisposedException
& )
280 m_xStatusBar
.clear();
286 uno::Reference
< uno::XInterface
> SAL_CALL
ProgressBarWrapper::getRealInterface()
291 return uno::Reference
< uno::XInterface
>();
294 uno::Reference
< uno::XInterface
> xComp( m_xProgressBarIfacWrapper
);
297 rtl::Reference
<StatusIndicatorInterfaceWrapper
> pWrapper
=
298 new StatusIndicatorInterfaceWrapper( uno::Reference
< lang::XComponent
>(this) );
299 xComp
.set(static_cast< cppu::OWeakObject
* >( pWrapper
.get() ),
301 m_xProgressBarIfacWrapper
= xComp
;
308 } // namespace framework
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */