1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_framework.hxx" 26 27 #ifndef __FRAMEWORK_UIELEMENT_PROGRESSBARWRAPPER_HXX_ 28 #include <uielement/progressbarwrapper.hxx> 29 #endif 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 #include <helper/statusindicator.hxx> 35 #include <threadhelp/resetableguard.hxx> 36 #include <uielement/statusindicatorinterfacewrapper.hxx> 37 38 //_________________________________________________________________________________________________________________ 39 // interface includes 40 //_________________________________________________________________________________________________________________ 41 #include <com/sun/star/ui/UIElementType.hpp> 42 #include <com/sun/star/lang/DisposedException.hpp> 43 44 //_________________________________________________________________________________________________________________ 45 // includes of other projects 46 //_________________________________________________________________________________________________________________ 47 #include <vcl/svapp.hxx> 48 #include <toolkit/helper/vclunohelper.hxx> 49 50 //_________________________________________________________________________________________________________________ 51 // namespace 52 //_________________________________________________________________________________________________________________ 53 using namespace ::com::sun::star; 54 55 namespace framework{ 56 57 //_________________________________________________________________________________________________________________ 58 // non exported const 59 //_________________________________________________________________________________________________________________ 60 61 //_________________________________________________________________________________________________________________ 62 // non exported definitions 63 //_________________________________________________________________________________________________________________ 64 65 //_________________________________________________________________________________________________________________ 66 // declarations 67 //_________________________________________________________________________________________________________________ 68 69 ProgressBarWrapper::ProgressBarWrapper() : 70 UIElementWrapperBase( ::com::sun::star::ui::UIElementType::PROGRESSBAR ) 71 , m_bOwnsInstance( sal_False ) 72 , m_nRange( 100 ) 73 , m_nValue( 0 ) 74 { 75 } 76 77 ProgressBarWrapper::~ProgressBarWrapper() 78 { 79 } 80 81 // public interfaces 82 void ProgressBarWrapper::setStatusBar( const uno::Reference< awt::XWindow >& rStatusBar, sal_Bool bOwnsInstance ) 83 { 84 ResetableGuard aGuard( m_aLock ); 85 86 if ( m_bDisposed ) 87 return; 88 89 if ( m_bOwnsInstance ) 90 { 91 // dispose XWindow reference our our status bar 92 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY ); 93 try 94 { 95 if ( xComponent.is() ) 96 xComponent->dispose(); 97 } 98 catch ( uno::Exception& ) 99 { 100 } 101 m_xStatusBar.clear(); 102 } 103 104 m_bOwnsInstance = bOwnsInstance; 105 m_xStatusBar = rStatusBar; 106 } 107 108 uno::Reference< awt::XWindow > ProgressBarWrapper::getStatusBar() const 109 { 110 ResetableGuard aGuard( m_aLock ); 111 112 if ( m_bDisposed ) 113 return uno::Reference< awt::XWindow >(); 114 115 return m_xStatusBar; 116 } 117 118 // wrapped methods of ::com::sun::star::task::XStatusIndicator 119 void ProgressBarWrapper::start( const ::rtl::OUString& Text, ::sal_Int32 Range ) 120 throw (uno::RuntimeException) 121 { 122 uno::Reference< awt::XWindow > xWindow; 123 sal_Int32 nValue( 0 ); 124 125 { 126 ResetableGuard aGuard( m_aLock ); 127 128 if ( m_bDisposed ) 129 return; 130 131 xWindow = m_xStatusBar; 132 m_nValue = 0; 133 m_nRange = Range; 134 nValue = m_nValue; 135 } 136 137 if ( xWindow.is() ) 138 { 139 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 140 Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 141 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR ) 142 { 143 StatusBar* pStatusBar = (StatusBar *)pWindow; 144 if ( !pStatusBar->IsProgressMode() ) 145 pStatusBar->StartProgressMode( Text ); 146 else 147 { 148 pStatusBar->SetUpdateMode( sal_False ); 149 pStatusBar->EndProgressMode(); 150 pStatusBar->StartProgressMode( Text ); 151 pStatusBar->SetProgressValue( sal_uInt16( nValue )); 152 pStatusBar->SetUpdateMode( sal_True ); 153 } 154 pStatusBar->Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE ); 155 } 156 } 157 } 158 159 void ProgressBarWrapper::end() 160 throw (uno::RuntimeException) 161 { 162 uno::Reference< awt::XWindow > xWindow; 163 164 { 165 ResetableGuard aGuard( m_aLock ); 166 167 if ( m_bDisposed ) 168 return; 169 170 xWindow = m_xStatusBar; 171 m_nRange = 100; 172 m_nValue = 0; 173 } 174 175 if ( xWindow.is() ) 176 { 177 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 178 Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 179 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR ) 180 { 181 StatusBar* pStatusBar = (StatusBar *)pWindow; 182 if ( pStatusBar->IsProgressMode() ) 183 pStatusBar->EndProgressMode(); 184 } 185 } 186 } 187 188 void ProgressBarWrapper::setText( const ::rtl::OUString& Text ) 189 throw (uno::RuntimeException) 190 { 191 uno::Reference< awt::XWindow > xWindow; 192 sal_Int32 nValue( 0 ); 193 194 { 195 ResetableGuard aGuard( m_aLock ); 196 197 if ( m_bDisposed ) 198 return; 199 200 xWindow = m_xStatusBar; 201 m_aText = Text; 202 nValue = m_nValue; 203 } 204 205 if ( xWindow.is() ) 206 { 207 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 208 Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 209 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR ) 210 { 211 StatusBar* pStatusBar = (StatusBar *)pWindow; 212 if( pStatusBar->IsProgressMode() ) 213 { 214 pStatusBar->SetUpdateMode( sal_False ); 215 pStatusBar->EndProgressMode(); 216 pStatusBar->StartProgressMode( Text ); 217 pStatusBar->SetProgressValue( sal_uInt16( nValue )); 218 pStatusBar->SetUpdateMode( sal_True ); 219 } 220 else 221 pStatusBar->SetText( Text ); 222 } 223 } 224 } 225 226 void ProgressBarWrapper::setValue( ::sal_Int32 nValue ) 227 throw (uno::RuntimeException) 228 { 229 uno::Reference< awt::XWindow > xWindow; 230 rtl::OUString aText; 231 sal_Bool bSetValue( sal_False ); 232 233 { 234 ResetableGuard aGuard( m_aLock ); 235 236 if ( m_bDisposed ) 237 return; 238 239 xWindow = m_xStatusBar; 240 241 double fVal( 0 ); 242 if ( m_nRange > 0 ) 243 { 244 fVal = ( double( nValue ) / double( m_nRange )) * 100; 245 fVal = std::max( double( 0 ), std::min( fVal, double( 100 ))); 246 } 247 248 if ( m_nValue != sal_Int32( fVal )) 249 { 250 m_nValue = sal_Int32( fVal ); 251 bSetValue = sal_True; 252 } 253 254 nValue = m_nValue; 255 aText = m_aText; 256 } 257 258 if ( xWindow.is() && bSetValue ) 259 { 260 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 261 Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 262 if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR ) 263 { 264 StatusBar* pStatusBar = (StatusBar *)pWindow; 265 if ( !pStatusBar->IsProgressMode() ) 266 pStatusBar->StartProgressMode( aText ); 267 pStatusBar->SetProgressValue( sal_uInt16( nValue )); 268 } 269 } 270 } 271 272 void ProgressBarWrapper::reset() 273 throw (uno::RuntimeException) 274 { 275 setText( rtl::OUString() ); 276 setValue( 0 ); 277 } 278 279 // XInitialization 280 void SAL_CALL ProgressBarWrapper::initialize( const uno::Sequence< uno::Any >& ) 281 throw (uno::Exception, uno::RuntimeException) 282 { 283 // dummy - do nothing 284 } 285 286 // XUpdatable 287 void SAL_CALL ProgressBarWrapper::update() 288 throw (uno::RuntimeException) 289 { 290 // dummy - do nothing 291 } 292 293 // XComponent 294 void SAL_CALL ProgressBarWrapper::dispose() 295 throw (uno::RuntimeException) 296 { 297 uno::Reference< lang::XComponent > xThis( 298 static_cast< cppu::OWeakObject* >(this), 299 uno::UNO_QUERY ); 300 301 { 302 ResetableGuard aLock( m_aLock ); 303 304 if ( m_bDisposed ) 305 return; 306 } 307 308 { 309 lang::EventObject aEvent( xThis ); 310 m_aListenerContainer.disposeAndClear( aEvent ); 311 312 ResetableGuard aLock( m_aLock ); 313 if ( m_bOwnsInstance ) 314 { 315 try 316 { 317 uno::Reference< lang::XComponent > xComponent( m_xStatusBar, uno::UNO_QUERY ); 318 if ( xComponent.is() ) 319 xComponent->dispose(); 320 } 321 catch ( lang::DisposedException& ) 322 { 323 } 324 } 325 326 m_xStatusBar.clear(); 327 m_bDisposed = sal_True; 328 } 329 } 330 331 // XUIElement 332 uno::Reference< uno::XInterface > SAL_CALL ProgressBarWrapper::getRealInterface() 333 throw (uno::RuntimeException) 334 { 335 /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 336 // Ready for multithreading 337 ResetableGuard aLock( m_aLock ); 338 339 if ( m_bDisposed ) 340 return uno::Reference< uno::XInterface >(); 341 else 342 { 343 uno::Reference< uno::XInterface > xComp( m_xProgressBarIfacWrapper ); 344 if ( !xComp.is() ) 345 { 346 StatusIndicatorInterfaceWrapper* pWrapper = 347 new StatusIndicatorInterfaceWrapper( 348 uno::Reference< lang::XComponent >( 349 static_cast< cppu::OWeakObject* >( this ), 350 uno::UNO_QUERY )); 351 xComp = uno::Reference< uno::XInterface >( 352 static_cast< cppu::OWeakObject* >( pWrapper ), 353 uno::UNO_QUERY ); 354 m_xProgressBarIfacWrapper = xComp; 355 } 356 357 return xComp; 358 } 359 } 360 361 } // namespace framework 362