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