fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / progressbarwrapper.cxx
blobb441d83ed6b77f8fa1e4c7903708580556c454f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
34 namespace framework{
36 ProgressBarWrapper::ProgressBarWrapper() :
37 UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR )
38 , m_bOwnsInstance( false )
39 , m_nRange( 100 )
40 , m_nValue( 0 )
44 ProgressBarWrapper::~ProgressBarWrapper()
48 // public interfaces
49 void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, bool bOwnsInstance )
51 SolarMutexGuard g;
53 if ( m_bDisposed )
54 return;
56 if ( m_bOwnsInstance )
58 // dispose XWindow reference our our status bar
59 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY );
60 try
62 if ( xComponent.is() )
63 xComponent->dispose();
65 catch ( const uno::Exception& )
68 m_xStatusBar.clear();
71 m_bOwnsInstance = bOwnsInstance;
72 m_xStatusBar = rStatusBar;
75 uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const
77 SolarMutexGuard g;
79 if ( m_bDisposed )
80 return uno::Reference< awt::XWindow >();
82 return m_xStatusBar;
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 );
93 SolarMutexGuard g;
95 if ( m_bDisposed )
96 return;
98 xWindow = m_xStatusBar;
99 m_nValue = 0;
100 m_nRange = Range;
101 nValue = m_nValue;
104 if ( xWindow.is() )
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 );
113 else
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;
132 SolarMutexGuard g;
134 if ( m_bDisposed )
135 return;
137 xWindow = m_xStatusBar;
138 m_nRange = 100;
139 m_nValue = 0;
142 if ( xWindow.is() )
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 );
162 SolarMutexGuard g;
164 if ( m_bDisposed )
165 return;
167 xWindow = m_xStatusBar;
168 m_aText = Text;
169 nValue = m_nValue;
172 if ( xWindow.is() )
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 );
187 else
188 pStatusBar->SetText( Text );
193 void ProgressBarWrapper::setValue( ::sal_Int32 nValue )
194 throw (uno::RuntimeException, std::exception)
196 uno::Reference< awt::XWindow > xWindow;
197 OUString aText;
198 bool bSetValue( false );
201 SolarMutexGuard g;
203 if ( m_bDisposed )
204 return;
206 xWindow = m_xStatusBar;
208 double fVal( 0 );
209 if ( m_nRange > 0 )
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 );
218 bSetValue = true;
221 nValue = m_nValue;
222 aText = m_aText;
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() );
243 setValue( 0 );
246 // XInitialization
247 void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& )
248 throw (uno::Exception, uno::RuntimeException, std::exception)
250 // dummy - do nothing
253 // XUpdatable
254 void SAL_CALL ProgressBarWrapper::update()
255 throw (uno::RuntimeException, std::exception)
257 // dummy - do nothing
260 // XComponent
261 void SAL_CALL ProgressBarWrapper::dispose()
262 throw (uno::RuntimeException, std::exception)
264 uno::Reference< lang::XComponent > xThis(
265 static_cast< cppu::OWeakObject* >(this),
266 uno::UNO_QUERY );
269 SolarMutexGuard g;
271 if ( m_bDisposed )
272 return;
276 lang::EventObject aEvent( xThis );
277 m_aListenerContainer.disposeAndClear( aEvent );
279 SolarMutexGuard g;
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();
294 m_bDisposed = true;
298 // XUIElement
299 uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface()
300 throw (uno::RuntimeException, std::exception)
302 SolarMutexGuard g;
304 if ( m_bDisposed )
305 return uno::Reference< uno::XInterface >();
306 else
308 uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper );
309 if ( !xComp.is() )
311 StatusIndicatorInterfaceWrapper* pWrapper =
312 new StatusIndicatorInterfaceWrapper(
313 uno::Reference< lang::XComponent >(
314 static_cast< cppu::OWeakObject* >( this ),
315 uno::UNO_QUERY ));
316 xComp = uno::Reference< uno::XInterface >(
317 static_cast< cppu::OWeakObject* >( pWrapper ),
318 uno::UNO_QUERY );
319 m_xProgressBarIfacWrapper = xComp;
322 return xComp;
326 } // namespace framework
328 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */