1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir  *
25*cdf0e10cSrcweir  ************************************************************************/
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "toolkit/awt/animatedimagespeer.hxx"
30*cdf0e10cSrcweir #include "toolkit/helper/property.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir /** === begin UNO includes === **/
33*cdf0e10cSrcweir #include <com/sun/star/awt/XAnimatedImages.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/awt/ImageScaleMode.hpp>
39*cdf0e10cSrcweir /** === end UNO includes === **/
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
42*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
43*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
45*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
46*cdf0e10cSrcweir #include <tools/urlobj.hxx>
47*cdf0e10cSrcweir #include <vcl/throbber.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <limits>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //......................................................................................................................
52*cdf0e10cSrcweir namespace toolkit
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir //......................................................................................................................
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 	/** === begin UNO using === **/
57*cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
58*cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
59*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
60*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
61*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
62*cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
63*cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
64*cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
65*cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
66*cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
67*cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
68*cdf0e10cSrcweir     using ::com::sun::star::lang::EventObject;
69*cdf0e10cSrcweir     using ::com::sun::star::container::ContainerEvent;
70*cdf0e10cSrcweir     using ::com::sun::star::awt::XAnimatedImages;
71*cdf0e10cSrcweir     using ::com::sun::star::awt::Size;
72*cdf0e10cSrcweir     using ::com::sun::star::lang::XMultiServiceFactory;
73*cdf0e10cSrcweir     using ::com::sun::star::graphic::XGraphicProvider;
74*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySet;
75*cdf0e10cSrcweir     using ::com::sun::star::graphic::XGraphic;
76*cdf0e10cSrcweir 	/** === end UNO using === **/
77*cdf0e10cSrcweir     namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	//==================================================================================================================
80*cdf0e10cSrcweir 	//= AnimatedImagesPeer_Data
81*cdf0e10cSrcweir 	//==================================================================================================================
82*cdf0e10cSrcweir     struct CachedImage
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         ::rtl::OUString                 sImageURL;
85*cdf0e10cSrcweir         mutable Reference< XGraphic >   xGraphic;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         CachedImage()
88*cdf0e10cSrcweir             :sImageURL()
89*cdf0e10cSrcweir             ,xGraphic()
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir         }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         CachedImage( ::rtl::OUString const& i_imageURL )
94*cdf0e10cSrcweir             :sImageURL( i_imageURL )
95*cdf0e10cSrcweir             ,xGraphic()
96*cdf0e10cSrcweir         {
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir     };
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     struct AnimatedImagesPeer_Data
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         AnimatedImagesPeer&                             rAntiImpl;
103*cdf0e10cSrcweir         ::std::vector< ::std::vector< CachedImage > >   aCachedImageSets;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         AnimatedImagesPeer_Data( AnimatedImagesPeer& i_antiImpl )
106*cdf0e10cSrcweir             :rAntiImpl( i_antiImpl )
107*cdf0e10cSrcweir             ,aCachedImageSets()
108*cdf0e10cSrcweir         {
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir     };
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	//==================================================================================================================
113*cdf0e10cSrcweir 	//= helper
114*cdf0e10cSrcweir 	//==================================================================================================================
115*cdf0e10cSrcweir     namespace
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
118*cdf0e10cSrcweir         ::rtl::OUString lcl_getHighContrastURL( ::rtl::OUString const& i_imageURL )
119*cdf0e10cSrcweir         {
120*cdf0e10cSrcweir             INetURLObject aURL( i_imageURL );
121*cdf0e10cSrcweir             if ( aURL.GetProtocol() != INET_PROT_PRIV_SOFFICE )
122*cdf0e10cSrcweir             {
123*cdf0e10cSrcweir                 OSL_VERIFY( aURL.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hicontrast" ) ), false, 0 ) );
124*cdf0e10cSrcweir                 return aURL.GetMainURL( INetURLObject::NO_DECODE );
125*cdf0e10cSrcweir             }
126*cdf0e10cSrcweir             // the private: scheme is not considered to be hierarchical by INetURLObject, so manually insert the
127*cdf0e10cSrcweir             // segment
128*cdf0e10cSrcweir             const sal_Int32 separatorPos = i_imageURL.indexOf( '/' );
129*cdf0e10cSrcweir             ENSURE_OR_RETURN( separatorPos != -1, "lcl_getHighContrastURL: unsipported URL scheme - cannot automatically determine HC version!", i_imageURL );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir             ::rtl::OUStringBuffer composer;
132*cdf0e10cSrcweir             composer.append( i_imageURL.copy( 0, separatorPos ) );
133*cdf0e10cSrcweir             composer.appendAscii( "/hicontrast" );
134*cdf0e10cSrcweir             composer.append( i_imageURL.copy( separatorPos ) );
135*cdf0e10cSrcweir             return composer.makeStringAndClear();
136*cdf0e10cSrcweir         }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
139*cdf0e10cSrcweir         bool lcl_ensureImage_throw( Reference< XGraphicProvider > const& i_graphicProvider, const bool i_isHighContrast, const CachedImage& i_cachedImage )
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             if ( !i_cachedImage.xGraphic.is() )
142*cdf0e10cSrcweir             {
143*cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aMediaProperties;
144*cdf0e10cSrcweir                 if ( i_isHighContrast )
145*cdf0e10cSrcweir                 {
146*cdf0e10cSrcweir                     // try (to find) the high-contrast version of the graphic first
147*cdf0e10cSrcweir                     aMediaProperties.put( "URL", lcl_getHighContrastURL( i_cachedImage.sImageURL ) );
148*cdf0e10cSrcweir                     i_cachedImage.xGraphic.set( i_graphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ), UNO_QUERY );
149*cdf0e10cSrcweir                 }
150*cdf0e10cSrcweir                 if ( !i_cachedImage.xGraphic.is() )
151*cdf0e10cSrcweir                 {
152*cdf0e10cSrcweir                     aMediaProperties.put( "URL", i_cachedImage.sImageURL );
153*cdf0e10cSrcweir                     i_cachedImage.xGraphic.set( i_graphicProvider->queryGraphic( aMediaProperties.getPropertyValues() ), UNO_QUERY );
154*cdf0e10cSrcweir                 }
155*cdf0e10cSrcweir             }
156*cdf0e10cSrcweir             return i_cachedImage.xGraphic.is();
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
160*cdf0e10cSrcweir         Size lcl_getGraphicSizePixel( Reference< XGraphic > const& i_graphic )
161*cdf0e10cSrcweir         {
162*cdf0e10cSrcweir             Size aSizePixel;
163*cdf0e10cSrcweir             try
164*cdf0e10cSrcweir             {
165*cdf0e10cSrcweir                 if ( i_graphic.is() )
166*cdf0e10cSrcweir                 {
167*cdf0e10cSrcweir                     const Reference< XPropertySet > xGraphicProps( i_graphic, UNO_QUERY_THROW );
168*cdf0e10cSrcweir                     OSL_VERIFY( xGraphicProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SizePixel" ) ) ) >>= aSizePixel );
169*cdf0e10cSrcweir                 }
170*cdf0e10cSrcweir             }
171*cdf0e10cSrcweir             catch( const Exception& )
172*cdf0e10cSrcweir             {
173*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
174*cdf0e10cSrcweir             }
175*cdf0e10cSrcweir             return aSizePixel;
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
179*cdf0e10cSrcweir         void lcl_init( Sequence< ::rtl::OUString > const& i_imageURLs, ::std::vector< CachedImage >& o_images )
180*cdf0e10cSrcweir         {
181*cdf0e10cSrcweir             o_images.resize(0);
182*cdf0e10cSrcweir             size_t count = size_t( i_imageURLs.getLength() );
183*cdf0e10cSrcweir             o_images.reserve( count );
184*cdf0e10cSrcweir             for ( size_t i = 0; i < count; ++i )
185*cdf0e10cSrcweir             {
186*cdf0e10cSrcweir                 o_images.push_back( CachedImage( i_imageURLs[i] ) );
187*cdf0e10cSrcweir             }
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
191*cdf0e10cSrcweir         void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data )
192*cdf0e10cSrcweir         {
193*cdf0e10cSrcweir             Throbber* pThrobber = dynamic_cast< Throbber* >( i_data.rAntiImpl.GetWindow() );
194*cdf0e10cSrcweir             if ( pThrobber == NULL )
195*cdf0e10cSrcweir                 return;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir             try
198*cdf0e10cSrcweir             {
199*cdf0e10cSrcweir                 // collect the image sizes of the different image sets
200*cdf0e10cSrcweir                 const ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
201*cdf0e10cSrcweir                 const Reference< XGraphicProvider > xGraphicProvider( aContext.createComponent( "com.sun.star.graphic.GraphicProvider" ), UNO_QUERY_THROW );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir                 const bool isHighContrast = pThrobber->GetSettings().GetStyleSettings().GetHighContrastMode();
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir                 sal_Int32 nPreferredSet = -1;
206*cdf0e10cSrcweir                 const size_t nImageSetCount = i_data.aCachedImageSets.size();
207*cdf0e10cSrcweir                 if ( nImageSetCount < 2 )
208*cdf0e10cSrcweir                 {
209*cdf0e10cSrcweir                     nPreferredSet = sal_Int32( nImageSetCount ) - 1;
210*cdf0e10cSrcweir                 }
211*cdf0e10cSrcweir                 else
212*cdf0e10cSrcweir                 {
213*cdf0e10cSrcweir                     ::std::vector< Size > aImageSizes( nImageSetCount );
214*cdf0e10cSrcweir                     for ( sal_Int32 nImageSet = 0; size_t( nImageSet ) < nImageSetCount; ++nImageSet )
215*cdf0e10cSrcweir                     {
216*cdf0e10cSrcweir                         ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nImageSet ] );
217*cdf0e10cSrcweir                         if  (   ( rImageSet.empty() )
218*cdf0e10cSrcweir                             ||  ( !lcl_ensureImage_throw( xGraphicProvider, isHighContrast, rImageSet[0] ) )
219*cdf0e10cSrcweir                             )
220*cdf0e10cSrcweir                         {
221*cdf0e10cSrcweir                             aImageSizes[ nImageSet ] = Size( ::std::numeric_limits< long >::max(), ::std::numeric_limits< long >::max() );
222*cdf0e10cSrcweir                         }
223*cdf0e10cSrcweir                         else
224*cdf0e10cSrcweir                         {
225*cdf0e10cSrcweir                             aImageSizes[ nImageSet ] = lcl_getGraphicSizePixel( rImageSet[0].xGraphic );
226*cdf0e10cSrcweir                         }
227*cdf0e10cSrcweir                     }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir                     // find the set with the smallest difference between window size and image size
230*cdf0e10cSrcweir                     const ::Size aWindowSizePixel = pThrobber->GetSizePixel();
231*cdf0e10cSrcweir                     long nMinimalDistance = ::std::numeric_limits< long >::max();
232*cdf0e10cSrcweir                     for (   ::std::vector< Size >::const_iterator check = aImageSizes.begin();
233*cdf0e10cSrcweir                             check != aImageSizes.end();
234*cdf0e10cSrcweir                             ++check
235*cdf0e10cSrcweir                         )
236*cdf0e10cSrcweir                     {
237*cdf0e10cSrcweir                         if  (   ( check->Width > aWindowSizePixel.Width() )
238*cdf0e10cSrcweir                             ||  ( check->Height > aWindowSizePixel.Height() )
239*cdf0e10cSrcweir                             )
240*cdf0e10cSrcweir                             // do not use an image set which doesn't fit into the window
241*cdf0e10cSrcweir                             continue;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir                         const sal_Int64 distance =
244*cdf0e10cSrcweir                                 ( aWindowSizePixel.Width() - check->Width ) * ( aWindowSizePixel.Width() - check->Width )
245*cdf0e10cSrcweir                             +   ( aWindowSizePixel.Height() - check->Height ) * ( aWindowSizePixel.Height() - check->Height );
246*cdf0e10cSrcweir                         if ( distance < nMinimalDistance )
247*cdf0e10cSrcweir                         {
248*cdf0e10cSrcweir                             nMinimalDistance = distance;
249*cdf0e10cSrcweir                             nPreferredSet = check - aImageSizes.begin();
250*cdf0e10cSrcweir                         }
251*cdf0e10cSrcweir                     }
252*cdf0e10cSrcweir                 }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir                 // found a set?
255*cdf0e10cSrcweir                 Sequence< Reference< XGraphic > > aImages;
256*cdf0e10cSrcweir                 if ( ( nPreferredSet >= 0 ) && ( size_t( nPreferredSet ) < nImageSetCount ) )
257*cdf0e10cSrcweir                 {
258*cdf0e10cSrcweir                     // => set the images
259*cdf0e10cSrcweir                     ::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nPreferredSet ] );
260*cdf0e10cSrcweir                     aImages.realloc( rImageSet.size() );
261*cdf0e10cSrcweir                     sal_Int32 imageIndex = 0;
262*cdf0e10cSrcweir                     for (   ::std::vector< CachedImage >::const_iterator cachedImage = rImageSet.begin();
263*cdf0e10cSrcweir                             cachedImage != rImageSet.end();
264*cdf0e10cSrcweir                             ++cachedImage, ++imageIndex
265*cdf0e10cSrcweir                         )
266*cdf0e10cSrcweir                     {
267*cdf0e10cSrcweir                         lcl_ensureImage_throw( xGraphicProvider, isHighContrast, *cachedImage );
268*cdf0e10cSrcweir                         aImages[ imageIndex ] = cachedImage->xGraphic;
269*cdf0e10cSrcweir                     }
270*cdf0e10cSrcweir                 }
271*cdf0e10cSrcweir                 pThrobber->setImageList( aImages );
272*cdf0e10cSrcweir             }
273*cdf0e10cSrcweir             catch( const Exception& )
274*cdf0e10cSrcweir             {
275*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
276*cdf0e10cSrcweir             }
277*cdf0e10cSrcweir         }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 	    //--------------------------------------------------------------------------------------------------------------
280*cdf0e10cSrcweir         void lcl_updateImageList_nothrow( AnimatedImagesPeer_Data& i_data, const Reference< XAnimatedImages >& i_images )
281*cdf0e10cSrcweir         {
282*cdf0e10cSrcweir             try
283*cdf0e10cSrcweir             {
284*cdf0e10cSrcweir                 const sal_Int32 nImageSetCount = i_images->getImageSetCount();
285*cdf0e10cSrcweir                 i_data.aCachedImageSets.resize(0);
286*cdf0e10cSrcweir                 for ( sal_Int32 set = 0;  set < nImageSetCount; ++set )
287*cdf0e10cSrcweir                 {
288*cdf0e10cSrcweir                     const Sequence< ::rtl::OUString > aImageURLs( i_images->getImageSet( set ) );
289*cdf0e10cSrcweir                     ::std::vector< CachedImage > aImages;
290*cdf0e10cSrcweir                     lcl_init( aImageURLs, aImages );
291*cdf0e10cSrcweir                     i_data.aCachedImageSets.push_back( aImages );
292*cdf0e10cSrcweir                 }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir                 lcl_updateImageList_nothrow( i_data );
295*cdf0e10cSrcweir             }
296*cdf0e10cSrcweir             catch( const Exception& )
297*cdf0e10cSrcweir             {
298*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
299*cdf0e10cSrcweir             }
300*cdf0e10cSrcweir         }
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	//==================================================================================================================
304*cdf0e10cSrcweir 	//= AnimatedImagesPeer
305*cdf0e10cSrcweir 	//==================================================================================================================
306*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
307*cdf0e10cSrcweir     AnimatedImagesPeer::AnimatedImagesPeer()
308*cdf0e10cSrcweir         :AnimatedImagesPeer_Base()
309*cdf0e10cSrcweir         ,m_pData( new AnimatedImagesPeer_Data( *this ) )
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
314*cdf0e10cSrcweir     AnimatedImagesPeer::~AnimatedImagesPeer()
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
319*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::startAnimation(  ) throw (RuntimeException)
320*cdf0e10cSrcweir     {
321*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
322*cdf0e10cSrcweir         Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) );
323*cdf0e10cSrcweir         if ( pThrobber != NULL)
324*cdf0e10cSrcweir             pThrobber->start();
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
328*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::stopAnimation(  ) throw (RuntimeException)
329*cdf0e10cSrcweir     {
330*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
331*cdf0e10cSrcweir         Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) );
332*cdf0e10cSrcweir         if ( pThrobber != NULL)
333*cdf0e10cSrcweir             pThrobber->stop();
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
337*cdf0e10cSrcweir     ::sal_Bool SAL_CALL AnimatedImagesPeer::isAnimationRunning(  ) throw (RuntimeException)
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
340*cdf0e10cSrcweir         Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) );
341*cdf0e10cSrcweir         if ( pThrobber != NULL)
342*cdf0e10cSrcweir             return pThrobber->isRunning();
343*cdf0e10cSrcweir         return sal_False;
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
347*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::setProperty( const ::rtl::OUString& i_propertyName, const Any& i_value ) throw(RuntimeException)
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir 	    ::vos::OGuard aGuard( GetMutex() );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) );
352*cdf0e10cSrcweir         if ( pThrobber == NULL )
353*cdf0e10cSrcweir         {
354*cdf0e10cSrcweir             VCLXWindow::setProperty( i_propertyName, i_value );
355*cdf0e10cSrcweir             return;
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir         const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName );
359*cdf0e10cSrcweir         switch ( nPropertyId )
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir             case BASEPROPERTY_STEP_TIME:
362*cdf0e10cSrcweir             {
363*cdf0e10cSrcweir                 sal_Int32 nStepTime( 0 );
364*cdf0e10cSrcweir                 if ( i_value >>= nStepTime )
365*cdf0e10cSrcweir                     pThrobber->setStepTime( nStepTime );
366*cdf0e10cSrcweir                 break;
367*cdf0e10cSrcweir             }
368*cdf0e10cSrcweir             case BASEPROPERTY_AUTO_REPEAT:
369*cdf0e10cSrcweir             {
370*cdf0e10cSrcweir                 sal_Bool bRepeat( sal_True );
371*cdf0e10cSrcweir                 if ( i_value >>= bRepeat )
372*cdf0e10cSrcweir                     pThrobber->setRepeat( bRepeat );
373*cdf0e10cSrcweir                 break;
374*cdf0e10cSrcweir             }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir             case BASEPROPERTY_IMAGE_SCALE_MODE:
377*cdf0e10cSrcweir             {
378*cdf0e10cSrcweir                 sal_Int16 nScaleMode( ImageScaleMode::Anisotropic );
379*cdf0e10cSrcweir                 ImageControl* pImageControl = dynamic_cast< ImageControl* >( GetWindow() );
380*cdf0e10cSrcweir                 if ( pImageControl && ( i_value >>= nScaleMode ) )
381*cdf0e10cSrcweir                 {
382*cdf0e10cSrcweir                     pImageControl->SetScaleMode( nScaleMode );
383*cdf0e10cSrcweir                 }
384*cdf0e10cSrcweir             }
385*cdf0e10cSrcweir             break;
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir             default:
388*cdf0e10cSrcweir                 AnimatedImagesPeer_Base::setProperty( i_propertyName, i_value );
389*cdf0e10cSrcweir                 break;
390*cdf0e10cSrcweir         }
391*cdf0e10cSrcweir     }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
394*cdf0e10cSrcweir     Any SAL_CALL AnimatedImagesPeer::getProperty( const ::rtl::OUString& i_propertyName ) throw(RuntimeException)
395*cdf0e10cSrcweir     {
396*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         Any aReturn;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir         Throbber* pThrobber( dynamic_cast< Throbber* >( GetWindow() ) );
401*cdf0e10cSrcweir         if ( pThrobber == NULL )
402*cdf0e10cSrcweir             return VCLXWindow::getProperty( i_propertyName );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir         const sal_uInt16 nPropertyId = GetPropertyId( i_propertyName );
405*cdf0e10cSrcweir         switch ( nPropertyId )
406*cdf0e10cSrcweir         {
407*cdf0e10cSrcweir         case BASEPROPERTY_STEP_TIME:
408*cdf0e10cSrcweir             aReturn <<= pThrobber->getStepTime();
409*cdf0e10cSrcweir             break;
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir         case BASEPROPERTY_AUTO_REPEAT:
412*cdf0e10cSrcweir             aReturn <<= pThrobber->getRepeat();
413*cdf0e10cSrcweir             break;
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir         case BASEPROPERTY_IMAGE_SCALE_MODE:
416*cdf0e10cSrcweir             {
417*cdf0e10cSrcweir                 ImageControl const* pImageControl = dynamic_cast< ImageControl* >( GetWindow() );
418*cdf0e10cSrcweir                 aReturn <<= ( pImageControl ? pImageControl->GetScaleMode() : ImageScaleMode::Anisotropic );
419*cdf0e10cSrcweir             }
420*cdf0e10cSrcweir             break;
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir         default:
423*cdf0e10cSrcweir             aReturn = AnimatedImagesPeer_Base::getProperty( i_propertyName );
424*cdf0e10cSrcweir             break;
425*cdf0e10cSrcweir         }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         return aReturn;
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
431*cdf0e10cSrcweir     void AnimatedImagesPeer::ProcessWindowEvent( const VclWindowEvent& i_windowEvent )
432*cdf0e10cSrcweir     {
433*cdf0e10cSrcweir         switch ( i_windowEvent.GetId() )
434*cdf0e10cSrcweir         {
435*cdf0e10cSrcweir         case VCLEVENT_WINDOW_RESIZE:
436*cdf0e10cSrcweir             lcl_updateImageList_nothrow( *m_pData );
437*cdf0e10cSrcweir             break;
438*cdf0e10cSrcweir         }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         AnimatedImagesPeer_Base::ProcessWindowEvent( i_windowEvent );
441*cdf0e10cSrcweir     }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
444*cdf0e10cSrcweir     void AnimatedImagesPeer::impl_updateImages_nolck( const Reference< XInterface >& i_animatedImages )
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         lcl_updateImageList_nothrow( *m_pData, Reference< XAnimatedImages >( i_animatedImages, UNO_QUERY_THROW ) );
449*cdf0e10cSrcweir     }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
452*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::elementInserted( const ContainerEvent& i_event ) throw (RuntimeException)
453*cdf0e10cSrcweir     {
454*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
455*cdf0e10cSrcweir         Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir         sal_Int32 nPosition(0);
458*cdf0e10cSrcweir         OSL_VERIFY( i_event.Accessor >>= nPosition );
459*cdf0e10cSrcweir         size_t position = size_t( nPosition );
460*cdf0e10cSrcweir         if ( position > m_pData->aCachedImageSets.size() )
461*cdf0e10cSrcweir         {
462*cdf0e10cSrcweir             OSL_ENSURE( false, "AnimatedImagesPeer::elementInserted: illegal accessor/index!" );
463*cdf0e10cSrcweir             lcl_updateImageList_nothrow( *m_pData, xAnimatedImages );
464*cdf0e10cSrcweir         }
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aImageURLs;
467*cdf0e10cSrcweir         OSL_VERIFY( i_event.Element >>= aImageURLs );
468*cdf0e10cSrcweir         ::std::vector< CachedImage > aImages;
469*cdf0e10cSrcweir         lcl_init( aImageURLs, aImages );
470*cdf0e10cSrcweir         m_pData->aCachedImageSets.insert( m_pData->aCachedImageSets.begin() + position, aImages );
471*cdf0e10cSrcweir         lcl_updateImageList_nothrow( *m_pData );
472*cdf0e10cSrcweir     }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
475*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::elementRemoved( const ContainerEvent& i_event ) throw (RuntimeException)
476*cdf0e10cSrcweir     {
477*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
478*cdf0e10cSrcweir         Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir         sal_Int32 nPosition(0);
481*cdf0e10cSrcweir         OSL_VERIFY( i_event.Accessor >>= nPosition );
482*cdf0e10cSrcweir         size_t position = size_t( nPosition );
483*cdf0e10cSrcweir         if ( position >= m_pData->aCachedImageSets.size() )
484*cdf0e10cSrcweir         {
485*cdf0e10cSrcweir             OSL_ENSURE( false, "AnimatedImagesPeer::elementRemoved: illegal accessor/index!" );
486*cdf0e10cSrcweir             lcl_updateImageList_nothrow( *m_pData, xAnimatedImages );
487*cdf0e10cSrcweir         }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir         m_pData->aCachedImageSets.erase( m_pData->aCachedImageSets.begin() + position );
490*cdf0e10cSrcweir         lcl_updateImageList_nothrow( *m_pData );
491*cdf0e10cSrcweir     }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
494*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::elementReplaced( const ContainerEvent& i_event ) throw (RuntimeException)
495*cdf0e10cSrcweir     {
496*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
497*cdf0e10cSrcweir         Reference< XAnimatedImages > xAnimatedImages( i_event.Source, UNO_QUERY_THROW );
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir         sal_Int32 nPosition(0);
500*cdf0e10cSrcweir         OSL_VERIFY( i_event.Accessor >>= nPosition );
501*cdf0e10cSrcweir         size_t position = size_t( nPosition );
502*cdf0e10cSrcweir         if ( position >= m_pData->aCachedImageSets.size() )
503*cdf0e10cSrcweir         {
504*cdf0e10cSrcweir             OSL_ENSURE( false, "AnimatedImagesPeer::elementReplaced: illegal accessor/index!" );
505*cdf0e10cSrcweir             lcl_updateImageList_nothrow( *m_pData, xAnimatedImages );
506*cdf0e10cSrcweir         }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aImageURLs;
509*cdf0e10cSrcweir         OSL_VERIFY( i_event.Element >>= aImageURLs );
510*cdf0e10cSrcweir         ::std::vector< CachedImage > aImages;
511*cdf0e10cSrcweir         lcl_init( aImageURLs, aImages );
512*cdf0e10cSrcweir         m_pData->aCachedImageSets[ position ] = aImages;
513*cdf0e10cSrcweir         lcl_updateImageList_nothrow( *m_pData );
514*cdf0e10cSrcweir     }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
517*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::disposing( const EventObject& i_event ) throw (RuntimeException)
518*cdf0e10cSrcweir     {
519*cdf0e10cSrcweir         VCLXWindow::disposing( i_event );
520*cdf0e10cSrcweir     }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
523*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::modified( const EventObject& i_event ) throw (RuntimeException)
524*cdf0e10cSrcweir     {
525*cdf0e10cSrcweir         impl_updateImages_nolck( i_event.Source );
526*cdf0e10cSrcweir     }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
529*cdf0e10cSrcweir     void SAL_CALL AnimatedImagesPeer::dispose(  ) throw(RuntimeException)
530*cdf0e10cSrcweir     {
531*cdf0e10cSrcweir         AnimatedImagesPeer_Base::dispose();
532*cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
533*cdf0e10cSrcweir         m_pData->aCachedImageSets.resize(0);
534*cdf0e10cSrcweir     }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //......................................................................................................................
537*cdf0e10cSrcweir } // namespace toolkit
538*cdf0e10cSrcweir //......................................................................................................................
539