22#include <helper/property.hxx>
24#include <com/sun/star/awt/Size.hpp>
25#include <com/sun/star/graphic/GraphicProvider.hpp>
26#include <com/sun/star/graphic/XGraphicProvider.hpp>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/awt/ImageScaleMode.hpp>
46 using ::com::sun::star::uno::XComponentContext;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::XInterface;
49 using ::com::sun::star::uno::UNO_QUERY_THROW;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::uno::Sequence;
53 using ::com::sun::star::lang::EventObject;
54 using ::com::sun::star::container::ContainerEvent;
55 using ::com::sun::star::awt::XAnimatedImages;
56 using ::com::sun::star::awt::Size;
57 using ::com::sun::star::graphic::XGraphicProvider;
58 using ::com::sun::star::beans::XPropertySet;
59 using ::com::sun::star::graphic::XGraphic;
61 namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
68 OUString lcl_getHighContrastURL( OUString
const& i_imageURL )
71 if (
aURL.GetProtocol() != INetProtocol::PrivSoffice )
73 OSL_VERIFY(
aURL.insertName(
u"sifr",
false, 0 ) );
78 const sal_Int32 separatorPos = i_imageURL.indexOf(
'/' );
79 ENSURE_OR_RETURN( separatorPos != -1,
"lcl_getHighContrastURL: unsupported URL scheme - cannot automatically determine HC version!", i_imageURL );
81 OUString composer = OUString::Concat(i_imageURL.subView(0, separatorPos)) +
"/sifr" +
82 i_imageURL.subView(separatorPos);
87 bool lcl_ensureImage_throw( Reference< XGraphicProvider >
const& i_graphicProvider,
const bool i_isHighContrast,
const AnimatedImagesPeer::CachedImage& i_cachedImage )
92 if ( i_isHighContrast )
95 aMediaProperties.
put(
"URL", lcl_getHighContrastURL( i_cachedImage.
sImageURL ) );
108 Size lcl_getGraphicSizePixel( Reference< XGraphic >
const& i_graphic )
113 if ( i_graphic.is() )
115 const Reference< XPropertySet > xGraphicProps( i_graphic, UNO_QUERY_THROW );
116 OSL_VERIFY( xGraphicProps->getPropertyValue(
"SizePixel") >>= aSizePixel );
127 void lcl_init( Sequence< OUString >
const& i_imageURLs, ::std::vector< AnimatedImagesPeer::CachedImage >& o_images )
130 size_t count = size_t( i_imageURLs.getLength() );
131 o_images.reserve(
count );
132 for (
const auto& rImageURL : i_imageURLs )
176 return pThrobber->isRunning();
196 sal_Int32 nStepTime( 0 );
197 if ( i_value >>= nStepTime )
198 pThrobber->setStepTime( nStepTime );
203 bool bRepeat(
true );
204 if ( i_value >>= bRepeat )
205 pThrobber->setRepeat( bRepeat );
211 sal_Int16 nScaleMode( ImageScaleMode::ANISOTROPIC );
213 if ( pImageControl && ( i_value >>= nScaleMode ) )
214 pImageControl->SetScaleMode( nScaleMode );
219 AnimatedImagesPeer_Base::setProperty( i_propertyName, i_value );
239 aReturn <<= pThrobber->getStepTime();
243 aReturn <<= pThrobber->getRepeat();
249 aReturn <<= ( pImageControl ? pImageControl->GetScaleMode() : ImageScaleMode::ANISOTROPIC );
254 aReturn = AnimatedImagesPeer_Base::getProperty( i_propertyName );
264 if ( i_windowEvent.
GetId() == VclEventId::WindowResize )
269 AnimatedImagesPeer_Base::ProcessWindowEvent( i_windowEvent );
284 Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
286 sal_Int32 nPosition(0);
287 OSL_VERIFY( i_event.Accessor >>= nPosition );
288 size_t position = size_t( nPosition );
291 OSL_ENSURE(
false,
"AnimatedImagesPeer::elementInserted: illegal accessor/index!" );
295 Sequence< OUString > aImageURLs;
296 OSL_VERIFY( i_event.Element >>= aImageURLs );
297 ::std::vector< CachedImage > aImages;
298 lcl_init( aImageURLs, aImages );
307 Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
309 sal_Int32 nPosition(0);
310 OSL_VERIFY( i_event.Accessor >>= nPosition );
311 size_t position = size_t( nPosition );
314 OSL_ENSURE(
false,
"AnimatedImagesPeer::elementRemoved: illegal accessor/index!" );
326 Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
328 sal_Int32 nPosition(0);
329 OSL_VERIFY( i_event.Accessor >>= nPosition );
330 size_t position = size_t( nPosition );
333 OSL_ENSURE(
false,
"AnimatedImagesPeer::elementReplaced: illegal accessor/index!" );
337 Sequence< OUString > aImageURLs;
338 OSL_VERIFY( i_event.Element >>= aImageURLs );
339 ::std::vector< CachedImage > aImages;
340 lcl_init( aImageURLs, aImages );
360 AnimatedImagesPeer_Base::dispose();
374 const Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
375 const Reference< XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create(xContext) );
377 const bool isHighContrast = pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode();
379 sal_Int32 nPreferredSet = -1;
381 if ( nImageSetCount < 2 )
383 nPreferredSet = sal_Int32( nImageSetCount ) - 1;
387 ::std::vector< Size > aImageSizes( nImageSetCount );
388 for (
size_t nImageSet = 0; nImageSet < nImageSetCount; ++nImageSet )
391 if ( ( rImageSet.empty() )
392 || ( !lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rImageSet[0] ) )
399 aImageSizes[ nImageSet ] = lcl_getGraphicSizePixel( rImageSet[0].xGraphic );
404 const ::Size aWindowSizePixel = pThrobber->GetSizePixel();
405 tools::Long nMinimalDistance = ::std::numeric_limits< tools::Long >::max();
406 for ( ::std::vector< Size >::const_iterator
check = aImageSizes.begin();
407 check != aImageSizes.end();
411 if ( (
check->Width > aWindowSizePixel.Width() )
412 || (
check->Height > aWindowSizePixel.Height() )
418 ( aWindowSizePixel.Width() -
check->Width ) * ( aWindowSizePixel.Width() -
check->Width )
419 + ( aWindowSizePixel.Height() -
check->Height ) * ( aWindowSizePixel.Height() -
check->Height );
423 nPreferredSet =
check - aImageSizes.begin();
429 std::vector< Image > aImages;
433 ::std::vector< CachedImage >
const& rImageSet(
maCachedImageSets[ nPreferredSet ] );
434 aImages.resize( rImageSet.size() );
435 sal_Int32 imageIndex = 0;
436 for (
const auto& rCachedImage : rImageSet )
438 lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rCachedImage );
439 aImages[ imageIndex++ ] =
Image(rCachedImage.xGraphic);
442 pThrobber->setImageList( std::move(aImages) );
455 const sal_Int32 nImageSetCount = i_images->getImageSetCount();
457 for ( sal_Int32 set = 0;
set < nImageSetCount; ++
set )
459 const Sequence< OUString > aImageURLs( i_images->getImageSet( set ) );
460 ::std::vector< CachedImage > aImages;
461 lcl_init( aImageURLs, aImages );
467 catch(
const Exception& )
css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
#define ENSURE_OR_RETURN(c, m, r)
#define DBG_UNHANDLED_EXCEPTION(...)
void set(css::uno::UnoInterfaceReference const &value)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_uInt16 GetPropertyId(const OUString &rPropertyName)
#define BASEPROPERTY_STEP_TIME
#define BASEPROPERTY_AUTO_REPEAT
#define BASEPROPERTY_IMAGE_SCALE_MODE