From 874cb08467709b5e37163193f9b8073398432400 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 6 Oct 2010 14:21:47 +0200 Subject: dba34b: #i112779# new 'animated images' UNO control, superseding the (X)SimpleAnimation and Throbber controls --- toolkit/source/awt/xsimpleanimation.cxx | 41 +++++++-------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) (limited to 'toolkit/source/awt/xsimpleanimation.cxx') diff --git a/toolkit/source/awt/xsimpleanimation.cxx b/toolkit/source/awt/xsimpleanimation.cxx index c7ccbde118f4..63de993e0e43 100644 --- a/toolkit/source/awt/xsimpleanimation.cxx +++ b/toolkit/source/awt/xsimpleanimation.cxx @@ -46,35 +46,28 @@ namespace toolkit //-------------------------------------------------------------------- XSimpleAnimation::XSimpleAnimation() + :mpThrobber( new Throbber_Impl( *this ) ) { DBG_CTOR( XSimpleAnimation, NULL ); - mbRepeat = sal_True; - mnStepTime = 100; - mpThrobber = new Throbber_Impl( this, mnStepTime, mbRepeat ); } //-------------------------------------------------------------------- XSimpleAnimation::~XSimpleAnimation() { DBG_DTOR( XSimpleAnimation, NULL ); - delete mpThrobber; } - //-------------------------------------------------------------------- - IMPLEMENT_FORWARD_XINTERFACE2( XSimpleAnimation, VCLXWindow, XSimpleAnimation_Base ) - - //-------------------------------------------------------------------- - IMPLEMENT_FORWARD_XTYPEPROVIDER2( XSimpleAnimation, VCLXWindow, XSimpleAnimation_Base ) - //-------------------------------------------------------------------- void SAL_CALL XSimpleAnimation::start() throw ( uno::RuntimeException ) { + ::vos::OGuard aGuard( GetMutex() ); mpThrobber->start(); } //-------------------------------------------------------------------- void SAL_CALL XSimpleAnimation::stop() throw ( uno::RuntimeException ) { + ::vos::OGuard aGuard( GetMutex() ); mpThrobber->stop(); } @@ -82,22 +75,10 @@ namespace toolkit void SAL_CALL XSimpleAnimation::setImageList( const uno::Sequence< uno::Reference< graphic::XGraphic > >& rImageList ) throw ( uno::RuntimeException ) { + ::vos::OGuard aGuard( GetMutex() ); mpThrobber->setImageList( rImageList ); } - //-------------------------------------------------------------------- - void XSimpleAnimation::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) - { - // TODO: XSimpleAnimation::ProcessWindowEvent - //::vos::OClearableGuard aGuard( GetMutex() ); - //Reference< XSimpleAnimation > xKeepAlive( this ); - //SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() ); - //if ( !pSpinButton ) - // return; - - VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); - } - //-------------------------------------------------------------------- void SAL_CALL XSimpleAnimation::setProperty( const ::rtl::OUString& PropertyName, const uno::Any& Value ) throw( uno::RuntimeException ) @@ -112,20 +93,14 @@ namespace toolkit case BASEPROPERTY_STEP_TIME: { sal_Int32 nStepTime( 0 ); if ( Value >>= nStepTime ) - { - mnStepTime = nStepTime; - mpThrobber->setStepTime( mnStepTime ); - } + mpThrobber->setStepTime( nStepTime ); break; } case BASEPROPERTY_REPEAT: { sal_Bool bRepeat( sal_True ); if ( Value >>= bRepeat ) - { - mbRepeat = bRepeat; - mpThrobber->setRepeat( mbRepeat ); - } + mpThrobber->setRepeat( bRepeat ); break; } default: @@ -148,10 +123,10 @@ namespace toolkit switch ( nPropertyId ) { case BASEPROPERTY_STEP_TIME: - aReturn <<= mnStepTime; + aReturn <<= mpThrobber->getStepTime(); break; case BASEPROPERTY_REPEAT: - aReturn <<= mbRepeat; + aReturn <<= mpThrobber->getRepeat(); break; default: aReturn = VCLXWindow::getProperty( PropertyName ); -- cgit v1.2.3 From 381af19adb8a081296f4322f8fd880dfba33a1fe Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 7 Oct 2010 13:22:07 +0200 Subject: dba34b: outsourced the Throbber_Impl from toolkit to VCL, promoted to a 'real' control --- toolkit/inc/toolkit/awt/xsimpleanimation.hxx | 4 - toolkit/inc/toolkit/awt/xthrobber.hxx | 5 +- toolkit/inc/toolkit/helper/throbberimpl.hxx | 89 --------- toolkit/source/awt/animatedimagespeer.cxx | 49 +++-- toolkit/source/awt/vclxtoolkit.cxx | 14 +- toolkit/source/awt/xsimpleanimation.cxx | 85 ++++---- toolkit/source/awt/xthrobber.cxx | 28 ++- toolkit/source/helper/makefile.mk | 1 - toolkit/source/helper/throbberimpl.cxx | 149 -------------- vcl/inc/vcl/imgctrl.hxx | 1 + vcl/inc/vcl/throbber.hxx | 103 ++++++++++ vcl/prj/d.lst | 1 + vcl/source/control/imgctrl.cxx | 15 +- vcl/source/control/makefile.mk | 22 +-- vcl/source/control/throbber.cxx | 283 +++++++++++++++++++++++++++ 15 files changed, 523 insertions(+), 326 deletions(-) delete mode 100644 toolkit/inc/toolkit/helper/throbberimpl.hxx delete mode 100644 toolkit/source/helper/throbberimpl.cxx create mode 100644 vcl/inc/vcl/throbber.hxx create mode 100644 vcl/source/control/throbber.cxx (limited to 'toolkit/source/awt/xsimpleanimation.cxx') diff --git a/toolkit/inc/toolkit/awt/xsimpleanimation.hxx b/toolkit/inc/toolkit/awt/xsimpleanimation.hxx index 673c7eaddf61..9e6043b7d9ef 100644 --- a/toolkit/inc/toolkit/awt/xsimpleanimation.hxx +++ b/toolkit/inc/toolkit/awt/xsimpleanimation.hxx @@ -38,7 +38,6 @@ //........................................................................ namespace toolkit { - class Throbber_Impl; //........................................................................ //==================================================================== @@ -50,9 +49,6 @@ namespace toolkit class XSimpleAnimation : public XSimpleAnimation_Base { - private: - ::boost::scoped_ptr< Throbber_Impl > mpThrobber; - public: XSimpleAnimation(); diff --git a/toolkit/inc/toolkit/awt/xthrobber.hxx b/toolkit/inc/toolkit/awt/xthrobber.hxx index fa0df0047180..67015e049a48 100644 --- a/toolkit/inc/toolkit/awt/xthrobber.hxx +++ b/toolkit/inc/toolkit/awt/xthrobber.hxx @@ -40,7 +40,6 @@ namespace toolkit { //........................................................................ - class Throbber_Impl; //==================================================================== //= XThrobber @@ -53,7 +52,6 @@ namespace toolkit ,public ::boost::noncopyable { private: - Throbber_Impl *mpThrobber; void SAL_CALL InitImageList() throw(::com::sun::star::uno::RuntimeException); public: @@ -66,6 +64,9 @@ namespace toolkit virtual void SAL_CALL start() throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL stop() throw (::com::sun::star::uno::RuntimeException); + // VCLXWindow + virtual void SetWindow( Window* pWindow ); + private: XThrobber( const XThrobber& ); // never implemented XThrobber& operator=( const XThrobber& ); // never implemented diff --git a/toolkit/inc/toolkit/helper/throbberimpl.hxx b/toolkit/inc/toolkit/helper/throbberimpl.hxx deleted file mode 100644 index 92fb177fd89d..000000000000 --- a/toolkit/inc/toolkit/helper/throbberimpl.hxx +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _TOOLKIT_HELPER_THROBBERIMPL_HXX_ -#define _TOOLKIT_HELPER_THROBBERIMPL_HXX_ - -#include -#include - -#include -#include -#include - -//........................................................................ -namespace toolkit -//........................................................................ -{ - - class Throbber_Impl - { - private: - vos::IMutex& mrMutex; // Reference to SolarMutex - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > > maImageList; - VCLXWindow& mrParent; - - sal_Bool mbRepeat; - sal_Int32 mnStepTime; - sal_Int32 mnCurStep; - sal_Int32 mnStepCount; - AutoTimer maWaitTimer; - - DECL_LINK( TimeOutHdl, Throbber_Impl* ); - - vos::IMutex& GetMutex() { return mrMutex; } - - public: - Throbber_Impl( VCLXWindow& i_rParent ); - ~Throbber_Impl(); - - // Properties - void setStepTime( sal_Int32 nStepTime ) { mnStepTime = nStepTime; } - sal_Int32 getStepTime() const { return mnStepTime; } - - void setRepeat( sal_Bool bRepeat ) { mbRepeat = bRepeat; } - sal_Bool getRepeat() const { return mbRepeat; } - - Window const* getWindow() const { return mrParent.GetWindow(); } - Window* getWindow() { return mrParent.GetWindow(); } - - // XSimpleAnimation - void start(); - void stop(); - bool isRunning() const; - void setImageList( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > >& ImageList ); - - // Helpers - sal_Bool isHCMode(); - }; - -//........................................................................ -} // namespacetoolkit -//........................................................................ - -#endif //_TOOLKIT_HELPER_THROBBERIMPL_HXX_ - diff --git a/toolkit/source/awt/animatedimagespeer.cxx b/toolkit/source/awt/animatedimagespeer.cxx index 6acf946930be..4130b841f34a 100755 --- a/toolkit/source/awt/animatedimagespeer.cxx +++ b/toolkit/source/awt/animatedimagespeer.cxx @@ -28,7 +28,6 @@ #include "toolkit/awt/animatedimagespeer.hxx" #include "toolkit/helper/property.hxx" -#include "toolkit/helper/throbberimpl.hxx" /** === begin UNO includes === **/ #include @@ -43,7 +42,7 @@ #include #include #include -#include +#include #include @@ -80,11 +79,11 @@ namespace toolkit //================================================================================================================== struct AnimatedImagesPeer_Data { - Throbber_Impl aThrobber; + AnimatedImagesPeer& rAntiImpl; ::std::vector< Sequence< ::rtl::OUString > > aCachedImageSets; - AnimatedImagesPeer_Data( VCLXWindow& i_window ) - :aThrobber( i_window ) + AnimatedImagesPeer_Data( AnimatedImagesPeer& i_antiImpl ) + :rAntiImpl( i_antiImpl ) ,aCachedImageSets() { } @@ -124,8 +123,8 @@ namespace toolkit //-------------------------------------------------------------------------------------------------------------- void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data ) { - const Window* pWindow = i_data.aThrobber.getWindow(); - if ( pWindow == NULL ) + Throbber* pThrobber = dynamic_cast< Throbber* >( i_data.rAntiImpl.GetWindow() ); + if ( pThrobber == NULL ) return; try @@ -146,7 +145,7 @@ namespace toolkit } // find the set with the smallest difference between window size and image size - const ::Size aWindowSizePixel = pWindow->GetSizePixel(); + const ::Size aWindowSizePixel = pThrobber->GetSizePixel(); sal_Int32 nPreferredSet = -1; long nMinimalDistance = ::std::numeric_limits< long >::max(); for ( ::std::vector< Size >::const_iterator check = aImageSizes.begin(); @@ -180,7 +179,7 @@ namespace toolkit aImages[ imageIndex ] = lcl_getGraphic_throw( xGraphicProvider, *pImageURL ); } } - i_data.aThrobber.setImageList( aImages ); + pThrobber->setImageList( aImages ); } catch( const Exception& ) { @@ -226,21 +225,28 @@ namespace toolkit void SAL_CALL AnimatedImagesPeer::startAnimation( ) throw (RuntimeException) { ::vos::OGuard aGuard( GetMutex() ); - m_pData->aThrobber.start(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->start(); } //------------------------------------------------------------------------------------------------------------------ void SAL_CALL AnimatedImagesPeer::stopAnimation( ) throw (RuntimeException) { ::vos::OGuard aGuard( GetMutex() ); - m_pData->aThrobber.stop(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->stop(); } //------------------------------------------------------------------------------------------------------------------ ::sal_Bool SAL_CALL AnimatedImagesPeer::isAnimationRunning( ) throw (RuntimeException) { ::vos::OGuard aGuard( GetMutex() ); - return m_pData->aThrobber.isRunning(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + return pThrobber->isRunning(); + return sal_False; } //------------------------------------------------------------------------------------------------------------------ @@ -248,6 +254,13 @@ namespace toolkit { ::vos::OGuard aGuard( GetMutex() ); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber == NULL ) + { + VCLXWindow::setProperty( i_propertyName, i_value ); + return; + } + const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName ); switch ( nPropertyId ) { @@ -255,14 +268,14 @@ namespace toolkit { sal_Int32 nStepTime( 0 ); if ( i_value >>= nStepTime ) - m_pData->aThrobber.setStepTime( nStepTime ); + pThrobber->setStepTime( nStepTime ); break; } case BASEPROPERTY_AUTO_REPEAT: { sal_Bool bRepeat( sal_True ); if ( i_value >>= bRepeat ) - m_pData->aThrobber.setRepeat( bRepeat ); + pThrobber->setRepeat( bRepeat ); break; } @@ -290,15 +303,19 @@ namespace toolkit Any aReturn; + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber == NULL ) + return VCLXWindow::getProperty( i_propertyName ); + const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName ); switch ( nPropertyId ) { case BASEPROPERTY_STEP_TIME: - aReturn <<= m_pData->aThrobber.getStepTime(); + aReturn <<= pThrobber->getStepTime(); break; case BASEPROPERTY_AUTO_REPEAT: - aReturn <<= m_pData->aThrobber.getRepeat(); + aReturn <<= pThrobber->getRepeat(); break; case BASEPROPERTY_IMAGE_SCALE_MODE: diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 5d4dbe77116c..a609a7df3268 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -33,6 +33,7 @@ #include #endif #include +#include #include #include #include @@ -116,6 +117,7 @@ #include #include #include +#include #include "toolkit/awt/vclxspinbutton.hxx" #include @@ -986,19 +988,23 @@ Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, } break; case WINDOW_CONTROL: - if ( aServiceName.EqualsAscii( "simpleanimation" ) ) + if ( aServiceName.EqualsAscii( "simpleanimation" ) ) { - pNewWindow = new FixedImage( pParent, nWinBits | WB_SCALE ); + pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE ); + ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic ); + // (compatibility) *ppNewComp = new ::toolkit::XSimpleAnimation; } else if ( aServiceName.EqualsAscii( "throbber" ) ) { - pNewWindow = new FixedImage( pParent, nWinBits | WB_SCALE ); + pNewWindow = new Throbber( pParent, nWinBits, Throbber::IMAGES_NONE ); + ((Throbber*)pNewWindow)->SetScaleMode( css::awt::ImageScaleMode::Anisotropic ); + // (compatibility) *ppNewComp = new ::toolkit::XThrobber; } else if ( aServiceName.EqualsAscii( "animatedimages" ) ) { - pNewWindow = new ImageControl( pParent, nWinBits ); + pNewWindow = new Throbber( pParent, nWinBits ); *ppNewComp = new ::toolkit::AnimatedImagesPeer; } break; diff --git a/toolkit/source/awt/xsimpleanimation.cxx b/toolkit/source/awt/xsimpleanimation.cxx index 63de993e0e43..75701cb94b46 100644 --- a/toolkit/source/awt/xsimpleanimation.cxx +++ b/toolkit/source/awt/xsimpleanimation.cxx @@ -29,8 +29,8 @@ #include "precompiled_toolkit.hxx" #include "toolkit/awt/xsimpleanimation.hxx" #include "toolkit/helper/property.hxx" -#include "toolkit/helper/throbberimpl.hxx" #include +#include //........................................................................ namespace toolkit @@ -46,7 +46,6 @@ namespace toolkit //-------------------------------------------------------------------- XSimpleAnimation::XSimpleAnimation() - :mpThrobber( new Throbber_Impl( *this ) ) { DBG_CTOR( XSimpleAnimation, NULL ); } @@ -61,14 +60,18 @@ namespace toolkit void SAL_CALL XSimpleAnimation::start() throw ( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); - mpThrobber->start(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->start(); } //-------------------------------------------------------------------- void SAL_CALL XSimpleAnimation::stop() throw ( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); - mpThrobber->stop(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->stop(); } //-------------------------------------------------------------------- @@ -76,7 +79,9 @@ namespace toolkit throw ( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); - mpThrobber->setImageList( rImageList ); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->setImageList( rImageList ); } //-------------------------------------------------------------------- @@ -85,27 +90,31 @@ namespace toolkit { ::vos::OGuard aGuard( GetMutex() ); - if ( GetWindow() ) + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber == NULL ) { - sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); - switch ( nPropertyId ) - { - case BASEPROPERTY_STEP_TIME: { - sal_Int32 nStepTime( 0 ); - if ( Value >>= nStepTime ) - mpThrobber->setStepTime( nStepTime ); - - break; - } - case BASEPROPERTY_REPEAT: { - sal_Bool bRepeat( sal_True ); - if ( Value >>= bRepeat ) - mpThrobber->setRepeat( bRepeat ); - break; - } - default: - VCLXWindow::setProperty( PropertyName, Value ); + VCLXWindow::setProperty( PropertyName, Value ); + return; + } + + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_STEP_TIME: { + sal_Int32 nStepTime( 0 ); + if ( Value >>= nStepTime ) + pThrobber->setStepTime( nStepTime ); + + break; + } + case BASEPROPERTY_REPEAT: { + sal_Bool bRepeat( sal_True ); + if ( Value >>= bRepeat ) + pThrobber->setRepeat( bRepeat ); + break; } + default: + VCLXWindow::setProperty( PropertyName, Value ); } } @@ -115,22 +124,22 @@ namespace toolkit { ::vos::OGuard aGuard( GetMutex() ); - uno::Any aReturn; + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber == NULL ) + return VCLXWindow::getProperty( PropertyName ); - if ( GetWindow() ) + uno::Any aReturn; + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) { - sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); - switch ( nPropertyId ) - { - case BASEPROPERTY_STEP_TIME: - aReturn <<= mpThrobber->getStepTime(); - break; - case BASEPROPERTY_REPEAT: - aReturn <<= mpThrobber->getRepeat(); - break; - default: - aReturn = VCLXWindow::getProperty( PropertyName ); - } + case BASEPROPERTY_STEP_TIME: + aReturn <<= pThrobber->getStepTime(); + break; + case BASEPROPERTY_REPEAT: + aReturn <<= pThrobber->getRepeat(); + break; + default: + aReturn = VCLXWindow::getProperty( PropertyName ); } return aReturn; } diff --git a/toolkit/source/awt/xthrobber.cxx b/toolkit/source/awt/xthrobber.cxx index 2a5d8d2d19af..768bd6ab4330 100644 --- a/toolkit/source/awt/xthrobber.cxx +++ b/toolkit/source/awt/xthrobber.cxx @@ -30,7 +30,6 @@ #include "toolkit/awt/xthrobber.hxx" #include "toolkit/helper/property.hxx" #include -#include #ifndef _TOOLKIT_AWT_XTHROBBER_HRC_ #include "xthrobber.hrc" @@ -38,6 +37,7 @@ #include #include #include +#include //........................................................................ namespace toolkit @@ -53,10 +53,8 @@ namespace toolkit //-------------------------------------------------------------------- XThrobber::XThrobber() - :mpThrobber( new Throbber_Impl( *this ) ) { DBG_CTOR( XThrobber, NULL ); - InitImageList(); } //-------------------------------------------------------------------- @@ -69,14 +67,25 @@ namespace toolkit void SAL_CALL XThrobber::start() throw ( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); - mpThrobber->start(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->start(); } //-------------------------------------------------------------------- void SAL_CALL XThrobber::stop() throw ( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); - mpThrobber->stop(); + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + pThrobber->stop(); + } + + //-------------------------------------------------------------------- + void XThrobber::SetWindow( Window* pWindow ) + { + XThrobber_Base::SetWindow( pWindow ); + InitImageList(); } //-------------------------------------------------------------------- @@ -84,10 +93,15 @@ namespace toolkit throw( uno::RuntimeException ) { ::vos::OGuard aGuard( GetMutex() ); + + Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) ); + if ( pThrobber != NULL) + return; + uno::Sequence< uno::Reference< graphic::XGraphic > > aImageList(12); sal_uInt16 nIconIdStart = RID_TK_ICON_THROBBER_START; - if ( mpThrobber->isHCMode() ) + if ( pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode() ) nIconIdStart = RID_TK_HC_ICON_THROBBER_START; for ( sal_uInt16 i=0; i<12; i++ ) @@ -96,7 +110,7 @@ namespace toolkit aImageList[i] = aImage.GetXGraphic(); } - mpThrobber->setImageList( aImageList ); + pThrobber->setImageList( aImageList ); } //........................................................................ diff --git a/toolkit/source/helper/makefile.mk b/toolkit/source/helper/makefile.mk index bf10b0aa0178..a0a254ef1f00 100644 --- a/toolkit/source/helper/makefile.mk +++ b/toolkit/source/helper/makefile.mk @@ -53,7 +53,6 @@ SLOFILES= \ $(SLO)$/vclunohelper.obj \ $(SLO)$/externallock.obj \ $(SLO)$/imagealign.obj \ - $(SLO)$/throbberimpl.obj \ $(SLO)$/formpdfexport.obj \ $(SLO)$/accessibilityclient.obj \ $(SLO)$/fixedhyperbase.obj diff --git a/toolkit/source/helper/throbberimpl.cxx b/toolkit/source/helper/throbberimpl.cxx deleted file mode 100644 index 5eb6b838a924..000000000000 --- a/toolkit/source/helper/throbberimpl.cxx +++ /dev/null @@ -1,149 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#include "precompiled_toolkit.hxx" -#include - -#include -#include - -//........................................................................ -namespace toolkit -//........................................................................ -{ - using namespace ::com::sun::star; - - //-------------------------------------------------------------------- - Throbber_Impl::Throbber_Impl( VCLXWindow& i_rParent ) - :mrMutex( Application::GetSolarMutex() ) - ,mrParent( i_rParent ) - ,mbRepeat( sal_True ) - ,mnStepTime( 100 ) - ,mnCurStep( 0 ) - ,mnStepCount( 0 ) - { - maWaitTimer.SetTimeout( mnStepTime ); - maWaitTimer.SetTimeoutHdl( LINK( this, Throbber_Impl, TimeOutHdl ) ); - } - - //-------------------------------------------------------------------- - Throbber_Impl::~Throbber_Impl() - { - maWaitTimer.Stop(); - } - - //-------------------------------------------------------------------- - void Throbber_Impl::start() - { - DBG_TESTSOLARMUTEX(); - maWaitTimer.Start(); - } - - //-------------------------------------------------------------------- - void Throbber_Impl::stop() - { - DBG_TESTSOLARMUTEX(); - maWaitTimer.Stop(); - } - - //-------------------------------------------------------------------- - bool Throbber_Impl::isRunning() const - { - DBG_TESTSOLARMUTEX(); - return maWaitTimer.IsActive(); - } - - //-------------------------------------------------------------------- - namespace - { - void lcl_setImage( FixedImage& i_fixedImage, Image const& i_image ) - { - ImageControl* pImageControl = dynamic_cast< ImageControl* >( &i_fixedImage ); - if ( pImageControl != NULL ) - pImageControl->SetBitmap( i_image.GetBitmapEx() ); - else - i_fixedImage.SetImage( i_image ); - } - } - - //-------------------------------------------------------------------- - void Throbber_Impl::setImageList( const uno::Sequence< uno::Reference< graphic::XGraphic > >& rImageList ) - { - DBG_TESTSOLARMUTEX(); - - maImageList = rImageList; - - mnStepCount = maImageList.getLength(); - FixedImage* pFixedImage = dynamic_cast< FixedImage* >( mrParent.GetWindow() ); - if ( pFixedImage ) - lcl_setImage( *pFixedImage, mnStepCount ? maImageList[ 0 ] : Image() ); - } - - //-------------------------------------------------------------------- - sal_Bool Throbber_Impl::isHCMode() - { - FixedImage* pImage = dynamic_cast< FixedImage* >( mrParent.GetWindow() ); - if ( pImage ) - return pImage->GetSettings().GetStyleSettings().GetHighContrastMode(); - else - return Application::GetSettings().GetStyleSettings().GetHighContrastMode(); - } - - // ----------------------------------------------------------------------- - IMPL_LINK( Throbber_Impl, TimeOutHdl, Throbber_Impl*, EMPTYARG ) - { - ::vos::OGuard aGuard( GetMutex() ); - if ( !maImageList.getLength() ) - return 0; - - FixedImage* pFixedImage = dynamic_cast< FixedImage* >( mrParent.GetWindow() ); - if ( pFixedImage == NULL ) - return 0; - - if ( mnCurStep < mnStepCount - 1 ) - mnCurStep += 1; - else - { - if ( mbRepeat ) - { - // start over - mnCurStep = 0; - } - else - { - stop(); - } - } - - lcl_setImage( *pFixedImage, maImageList[ mnCurStep ] ); - - return 0; - } - -//........................................................................ -} // namespacetoolkit -//........................................................................ - diff --git a/vcl/inc/vcl/imgctrl.hxx b/vcl/inc/vcl/imgctrl.hxx index fa3b01463f34..83bd300379d6 100644 --- a/vcl/inc/vcl/imgctrl.hxx +++ b/vcl/inc/vcl/imgctrl.hxx @@ -46,6 +46,7 @@ private: public: ImageControl( Window* pParent, WinBits nStyle = 0 ); + ImageControl( Window* pParent, const ResId& rResId ); // set/get the scale mode. This is one of the css.awt.ImageScaleMode constants void SetScaleMode( const ::sal_Int16 _nMode ); diff --git a/vcl/inc/vcl/throbber.hxx b/vcl/inc/vcl/throbber.hxx new file mode 100644 index 000000000000..f86a9944e28f --- /dev/null +++ b/vcl/inc/vcl/throbber.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VCL_THROBBER_HXX +#define VCL_THROBBER_HXX + +#include "vcl/dllapi.h" +#include "vcl/imgctrl.hxx" +#include "vcl/timer.hxx" + +#include + +#include + +#include + +class VCL_DLLPUBLIC Throbber : public ImageControl +{ +public: + enum ImageSet + { + /// no (default) images at all + IMAGES_NONE, + /// automatically decide between different image sets, depending on what fits best the actual size + IMAGES_AUTO, + /// default images, 16x16 pixels + IMAGES_16_PX, + /// default images, 32x32 pixels + IMAGES_32_PX, + /// default images, 64x64 pixels + IMAGES_64_PX, + }; + +public: + Throbber( Window* i_parentWindow, WinBits i_style, const ImageSet i_imageSet = IMAGES_AUTO ); + Throbber( Window* i_parentWindow, const ResId& i_resId, const ImageSet i_imageSet = IMAGES_AUTO ); + ~Throbber(); + + // Properties + void setStepTime( sal_Int32 nStepTime ) { mnStepTime = nStepTime; } + sal_Int32 getStepTime() const { return mnStepTime; } + + void setRepeat( sal_Bool bRepeat ) { mbRepeat = bRepeat; } + sal_Bool getRepeat() const { return mbRepeat; } + + // animation control + void start(); + void stop(); + bool isRunning() const; + + void setImageList( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > >& ImageList ); + void setImageList( ::std::vector< Image > const& i_images ); + + // default images + static ::std::vector< ::rtl::OUString > + getDefaultImageURLs( const ImageSet i_imageSet ); + +protected: + // Window overridables + virtual void Resize(); + +private: + SAL_DLLPRIVATE void initImages(); + +private: + ::std::vector< Image > maImageList; + + sal_Bool mbRepeat; + sal_Int32 mnStepTime; + sal_Int32 mnCurStep; + sal_Int32 mnStepCount; + AutoTimer maWaitTimer; + ImageSet meImageSet; + + DECL_LINK( TimeOutHdl, void* ); +}; + +#endif // VCL_THROBBER_HXX + diff --git a/vcl/prj/d.lst b/vcl/prj/d.lst index 59efccb8ee02..6af056eec45b 100644 --- a/vcl/prj/d.lst +++ b/vcl/prj/d.lst @@ -58,6 +58,7 @@ mkdir: %_DEST%\inc%_EXT%\vcl ..\inc\vcl\image.hxx %_DEST%\inc%_EXT%\vcl\image.hxx ..\inc\vcl\imagerepository.hxx %_DEST%\inc%_EXT%\vcl\imagerepository.hxx ..\inc\vcl\imgctrl.hxx %_DEST%\inc%_EXT%\vcl\imgctrl.hxx +..\inc\vcl\throbber.hxx %_DEST%\inc%_EXT%\vcl\throbber.hxx ..\inc\vcl\impdel.hxx %_DEST%\inc%_EXT%\vcl\impdel.hxx ..\inc\vcl\inputctx.hxx %_DEST%\inc%_EXT%\vcl\inputctx.hxx ..\inc\vcl\javachild.hxx %_DEST%\inc%_EXT%\vcl\javachild.hxx diff --git a/vcl/source/control/imgctrl.cxx b/vcl/source/control/imgctrl.cxx index 075a8b1b95e2..d0ed042db354 100644 --- a/vcl/source/control/imgctrl.cxx +++ b/vcl/source/control/imgctrl.cxx @@ -30,6 +30,7 @@ #include #include +#include #include @@ -37,10 +38,18 @@ namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; // ----------------------------------------------------------------------- -ImageControl::ImageControl( Window* pParent, WinBits nStyle ) : - FixedImage( pParent, nStyle ) +ImageControl::ImageControl( Window* pParent, WinBits nStyle ) + :FixedImage( pParent, nStyle ) + ,mnScaleMode( ImageScaleMode::Anisotropic ) +{ +} + +// ----------------------------------------------------------------------- + +ImageControl::ImageControl( Window* pParent, const ResId& rResId ) + :FixedImage( pParent, rResId ) + ,mnScaleMode( ImageScaleMode::Anisotropic ) { - mnScaleMode = ImageScaleMode::Anisotropic; } // ----------------------------------------------------------------------- diff --git a/vcl/source/control/makefile.mk b/vcl/source/control/makefile.mk index b1644e58ccd9..3c0a364499ad 100644 --- a/vcl/source/control/makefile.mk +++ b/vcl/source/control/makefile.mk @@ -43,16 +43,21 @@ CDEFS+=-D_STD_NO_NAMESPACE -D_VOS_NO_NAMESPACE -D_UNO_NO_NAMESPACE # --- Files -------------------------------------------------------- -SLOFILES= $(SLO)$/button.obj \ +EXCEPTIONSFILES= \ + $(SLO)$/button.obj \ $(SLO)$/ctrl.obj \ - $(SLO)$/combobox.obj \ $(SLO)$/edit.obj \ - $(SLO)$/field.obj \ $(SLO)$/field2.obj \ + $(SLO)$/ilstbox.obj \ + $(SLO)$/tabctrl.obj \ + $(SLO)$/throbber.obj + +SLOFILES= $(EXCEPTIONSFILES) \ + $(SLO)$/combobox.obj \ + $(SLO)$/field.obj \ $(SLO)$/fixbrd.obj \ $(SLO)$/fixed.obj \ $(SLO)$/group.obj \ - $(SLO)$/ilstbox.obj \ $(SLO)$/imgctrl.obj \ $(SLO)$/longcurr.obj \ $(SLO)$/lstbox.obj \ @@ -62,17 +67,8 @@ SLOFILES= $(SLO)$/button.obj \ $(SLO)$/slider.obj \ $(SLO)$/spinfld.obj \ $(SLO)$/spinbtn.obj \ - $(SLO)$/tabctrl.obj \ $(SLO)$/quickselectionengine.obj -EXCEPTIONSFILES= \ - $(SLO)$/button.obj \ - $(SLO)$/ctrl.obj \ - $(SLO)$/edit.obj \ - $(SLO)$/field2.obj \ - $(SLO)$/ilstbox.obj \ - $(SLO)$/tabctrl.obj - # --- Targets ------------------------------------------------------ .INCLUDE : target.mk diff --git a/vcl/source/control/throbber.cxx b/vcl/source/control/throbber.cxx new file mode 100644 index 000000000000..eab39b735b4d --- /dev/null +++ b/vcl/source/control/throbber.cxx @@ -0,0 +1,283 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_vcl.hxx" + +#include "vcl/throbber.hxx" +#include "vcl/svapp.hxx" + +#include +#include + +#include +#include +#include +#include +#include + +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::graphic::XGraphic; +using ::com::sun::star::graphic::XGraphicProvider; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::Exception; +namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; + +//-------------------------------------------------------------------- +Throbber::Throbber( Window* i_parentWindow, WinBits i_style, const ImageSet i_imageSet ) + :ImageControl( i_parentWindow, i_style ) + ,mbRepeat( sal_True ) + ,mnStepTime( 100 ) + ,mnCurStep( 0 ) + ,mnStepCount( 0 ) + ,meImageSet( i_imageSet ) +{ + maWaitTimer.SetTimeout( mnStepTime ); + maWaitTimer.SetTimeoutHdl( LINK( this, Throbber, TimeOutHdl ) ); + + SetScaleMode( ImageScaleMode::None ); + initImages(); +} + +//-------------------------------------------------------------------- +Throbber::Throbber( Window* i_parentWindow, const ResId& i_resId, const ImageSet i_imageSet ) + :ImageControl( i_parentWindow, i_resId ) + ,mbRepeat( sal_True ) + ,mnStepTime( 100 ) + ,mnCurStep( 0 ) + ,mnStepCount( 0 ) + ,meImageSet( i_imageSet ) +{ + maWaitTimer.SetTimeout( mnStepTime ); + maWaitTimer.SetTimeoutHdl( LINK( this, Throbber, TimeOutHdl ) ); + + SetScaleMode( ImageScaleMode::None ); + initImages(); +} + +//-------------------------------------------------------------------- +Throbber::~Throbber() +{ + maWaitTimer.Stop(); +} + +//-------------------------------------------------------------------- +namespace +{ + ::std::vector< Image > lcl_loadImageSet( const Throbber::ImageSet i_imageSet ) + { + ::std::vector< Image > aImages; + ENSURE_OR_RETURN( i_imageSet != Throbber::IMAGES_NONE, "lcl_loadImageSet: illegal image set", aImages ); + + const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + const Reference< XGraphicProvider > xGraphicProvider( aContext.createComponent( "com.sun.star.graphic.GraphicProvider" ), UNO_QUERY_THROW ); + + ::std::vector< ::rtl::OUString > aImageURLs( Throbber::getDefaultImageURLs( i_imageSet ) ); + aImages.reserve( aImageURLs.size() ); + + ::comphelper::NamedValueCollection aMediaProperties; + for ( ::std::vector< ::rtl::OUString >::const_iterator imageURL = aImageURLs.begin(); + imageURL != aImageURLs.end(); + ++imageURL + ) + { + aMediaProperties.put( "URL", *imageURL ); + const Reference< XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ), UNO_QUERY ); + aImages.push_back( Image( xGraphic ) ); + } + + return aImages; + } +} + +//-------------------------------------------------------------------- +void Throbber::Resize() +{ + ImageControl::Resize(); + + if ( meImageSet == IMAGES_AUTO ) + initImages(); +} + +//-------------------------------------------------------------------- +void Throbber::initImages() +{ + if ( meImageSet == IMAGES_NONE ) + return; + + try + { + ::std::vector< ::std::vector< Image > > aImageSets; + if ( meImageSet == IMAGES_AUTO ) + { + aImageSets.push_back( lcl_loadImageSet( IMAGES_16_PX ) ); + aImageSets.push_back( lcl_loadImageSet( IMAGES_32_PX ) ); + aImageSets.push_back( lcl_loadImageSet( IMAGES_64_PX ) ); + } + else + { + aImageSets.push_back( lcl_loadImageSet( meImageSet ) ); + } + + // find the best matching image set (size-wise) + const ::Size aWindowSizePixel = GetSizePixel(); + size_t nPreferredSet = 0; + if ( aImageSets.size() > 1 ) + { + long nMinimalDistance = ::std::numeric_limits< long >::max(); + for ( ::std::vector< ::std::vector< Image > >::const_iterator check = aImageSets.begin(); + check != aImageSets.end(); + ++check + ) + { + ENSURE_OR_CONTINUE( !check->empty(), "Throbber::initImages: illegal image!" ); + const Size aImageSize = (*check)[0].GetSizePixel(); + const sal_Int64 distance = + ( aWindowSizePixel.Width() - aImageSize.Width() ) * ( aWindowSizePixel.Width() - aImageSize.Width() ) + + ( aWindowSizePixel.Height() - aImageSize.Height() ) * ( aWindowSizePixel.Height() - aImageSize.Height() ); + if ( distance < nMinimalDistance ) + { + nMinimalDistance = distance; + nPreferredSet = check - aImageSets.begin(); + } + } + } + + if ( nPreferredSet < aImageSets.size() ) + setImageList( aImageSets[nPreferredSet] ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +//-------------------------------------------------------------------- +void Throbber::start() +{ + maWaitTimer.Start(); +} + +//-------------------------------------------------------------------- +void Throbber::stop() +{ + maWaitTimer.Stop(); +} + +//-------------------------------------------------------------------- +bool Throbber::isRunning() const +{ + return maWaitTimer.IsActive(); +} + +//-------------------------------------------------------------------- +void Throbber::setImageList( ::std::vector< Image > const& i_images ) +{ + maImageList = i_images; + + mnStepCount = maImageList.size(); + const Image aInitialImage( mnStepCount ? maImageList[ 0 ] : Image() ); + SetBitmap( aInitialImage.GetBitmapEx() ); +} + +//-------------------------------------------------------------------- +void Throbber::setImageList( const Sequence< Reference< XGraphic > >& rImageList ) +{ + ::std::vector< Image > aImages( rImageList.getLength() ); + ::std::copy( + rImageList.getConstArray(), + rImageList.getConstArray() + rImageList.getLength(), + aImages.begin() + ); + setImageList( aImages ); +} + +// ----------------------------------------------------------------------- +::std::vector< ::rtl::OUString > Throbber::getDefaultImageURLs( const ImageSet i_imageSet ) +{ + ::std::vector< ::rtl::OUString > aImageURLs; + + sal_Char const* const pResolutions[] = { "16", "32", "64" }; + size_t const nImageCounts[] = { 6, 12, 12 }; + + size_t index = 0; + switch ( i_imageSet ) + { + case IMAGES_16_PX: index = 0; break; + case IMAGES_32_PX: index = 1; break; + case IMAGES_64_PX: index = 2; break; + case IMAGES_NONE: + case IMAGES_AUTO: + OSL_ENSURE( false, "Throbber::getDefaultImageURLs: illegal image set!" ); + return aImageURLs; + } + + aImageURLs.reserve( nImageCounts[index] ); + for ( size_t i=0; i