23#include <com/sun/star/uno/XComponentContext.hpp>
24#include <com/sun/star/graphic/GraphicProvider.hpp>
25#include <com/sun/star/graphic/XGraphicProvider.hpp>
26#include <com/sun/star/awt/ImageScaleMode.hpp>
30#include <rtl/ustrbuf.hxx>
36using ::com::sun::star::uno::Reference;
37using ::com::sun::star::graphic::XGraphic;
38using ::com::sun::star::graphic::XGraphicProvider;
39using ::com::sun::star::uno::Exception;
40namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
43 :ImageControl( i_parentWindow, i_style )
47 ,maWaitTimer(
"Throbber maWaitTimer")
49 maWaitTimer.SetTimeout( mnStepTime );
50 maWaitTimer.SetInvokeHandler(
LINK(
this, Throbber, TimeOutHdl ) );
52 SetScaleMode( ImageScaleMode::NONE );
61void Throbber::dispose()
64 ImageControl::dispose();
69 ::std::vector< Image > lcl_loadImageSet(
const Throbber::ImageSet i_imageSet )
71 ::std::vector< Image > aImages;
73 const Reference< css::uno::XComponentContext > aContext( ::comphelper::getProcessComponentContext() );
74 const Reference< XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create(aContext) );
76 ::std::vector< OUString > aImageURLs( Throbber::getDefaultImageURLs( i_imageSet ) );
77 aImages.reserve( aImageURLs.size() );
80 for (
const auto& rImageURL : aImageURLs )
82 Reference< XGraphic > xGraphic;
83 aMediaProperties.
put(
"URL", rImageURL );
84 xGraphic = xGraphicProvider->queryGraphic( aMediaProperties.
getPropertyValues() );
85 aImages.emplace_back( xGraphic );
92void Throbber::Resize()
94 ImageControl::Resize();
98void Throbber::initImages()
102 ::std::vector< ::std::vector< Image > > aImageSets
104 lcl_loadImageSet( ImageSet::N16px ),
105 lcl_loadImageSet( ImageSet::N32px ),
106 lcl_loadImageSet( ImageSet::N64px )
110 const ::Size aWindowSizePixel = GetSizePixel();
111 size_t nPreferredSet = 0;
112 if ( aImageSets.size() > 1 )
114 tools::Long nMinimalDistance = ::std::numeric_limits< tools::Long >::max();
115 for ( ::std::vector< ::std::vector< Image > >::const_iterator check = aImageSets.begin();
116 check != aImageSets.end();
120 if (
check->empty() )
122 SAL_WARN(
"vcl.control",
"Throbber::initImages: illegal image!" );
126 const Size aImageSize = (*check)[0].GetSizePixel();
128 if ( ( aImageSize.
Width() > aWindowSizePixel.Width() )
129 || ( aImageSize.
Height() > aWindowSizePixel.Height() )
135 ( aWindowSizePixel.Width() - aImageSize.
Width() ) * ( aWindowSizePixel.Width() - aImageSize.
Width() )
136 + ( aWindowSizePixel.Height() - aImageSize.
Height() ) * ( aWindowSizePixel.Height() - aImageSize.
Height() );
137 if ( distance < nMinimalDistance )
140 nPreferredSet =
check - aImageSets.begin();
145 if ( nPreferredSet < aImageSets.size() )
146 setImageList( std::vector(aImageSets[nPreferredSet]) );
148 catch(
const Exception& )
153void Throbber::start()
163bool Throbber::isRunning()
const
165 return maWaitTimer.IsActive();
168void Throbber::setImageList( ::std::vector< Image > && i_images )
170 SAL_WARN_IF( i_images.size()>=SAL_MAX_INT32,
"vcl.control",
"Throbber::setImageList: too many images!" );
172 maImageList = std::move(i_images);
174 const Image aInitialImage( !maImageList.empty() ? maImageList[ 0 ] :
Image() );
175 SetImage( aInitialImage );
178::std::vector< OUString > Throbber::getDefaultImageURLs(
const ImageSet i_imageSet )
180 ::std::vector< OUString > aImageURLs;
182 sal_Unicode const*
const pResolutions[] = {
u"16",
u"32",
u"64" };
183 size_t const nImageCounts[] = { 6, 12, 12 };
186 switch ( i_imageSet )
188 case ImageSet::N16px:
index = 0;
break;
189 case ImageSet::N32px:
index = 1;
break;
190 case ImageSet::N64px:
index = 2;
break;
193 aImageURLs.reserve( nImageCounts[index] );
194 for (
size_t i=0;
i<nImageCounts[
index]; ++
i )
196 OUStringBuffer
aURL( OUString::Concat(
"private:graphicrepository/vcl/res/spinner-")
197 + pResolutions[index]
201 aURL.append( OUString::number( sal_Int32( i + 1 ) ) +
".png" );
203 aImageURLs.push_back(
aURL.makeStringAndClear() );
212 if ( maImageList.empty() )
215 if ( mnCurStep <
static_cast<sal_Int32
>(maImageList.size()-1) )
230 SetImage( maImageList[ mnCurStep ] );
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
#define LINK(Instance, Class, Member)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
IMPL_LINK_NOARG(Throbber, TimeOutHdl, Timer *, void)