diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-21 11:55:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-21 21:47:57 +0200 |
commit | 603552c209f8652aa23a688b36d4a2abac933717 (patch) | |
tree | d4f4562cc8fc04d0ddfa084777655ffdab78ff49 /toolkit | |
parent | 1c7a9ac8594f12329dcba0516071e9562ee8df70 (diff) |
remove pimpl in AnimatedImagesPeer
Change-Id: Ia9109fb0b68a28612129e4f2fc3eae0f92a4dabd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119326
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/inc/awt/animatedimagespeer.hxx | 13 | ||||
-rw-r--r-- | toolkit/source/awt/animatedimagespeer.cxx | 291 |
2 files changed, 137 insertions, 167 deletions
diff --git a/toolkit/inc/awt/animatedimagespeer.hxx b/toolkit/inc/awt/animatedimagespeer.hxx index ff07c291c237..71861f8b3e38 100644 --- a/toolkit/inc/awt/animatedimagespeer.hxx +++ b/toolkit/inc/awt/animatedimagespeer.hxx @@ -22,7 +22,9 @@ #include <toolkit/awt/vclxwindow.hxx> #include <com/sun/star/container/XContainerListener.hpp> +#include <com/sun/star/awt/XAnimatedImages.hpp> #include <com/sun/star/awt/XAnimation.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/util/XModifyListener.hpp> #include <cppuhelper/implbase.hxx> @@ -74,6 +76,12 @@ namespace toolkit // XComponent void SAL_CALL dispose( ) override; + struct CachedImage + { + OUString sImageURL; + mutable css::uno::Reference< css::graphic::XGraphic > xGraphic; + }; + private: void ProcessWindowEvent( const VclWindowEvent& i_windowEvent ) override; @@ -84,7 +92,10 @@ namespace toolkit AnimatedImagesPeer(const AnimatedImagesPeer&) = delete; AnimatedImagesPeer& operator=(const AnimatedImagesPeer&) = delete; - std::unique_ptr< AnimatedImagesPeer_Data > m_xData; + void updateImageList_nothrow(); + void updateImageList_nothrow( const css::uno::Reference< css::awt::XAnimatedImages >& i_images ); + + std::vector< std::vector< CachedImage > > maCachedImageSets; }; diff --git a/toolkit/source/awt/animatedimagespeer.cxx b/toolkit/source/awt/animatedimagespeer.cxx index bcbf42d62a72..919bca9ba5df 100644 --- a/toolkit/source/awt/animatedimagespeer.cxx +++ b/toolkit/source/awt/animatedimagespeer.cxx @@ -21,12 +21,10 @@ #include <awt/animatedimagespeer.hxx> #include <toolkit/helper/property.hxx> -#include <com/sun/star/awt/XAnimatedImages.hpp> #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/graphic/GraphicProvider.hpp> #include <com/sun/star/graphic/XGraphicProvider.hpp> #include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/awt/ImageScaleMode.hpp> #include <comphelper/namedvaluecollection.hxx> @@ -63,44 +61,6 @@ namespace toolkit namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; - - //= AnimatedImagesPeer_Data - - namespace { - - struct CachedImage - { - OUString sImageURL; - mutable Reference< XGraphic > xGraphic; - - CachedImage() - :sImageURL() - ,xGraphic() - { - } - - explicit CachedImage( OUString const& i_imageURL ) - :sImageURL( i_imageURL ) - ,xGraphic() - { - } - }; - - } - - struct AnimatedImagesPeer_Data - { - AnimatedImagesPeer& rAntiImpl; - ::std::vector< ::std::vector< CachedImage > > aCachedImageSets; - - explicit AnimatedImagesPeer_Data( AnimatedImagesPeer& i_antiImpl ) - :rAntiImpl( i_antiImpl ) - ,aCachedImageSets() - { - } - }; - - //= helper namespace @@ -125,7 +85,7 @@ namespace toolkit } - bool lcl_ensureImage_throw( Reference< XGraphicProvider > const& i_graphicProvider, const bool i_isHighContrast, const CachedImage& i_cachedImage ) + bool lcl_ensureImage_throw( Reference< XGraphicProvider > const& i_graphicProvider, const bool i_isHighContrast, const AnimatedImagesPeer::CachedImage& i_cachedImage ) { if ( !i_cachedImage.xGraphic.is() ) { @@ -165,125 +125,18 @@ namespace toolkit } - void lcl_init( Sequence< OUString > const& i_imageURLs, ::std::vector< CachedImage >& o_images ) + void lcl_init( Sequence< OUString > const& i_imageURLs, ::std::vector< AnimatedImagesPeer::CachedImage >& o_images ) { o_images.resize(0); size_t count = size_t( i_imageURLs.getLength() ); o_images.reserve( count ); for ( const auto& rImageURL : i_imageURLs ) { - o_images.emplace_back( rImageURL ); - } - } - - - void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data ) - { - VclPtr<Throbber> pThrobber = i_data.rAntiImpl.GetAsDynamic<Throbber>(); - if ( !pThrobber ) - return; - - try - { - // collect the image sizes of the different image sets - const Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - const Reference< XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create(xContext) ); - - const bool isHighContrast = pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode(); - - sal_Int32 nPreferredSet = -1; - const size_t nImageSetCount = i_data.aCachedImageSets.size(); - if ( nImageSetCount < 2 ) - { - nPreferredSet = sal_Int32( nImageSetCount ) - 1; - } - else - { - ::std::vector< Size > aImageSizes( nImageSetCount ); - for ( size_t nImageSet = 0; nImageSet < nImageSetCount; ++nImageSet ) - { - ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nImageSet ] ); - if ( ( rImageSet.empty() ) - || ( !lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rImageSet[0] ) ) - ) - { - aImageSizes[ nImageSet ] = Size( SAL_MAX_INT32, SAL_MAX_INT32 ); - } - else - { - aImageSizes[ nImageSet ] = lcl_getGraphicSizePixel( rImageSet[0].xGraphic ); - } - } - - // find the set with the smallest difference between window size and image size - const ::Size aWindowSizePixel = pThrobber->GetSizePixel(); - tools::Long nMinimalDistance = ::std::numeric_limits< tools::Long >::max(); - for ( ::std::vector< Size >::const_iterator check = aImageSizes.begin(); - check != aImageSizes.end(); - ++check - ) - { - if ( ( check->Width > aWindowSizePixel.Width() ) - || ( check->Height > aWindowSizePixel.Height() ) - ) - // do not use an image set which doesn't fit into the window - continue; - - const sal_Int64 distance = - ( aWindowSizePixel.Width() - check->Width ) * ( aWindowSizePixel.Width() - check->Width ) - + ( aWindowSizePixel.Height() - check->Height ) * ( aWindowSizePixel.Height() - check->Height ); - if ( distance < nMinimalDistance ) - { - nMinimalDistance = distance; - nPreferredSet = check - aImageSizes.begin(); - } - } - } - - // found a set? - std::vector< Image > aImages; - if ( ( nPreferredSet >= 0 ) && ( o3tl::make_unsigned( nPreferredSet ) < nImageSetCount ) ) - { - // => set the images - ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nPreferredSet ] ); - aImages.resize( rImageSet.size() ); - sal_Int32 imageIndex = 0; - for ( const auto& rCachedImage : rImageSet ) - { - lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rCachedImage ); - aImages[ imageIndex++ ] = Image(rCachedImage.xGraphic); - } - } - pThrobber->setImageList( aImages ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("toolkit"); + o_images.emplace_back( AnimatedImagesPeer::CachedImage{ rImageURL, nullptr } ); } } - void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data, const Reference< XAnimatedImages >& i_images ) - { - try - { - const sal_Int32 nImageSetCount = i_images->getImageSetCount(); - i_data.aCachedImageSets.resize(0); - for ( sal_Int32 set = 0; set < nImageSetCount; ++set ) - { - const Sequence< OUString > aImageURLs( i_images->getImageSet( set ) ); - ::std::vector< CachedImage > aImages; - lcl_init( aImageURLs, aImages ); - i_data.aCachedImageSets.push_back( aImages ); - } - - lcl_updateImageList_nothrow( i_data ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("toolkit"); - } - } } @@ -292,7 +145,6 @@ namespace toolkit AnimatedImagesPeer::AnimatedImagesPeer() :AnimatedImagesPeer_Base() - ,m_xData( new AnimatedImagesPeer_Data( *this ) ) { } @@ -413,7 +265,7 @@ namespace toolkit { if ( i_windowEvent.GetId() == VclEventId::WindowResize ) { - lcl_updateImageList_nothrow( *m_xData ); + updateImageList_nothrow(); } AnimatedImagesPeer_Base::ProcessWindowEvent( i_windowEvent ); @@ -424,7 +276,7 @@ namespace toolkit { SolarMutexGuard aGuard; - lcl_updateImageList_nothrow( *m_xData, Reference< XAnimatedImages >( i_animatedImages, UNO_QUERY_THROW ) ); + updateImageList_nothrow( Reference< XAnimatedImages >( i_animatedImages, UNO_QUERY_THROW ) ); } @@ -436,18 +288,18 @@ namespace toolkit sal_Int32 nPosition(0); OSL_VERIFY( i_event.Accessor >>= nPosition ); size_t position = size_t( nPosition ); - if ( position > m_xData->aCachedImageSets.size() ) + if ( position > maCachedImageSets.size() ) { OSL_ENSURE( false, "AnimatedImagesPeer::elementInserted: illegal accessor/index!" ); - lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + updateImageList_nothrow( xAnimatedImages ); } Sequence< OUString > aImageURLs; OSL_VERIFY( i_event.Element >>= aImageURLs ); ::std::vector< CachedImage > aImages; lcl_init( aImageURLs, aImages ); - m_xData->aCachedImageSets.insert( m_xData->aCachedImageSets.begin() + position, aImages ); - lcl_updateImageList_nothrow( *m_xData ); + maCachedImageSets.insert( maCachedImageSets.begin() + position, aImages ); + updateImageList_nothrow(); } @@ -459,14 +311,14 @@ namespace toolkit sal_Int32 nPosition(0); OSL_VERIFY( i_event.Accessor >>= nPosition ); size_t position = size_t( nPosition ); - if ( position >= m_xData->aCachedImageSets.size() ) + if ( position >= maCachedImageSets.size() ) { OSL_ENSURE( false, "AnimatedImagesPeer::elementRemoved: illegal accessor/index!" ); - lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + updateImageList_nothrow( xAnimatedImages ); } - m_xData->aCachedImageSets.erase( m_xData->aCachedImageSets.begin() + position ); - lcl_updateImageList_nothrow( *m_xData ); + maCachedImageSets.erase( maCachedImageSets.begin() + position ); + updateImageList_nothrow(); } @@ -478,18 +330,18 @@ namespace toolkit sal_Int32 nPosition(0); OSL_VERIFY( i_event.Accessor >>= nPosition ); size_t position = size_t( nPosition ); - if ( position >= m_xData->aCachedImageSets.size() ) + if ( position >= maCachedImageSets.size() ) { OSL_ENSURE( false, "AnimatedImagesPeer::elementReplaced: illegal accessor/index!" ); - lcl_updateImageList_nothrow( *m_xData, xAnimatedImages ); + updateImageList_nothrow( xAnimatedImages ); } Sequence< OUString > aImageURLs; OSL_VERIFY( i_event.Element >>= aImageURLs ); ::std::vector< CachedImage > aImages; lcl_init( aImageURLs, aImages ); - m_xData->aCachedImageSets[ position ] = aImages; - lcl_updateImageList_nothrow( *m_xData ); + maCachedImageSets[ position ] = aImages; + updateImageList_nothrow(); } @@ -509,9 +361,116 @@ namespace toolkit { AnimatedImagesPeer_Base::dispose(); SolarMutexGuard aGuard; - m_xData->aCachedImageSets.resize(0); + maCachedImageSets.resize(0); } + void AnimatedImagesPeer::updateImageList_nothrow() + { + VclPtr<Throbber> pThrobber = GetAsDynamic<Throbber>(); + if ( !pThrobber ) + return; + + try + { + // collect the image sizes of the different image sets + const Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); + const Reference< XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create(xContext) ); + + const bool isHighContrast = pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode(); + + sal_Int32 nPreferredSet = -1; + const size_t nImageSetCount = maCachedImageSets.size(); + if ( nImageSetCount < 2 ) + { + nPreferredSet = sal_Int32( nImageSetCount ) - 1; + } + else + { + ::std::vector< Size > aImageSizes( nImageSetCount ); + for ( size_t nImageSet = 0; nImageSet < nImageSetCount; ++nImageSet ) + { + ::std::vector< CachedImage > const& rImageSet( maCachedImageSets[ nImageSet ] ); + if ( ( rImageSet.empty() ) + || ( !lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rImageSet[0] ) ) + ) + { + aImageSizes[ nImageSet ] = Size( SAL_MAX_INT32, SAL_MAX_INT32 ); + } + else + { + aImageSizes[ nImageSet ] = lcl_getGraphicSizePixel( rImageSet[0].xGraphic ); + } + } + + // find the set with the smallest difference between window size and image size + const ::Size aWindowSizePixel = pThrobber->GetSizePixel(); + tools::Long nMinimalDistance = ::std::numeric_limits< tools::Long >::max(); + for ( ::std::vector< Size >::const_iterator check = aImageSizes.begin(); + check != aImageSizes.end(); + ++check + ) + { + if ( ( check->Width > aWindowSizePixel.Width() ) + || ( check->Height > aWindowSizePixel.Height() ) + ) + // do not use an image set which doesn't fit into the window + continue; + + const sal_Int64 distance = + ( aWindowSizePixel.Width() - check->Width ) * ( aWindowSizePixel.Width() - check->Width ) + + ( aWindowSizePixel.Height() - check->Height ) * ( aWindowSizePixel.Height() - check->Height ); + if ( distance < nMinimalDistance ) + { + nMinimalDistance = distance; + nPreferredSet = check - aImageSizes.begin(); + } + } + } + + // found a set? + std::vector< Image > aImages; + if ( ( nPreferredSet >= 0 ) && ( o3tl::make_unsigned( nPreferredSet ) < nImageSetCount ) ) + { + // => set the images + ::std::vector< CachedImage > const& rImageSet( maCachedImageSets[ nPreferredSet ] ); + aImages.resize( rImageSet.size() ); + sal_Int32 imageIndex = 0; + for ( const auto& rCachedImage : rImageSet ) + { + lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rCachedImage ); + aImages[ imageIndex++ ] = Image(rCachedImage.xGraphic); + } + } + pThrobber->setImageList( aImages ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } + + + void AnimatedImagesPeer::updateImageList_nothrow( const Reference< XAnimatedImages >& i_images ) + { + try + { + const sal_Int32 nImageSetCount = i_images->getImageSetCount(); + maCachedImageSets.resize(0); + for ( sal_Int32 set = 0; set < nImageSetCount; ++set ) + { + const Sequence< OUString > aImageURLs( i_images->getImageSet( set ) ); + ::std::vector< CachedImage > aImages; + lcl_init( aImageURLs, aImages ); + maCachedImageSets.push_back( aImages ); + } + + updateImageList_nothrow(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("toolkit"); + } + } } // namespace toolkit |