1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 29*cdf0e10cSrcweir // my own includes 30*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "statusindicator.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 35*cdf0e10cSrcweir // includes of other projects 36*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 37*cdf0e10cSrcweir #include <com/sun/star/awt/InvalidateStyle.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp> 39*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 40*cdf0e10cSrcweir #include <tools/debug.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 43*cdf0e10cSrcweir // includes of my project 44*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 45*cdf0e10cSrcweir #include "progressbar.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 48*cdf0e10cSrcweir // namespace 49*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir using namespace ::cppu ; 52*cdf0e10cSrcweir using namespace ::osl ; 53*cdf0e10cSrcweir using namespace ::rtl ; 54*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 55*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 56*cdf0e10cSrcweir using namespace ::com::sun::star::awt ; 57*cdf0e10cSrcweir using namespace ::com::sun::star::task ; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace unocontrols{ 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 62*cdf0e10cSrcweir // construct/destruct 63*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir StatusIndicator::StatusIndicator( const Reference< XMultiServiceFactory >& xFactory ) 66*cdf0e10cSrcweir : BaseContainerControl ( xFactory ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir // Its not allowed to work with member in this method (refcounter !!!) 69*cdf0e10cSrcweir // But with a HACK (++refcount) its "OK" :-( 70*cdf0e10cSrcweir ++m_refCount ; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir // Create instances for fixedtext and progress ... 73*cdf0e10cSrcweir m_xText = Reference< XFixedText > ( xFactory->createInstance( OUString::createFromAscii( FIXEDTEXT_SERVICENAME ) ), UNO_QUERY ); 74*cdf0e10cSrcweir m_xProgressBar = Reference< XProgressBar > ( xFactory->createInstance( OUString::createFromAscii( SERVICENAME_PROGRESSBAR ) ), UNO_QUERY ); 75*cdf0e10cSrcweir // ... cast controls to Reference< XControl > and set model ... 76*cdf0e10cSrcweir // ( ProgressBar has no model !!! ) 77*cdf0e10cSrcweir Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); 78*cdf0e10cSrcweir Reference< XControl > xProgressControl ( m_xProgressBar, UNO_QUERY ); 79*cdf0e10cSrcweir xTextControl->setModel( Reference< XControlModel >( xFactory->createInstance( OUString::createFromAscii( FIXEDTEXT_MODELNAME ) ), UNO_QUERY ) ); 80*cdf0e10cSrcweir // ... and add controls to basecontainercontrol! 81*cdf0e10cSrcweir addControl( OUString::createFromAscii( CONTROLNAME_TEXT ), xTextControl ); 82*cdf0e10cSrcweir addControl( OUString::createFromAscii( CONTROLNAME_PROGRESSBAR ), xProgressControl ); 83*cdf0e10cSrcweir // FixedText make it automaticly visible by himself ... but not the progressbar !!! 84*cdf0e10cSrcweir // it must be set explicitly 85*cdf0e10cSrcweir Reference< XWindow > xProgressWindow( m_xProgressBar, UNO_QUERY ); 86*cdf0e10cSrcweir xProgressWindow->setVisible( sal_True ); 87*cdf0e10cSrcweir // Reset to defaults !!! 88*cdf0e10cSrcweir // (progressbar take automaticly its own defaults) 89*cdf0e10cSrcweir m_xText->setText( OUString::createFromAscii( DEFAULT_TEXT ) ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir --m_refCount ; 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir StatusIndicator::~StatusIndicator() 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir // Release all references 97*cdf0e10cSrcweir m_xText = Reference< XFixedText >(); 98*cdf0e10cSrcweir m_xProgressBar = Reference< XProgressBar >(); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 102*cdf0e10cSrcweir // XInterface 103*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir Any SAL_CALL StatusIndicator::queryInterface( const Type& rType ) throw( RuntimeException ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir // Attention: 108*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 109*cdf0e10cSrcweir Any aReturn ; 110*cdf0e10cSrcweir Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator(); 111*cdf0e10cSrcweir if ( xDel.is() ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // If an delegator exist, forward question to his queryInterface. 114*cdf0e10cSrcweir // Delegator will ask his own queryAggregation! 115*cdf0e10cSrcweir aReturn = xDel->queryInterface( rType ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir else 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir // If an delegator unknown, forward question to own queryAggregation. 120*cdf0e10cSrcweir aReturn = queryAggregation( rType ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir return aReturn ; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 127*cdf0e10cSrcweir // XInterface 128*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir void SAL_CALL StatusIndicator::acquire() throw() 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir // Attention: 133*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // Forward to baseclass 136*cdf0e10cSrcweir BaseControl::acquire(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 140*cdf0e10cSrcweir // XInterface 141*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir void SAL_CALL StatusIndicator::release() throw() 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // Attention: 146*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // Forward to baseclass 149*cdf0e10cSrcweir BaseControl::release(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 153*cdf0e10cSrcweir // XTypeProvider 154*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir Sequence< Type > SAL_CALL StatusIndicator::getTypes() throw( RuntimeException ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir // Optimize this method ! 159*cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 160*cdf0e10cSrcweir // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! 161*cdf0e10cSrcweir static OTypeCollection* pTypeCollection = NULL ; 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir if ( pTypeCollection == NULL ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // Ready for multithreading; get global mutex for first call of this method only! see before 166*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // Control these pointer again ... it can be, that another instance will be faster then these! 169*cdf0e10cSrcweir if ( pTypeCollection == NULL ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir // Create a static typecollection ... 172*cdf0e10cSrcweir static OTypeCollection aTypeCollection ( ::getCppuType(( const Reference< XLayoutConstrains >*)NULL ) , 173*cdf0e10cSrcweir ::getCppuType(( const Reference< XStatusIndicator >*)NULL ) , 174*cdf0e10cSrcweir BaseContainerControl::getTypes() 175*cdf0e10cSrcweir ); 176*cdf0e10cSrcweir // ... and set his address to static pointer! 177*cdf0e10cSrcweir pTypeCollection = &aTypeCollection ; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir return pTypeCollection->getTypes(); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 185*cdf0e10cSrcweir // XAggregation 186*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir Any SAL_CALL StatusIndicator::queryAggregation( const Type& aType ) throw( RuntimeException ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir // Ask for my own supported interfaces ... 191*cdf0e10cSrcweir // Attention: XTypeProvider and XInterface are supported by OComponentHelper! 192*cdf0e10cSrcweir Any aReturn ( ::cppu::queryInterface( aType , 193*cdf0e10cSrcweir static_cast< XLayoutConstrains* > ( this ) , 194*cdf0e10cSrcweir static_cast< XStatusIndicator* > ( this ) 195*cdf0e10cSrcweir ) 196*cdf0e10cSrcweir ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // If searched interface not supported by this class ... 199*cdf0e10cSrcweir if ( aReturn.hasValue() == sal_False ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir // ... ask baseclasses. 202*cdf0e10cSrcweir aReturn = BaseControl::queryAggregation( aType ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir return aReturn ; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 209*cdf0e10cSrcweir // XStatusIndicator 210*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir void SAL_CALL StatusIndicator::start( const OUString& sText, sal_Int32 nRange ) throw( RuntimeException ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir // Ready for multithreading 215*cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // Initialize status controls with given values. 218*cdf0e10cSrcweir m_xText->setText( sText ); 219*cdf0e10cSrcweir m_xProgressBar->setRange( 0, nRange ); 220*cdf0e10cSrcweir // force repaint ... fixedtext has changed ! 221*cdf0e10cSrcweir impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,impl_getWidth(),impl_getHeight(),0,0,0,0) ) ; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 225*cdf0e10cSrcweir // XStatusIndicator 226*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void SAL_CALL StatusIndicator::end() throw( RuntimeException ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir // Ready for multithreading 231*cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir // Clear values of status controls. 234*cdf0e10cSrcweir m_xText->setText( OUString() ); 235*cdf0e10cSrcweir m_xProgressBar->setValue( 0 ); 236*cdf0e10cSrcweir setVisible( sal_False ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 240*cdf0e10cSrcweir // XStatusIndicator 241*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir void SAL_CALL StatusIndicator::setText( const OUString& sText ) throw( RuntimeException ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir // Ready for multithreading 246*cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // Take text on right control 249*cdf0e10cSrcweir m_xText->setText( sText ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 253*cdf0e10cSrcweir // XStatusIndicator 254*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir void SAL_CALL StatusIndicator::setValue( sal_Int32 nValue ) throw( RuntimeException ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir // Ready for multithreading 259*cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // Take value on right control 262*cdf0e10cSrcweir m_xProgressBar->setValue( nValue ); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 266*cdf0e10cSrcweir // XStatusIndicator 267*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir void SAL_CALL StatusIndicator::reset() throw( RuntimeException ) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir // Ready for multithreading 272*cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir // Clear values of status controls. 275*cdf0e10cSrcweir // (Don't hide the window! User will reset current values ... but he will not finish using of indicator!) 276*cdf0e10cSrcweir m_xText->setText( OUString() ); 277*cdf0e10cSrcweir m_xProgressBar->setValue( 0 ); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 281*cdf0e10cSrcweir // XLayoutConstrains 282*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir Size SAL_CALL StatusIndicator::getMinimumSize () throw( RuntimeException ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir return Size (DEFAULT_WIDTH, DEFAULT_HEIGHT) ; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 290*cdf0e10cSrcweir // XLayoutConstrains 291*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir Size SAL_CALL StatusIndicator::getPreferredSize () throw( RuntimeException ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir // Ready for multithreading 296*cdf0e10cSrcweir ClearableMutexGuard aGuard ( m_aMutex ) ; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // get information about required place of child controls 299*cdf0e10cSrcweir Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); 300*cdf0e10cSrcweir Size aTextSize = xTextLayout->getPreferredSize(); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir aGuard.clear () ; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir // calc preferred size of status indicator 305*cdf0e10cSrcweir sal_Int32 nWidth = impl_getWidth() ; 306*cdf0e10cSrcweir sal_Int32 nHeight = (2*FREEBORDER)+aTextSize.Height ; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir // norm to minimum 309*cdf0e10cSrcweir if ( nWidth<DEFAULT_WIDTH ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir nWidth = DEFAULT_WIDTH ; 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir if ( nHeight<DEFAULT_HEIGHT ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir nHeight = DEFAULT_HEIGHT ; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // return to caller 319*cdf0e10cSrcweir return Size ( nWidth, nHeight ) ; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 323*cdf0e10cSrcweir // XLayoutConstrains 324*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir Size SAL_CALL StatusIndicator::calcAdjustedSize ( const Size& /*rNewSize*/ ) throw( RuntimeException ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir return getPreferredSize () ; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 332*cdf0e10cSrcweir // XControl 333*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir void SAL_CALL StatusIndicator::createPeer ( const Reference< XToolkit > & rToolkit, const Reference< XWindowPeer > & rParent ) throw( RuntimeException ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir if( getPeer().is() == sal_False ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir BaseContainerControl::createPeer( rToolkit, rParent ); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir // If user forget to call "setPosSize()", we have still a correct size. 342*cdf0e10cSrcweir // And a "MinimumSize" IS A "MinimumSize"! 343*cdf0e10cSrcweir // We change not the position of control at this point. 344*cdf0e10cSrcweir Size aDefaultSize = getMinimumSize () ; 345*cdf0e10cSrcweir setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE ) ; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 350*cdf0e10cSrcweir // XControl 351*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir sal_Bool SAL_CALL StatusIndicator::setModel ( const Reference< XControlModel > & /*rModel*/ ) throw( RuntimeException ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir // We have no model. 356*cdf0e10cSrcweir return sal_False ; 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 360*cdf0e10cSrcweir // XControl 361*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir Reference< XControlModel > SAL_CALL StatusIndicator::getModel () throw( RuntimeException ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir // We have no model. 366*cdf0e10cSrcweir // return (XControlModel*)this ; 367*cdf0e10cSrcweir return Reference< XControlModel > () ; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 371*cdf0e10cSrcweir // XComponent 372*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir void SAL_CALL StatusIndicator::dispose () throw( RuntimeException ) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir // Ready for multithreading 377*cdf0e10cSrcweir MutexGuard aGuard ( m_aMutex ) ; 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir // "removeControl()" control the state of a reference 380*cdf0e10cSrcweir Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); 381*cdf0e10cSrcweir Reference< XControl > xProgressControl ( m_xProgressBar, UNO_QUERY ); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir removeControl( xTextControl ); 384*cdf0e10cSrcweir removeControl( xProgressControl ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir // do'nt use "...->clear ()" or "... = XFixedText ()" 387*cdf0e10cSrcweir // when other hold a reference at this object !!! 388*cdf0e10cSrcweir xTextControl->dispose(); 389*cdf0e10cSrcweir xProgressControl->dispose(); 390*cdf0e10cSrcweir BaseContainerControl::dispose(); 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 394*cdf0e10cSrcweir // XWindow 395*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir void SAL_CALL StatusIndicator::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) throw( RuntimeException ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir Rectangle aBasePosSize = getPosSize () ; 400*cdf0e10cSrcweir BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags) ; 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // if position or size changed 403*cdf0e10cSrcweir if ( 404*cdf0e10cSrcweir ( nWidth != aBasePosSize.Width ) || 405*cdf0e10cSrcweir ( nHeight != aBasePosSize.Height) 406*cdf0e10cSrcweir ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir // calc new layout for controls 409*cdf0e10cSrcweir impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,nWidth,nHeight,0,0,0,0) ) ; 410*cdf0e10cSrcweir // clear background (!) 411*cdf0e10cSrcweir // [Childs was repainted in "recalcLayout" by setPosSize() automaticly!] 412*cdf0e10cSrcweir getPeer()->invalidate(2); 413*cdf0e10cSrcweir // and repaint the control 414*cdf0e10cSrcweir impl_paint ( 0, 0, impl_getGraphicsPeer() ) ; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 419*cdf0e10cSrcweir // impl but public method to register service 420*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir const Sequence< OUString > StatusIndicator::impl_getStaticSupportedServiceNames() 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 425*cdf0e10cSrcweir Sequence< OUString > seqServiceNames( 1 ); 426*cdf0e10cSrcweir seqServiceNames.getArray() [0] = OUString::createFromAscii( SERVICENAME_STATUSINDICATOR ); 427*cdf0e10cSrcweir return seqServiceNames ; 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 431*cdf0e10cSrcweir // impl but public method to register service 432*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir const OUString StatusIndicator::impl_getStaticImplementationName() 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir return OUString::createFromAscii( IMPLEMENTATIONNAME_STATUSINDICATOR ); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 440*cdf0e10cSrcweir // protected method 441*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir WindowDescriptor* StatusIndicator::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!! 446*cdf0e10cSrcweir // - if you will change the descriptor-values, you must override this virtuell function 447*cdf0e10cSrcweir // - the caller must release the memory for this dynamical descriptor !!! 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir WindowDescriptor* pDescriptor = new WindowDescriptor ; 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir pDescriptor->Type = WindowClass_SIMPLE ; 452*cdf0e10cSrcweir pDescriptor->WindowServiceName = OUString::createFromAscii( "floatingwindow" ) ; 453*cdf0e10cSrcweir pDescriptor->ParentIndex = -1 ; 454*cdf0e10cSrcweir pDescriptor->Parent = xParentPeer ; 455*cdf0e10cSrcweir pDescriptor->Bounds = getPosSize () ; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir return pDescriptor ; 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 461*cdf0e10cSrcweir // protected method 462*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir void StatusIndicator::impl_paint ( sal_Int32 nX, sal_Int32 nY, const Reference< XGraphics > & rGraphics ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir // This paint method ist not buffered !! 467*cdf0e10cSrcweir // Every request paint the completely control. ( but only, if peer exist ) 468*cdf0e10cSrcweir if ( rGraphics.is () ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir MutexGuard aGuard (m_aMutex) ; 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir // background = gray 473*cdf0e10cSrcweir Reference< XWindowPeer > xPeer( impl_getPeerWindow(), UNO_QUERY ); 474*cdf0e10cSrcweir if( xPeer.is() == sal_True ) 475*cdf0e10cSrcweir xPeer->setBackground( BACKGROUNDCOLOR ); 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir // FixedText background = gray 478*cdf0e10cSrcweir Reference< XControl > xTextControl( m_xText, UNO_QUERY ); 479*cdf0e10cSrcweir xPeer = xTextControl->getPeer(); 480*cdf0e10cSrcweir if( xPeer.is() == sal_True ) 481*cdf0e10cSrcweir xPeer->setBackground( BACKGROUNDCOLOR ); 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir // Progress background = gray 484*cdf0e10cSrcweir xPeer = Reference< XWindowPeer >( m_xProgressBar, UNO_QUERY ); 485*cdf0e10cSrcweir if( xPeer.is() == sal_True ) 486*cdf0e10cSrcweir xPeer->setBackground( BACKGROUNDCOLOR ); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir // paint shadow border 489*cdf0e10cSrcweir rGraphics->setLineColor ( LINECOLOR_BRIGHT ); 490*cdf0e10cSrcweir rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); 491*cdf0e10cSrcweir rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir rGraphics->setLineColor ( LINECOLOR_SHADOW ); 494*cdf0e10cSrcweir rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); 495*cdf0e10cSrcweir rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 500*cdf0e10cSrcweir // protected method 501*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir void StatusIndicator::impl_recalcLayout ( const WindowEvent& aEvent ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir sal_Int32 nX_ProgressBar ; 506*cdf0e10cSrcweir sal_Int32 nY_ProgressBar ; 507*cdf0e10cSrcweir sal_Int32 nWidth_ProgressBar ; 508*cdf0e10cSrcweir sal_Int32 nHeight_ProgressBar ; 509*cdf0e10cSrcweir sal_Int32 nX_Text ; 510*cdf0e10cSrcweir sal_Int32 nY_Text ; 511*cdf0e10cSrcweir sal_Int32 nWidth_Text ; 512*cdf0e10cSrcweir sal_Int32 nHeight_Text ; 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // Ready for multithreading 515*cdf0e10cSrcweir MutexGuard aGuard ( m_aMutex ) ; 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir // get information about required place of child controls 518*cdf0e10cSrcweir Size aWindowSize ( aEvent.Width, aEvent.Height ); 519*cdf0e10cSrcweir Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); 520*cdf0e10cSrcweir Size aTextSize = xTextLayout->getPreferredSize(); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir if( aWindowSize.Width < DEFAULT_WIDTH ) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir aWindowSize.Width = DEFAULT_WIDTH; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir if( aWindowSize.Height < DEFAULT_HEIGHT ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir aWindowSize.Height = DEFAULT_HEIGHT; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // calc position and size of child controls 532*cdf0e10cSrcweir nX_Text = FREEBORDER ; 533*cdf0e10cSrcweir nY_Text = FREEBORDER ; 534*cdf0e10cSrcweir nWidth_Text = aTextSize.Width ; 535*cdf0e10cSrcweir nHeight_Text = aTextSize.Height ; 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir nX_ProgressBar = nX_Text+nWidth_Text+FREEBORDER ; 538*cdf0e10cSrcweir nY_ProgressBar = nY_Text ; 539*cdf0e10cSrcweir nWidth_ProgressBar = aWindowSize.Width-nWidth_Text-(3*FREEBORDER) ; 540*cdf0e10cSrcweir nHeight_ProgressBar = nHeight_Text ; 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // Set new position and size on all controls 543*cdf0e10cSrcweir Reference< XWindow > xTextWindow ( m_xText , UNO_QUERY ); 544*cdf0e10cSrcweir Reference< XWindow > xProgressWindow ( m_xProgressBar, UNO_QUERY ); 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir xTextWindow->setPosSize ( nX_Text , nY_Text , nWidth_Text , nHeight_Text , 15 ) ; 547*cdf0e10cSrcweir xProgressWindow->setPosSize ( nX_ProgressBar, nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar , 15 ) ; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 551*cdf0e10cSrcweir // debug methods 552*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir #endif // #if OSL_DEBUG_LEVEL > 1 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir } // namespace unocontrols 559